* [PATCH RESEND v2] btrfs: fix use-after-free in mark_block_group_to_copy
@ 2026-08-31 5:38 Hongling Zeng
2026-09-02 9:55 ` Johannes Thumshirn
0 siblings, 1 reply; 2+ messages in thread
From: Hongling Zeng @ 2026-08-31 5:38 UTC (permalink / raw)
To: clm, dsterba, naohiro.aota, josef
Cc: linux-btrfs, linux-kernel, zhongling0719, Hongling Zeng, stable
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 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
Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
---
- Use path->need_commit_sem instead of manual commit_root_sem locking
suggested by Qu Wenruo.
- Remove the unmatched manual up_read().
- Add LLM usage disclosure
---
fs/btrfs/dev-replace.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index dc0834f920c3..0310aa3add54 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -494,6 +494,7 @@ static int mark_block_group_to_copy(struct btrfs_fs_info *fs_info,
path->reada = READA_FORWARD;
path->search_commit_root = true;
path->skip_locking = true;
+ path->need_commit_sem = true;
key.objectid = src_dev->devid;
key.type = BTRFS_DEV_EXTENT_KEY;
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH RESEND v2] btrfs: fix use-after-free in mark_block_group_to_copy
2026-08-31 5:38 [PATCH RESEND v2] btrfs: fix use-after-free in mark_block_group_to_copy Hongling Zeng
@ 2026-09-02 9:55 ` Johannes Thumshirn
0 siblings, 0 replies; 2+ messages in thread
From: Johannes Thumshirn @ 2026-09-02 9:55 UTC (permalink / raw)
To: Hongling Zeng
Cc: clm, dsterba, naohiro.aota, josef, linux-btrfs, linux-kernel,
zhongling0719, stable
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-02 9:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-31 5:38 [PATCH RESEND v2] btrfs: fix use-after-free in mark_block_group_to_copy Hongling Zeng
2026-09-02 9:55 ` Johannes Thumshirn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox