From: Damien Le Moal <dlemoal@kernel.org>
To: Yingjie Wang <x-professor@outlook.com>,
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>,
Hannes Reinecke <hare@suse.de>,
"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH v2 3/3] dm zoned: handle labels that are not NUL-terminated
Date: Fri, 4 Dec 2026 16:42:51 +0900 [thread overview]
Message-ID: <68eb8bee-1ab7-483d-a589-8dbd65ef3e64@kernel.org> (raw)
In-Reply-To: <20261203090306.1181043-1-x-professor@outlook.com>
On 12/3/26 18:03, Yingjie Wang wrote:
> If the label in the superblock uses all 32 bytes, it is not
> NUL-terminated. It is copied to zmd->label, which has the same size and
> is used as a string. With CONFIG_FORTIFY_SOURCE, the next call of
> dmz_check_sb() crashes:
>
> strlen: detected buffer overflow: 33 byte read of buffer size 32
> kernel BUG at lib/string_helpers.c:1044!
>
> If the label does not match, it is also printed directly from the
> superblock, which can read past the end of the block:
>
> BUG: KASAN: use-after-free in string
> Read of size 1
>
> dmzadm 2.0.0 to 2.1.3 create such a label by default if the name of
> the device has at least 28 characters.
>
> Add space for the terminating NUL byte to zmd->label, so that labels
> of up to 32 characters are supported, and limit the length of the
> label that is printed from the superblock.
>
> Fixes: bd5c40313a14 ("dm zoned: metadata version 2")
> Cc: stable@vger.kernel.org
> Signed-off-by: Yingjie Wang <x-professor@outlook.com>
> ---
> v2: Fix the commit message, the code is unchanged. Volumes with such a
> label from dmzadm 2.0.0 and 2.1.3 (28-character device name, single and
> two devices) now load and work; without the patch, they hit the strlen()
> BUG above with CONFIG_FORTIFY_SOURCE.
>
> drivers/md/dm-zoned-metadata.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c
> index 64e0edaa0044..04ae8e2b3627 100644
> --- a/drivers/md/dm-zoned-metadata.c
> +++ b/drivers/md/dm-zoned-metadata.c
> @@ -145,7 +145,7 @@ struct dmz_metadata {
> unsigned int nr_devs;
>
> char devname[BDEVNAME_SIZE];
> - char label[BDEVNAME_SIZE];
> + char label[BDEVNAME_SIZE + 1];
> uuid_t uuid;
>
> sector_t zone_bitmap_size;
> @@ -1026,7 +1026,7 @@ static int dmz_check_sb(struct dmz_metadata *zmd, struct dmz_sb *dsb,
> }
> if (strlen(zmd->label) &&
> memcmp(zmd->label, sb->dmz_label, BDEVNAME_SIZE)) {
> - dmz_dev_err(dev, "mismatching DM-Zoned label, is %s expected %s",
> + dmz_dev_err(dev, "mismatching DM-Zoned label, is %.32s expected %s",
The copy of the label is at most BDEVNAME_SIZE, so the +1 char is always NUL and
this change is not needed.
> sb->dmz_label, zmd->label);
> return -ENXIO;
> }
--
Damien Le Moal
Western Digital Research
prev parent reply other threads:[~2026-12-04 7:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261203090240.1180833-1-x-professor@outlook.com>
2026-12-03 9:02 ` [PATCH v2 1/3] dm zoned: do not update metadata state from an invalid superblock Yingjie Wang
2026-12-03 9:02 ` [PATCH v2 2/3] dm zoned: validate the metadata layout in the superblock Yingjie Wang
2026-12-03 9:03 ` [PATCH v2 3/3] dm zoned: handle labels that are not NUL-terminated Yingjie Wang
2026-12-04 7:42 ` Damien Le Moal [this message]
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=68eb8bee-1ab7-483d-a589-8dbd65ef3e64@kernel.org \
--to=dlemoal@kernel.org \
--cc=agk@redhat.com \
--cc=bmarzins@redhat.com \
--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 \
--cc=x-professor@outlook.com \
/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