All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: zoned: skip missing devices when releasing active zone reservations
@ 2026-11-17 23:55 Miroslav Cimerman
  2026-11-18  7:10 ` Johannes Thumshirn
  2026-11-18  7:13 ` Johannes Thumshirn
  0 siblings, 2 replies; 3+ messages in thread
From: Miroslav Cimerman @ 2026-11-17 23:55 UTC (permalink / raw)
  To: linux-btrfs
  Cc: David Sterba, Chris Mason, Naohiro Aota, Johannes Thumshirn,
	linux-kernel

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: zoned: skip missing devices when releasing active zone reservations
  2026-11-17 23:55 [PATCH] btrfs: zoned: skip missing devices when releasing active zone reservations Miroslav Cimerman
@ 2026-11-18  7:10 ` Johannes Thumshirn
  2026-11-18  7:13 ` Johannes Thumshirn
  1 sibling, 0 replies; 3+ messages in thread
From: Johannes Thumshirn @ 2026-11-18  7:10 UTC (permalink / raw)
  To: Miroslav Cimerman, linux-btrfs
  Cc: David Sterba, Chris Mason, Naohiro Aota, linux-kernel

Looks good,

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: zoned: skip missing devices when releasing active zone reservations
  2026-11-17 23:55 [PATCH] btrfs: zoned: skip missing devices when releasing active zone reservations Miroslav Cimerman
  2026-11-18  7:10 ` Johannes Thumshirn
@ 2026-11-18  7:13 ` Johannes Thumshirn
  1 sibling, 0 replies; 3+ messages in thread
From: Johannes Thumshirn @ 2026-11-18  7:13 UTC (permalink / raw)
  To: Miroslav Cimerman, linux-btrfs
  Cc: David Sterba, Chris Mason, Naohiro Aota, linux-kernel

Added to for-next,

Thanks


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-18  7:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 23:55 [PATCH] btrfs: zoned: skip missing devices when releasing active zone reservations Miroslav Cimerman
2026-11-18  7:10 ` Johannes Thumshirn
2026-11-18  7:13 ` Johannes Thumshirn

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.