Re: [PATCH 2/3] dm zoned: validate the metadata layout in the superblock

From: Damien Le Moal

Date: Wed Dec 02 2026 - 01:43:20 EST


On 12/1/26 19:56, Yingjie Wang wrote:
> dmz_check_sb() does not check all the superblock fields that describe
> the metadata layout:
>
> - nr_map_blocks is used to allocate zmd->map_mblk[], which
> dmz_load_mapping() then fills according to nr_chunks. If there are
> not enough mapping blocks for nr_chunks, it writes past the end of
> the array:
>
> BUG: KASAN: slab-out-of-bounds in dmz_ctr_metadata
> Write of size 8
>
> - nr_bitmap_blocks is not used to locate the bitmap of a zone.
> dmz_get_bitmap() assumes that there is a bitmap for every zone.
> This is not the case if the device has grown since it was formatted.
> The bitmaps of the new zones are not part of the metadata sets then,
> and the data in these zones can be lost after a set was recovered.
>
> - The mapping and bitmap blocks may exceed nr_meta_blocks, so that
> metadata accesses go past the end of the metadata set. This can
> overwrite the data of other chunks.
>
> - nr_reserved_seq is checked against the number of zones that remain
> after subtracting one metadata set, but nr_data_zones is calculated
> by subtracting both sets. The result can underflow, which defeats
> the check of nr_chunks.
>
> Add the missing checks. dmzadm creates one bitmap for every zone,
> including metadata, read-only and offline zones, so that volumes it
> formatted are not affected unless the device has grown.
>
> Fixes: 3b1a94c88b79 ("dm zoned: drive-managed zoned block device target")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Yingjie Wang <x-professor@xxxxxxxxxxx>

Looks good.

Reviewed-by: Damien Le Moal <dlemoal@xxxxxxxxxx>

--
Damien Le Moal
Western Digital Research