Skip to contentSkip to conversation

FAILED: patch "[PATCH] btrfs: take commit root semaphore when iterating in" failed to apply to 6.1-stable tree

PATCH New [email protected] 2 participants 2 messages Sep 22

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x 0594e3423f4ba3137c734371169491f9a98e9af4
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026092246-darkened-imminent-3978@gregkh' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 0594e3423f4ba3137c734371169491f9a98e9af4 Mon Sep 17 00:00:00 2001
From: Hongling Zeng <[email protected]>
Date: Mon, 31 Aug 2026 13:38:01 +0800
Subject: [PATCH] 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")
Assisted-by Codex:gpt-5.5
fs/btrfs/dev-replace.c +1 -0
index bf0b78790171..1894c7ebe9d9 100644
@@ -493,6 +493,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;
maintainer
#1 lore raw

PATCH 1/1 btrfs: take commit root semaphore when iterating in mark_block_group_to_copy()

From: Hongling Zeng <[email protected]>

[ Upstream commit 0594e3423f4ba3137c734371169491f9a98e9af4 ]

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")
Assisted-by Codex:gpt-5.5
[ changed path->need_commit_sem assignment from true to 1 to match the older unsigned bitfield representation. ]
---
 fs/btrfs/dev-replace.c | 1 +
 1 file changed, 1 insertion(+)
fs/btrfs/dev-replace.c +1 -0
index 9c856a73d5333..f9c43aadc78ad 100644
@@ -520,6 +520,7 @@ static int mark_block_group_to_copy(struct btrfs_fs_info *fs_info,
 	path->reada = READA_FORWARD;
 	path->search_commit_root = 1;
 	path->skip_locking = 1;
+	path->need_commit_sem = 1;
 
 	key.objectid = src_dev->devid;
 	key.type = BTRFS_DEV_EXTENT_KEY;
Signature · 1 line
2.53.0