From: Guanghui Yang <3497809730@qq.com>
To: linux-btrfs@vger.kernel.org
Cc: Guanghui Yang <3497809730@qq.com>,
clm@fb.com, dsterba@suse.com, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: [PATCH v2 2/3] btrfs: restore active device pointers after failed sprout
Date: Mon, 10 Aug 2026 18:59:15 +0800 [thread overview]
Message-ID: <tencent_3797A74151C2F32C84C30D1DC22F66846A05@qq.com> (raw)
In-Reply-To: <cover.1786358930.git.3497809730@qq.com>
btrfs_init_new_device() switches latest_dev and possibly s_bdev from the
seed device to the new sprout device before creating the first writable
chunks.
If chunk creation or the subsequent sprout setup fails, the error path
releases the new device without switching those pointers back.
btrfs_show_devname() can then dereference the freed latest_dev and crash.
Restore the active device pointers to the latest seed device before
removing and releasing the failed sprout device.
Fixes: b7cb29e666fe ("btrfs: update latest_dev when we create a sprout device")
Cc: stable@vger.kernel.org
Signed-off-by: Guanghui Yang <3497809730@qq.com>
---
fs/btrfs/volumes.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index ffd076e87..f3f77c89c 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2987,6 +2987,9 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
error_sysfs:
btrfs_sysfs_remove_device(device);
mutex_lock(&fs_info->fs_devices->device_list_mutex);
+ if (seeding_dev)
+ btrfs_assign_next_active_device(device,
+ seed_devices->latest_dev);
mutex_lock(&fs_info->chunk_mutex);
if (!list_empty(&device->post_commit_list))
list_del_init(&device->post_commit_list);
--
2.53.0
next prev parent reply other threads:[~2026-08-10 10:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1786358930.git.3497809730@qq.com>
2026-08-10 10:59 ` [PATCH v2 1/3] btrfs: detach failed sprout device from transaction update list Guanghui Yang
2026-08-10 10:59 ` Guanghui Yang [this message]
2026-08-10 10:59 ` [PATCH v2 3/3] btrfs: roll back sprout setup after device add failure Guanghui Yang
2026-08-10 12:16 ` [PATCH v3 0/3] btrfs: fix failed sprout device add rollback Guanghui Yang
2026-08-10 23:16 ` Qu Wenruo
2026-08-10 23:36 ` Qu Wenruo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_3797A74151C2F32C84C30D1DC22F66846A05@qq.com \
--to=3497809730@qq.com \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox