From nobody Thu Nov 12 15:08:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793229920; cv=none; d=zohomail.com; s=zohoarc; b=OKFPcTg8xrI2u7BHMhcMLEeZE9JOy836DTJTklIROq5MfzfTIrVF204MH49TfZ/XbUBbbeBxv8L9+xiVMTmVr2K5sW2huMPBXbYRygDAnZ3CQxMJUt8WKHOf6VqbNyeLSzrIBeWKfRrN47V+VYB5F4ecMreTscKvbUsPMTgqSHU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793229920; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EjBs/hEO3GPPBiAKxBtyso4NOxnnH42689CeC0JyZ/Q=; b=PiGuy0VfGoz0aMbUHAfU/jbMrF8CAmojRceHKh/bt2BBA4cPrIFZsXHfbX1npmyzZL8lGkZqXuZxhgWUHTYfvy9ReQGZ6WnvrNhHq/wjzP7MxKA3OpWRY4971fd9fWWJFJxZk+/l3xZFxXchrN37w9rim2ZPJR1T2r7peTgD+dk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793229920215558.689885623072; Wed, 28 Oct 2026 16:25:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMD0e-0001Om-Sk; Wed, 28 Oct 2026 19:24:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMD0G-0001MU-Ck for qemu-devel@nongnu.org; Wed, 28 Oct 2026 19:24:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMD0E-0003bM-FE for qemu-devel@nongnu.org; Wed, 28 Oct 2026 19:24:19 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-618-ItrBR4rAMbmafaE8Dp5ebQ-1; Wed, 28 Oct 2026 19:24:16 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 612DF18005A2; Wed, 28 Oct 2026 23:24:15 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.44.32.110]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4502F180057F; Wed, 28 Oct 2026 23:24:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793229857; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EjBs/hEO3GPPBiAKxBtyso4NOxnnH42689CeC0JyZ/Q=; b=H+DlUeUdnvwRLYdAty1RvEghN6SOyTUQ1dxulyLLvnw0aY/1wk1OLKV7wzDofqIvciMlks Pa0PQ19SX1dTkIgz+CkDGQbkS2UZk5BH3HkTx+G+XqGTvP7p5j2M/wBjazebt+hLvuOqFr rCL1I1SPDKDJTPRtyG8h+fcmx2p6C58= X-MC-Unique: ItrBR4rAMbmafaE8Dp5ebQ-1 X-Mimecast-MFC-AGG-ID: ItrBR4rAMbmafaE8Dp5ebQ_1793229855 From: Kevin Wolf 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 1/5] virtio-blk: Implement full NUL padding for GET_ID Date: Thu, 29 Oct 2026 00:23:56 +0100 Message-ID: <20261028232400.222535-2-kwolf@redhat.com> In-Reply-To: <20261028232400.222535-1-kwolf@redhat.com> References: <20261028232400.222535-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793229923021158500 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Stefan Hajnoczi --- 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 =3D s->conf.serial ? s->conf.serial : ""; - size_t size =3D MIN(strlen(serial) + 1, - MIN(iov_size(in_iov, in_num), - VIRTIO_BLK_ID_BYTES)); + size_t req_size =3D MIN(iov_size(in_iov, in_num), VIRTIO_BLK_ID_BY= TES); + size_t size =3D MIN(strlen(serial), req_size); + size_t padding =3D 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; --=20 2.56.0 From nobody Thu Nov 12 15:08:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793229920; cv=none; d=zohomail.com; s=zohoarc; b=mKQRD+e5LKo0eBb5LUbTKORvwRGkCorNtQsHfG5bTpsCuIsGzC/i2W3XrfBmlCXfmVu06PsVcdJgDtaANFH3m3tZ9k1c+Igs4EPaEQ5AtrOGGUH1+d2Egu1hdOXLdv7zlliC6wmf+Gmrif8kfFiXZ8NWuwtfqf5vbmj+0dQDtAg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793229920; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=v0/4AykAnGDmZJsej6ClZ/gqtGKLLIxuXVwRN7RCYQM=; b=LXjKViiWqhD1mCLVp+cq3EBrtL6WKOCd9tMShLQ+xL2IrOV0vVjEjoye8sjmH+Jotmb+y/aIL8hVJK8MqdDDjL+2a6hTIozFYjSAXFMZIK7heRjYLMOKVIj/uPysmKMKL0ZWzy+RrHahNcWo4WYpzWD51MZpu86yyRgjA5CkMeU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793229920062610.0760359603006; Wed, 28 Oct 2026 16:25:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMD0j-0001Qx-6O; Wed, 28 Oct 2026 19:24:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMD0I-0001Mt-UL for qemu-devel@nongnu.org; Wed, 28 Oct 2026 19:24:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMD0H-0003bq-BC for qemu-devel@nongnu.org; Wed, 28 Oct 2026 19:24:22 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-561-b5Rh2KaSPJWoNC4Vf1COag-1; Wed, 28 Oct 2026 19:24:19 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EEA7C1956057; Wed, 28 Oct 2026 23:24:17 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.44.32.110]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B176E180057F; Wed, 28 Oct 2026 23:24:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793229860; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v0/4AykAnGDmZJsej6ClZ/gqtGKLLIxuXVwRN7RCYQM=; b=HdiZF9N0XEXJ7XlrsSfquSAQnyg1XXIpQnOkyzRIZdGQlCO/eIbKbB8J0OsFNCTH7GW93f sO5FDHedOR9T+oHOx6SX80p3RnDDk/wUoC060XqKfHYj3hwf9yvG0lJbMVN2+9gINcnM9p FoIcZoot3KQeIDv2gkRzu8btw2n+0D4= X-MC-Unique: b5Rh2KaSPJWoNC4Vf1COag-1 X-Mimecast-MFC-AGG-ID: b5Rh2KaSPJWoNC4Vf1COag_1793229858 From: Kevin Wolf 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 2/5] virtio-blk-test: Add a basic GET_ID test case Date: Thu, 29 Oct 2026 00:23:57 +0100 Message-ID: <20261028232400.222535-3-kwolf@redhat.com> In-Reply-To: <20261028232400.222535-1-kwolf@redhat.com> References: <20261028232400.222535-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793229923939154100 Content-Type: text/plain; charset="utf-8" This covers the simple common case with no surprises: A serial that is shorter than 20 characters and can fit in the request buffer. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- tests/qtest/virtio-blk-test.c | 69 +++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tests/qtest/virtio-blk-test.c b/tests/qtest/virtio-blk-test.c index 98c906ebb4a..14fadcb4009 100644 --- a/tests/qtest/virtio-blk-test.c +++ b/tests/qtest/virtio-blk-test.c @@ -95,6 +95,8 @@ static uint64_t virtio_blk_request(QGuestAllocator *alloc= , QVirtioDevice *d, g_assert_cmpuint(data_size % sizeof(struct virtio_blk_discard_write_zeroes), = =3D=3D, 0); break; + case VIRTIO_BLK_T_GET_ID: + break; default: g_assert_cmpuint(data_size, =3D=3D, 0); } @@ -771,6 +773,68 @@ static void resize(void *obj, void *data, QGuestAlloca= tor *t_alloc) =20 } =20 +static QVirtQueue *get_id_setup(QVirtioDevice *dev, QGuestAllocator *t_all= oc) +{ + QVirtQueue *vq; + uint64_t features =3D qvirtio_get_features(dev); + + features =3D features & (1ull << VIRTIO_F_VERSION_1); + qvirtio_set_features(dev, features); + + vq =3D qvirtqueue_setup(dev, t_alloc, 0); + qvirtio_set_driver_ok(dev); + return vq; +} + +static uint8_t get_id_request(QVirtioDevice *dev, QVirtQueue *vq, + char *buf, size_t buf_len, + QGuestAllocator *t_alloc) +{ + QTestState *qts =3D global_qtest; + uint64_t req_addr; + uint32_t free_head; + uint8_t status; + + QVirtioBlkReq req =3D { + .type =3D VIRTIO_BLK_T_GET_ID, + .data =3D buf, + }; + + req_addr =3D virtio_blk_request(t_alloc, dev, &req, buf_len); + + memset(req.data, 0xa5, buf_len); + memwrite(req_addr + 16, req.data, buf_len); + + free_head =3D qvirtqueue_add(qts, vq, req_addr, 16, false, true); + qvirtqueue_add(qts, vq, req_addr + 16, buf_len, true, true); + qvirtqueue_add(qts, vq, req_addr + 16 + buf_len, 1, true, false); + + qvirtqueue_kick(qts, dev, vq, free_head); + + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, + QVIRTIO_BLK_TIMEOUT_US); + status =3D readb(req_addr + 16 + buf_len); + memread(req_addr + 16, buf, buf_len); + return status; +} + +static void get_id_serial_short(void *obj, void *data, QGuestAllocator *t_= alloc) +{ + QVirtioBlk *blk_if =3D obj; + QVirtioDevice *dev =3D blk_if->vdev; + QVirtQueue *vq; + uint8_t status; + const char expected[20] =3D "abc"; + char buf[20]; + + vq =3D get_id_setup(dev, t_alloc); + status =3D get_id_request(dev, vq, buf, 20, t_alloc); + g_assert_cmpint(status, =3D=3D, 0); + g_assert_cmpmem(buf, 20, expected, sizeof(expected)); + + qvirtqueue_cleanup(blk_if->vdev->bus, vq, t_alloc); +} + static void *virtio_blk_test_setup(GString *cmd_line, void *arg) { char *tmp_path =3D drive_create(); @@ -802,6 +866,11 @@ static void register_virtio_blk_test(void) qos_add_test("nxvirtq", "virtio-blk-pci", test_nonexistent_virtqueue, &opts); qos_add_test("hotplug", "virtio-blk-pci", pci_hotplug, &opts); + + /* serial number tests */ + opts.edge.extra_device_opts =3D "serial=3Dabc"; + qos_add_test("get_id/serial_short", "virtio-blk", + get_id_serial_short, &opts); } =20 libqos_init(register_virtio_blk_test); --=20 2.56.0 From nobody Thu Nov 12 15:08:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793229936; cv=none; d=zohomail.com; s=zohoarc; b=c2GzQecHdlJT4PSpZdEKvFTxF+vA6rgHAXkLdGIGbjvlxc+TmLPilg4hVg1h+oukA2GWvZ99GkjV4SjlRbQvW1zji+PBc4DpYA1G9EHNJ0wyRGI2K/Zvf0M0SsKth1WjjFl/TQnGtwwS0rak8TRJC+P9SY1gcutHMrwh9ra5cbg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793229936; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=chTClr+HVR2nSoTB2ocAzzp3GwHw1rMAeQAWZm1j0Lg=; b=H12aA+tHayucsqk6aC1y0UCrfFAJwNSJdeGfIvFNxTmqjE5s/rFXiDXcOf4dHkHbxCnPZC+YCZQtev1UssawE0HDKY8GCQUWJjDEAqBDU7dQLDc5Ogco6Tsd2cj9oNDlZ5nmDO4unpeeQfeYEiKx29Vkee86DMuHxsJKaMEnfRY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793229936975906.6264656653275; Wed, 28 Oct 2026 16:25:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMD0k-0001Qy-Qz; Wed, 28 Oct 2026 19:24:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMD0O-0001NV-1S for qemu-devel@nongnu.org; Wed, 28 Oct 2026 19:24:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMD0L-0003cU-Gz for qemu-devel@nongnu.org; Wed, 28 Oct 2026 19:24:27 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-118-MgGqgWlsNTCiS0RCq-ilEw-1; Wed, 28 Oct 2026 19:24:21 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 67983180034C; Wed, 28 Oct 2026 23:24:20 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.44.32.110]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 609B9180057F; Wed, 28 Oct 2026 23:24:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793229864; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=chTClr+HVR2nSoTB2ocAzzp3GwHw1rMAeQAWZm1j0Lg=; b=inezKUW8y2secjVvCQ6GSBs9wV+U56xqLRo/vK6PlCV8OqSqE3+SPUszZ6NVVx+Ejm7fDt 0wurFIrY8MS+y7155LnbThVDVG2D0qkUfMNHdQmrqx++pF0D9xqzIJWAFs6tT7SeeZtyma ivnz72h7FgmQghZ3yXLQq7WlSrFkZ0M= X-MC-Unique: MgGqgWlsNTCiS0RCq-ilEw-1 X-Mimecast-MFC-AGG-ID: MgGqgWlsNTCiS0RCq-ilEw_1793229860 From: Kevin Wolf 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 3/5] virtio-blk: Deprecate silent truncation of serial Date: Thu, 29 Oct 2026 00:23:58 +0100 Message-ID: <20261028232400.222535-4-kwolf@redhat.com> In-Reply-To: <20261028232400.222535-1-kwolf@redhat.com> References: <20261028232400.222535-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793229940117154100 Content-Type: text/plain; charset="utf-8" Commit a8686a9b, which made serial a qdev property instead of relying on -drive options, accidentally allowed specifying serial strings of arbitraty length while the virtio-blk protocol can only communicate 20 characters to the guest. This means that a longer serial number on the command line is silently truncated to 20 characters from the guest perspective. This is obviously bad behaviour. People are specifying longer serials in practice and guests will see something different than what was configured. Instead of silent truncation, this should be an error. Deprecate the silent truncation for now as a first step towards making it an error later. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- docs/about/deprecated.rst | 13 +++++++++++++ hw/block/virtio-blk.c | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index dab47b6ca38..0891bbc44de 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -362,6 +362,19 @@ the addition of volatile memory support, it is now nec= essary to distinguish between persistent and volatile memory backends. As such, memdev is depre= cated in favor of persistent-memdev. =20 +``-device virtio-blk,serial=3Dmore_than_20_characters`` (since 11.2) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The ``virtio-blk`` device has a limitation of 20 characters for the serial +string. Accidentally, QEMU started accepting longer strings on the command= line +in version 0.15.0, but it was still silently truncated to 20 characters for +guests. + +Specifying a longer serial than can be exposed to the guest is a configura= tion +error and deprecated; it will become a hard error in later versions. If the +truncation is intentional, explicitly specify the serial already in trunca= ted +form on the command line instead. + Block device options '''''''''''''''''''' =20 diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 3f236f22d57..eeeb405127c 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1849,6 +1849,12 @@ static void virtio_blk_device_realize(DeviceState *d= ev, Error **errp) return; } =20 + if (conf->serial && strlen(conf->serial) > VIRTIO_BLK_ID_BYTES) { + warn_report("serial is longer than %d characters and will be trunc= ated " + "for the guest. This configuration is deprecated.", + VIRTIO_BLK_ID_BYTES); + } + if (!blkconf_apply_backend_options(&conf->conf, !blk_supports_write_perm(conf->conf= .blk), true, errp)) { --=20 2.56.0 From nobody Thu Nov 12 15:08:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793229949; cv=none; d=zohomail.com; s=zohoarc; b=JM4C2t2hB/WtMiCLE/ixvO83RaObDtxVTMBD7L48Blzb0GsBsSZ0PQzPn331ivQhwJqv5WwBM7/HXvm26VDN7CJa+e6+uAx6WoUsmFnq2PEVALGR59hChB9pq4yQ1+Aaf21k/g0rOMb/iAPMxRcdknQ0pb/eYCosH21i5DBa8XA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793229949; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=S7wcCyMnE0ybIqXxztZ2I401lo+Dxwjs4srTlRXQncw=; b=nNahBYGqFCp98+2040rqhbokaAB1lBvHyZ9N/sM8dOMBpfBcJfw01/xiyWbva2qWW2m1TImWtl+zWoS+GS6qhiYFbmWz6bF0N+yzOzy0LVPA9Q28r2NnYTVWXEtNipiTncENBhtWkhrQKT/xiLZuZpY1qqwPDuh2JLXP7h/NjFc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793229949464173.42013109480718; Wed, 28 Oct 2026 16:25:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMD1A-0001Wq-If; Wed, 28 Oct 2026 19:25:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMD0W-0001Oo-To for qemu-devel@nongnu.org; Wed, 28 Oct 2026 19:24:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMD0R-0003dL-RZ for qemu-devel@nongnu.org; Wed, 28 Oct 2026 19:24:34 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-349-_A76uZUBM0uYUymabMa8BQ-1; Wed, 28 Oct 2026 19:24:24 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D5D951955F61; Wed, 28 Oct 2026 23:24:22 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.44.32.110]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CDF9B180057F; Wed, 28 Oct 2026 23:24:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793229871; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S7wcCyMnE0ybIqXxztZ2I401lo+Dxwjs4srTlRXQncw=; b=UReBqFkF2gg/C2Vok6K5Z4e8/phTKZlPIot5AbnjALryXzHshraw1MWN6s4yOrZW/Jn42O 4E+o1f8h6ewtm5iIzNqG9eLcgCqNnYRXGylTDCC7AobkGe9kzYUgrHzrWdJC9YFPjpC1LP zrVp82qJyvf9QDZyS1nETujm09OaB1c= X-MC-Unique: _A76uZUBM0uYUymabMa8BQ-1 X-Mimecast-MFC-AGG-ID: _A76uZUBM0uYUymabMa8BQ_1793229862 From: Kevin Wolf 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 4/5] virtio-blk: Represent truncated serial in qdev property Date: Thu, 29 Oct 2026 00:23:59 +0100 Message-ID: <20261028232400.222535-5-kwolf@redhat.com> In-Reply-To: <20261028232400.222535-1-kwolf@redhat.com> References: <20261028232400.222535-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793229950566158500 Content-Type: text/plain; charset="utf-8" If the guest can only see the first 20 characters of the serial, we shouldn't pretend to have a longer string in the 'serial' qdev property (which is visible through things like QOM or 'info qtree'). Truncate the serial already in the internal state of the device to make sure we don't mix both versions anywhere. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- hw/block/virtio-blk.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index eeeb405127c..cecd08a2f2e 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1850,9 +1850,15 @@ static void virtio_blk_device_realize(DeviceState *d= ev, Error **errp) } =20 if (conf->serial && strlen(conf->serial) > VIRTIO_BLK_ID_BYTES) { + char *truncated; + warn_report("serial is longer than %d characters and will be trunc= ated " "for the guest. This configuration is deprecated.", VIRTIO_BLK_ID_BYTES); + + truncated =3D g_strndup(conf->serial, VIRTIO_BLK_ID_BYTES); + g_free(conf->serial); + conf->serial =3D truncated; } =20 if (!blkconf_apply_backend_options(&conf->conf, --=20 2.56.0 From nobody Thu Nov 12 15:08:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793229926; cv=none; d=zohomail.com; s=zohoarc; b=GFIH50UQ7Bv02RbqG2UMfDDvA5Hqc5VbdQ7S9y9LMCi1MfPO+X5DcuXRBBd4u9LB44Afnu/xmSW7oaLDhRWpmM8HJJ/ppBubTE/a2+ABL/+iKhCivFHrRm653yyCLkjtyxa/sn9NjgqAhdUz/gxa7HOgOb2Q7FReu5NrRnSutY8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793229926; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ma2YrZhxOGAk3pcTKwyKhbOn2VE8E6MJUvg9VjIQPH0=; b=UFT3KgQNEhTvbILIgtmkX3idCyVjPFc/YqkdICYb/ZHjzcUCWgjKXPoHO4u27KBJf/Z48i3RLxyFv5kOPtBbbicXTK+gBIazZma9mbv/ro8L9j7T5hzKhjWvnnBmF2/k9CfoLphowWq4gdvCHF9lPdDBIU4bD0SPntuldA3EPNE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179322992602637.5975325999143; Wed, 28 Oct 2026 16:25:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xMD0n-0001RA-OG; Wed, 28 Oct 2026 19:24:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMD0R-0001O8-A0 for qemu-devel@nongnu.org; Wed, 28 Oct 2026 19:24:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xMD0O-0003cv-If for qemu-devel@nongnu.org; Wed, 28 Oct 2026 19:24:29 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-623-PYrtckJYNKK37mxar3ZT9w-1; Wed, 28 Oct 2026 19:24:26 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 44F92195422B; Wed, 28 Oct 2026 23:24:25 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.44.32.110]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 483E518004D2; Wed, 28 Oct 2026 23:24:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793229867; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ma2YrZhxOGAk3pcTKwyKhbOn2VE8E6MJUvg9VjIQPH0=; b=WsoCYIrXXx4+TuHIYq35zjPybLv6fqA+ThA5zcJvOXONIkotspzBwsEizLsoGq3Dis5lt+ xrURialIoCFk+ZG9iUhd8l3kTs8UH36K4TlqX2Af0EIcAfIEPK5nJskCf2vLWgGDIAZus3 87TIHUTMEX73Qw1ciwkIhCbNXWC7GBc= X-MC-Unique: PYrtckJYNKK37mxar3ZT9w-1 X-Mimecast-MFC-AGG-ID: PYrtckJYNKK37mxar3ZT9w_1793229865 From: Kevin Wolf 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 5/5] virtio-blk-test: Test truncated serial Date: Thu, 29 Oct 2026 00:24:00 +0100 Message-ID: <20261028232400.222535-6-kwolf@redhat.com> In-Reply-To: <20261028232400.222535-1-kwolf@redhat.com> References: <20261028232400.222535-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1793229927856154100 Content-Type: text/plain; charset="utf-8" Only 20 bytes are written to the passed buffer and the returned string doesn't have a NUL terminator. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- tests/qtest/virtio-blk-test.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/qtest/virtio-blk-test.c b/tests/qtest/virtio-blk-test.c index 14fadcb4009..99d785d9e1a 100644 --- a/tests/qtest/virtio-blk-test.c +++ b/tests/qtest/virtio-blk-test.c @@ -835,6 +835,25 @@ static void get_id_serial_short(void *obj, void *data,= QGuestAllocator *t_alloc) qvirtqueue_cleanup(blk_if->vdev->bus, vq, t_alloc); } =20 +static void get_id_serial_short_trunc(void *obj, void *data, + QGuestAllocator *t_alloc) +{ + QVirtioBlk *blk_if =3D obj; + QVirtioDevice *dev =3D blk_if->vdev; + QVirtQueue *vq; + uint8_t status; + /* Everything after the 20 character maximum is untouched, no '\0' */ + const char expected[25] =3D "01234567890123456789\xa5\xa5\xa5\xa5\xa5"; + char buf[25]; + + vq =3D get_id_setup(dev, t_alloc); + status =3D get_id_request(dev, vq, buf, 25, t_alloc); + g_assert_cmpint(status, =3D=3D, 0); + g_assert_cmpmem(buf, 25, expected, sizeof(expected)); + + qvirtqueue_cleanup(blk_if->vdev->bus, vq, t_alloc); +} + static void *virtio_blk_test_setup(GString *cmd_line, void *arg) { char *tmp_path =3D drive_create(); @@ -871,6 +890,10 @@ static void register_virtio_blk_test(void) opts.edge.extra_device_opts =3D "serial=3Dabc"; qos_add_test("get_id/serial_short", "virtio-blk", get_id_serial_short, &opts); + + opts.edge.extra_device_opts =3D "serial=3D0123456789012345678901234567= 89"; + qos_add_test("get_id/serial_short_trunc", "virtio-blk", + get_id_serial_short_trunc, &opts); } =20 libqos_init(register_virtio_blk_test); --=20 2.56.0