mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] dm zoned: fix NULL pointer dereference in dmz_load_sb()
@ 2026-11-20 18:50 Vasiliy Kovalev
  0 siblings, 0 replies; only message in thread
From: Vasiliy Kovalev @ 2026-11-20 18:50 UTC (permalink / raw)
  To: Alasdair Kergon, Mike Snitzer, Mikulas Patocka,
	Benjamin Marzinski, dm-devel
  Cc: linux-kernel, lvc-project, kovalev

When the primary super block is not valid, dmz_load_sb() searches for
the secondary one with dmz_lookup_secondary_sb(). If the search fails,
zmd->sb[1].dev is NULL, and the error is then reported with
dmz_dev_err(zmd->sb[1].dev, ...), which dereferences the device to
print its bdev:

device-mapper: zoned metadata: (ram0): Invalid meta magic (needed 0x445a4244, got 0x00000000)
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] SMP KASAN NOPTI
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
CPU: 2 UID: 0 PID: 1412 Comm: syz.1.17 Not tainted 7.4.0-rc1-next-20261104-alt-syz-box-drivers_md_bcache #1 PREEMPT(lazy)
RIP: 0010:dmz_load_sb drivers/md/dm-zoned-metadata.c:1259 [inline]
RIP: 0010:dmz_ctr_metadata+0x2389/0x4a20 drivers/md/dm-zoned-metadata.c:2897
Call Trace:
 <TASK>
 dmz_ctr+0xb53/0x1df0 drivers/md/dm-zoned-target.c:873
 dm_table_add_target+0x7c2/0xf30 drivers/md/dm-table.c:749
 populate_table drivers/md/dm-ioctl.c:1602 [inline]
 table_load+0x38b/0x910 drivers/md/dm-ioctl.c:1645
 ctl_ioctl+0x4d2/0xd70 drivers/md/dm-ioctl.c:2221
 dm_ctl_ioctl+0x1e/0x30 drivers/md/dm-ioctl.c:2243
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:597 [inline]
 __se_sys_ioctl fs/ioctl.c:583 [inline]
 __x64_sys_ioctl+0x18a/0x210 fs/ioctl.c:583
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x112/0x630 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x00007f443b88a829
 </TASK>

Loading a "zoned" table on top of devices that carry no dm-zoned
metadata is enough to trigger it.

The secondary super block always resides on the same device as the
primary one, so report the failure against zmd->sb[0].dev, which is
always set at this point.

Found by Linux Verification Center (linuxtesting.org) with Syzkaller.

Fixes: 977ff73e6415 ("dm-zoned: remove the ->name field in struct dmz_dev")
Cc: stable@vger.kernel.org
Signed-off-by: Vasiliy Kovalev <kovalev@altlinux.org>
---
 drivers/md/dm-zoned-metadata.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c
index 094b63215882..f7aa04954d2f 100644
--- a/drivers/md/dm-zoned-metadata.c
+++ b/drivers/md/dm-zoned-metadata.c
@@ -1256,7 +1256,7 @@ static int dmz_load_sb(struct dmz_metadata *zmd)
 		ret = dmz_lookup_secondary_sb(zmd);
 
 	if (ret) {
-		dmz_dev_err(zmd->sb[1].dev, "Read secondary super block failed");
+		dmz_dev_err(zmd->sb[0].dev, "Read secondary super block failed");
 		return ret;
 	}
 
-- 
2.50.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-20 18:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 18:50 [PATCH] dm zoned: fix NULL pointer dereference in dmz_load_sb() Vasiliy Kovalev

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®