Merge tag 'block-pull-request' of https://gitlab.com/stefanha/qemu into staging

Pull request

virtio-blk serial truncation deprecation by Kevin Wolf and a qed block driver
fix for CVE-2026-118594.

# -----BEGIN PGP SIGNATURE-----
#
# iQEzBAABCgAdFiEEhpWov9P5fNqsNXdanKSrs4Grc8gFAmrk8S8ACgkQnKSrs4Gr
# c8iOVgf/T1KrkxCdQlFn8ELWcBS742OdgBHrRjL+kVufTZ5fdF+CVHXvliYFLVLh
# L8pziGQqJpztnDLe7JKArISW5CNbAFpYOujt8WdL13l300kxFKOpoBj2NFjT0WGa
# QxRsHT7jZyCDyWdrhNfUVFeHGDsFfzo6NSYIP8LDgS3XyYREWSiLCbpeRZD9E7l2
# 7f2HngvNPbSI55h4Nq++adkzjFCaFjeVt3AEO5Zo80erLZz7GVPIyfSg2TjcdYWB
# kZGpouhsKNSHeP/aYoccEaKB3QTJ0Op4rEYY5G+k0uszotXrNtpTFB3mqJUy/D6D
# Zf73t1Zv6zZoiBK+r0VN7j6djixmqQ==
# =pkm0
# -----END PGP SIGNATURE-----
# gpg: Signature made Fri 30 Oct 2026 02:34:07 PM CDT
# gpg:                using RSA key 8695A8BFD3F97CDAAC35775A9CA4ABB381AB73C8
# gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>" [unknown]
# gpg:                 aka "Stefan Hajnoczi <stefanha@gmail.com>" [unknown]
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: 8695 A8BF D3F9 7CDA AC35  775A 9CA4 ABB3 81AB 73C8

* tag 'block-pull-request' of https://gitlab.com/stefanha/qemu:
  virtio-blk-test: Test truncated serial
  virtio-blk: Deprecate silent truncation of serial
  virtio-blk-test: Add a basic GET_ID test case
  virtio-blk: Implement full NUL padding for GET_ID
  qed: fix incorrect denominator in qed_bytes_to_clusters() (CVE-2026-118594)

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson committed 2026-10-30 15:26:36 -05:00
commit 4075aa42da
4 files changed
+147 -5

No files matched your search

+1 -1
View File
@@ -253,7 +253,7 @@ static inline uint64_t qed_offset_into_cluster(BDRVQEDState *s, uint64_t offset)
static inline uint64_t qed_bytes_to_clusters(BDRVQEDState *s, uint64_t bytes)
{
return qed_start_of_cluster(s, bytes + (s->header.cluster_size - 1)) /
(s->header.cluster_size - 1);
s->header.cluster_size;
}
static inline unsigned int qed_l1_index(BDRVQEDState *s, uint64_t pos)
+13
View File
@@ -362,6 +362,19 @@ the addition of volatile memory support, it is now necessary to distinguish
between persistent and volatile memory backends. As such, memdev is deprecated
in favor of persistent-memdev.
``-device virtio-blk,serial=more_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 configuration
error and deprecated; it will become a hard error in later versions. If the
truncation is intentional, explicitly specify the serial already in truncated
form on the command line instead.
Block device options
''''''''''''''''''''
+14 -4
View File
@@ -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;
@@ -1845,6 +1849,12 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
return;
}
if (conf->serial && strlen(conf->serial) > VIRTIO_BLK_ID_BYTES) {
warn_report("serial is longer than %d characters and will be truncated "
"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)) {
+119
View File
@@ -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), ==, 0);
break;
case VIRTIO_BLK_T_GET_ID:
break;
default:
g_assert_cmpuint(data_size, ==, 0);
}
@@ -771,6 +773,110 @@ static void resize(void *obj, void *data, QGuestAllocator *t_alloc)
}
static QVirtQueue *get_id_setup(QVirtioDevice *dev, QGuestAllocator *t_alloc)
{
QVirtQueue *vq;
uint64_t features = qvirtio_get_features(dev);
features = features & (1ull << VIRTIO_F_VERSION_1);
qvirtio_set_features(dev, features);
vq = 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,
char pattern_byte,
QGuestAllocator *t_alloc)
{
QTestState *qts = global_qtest;
uint64_t req_addr;
uint32_t free_head;
uint8_t status;
QVirtioBlkReq req = {
.type = VIRTIO_BLK_T_GET_ID,
.data = buf,
};
req_addr = virtio_blk_request(t_alloc, dev, &req, buf_len);
memset(req.data, pattern_byte, buf_len);
memwrite(req_addr + 16, req.data, buf_len);
free_head = 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 = readb(req_addr + 16 + buf_len);
memread(req_addr + 16, buf, buf_len);
guest_free(t_alloc, req_addr);
return status;
}
static void get_id_serial_short(void *obj, void *data, QGuestAllocator *t_alloc)
{
QVirtioBlk *blk_if = obj;
QVirtioDevice *dev = blk_if->vdev;
QVirtQueue *vq;
uint8_t status;
const char expected[20] = "abc";
char buf[20];
vq = get_id_setup(dev, t_alloc);
status = get_id_request(dev, vq, buf, 20, 0xa5, t_alloc);
g_assert_cmpint(status, ==, 0);
g_assert_cmpmem(buf, 20, expected, sizeof(expected));
qvirtqueue_cleanup(blk_if->vdev->bus, vq, t_alloc);
}
static void get_id_serial_short_20_characters(void *obj, void *data,
QGuestAllocator *t_alloc)
{
QVirtioBlk *blk_if = obj;
QVirtioDevice *dev = blk_if->vdev;
QVirtQueue *vq;
uint8_t status;
/* Edge case of a serial with exactly 20 characters: No NUL termination */
const char expected[25] = "01234567890123456789\xa5\xa5\xa5\xa5\xa5";
char buf[25];
vq = get_id_setup(dev, t_alloc);
status = get_id_request(dev, vq, buf, 25, 0xa5, t_alloc);
g_assert_cmpint(status, ==, 0);
g_assert_cmpmem(buf, 25, expected, sizeof(expected));
qvirtqueue_cleanup(blk_if->vdev->bus, vq, t_alloc);
}
static void get_id_serial_short_trunc(void *obj, void *data,
QGuestAllocator *t_alloc)
{
QVirtioBlk *blk_if = obj;
QVirtioDevice *dev = blk_if->vdev;
QVirtQueue *vq;
uint8_t status;
/* Everything after the 20 character maximum is untouched, no '\0' */
const char expected[25] = "01234567890123456789\xa5\xa5\xa5\xa5\xa5";
char buf[25];
vq = get_id_setup(dev, t_alloc);
status = get_id_request(dev, vq, buf, 25, 0xa5, t_alloc);
g_assert_cmpint(status, ==, 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 = drive_create();
@@ -802,6 +908,19 @@ 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 = "serial=abc";
qos_add_test("get_id/serial_short", "virtio-blk",
get_id_serial_short, &opts);
opts.edge.extra_device_opts = "serial=01234567890123456789";
qos_add_test("get_id/serial_short_20_characters", "virtio-blk",
get_id_serial_short_20_characters, &opts);
opts.edge.extra_device_opts = "serial=012345678901234567890123456789";
qos_add_test("get_id/serial_short_trunc", "virtio-blk",
get_id_serial_short_trunc, &opts);
}
libqos_init(register_virtio_blk_test);