* [PATCH hci-8.1] vhost-blk: pass full 20-byte serial to the guest
@ 2026-11-18 15:08 Andrey Zhadchenko
2026-11-18 15:23 ` Andrey Drobyshev
0 siblings, 1 reply; 2+ messages in thread
From: Andrey Zhadchenko @ 2026-11-18 15:08 UTC (permalink / raw)
To: andrey.drobyshev; +Cc: svt-core, den
vhost_blk_start() copies the serial with strncpy(..., VIRTIO_BLK_ID_BYTES - 1),
so a 20-character serial is truncated to 19 bytes before it is handed to
the kernel via VHOST_BLK_SET_SERIAL. The kernel already replies to
VIRTIO_BLK_T_GET_ID with min(strnlen + 1, 20) bytes, i.e. the same
convention as virtio-blk: NUL-terminated only when shorter than the
buffer.
Copy the whole serial zero-padded with strpadcpy() so the guest sees the
same ID as with virtio-blk. Print conf.serial in the error message, as the
buffer is no longer guaranteed to be NUL-terminated.
Found by hci-kubetest, which compares all 20 bytes of the serial.
https://virtuozzo.atlassian.net/browse/VSTOR-155058
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
hw/block/vhost-blk.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
index 4cebc91d33e..d8bbfcaff86 100644
--- a/hw/block/vhost-blk.c
+++ b/hw/block/vhost-blk.c
@@ -63,9 +63,10 @@ static int vhost_blk_start(VirtIODevice *vdev)
}
if (s->conf.serial) {
- strncpy(serial, s->conf.serial, VIRTIO_BLK_ID_BYTES - 1);
+ strpadcpy(serial, sizeof(serial), s->conf.serial, '\0');
if (ioctl(s->vhostfd, VHOST_BLK_SET_SERIAL, serial)) {
- error_report("vhost-blk: unable to set drive serial %s", serial);
+ error_report("vhost-blk: unable to set drive serial %s",
+ s->conf.serial);
return -EINVAL;
}
}
--
2.43.5
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH hci-8.1] vhost-blk: pass full 20-byte serial to the guest
2026-11-18 15:08 [PATCH hci-8.1] vhost-blk: pass full 20-byte serial to the guest Andrey Zhadchenko
@ 2026-11-18 15:23 ` Andrey Drobyshev
0 siblings, 0 replies; 2+ messages in thread
From: Andrey Drobyshev @ 2026-11-18 15:23 UTC (permalink / raw)
To: Andrey Zhadchenko; +Cc: svt-core, den
LGTM, Ack
Applied on hci-8.1, added:
Fixes: 0ff3cb5ff28f ("block: add vhost-blk backend")
On 11/18/26 5:08 PM, Andrey Zhadchenko wrote:
> vhost_blk_start() copies the serial with strncpy(..., VIRTIO_BLK_ID_BYTES - 1),
> so a 20-character serial is truncated to 19 bytes before it is handed to
> the kernel via VHOST_BLK_SET_SERIAL. The kernel already replies to
> VIRTIO_BLK_T_GET_ID with min(strnlen + 1, 20) bytes, i.e. the same
> convention as virtio-blk: NUL-terminated only when shorter than the
> buffer.
>
> Copy the whole serial zero-padded with strpadcpy() so the guest sees the
> same ID as with virtio-blk. Print conf.serial in the error message, as the
> buffer is no longer guaranteed to be NUL-terminated.
>
> Found by hci-kubetest, which compares all 20 bytes of the serial.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-155058
> Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
> ---
> hw/block/vhost-blk.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
> index 4cebc91d33e..d8bbfcaff86 100644
> --- a/hw/block/vhost-blk.c
> +++ b/hw/block/vhost-blk.c
> @@ -63,9 +63,10 @@ static int vhost_blk_start(VirtIODevice *vdev)
> }
>
> if (s->conf.serial) {
> - strncpy(serial, s->conf.serial, VIRTIO_BLK_ID_BYTES - 1);
> + strpadcpy(serial, sizeof(serial), s->conf.serial, '\0');
> if (ioctl(s->vhostfd, VHOST_BLK_SET_SERIAL, serial)) {
> - error_report("vhost-blk: unable to set drive serial %s", serial);
> + error_report("vhost-blk: unable to set drive serial %s",
> + s->conf.serial);
> return -EINVAL;
> }
> }
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-18 15:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 15:08 [PATCH hci-8.1] vhost-blk: pass full 20-byte serial to the guest Andrey Zhadchenko
2026-11-18 15:23 ` Andrey Drobyshev
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.