]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
btrfs: hold block group reference during entire move_existing_remap()
authorMark Harmstone <mark@harmstone.com>
Thu, 19 Feb 2026 17:03:53 +0000 (17:03 +0000)
committerDavid Sterba <dsterba@suse.com>
Tue, 17 Mar 2026 10:43:08 +0000 (11:43 +0100)
commit057495ccc0ad381015b45d3edf995c2b6b982474
treeaf9348355aa9bc944b2ccd82ee1b379d92275f39
parent5118130e722b1261a2e92b2fb0b067463c39ecc7
btrfs: hold block group reference during entire move_existing_remap()

There is a potential use-after-free in move_existing_remap(): we're calling
btrfs_put_block_group() on dest_bg, then passing it to
btrfs_add_block_group_free_space() a few lines later.

Fix this by getting the BG at the start of the function and putting it
near the end. This also means we're not doing a lookup twice for the
same thing.

Reported-by: Chris Mason <clm@fb.com>
Link: https://lore.kernel.org/linux-btrfs/20260125123908.2096548-1-clm@meta.com/
Fixes: bbea42dfb91f ("btrfs: move existing remaps before relocating block group")
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Mark Harmstone <mark@harmstone.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/relocation.c