[PATCH 3/3] dm zoned: handle labels that are not NUL-terminated
From: Yingjie Wang
Date: Tue Dec 01 2026 - 05:56:37 EST
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
Add space for the terminating NUL byte to zmd->label, and limit the
length of the label that is printed. dmzadm does not create such
labels.
Fixes: bd5c40313a14 ("dm zoned: metadata version 2")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Yingjie Wang <x-professor@xxxxxxxxxxx>
---
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",
sb->dmz_label, zmd->label);
return -ENXIO;
}
--
2.43.0