• Qu Wenruo's avatar
    btrfs: handle missing chunk mapping more gracefully · 1c3ab6df
    Qu Wenruo authored
    [BUG]
    During my scrub rework, I did a stupid thing like this:
    
            bio->bi_iter.bi_sector = stripe->logical;
            btrfs_submit_bio(fs_info, bio, stripe->mirror_num);
    
    Above bi_sector assignment is using logical address directly, which
    lacks ">> SECTOR_SHIFT".
    
    This results a read on a range which has no chunk mapping.
    
    This results the following crash:
    
      BTRFS critical (device dm-1): unable to find logical 11274289152 length 65536
      assertion failed: !IS_ERR(em), in fs/btrfs/volumes.c:6387
    
    Sure this is all my fault, but this shows a possible problem in real
    world, that some bit flip in file extents/tree block can point to
    unmapped ranges, and trigger above ASSERT(), or if CONFIG_BTRFS_ASSERT
    is not configured, cause invalid pointer access.
    
    [PROBLEMS]
    In the above call chain, we just don't handle the possible error from
    btrfs_get_chunk_map() inside __btrfs_map_block().
    
    [FIX]
    The fix is straightforward, replace the ASSERT() with proper error
    handling (callers handle errors already).
    Reviewed-by: default avatarAnand Jain <anand.jain@oracle.com>
    Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    1c3ab6df
volumes.c 218 KB