• Qu Wenruo's avatar
    btrfs: exit gracefully if reloc roots don't match · 05d7ce50
    Qu Wenruo authored
    [BUG]
    Syzbot reported a crash that an ASSERT() got triggered inside
    prepare_to_merge().
    
    [CAUSE]
    The root cause of the triggered ASSERT() is we can have a race between
    quota tree creation and relocation.
    
    This leads us to create a duplicated quota tree in the
    btrfs_read_fs_root() path, and since it's treated as fs tree, it would
    have ROOT_SHAREABLE flag, causing us to create a reloc tree for it.
    
    The bug itself is fixed by a dedicated patch for it, but this already
    taught us the ASSERT() is not something straightforward for
    developers.
    
    [ENHANCEMENT]
    Instead of using an ASSERT(), let's handle it gracefully and output
    extra info about the mismatch reloc roots to help debug.
    
    Also with the above ASSERT() removed, we can trigger ASSERT(0)s inside
    merge_reloc_roots() later.
    Also replace those ASSERT(0)s with WARN_ON()s.
    
    CC: stable@vger.kernel.org # 5.15+
    Reported-by: syzbot+ae97a827ae1c3336bbb4@syzkaller.appspotmail.com
    Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
    Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    05d7ce50
relocation.c 115 KB