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>, Dan Carpenter <error27@gmail.com>,
Yingjie Wang <x-professor@outlook.com>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: [PATCH 2/3] dm zoned: check the metadata zones before recovering a metadata set
Date: Mon, 30 Nov 2026 16:17:08 +0000 [thread overview]
Message-ID: <20261130161707.3536733-1-x-professor@outlook.com> (raw)
In-Reply-To: <20261130161425.3535695-1-x-professor@outlook.com>
dmz_ctr_metadata() verifies that the zones of both metadata sets exist
and are random or cache zones, but only after dmz_load_sb() has
returned. By then, dmz_recover_mblocks() may already have written to
these zones.
The position of the secondary superblock is not checked against the
number of metadata zones it describes either. If
dmz_lookup_secondary_sb() finds it in the first zone searched and it
describes two metadata zones per set, for example, recovering the
primary set overwrites the secondary superblock that it is recovering
from, and the table is loaded.
Move the zone checks to dmz_check_sb(), and also check there that the
zones are on the device that holds the metadata and that the secondary
superblock is where it is expected to be. Volumes formatted with dmzadm
are not affected, because it places the secondary set right after the
primary one and requires both to fit on that device.
This is needed before fixing dmz_lookup_secondary_sb(). Otherwise, more
superblocks would be found and used for recovery without these checks.
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 | 35 +++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c
index 1168537bb70d..91cc8d28e524 100644
--- a/drivers/md/dm-zoned-metadata.c
+++ b/drivers/md/dm-zoned-metadata.c
@@ -974,7 +974,7 @@ static int dmz_check_sb(struct dmz_metadata *zmd, struct dmz_sb *dsb,
{
struct dmz_super *sb = dsb->sb;
struct dmz_dev *dev = dsb->dev;
- unsigned int nr_meta_zones, nr_data_zones;
+ unsigned int nr_meta_zones, nr_data_zones, i;
u32 crc, stored_crc;
u64 gen, sb_block;
@@ -1059,6 +1059,27 @@ static int dmz_check_sb(struct dmz_metadata *zmd, struct dmz_sb *dsb,
return -ENXIO;
}
+ /* The secondary set immediately follows the primary set */
+ if (dsb == &zmd->sb[1] &&
+ dsb->zone->id != zmd->sb[0].zone->id + nr_meta_zones) {
+ dmz_dev_err(dev, "Invalid secondary superblock zone %u",
+ dsb->zone->id);
+ return -ENXIO;
+ }
+
+ for (i = 0; i < nr_meta_zones << 1; i++) {
+ struct dm_zone *zone = dmz_get(zmd, zmd->sb[0].zone->id + i);
+
+ if (!zone || zone->dev != dev) {
+ dmz_dev_err(dev, "metadata zone %u not present", i);
+ return -ENXIO;
+ }
+ if (!dmz_is_rnd(zone) && !dmz_is_cache(zone)) {
+ dmz_dev_err(dev, "metadata zone %u is not random", i);
+ return -ENXIO;
+ }
+ }
+
if (!le32_to_cpu(sb->nr_reserved_seq) ||
le32_to_cpu(sb->nr_reserved_seq) >= (zmd->nr_useable_zones - nr_meta_zones)) {
dmz_dev_err(dev, "Invalid number of reserved sequential zones");
@@ -2900,18 +2921,6 @@ int dmz_ctr_metadata(struct dmz_dev *dev, int num_dev,
/* Set metadata zones starting from sb_zone */
for (i = 0; i < zmd->nr_meta_zones << 1; i++) {
zone = dmz_get(zmd, zmd->sb[0].zone->id + i);
- if (!zone) {
- dmz_zmd_err(zmd,
- "metadata zone %u not present", i);
- ret = -ENXIO;
- goto err;
- }
- if (!dmz_is_rnd(zone) && !dmz_is_cache(zone)) {
- dmz_zmd_err(zmd,
- "metadata zone %d is not random", i);
- ret = -ENXIO;
- goto err;
- }
set_bit(DMZ_META, &zone->flags);
}
/* Load mapping table */
next prev parent reply other threads:[~2026-11-30 16:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 16:14 [PATCH 0/3] dm zoned: fix metadata recovery and a tertiary superblock crash Yingjie Wang
2026-11-30 16:17 ` [PATCH 1/3] dm zoned: fix invalid free when reading a tertiary superblock fails Yingjie Wang
2026-11-30 16:17 ` Yingjie Wang [this message]
2026-11-30 16:17 ` [PATCH 3/3] dm zoned: fix the search for the secondary superblock 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=20261130161707.3536733-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=error27@gmail.com \
--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®