btrfs-progs: check: verify name in dir_item for original mode
authorSu Yue <suy.fnst@cn.fujitsu.com>
Fri, 14 Jul 2017 07:47:44 +0000 (15:47 +0800)
committerDavid Sterba <dsterba@suse.com>
Thu, 24 Aug 2017 17:07:46 +0000 (19:07 +0200)
In original mode, we don't check if the name in dir_item matches the
hash in key.offset.

In the following case, original mode will report nothing wrong while
lowmem mode will detect the name and hash mismatch.

------
item 72 key (79177 DIR_ITEM 54846528) itemoff 12380 itemsize 88
        location key (4222342 INODE_ITEM 0) type FILE
        transid 170929 data_len 0 name_len 14
        name: deprecated.sxt
        location key (13590433 INODE_ITEM 0) type FILE
        transid 796448 data_len 0 name_len 14
        name: deprecated.txt
------
In above case, hash of "deprecated.txt" matches with 54846528,
while hash of "deprecated.sxt" should be 2008317993.

Reported-by: Filippe LeMarchand <gasinvein@gmail.com>
Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
cmds-check.c

index c5faa2b..48e9a07 100644 (file)
@@ -1528,6 +1528,14 @@ static int process_dir_item(struct extent_buffer *eb,
 
                read_extent_buffer(eb, namebuf, (unsigned long)(di + 1), len);
 
+               if (key->type == BTRFS_DIR_ITEM_KEY &&
+                   key->offset != btrfs_name_hash(namebuf, len)) {
+                       rec->errors |= I_ERR_ODD_DIR_ITEM;
+                       error("DIR_ITEM[%llu %llu] name %s namelen %u filetype %u mismatch with its hash, wanted %llu have %llu",
+                       key->objectid, key->offset, namebuf, len, filetype,
+                       key->offset, btrfs_name_hash(namebuf, len));
+               }
+
                if (location.type == BTRFS_INODE_ITEM_KEY) {
                        add_inode_backref(inode_cache, location.objectid,
                                          key->objectid, key->offset, namebuf,