dm zoned: fix NULL pointer dereference in dmz_load_sb()
PATCH 1/1 dm zoned: fix NULL pointer dereference in dmz_load_sb()
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.
--- drivers/md/dm-zoned-metadata.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-zoned-metadata.c +1 -1
@@ -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; }
Signature · 1 line
2.50.1