Re: [PATCH 3/3] dm zoned: handle labels that are not NUL-terminated
From: Yingjie Wang
Date: Tue Dec 01 2026 - 07:15:13 EST
Hi Damien,
On 12/1/26 20:06, Damien Le Moal wrote:
>> - char label[BDEVNAME_SIZE];
>> + char label[BDEVNAME_SIZE + 1];
>
> This alone does not guarantee that the label is NUL terminated either. Who says
> that this was written with dmzadm or that a chnage in dmzadm introduces a bug?
> So the strlen() call below can still crash.
zmd is kzalloc'ed and only 32 bytes are copied into the label, so the
last byte stays 0 and strlen() is fine.
But you're right about dmzadm, what I wrote in the commit message is
wrong. For the default label, 2.0.0 to 2.1.3 do
sprintf(dev->label, "dmz-%s", dev->bdev[0].name);
so if the device name has 28 or more characters, there is no NUL in the
32 bytes on disk, and loading the volume hits this crash. (If dmzadm is
built with _FORTIFY_SOURCE, it aborts instead.)
> So in addition to this change, we should check that the label has a terminating
> NUL character and reject the device as broken otherwise.
Agreed. That also rejects the volumes above, but they should be rare
and dmzadm 2.2.0 or later can relabel them. I'll add the check in v2,
fix the commit message and drop the extra byte, which isn't needed then.
Thanks,
Yingjie