• Qu Wenruo's avatar
    btrfs: tree-checker: Verify location key for DIR_ITEM/DIR_INDEX · 147a097c
    Qu Wenruo authored
    [PROBLEM]
    There is a user report in the mail list, showing the following corrupted
    tree blocks:
    
           item 62 key (486836 DIR_ITEM 2543451757) itemoff 6273 itemsize 74
                   location key (4065004 INODE_ITEM 1073741824) type FILE
                   transid 21397 data_len 0 name_len 44
                   name: FILENAME
    
    Note that location key, its offset should be 0 for all INODE_ITEMS.
    This caused failed lookup of the inode.
    
    [CAUSE]
    That offending value, 1073741824, is 0x40000000. So this looks like a
    memory bit flip.
    
    [FIX]
    This patch will enhance tree-checker to check location key of
    DIR_INDEX/DIR_ITEM/XATTR_ITEM.
    
    There are several different combinations needs to check:
    
    - item_key.type == DIR_INDEX/DIR_ITEM
    
      * location_key.type == BTRFS_INODE_ITEM_KEY
        This location_key should follow the check in inode_item check.
      * location_key.type == BTRFS_ROOT_ITEM_KEY
        Despite the existing check, DIR_INDEX/DIR_ITEM can only points to
        subvolume trees.
      * All other keys are not allowed.
    
    - item_key.type == XATTR_ITEM
      location_key should be all 0.
    Reported-by: default avatarMike Gilbert <floppymaster@gmail.com>
    Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
    Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    147a097c
tree-checker.c 51.1 KB