From: Thomas Fourier <fourier.thomas@gmail.com>
Cc: Thomas Fourier <fourier.thomas@gmail.com>,
David Sterba <dsterba@suse.com>, Chris Mason <mason@kernel.org>,
Johannes Thumshirn <johannes.thumshirn@wdc.com>,
linux-btrfs@vger.kernel.org (open list:BTRFS FILE SYSTEM),
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] btrfs: zoned: fix double free of bitmaps on clone failure
Date: Wed, 28 Oct 2026 10:50:51 +0100 [thread overview]
Message-ID: <20261028095053.20459-2-fourier.thomas@gmail.com> (raw)
btrfs_clone_dev_zone_info() duplicates the original orig_dev->zone_info
with kmemdup(), which also copies the seq_zones, empty_zones and
active_zones pointers. The clone then replaces them one by one with
fresh bitmaps. If one of the allocations fails, the error path frees all
three pointers, including those not yet replaced, which still point to
the bitmaps owned by the original device.
Clear the three pointers right after kmemdup() so the error path only frees
what this function allocated.
Fixes: 21e61ec6d0bb ("btrfs: zoned: clone zoned device info when cloning a device")
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
---
fs/btrfs/zoned.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 08a15465a087..7dab7aac7b96 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -645,6 +645,11 @@ struct btrfs_zoned_device_info *btrfs_clone_dev_zone_info(struct btrfs_device *o
if (!zone_info)
return NULL;
+ /* Don't let the error path free the bitmaps still owned by @orig_dev. */
+ zone_info->seq_zones = NULL;
+ zone_info->empty_zones = NULL;
+ zone_info->active_zones = NULL;
+
zone_info->seq_zones = bitmap_zalloc(zone_info->nr_zones, GFP_KERNEL);
if (!zone_info->seq_zones)
goto out;
--
2.53.0
next reply other threads:[~2026-10-28 9:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 9:50 Thomas Fourier [this message]
2026-10-28 10:42 ` Johannes Thumshirn
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=20261028095053.20459-2-fourier.thomas@gmail.com \
--to=fourier.thomas@gmail.com \
--cc=dsterba@suse.com \
--cc=johannes.thumshirn@wdc.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mason@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
all inboxes | Powered by JetHome®