From: Yingjie Wang <x-professor@outlook.com>
To: Alasdair Kergon <agk@redhat.com>,
Mike Snitzer <snitzer@kernel.org>,
Mikulas Patocka <mpatocka@redhat.com>,
Benjamin Marzinski <bmarzins@redhat.com>
Cc: "dm-devel@lists.linux.dev" <dm-devel@lists.linux.dev>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Damien Le Moal <dlemoal@kernel.org>,
Hannes Reinecke <hare@suse.de>,
Yingjie Wang <x-professor@outlook.com>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: [PATCH 2/3] dm zoned: validate the metadata layout in the superblock
Date: Tue, 1 Dec 2026 10:56:19 +0000 [thread overview]
Message-ID: <20261201105617.117226-1-x-professor@outlook.com> (raw)
In-Reply-To: <20261201105558.117053-1-x-professor@outlook.com>
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@vger.kernel.org
Signed-off-by: Yingjie Wang <x-professor@outlook.com>
---
drivers/md/dm-zoned-metadata.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c
index a6b8372010d8..64e0edaa0044 100644
--- a/drivers/md/dm-zoned-metadata.c
+++ b/drivers/md/dm-zoned-metadata.c
@@ -1079,7 +1079,8 @@ static int dmz_check_sb(struct dmz_metadata *zmd, struct dmz_sb *dsb,
}
if (!le32_to_cpu(sb->nr_reserved_seq) ||
- le32_to_cpu(sb->nr_reserved_seq) >= (zmd->nr_useable_zones - nr_meta_zones)) {
+ nr_meta_zones * 2ULL + le32_to_cpu(sb->nr_reserved_seq) >=
+ zmd->nr_useable_zones) {
dmz_dev_err(dev, "Invalid number of reserved sequential zones");
return -ENXIO;
}
@@ -1092,6 +1093,25 @@ static int dmz_check_sb(struct dmz_metadata *zmd, struct dmz_sb *dsb,
return -ENXIO;
}
+ if (le32_to_cpu(sb->nr_map_blocks) <
+ DIV_ROUND_UP(le32_to_cpu(sb->nr_chunks), DMZ_MAP_ENTRIES)) {
+ dmz_dev_err(dev, "Invalid number of mapping blocks");
+ return -ENXIO;
+ }
+
+ if (le32_to_cpu(sb->nr_bitmap_blocks) <
+ (u64)zmd->nr_zones * zmd->zone_nr_bitmap_blocks) {
+ dmz_dev_err(dev, "Invalid number of bitmap blocks");
+ return -ENXIO;
+ }
+
+ if (1ULL + le32_to_cpu(sb->nr_map_blocks) +
+ le32_to_cpu(sb->nr_bitmap_blocks) >
+ le32_to_cpu(sb->nr_meta_blocks)) {
+ dmz_dev_err(dev, "Invalid number of metadata blocks");
+ return -ENXIO;
+ }
+
/* OK */
zmd->nr_meta_blocks = le32_to_cpu(sb->nr_meta_blocks);
zmd->nr_reserved_seq = le32_to_cpu(sb->nr_reserved_seq);
--
2.43.0
next prev parent reply other threads:[~2026-12-01 10:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 10:56 [PATCH 0/3] dm zoned: fix the validation of the superblocks Yingjie Wang
2026-12-01 10:56 ` [PATCH 1/3] dm zoned: do not update metadata state from an invalid superblock Yingjie Wang
2026-12-01 10:56 ` Yingjie Wang [this message]
2026-12-01 10:56 ` [PATCH 3/3] dm zoned: handle labels that are not NUL-terminated Yingjie Wang
2026-12-01 11:06 ` Damien Le Moal
2026-12-01 12:15 ` Yingjie Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201105617.117226-1-x-professor@outlook.com \
--to=x-professor@outlook.com \
--cc=agk@redhat.com \
--cc=bmarzins@redhat.com \
--cc=dlemoal@kernel.org \
--cc=dm-devel@lists.linux.dev \
--cc=hare@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=snitzer@kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®