[PATCH 1/3] dm zoned: fix invalid free when reading a tertiary superblock fails

From: Yingjie Wang

Date: Mon Nov 30 2026 - 11:17:09 EST


dmz_get_sb() does not leave a block to free when it fails. If the read
fails, it frees the block and sets sb->mblk to NULL. If the allocation
fails, it does not touch sb->mblk, which is either NULL or, after the
first iteration of the loop, points to the block that was freed by the
previous one.

dmz_load_sb() nevertheless calls dmz_free_mblock() in this case. A
read error on the first block of a zoned device therefore results in a
NULL pointer dereference:

(zoned1): Read tertiary super block failed
KASAN: null-ptr-deref in range [0x0000000000000040-0x0000000000000047]

An allocation failure can result in a double free, as reported by
Smatch.

Remove the bogus dmz_free_mblock() call.

Fixes: 5d2c74f3ddc0 ("dm zoned: allocate temporary superblock for tertiary devices")
Reported-by: Dan Carpenter <error27@xxxxxxxxx>
Closes: https://lore.kernel.org/dm-devel/ahrruAVoUpDmh6Cf@stanley.mountain/
Suggested-by: Dan Carpenter <error27@xxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Yingjie Wang <x-professor@xxxxxxxxxxx>
---
drivers/md/dm-zoned-metadata.c | 1 -
1 file changed, 1 deletion(-)

diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c
index f7aa04954d2f..1168537bb70d 100644
--- a/drivers/md/dm-zoned-metadata.c
+++ b/drivers/md/dm-zoned-metadata.c
@@ -1327,7 +1327,6 @@ static int dmz_load_sb(struct dmz_metadata *zmd)
if (ret) {
dmz_dev_err(sb->dev,
"Read tertiary super block failed");
- dmz_free_mblock(zmd, sb->mblk);
goto out_kfree;
}
ret = dmz_check_sb(zmd, sb, true);