Re: [PATCH 1/3] dm zoned: fix invalid free when reading a tertiary superblock fails
From: Damien Le Moal
Date: Wed Dec 02 2026 - 00:55:27 EST
On 12/1/26 01:17, Yingjie Wang wrote:
> 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>
Reviewed-by: Damien Le Moal <dlemoal@xxxxxxxxxx>
--
Damien Le Moal
Western Digital Research