From: Miroslav Cimerman <mc@raidlab.org>
To: linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.com>, Chris Mason <mason@kernel.org>,
Naohiro Aota <naohiro.aota@wdc.com>,
Johannes Thumshirn <johannes.thumshirn@wdc.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH] btrfs: zoned: skip missing devices when releasing active zone reservations
Date: Tue, 17 Nov 2026 23:55:57 +0000 [thread overview]
Message-ID: <20261117235557.187781-1-mc@raidlab.org> (raw)
On a degraded mount of a zoned filesystem with a missing device, mount
can crash in btrfs_check_active_zone_reservation():
KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
RIP: 0010:btrfs_check_active_zone_reservation+0x369/0x5b0
Call Trace:
open_ctree+0x377d/0x4140
btrfs_get_tree.cold+0xb/0x1de
vfs_get_tree+0x80/0x2d0
The first loop of the function skips devices without a block device,
but the second one, which releases the reservation for the stripes of
the active metadata and system block groups, uses the zone_info of
every stripe's device. A missing device has no zone_info, so a RAID1
metadata block group with a stripe on it crashes the mount.
Skip stripes on devices without a block device, as the first loop does.
The same was fixed for zone activation and zone finishing in
commit 2bbc4a45e5eb ("btrfs: zoned: fix zone activation with missing
devices") and commit 35fec1089ebb ("btrfs: zoned: fix zone finishing
with missing devices").
Reproducer: two zoned null_blk devices, mkfs.btrfs -d raid1 -m raid1
-O raid-stripe-tree, write and sync a file, unmount, remove the second
device, mount the first with -o degraded.
Fixes: a7e1ac7bdc5a ("btrfs: zoned: reserve zones for an active metadata/system block group")
CC: stable@vger.kernel.org # 6.7+
Signed-off-by: Miroslav Cimerman <mc@raidlab.org>
---
Found with FuzzyRAID, a fault-injection tester for RAID that is not
public at the moment. The analysis, the fix, the tests and the commit
message were prepared with the help of an LLM. I reviewed everything.
This applies on top of 0c595e53b0c6 ("btrfs: zoned: don't release
active zone reservations for conventional zones") in for-next. Stable
trees without it need the same check in the old one line loop.
Tested on btrfs for-next (6f4bbde7e036) in QEMU with KASAN and zoned
null_blk: without the patch, 2 of 2 degraded mounts crash as above.
With it, both mount and the file reads back. A normal mount with both
devices present works with and without the patch.
fs/btrfs/zoned.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index b1be02eeba68..e6ce6f05ad75 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -3160,9 +3160,14 @@ void btrfs_check_active_zone_reservation(struct btrfs_fs_info *fs_info)
continue;
for (int i = 0; i < map->num_stripes; i++) {
- struct btrfs_zoned_device_info *zinfo = map->stripes[i].dev->zone_info;
+ struct btrfs_device *device = map->stripes[i].dev;
+ struct btrfs_zoned_device_info *zinfo = device->zone_info;
u64 physical = map->stripes[i].physical;
+ /* A missing device has no zone_info. */
+ if (!device->bdev)
+ continue;
+
if (!test_bit(physical >> zinfo->zone_size_shift, zinfo->active_zones))
continue;
--
2.53.0
next reply other threads:[~2026-11-17 23:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 23:55 Miroslav Cimerman [this message]
2026-11-18 7:10 ` [PATCH] btrfs: zoned: skip missing devices when releasing active zone reservations Johannes Thumshirn
2026-11-18 7:13 ` 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=20261117235557.187781-1-mc@raidlab.org \
--to=mc@raidlab.org \
--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 \
--cc=naohiro.aota@wdc.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.