]> git.hungrycats.org Git - linux/commit
btrfs: take commit root semaphore when iterating in mark_block_group_to_copy()
authorHongling Zeng <zenghongling@kylinos.cn>
Mon, 31 Aug 2026 05:38:01 +0000 (13:38 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 14 Sep 2026 11:23:37 +0000 (13:23 +0200)
commit2839600893b79eb3efcf4929c6ee062ed6f08d6e
tree0214a2d5166c39b19dc4df7fd9ebc4e87bce5c57
parent353953d3d6094be0d015001c814d57f551756081
btrfs: take commit root semaphore when iterating in mark_block_group_to_copy()

mark_block_group_to_copy() iterates over the commit root with
skip_locking=true. A concurrent transaction commit can swap and free
the commit root during iteration, causing use-after-free when
accessing extent buffers.

Fix it by using path->need_commit_sem to protect the commit root search.

Fixes: 78ce9fc269af ("btrfs: zoned: mark block groups to copy for device-replace")
CC: stable@vger.kernel.org
Assisted-by: Codex:gpt-5.5
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/dev-replace.c