From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, hreitz@redhat.com, stefanha@redhat.com,
mst@redhat.com, devel@lists.libvirt.org, qemu-devel@nongnu.org
Subject: [PATCH v2 1/4] virtio-blk: Implement full NUL padding for GET_ID
Date: Fri, 30 Oct 2026 00:09:58 +0100 [thread overview]
Message-ID: <20261029231001.194240-2-kwolf@redhat.com> (raw)
In-Reply-To: <20261029231001.194240-1-kwolf@redhat.com>
The spec requires not only NUL termination of the device ID string, but
NUL padding:
VIRTIO_BLK_T_GET_ID requests fetch the device ID string from the
device into data. The device ID string is a NUL-padded ASCII string
up to 20 bytes long. If the string is 20 bytes long then there is no
NUL terminator.
Zero out all of the remaining bytes in the request buffer.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
hw/block/virtio-blk.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 536d71a91ad..3f236f22d57 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -1011,14 +1011,18 @@ static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb)
case VIRTIO_BLK_T_GET_ID:
{
/*
- * NB: per existing s/n string convention the string is
+ * The spec requires NUL-padding for the output. The string is
* terminated by '\0' only when shorter than buffer.
*/
const char *serial = s->conf.serial ? s->conf.serial : "";
- size_t size = MIN(strlen(serial) + 1,
- MIN(iov_size(in_iov, in_num),
- VIRTIO_BLK_ID_BYTES));
+ size_t req_size = MIN(iov_size(in_iov, in_num), VIRTIO_BLK_ID_BYTES);
+ size_t size = MIN(strlen(serial), req_size);
+ size_t padding = req_size - size;
+
iov_from_buf(in_iov, in_num, 0, serial, size);
+ if (padding) {
+ iov_memset(in_iov, in_num, size, 0, padding);
+ }
virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
g_free(req);
break;
--
2.56.0
next prev parent reply other threads:[~2026-10-29 23:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 23:09 [PATCH v2 0/4] virtio-blk: Deprecate silent truncation of serial Kevin Wolf
2026-10-29 23:09 ` Kevin Wolf [this message]
2026-10-29 23:09 ` [PATCH v2 2/4] virtio-blk-test: Add a basic GET_ID test case Kevin Wolf
2026-10-30 19:30 ` Stefan Hajnoczi
2026-10-29 23:10 ` [PATCH v2 3/4] virtio-blk: Deprecate silent truncation of serial Kevin Wolf
2026-10-29 23:10 ` [PATCH v2 4/4] virtio-blk-test: Test truncated serial Kevin Wolf
2026-10-30 19:30 ` Stefan Hajnoczi
2026-10-30 19:31 ` [PATCH v2 0/4] virtio-blk: Deprecate silent truncation of serial Stefan Hajnoczi
2026-11-09 13:21 ` Christian Borntraeger
2026-11-13 13:31 ` Kevin Wolf
2026-11-13 16:39 ` Christian Borntraeger
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=20261029231001.194240-2-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=devel@lists.libvirt.org \
--cc=hreitz@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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 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.