From: "Michael S. Tsirkin" <mst@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: QEMU Developers <qemu-devel@nongnu.org>,
Peter Maydell <peter.maydell@linaro.org>,
Alexandr Moshkov <dtalexundeer@yandex-team.ru>,
Fabiano Rosas <farosas@suse.de>
Subject: Re: [PULL 17/30] vmstate: fix type confusion in vmstate_size() for VMSTATE_VBUFFER_UINT64
Date: Mon, 27 Jul 2026 04:53:15 -0400 [thread overview]
Message-ID: <20260727045220-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <CADLectmKQT+hU_3TG2Popan8f5QphEEpwsR+Ps=+WTZo-Z_M_Q@mail.gmail.com>
On Sun, Jul 26, 2026 at 08:31:57PM -0400, Peter Xu wrote:
> This patch is migration only change and hasn't been reviewed. Give us a few
> days to review it?
> Can't do it now because it is on cellphone and I just bathed my son.
>
> Please hold off merging.
>
> Thanks.
OK. I'll drop this and you will merge it through the migration tree
as appropriate?
> On Sun, Jul 26, 2026, 5:29 p.m. Michael S. Tsirkin <mst@redhat.com> wrote:
>
> vhost user currently saves the inflight buffer to the migration stream
> using VMSTATE_VBUFFER_UINT64. The size is controlled by the vhost-user
> backend.
>
> But the implementation of that is broken if size is >2G: it stores the
> buffer size in a uint64_t field, but vmstate_size() always reads the
> size field as int32_t regardless of the macro used. This, in turn,
> causes negative or truncated lengths on load, leading to undersized
> allocations and down the road out-of-bounds buffer access.
>
> There's no practical reason to support such large sizes, so it's enough
> to validate: read the field as uint64_t when VMS_VBUFFER_UINT64 is set,
> reject negative or oversized values, and propagate errors to
> vmstate_load_vmsd().
>
> Note: the large value is coming from the backend, not guest, so this
> shouldn't be considered a security issue. The CVE was assigned before
> the qemu security policy was updated to exclude this class of bugs.
>
> Fixes: CVE-2026-6426
> Fixes: f6fdd8b2bd ("vmstate: introduce VMSTATE_VBUFFER_UINT64")
> Cc: Alexandr Moshkov <dtalexundeer@yandex-team.ru>
> Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3675
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> Message-ID: <
> 801b1501ee10241f7ac49a10570d548352b36347.1784890517.git.mst@redhat.com>
> ---
> include/migration/vmstate.h | 5 ++++-
> migration/vmstate.c | 31 ++++++++++++++++++++++++++++---
> 2 files changed, 32 insertions(+), 4 deletions(-)
>
> diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
> index 1b7f295417..e7095cd977 100644
> --- a/include/migration/vmstate.h
> +++ b/include/migration/vmstate.h
> @@ -168,6 +168,9 @@ enum VMStateFlags {
> */
> VMS_ARRAY_OF_POINTER_AUTO_ALLOC = 0x10000,
>
> + /* Use a uint64_t size field for VMS_VBUFFER instead of int32_t. */
> + VMS_VBUFFER_UINT64 = 0x40000,
> +
> /* Marker for end of list */
> VMS_END = 0x20000,
> };
> @@ -788,7 +791,7 @@ extern const VMStateInfo vmstate_info_g_byte_array;
> .field_exists = (_test), \
> .size_offset = vmstate_offset_value(_state, _field_size, uint64_t),\
> .info = &vmstate_info_buffer, \
> - .flags = VMS_VBUFFER | VMS_POINTER, \
> + .flags = VMS_VBUFFER | VMS_VBUFFER_UINT64 | VMS_POINTER, \
> .offset = offsetof(_state, _field), \
> }
>
> diff --git a/migration/vmstate.c b/migration/vmstate.c
> index 50ebe37845..d7f03a9f5b 100644
> --- a/migration/vmstate.c
> +++ b/migration/vmstate.c
> @@ -103,10 +103,24 @@ static int vmstate_size(void *opaque, const
> VMStateField *field)
> int size;
>
> if (field->flags & VMS_VBUFFER) {
> - size = *(int32_t *)(opaque + field->size_offset);
> - if (field->flags & VMS_MULTIPLY) {
> - size *= field->size;
> + uint64_t usize64;
> +
> + if (field->flags & VMS_VBUFFER_UINT64) {
> + usize64 = *(uint64_t *)(opaque + field->size_offset);
> + } else {
> + int32_t ssize32 = *(int32_t *)(opaque + field->size_offset);
> + if (ssize32 < 0) {
> + return -1;
> + }
> + usize64 = ssize32;
> }
> + if (field->flags & VMS_MULTIPLY) {
> + usize64 *= field->size;
> + }
> + if (usize64 > INT_MAX) {
> + return -1;
> + }
> + size = usize64;
> } else if (field->flags & VMS_ARRAY_OF_POINTER) {
> /*
> * For an array of pointer, the each element is always size of a
> @@ -337,6 +351,11 @@ bool vmstate_load_vmsd(QEMUFile *f, const
> VMStateDescription *vmsd,
> void *first_elem = opaque + field->offset;
> int i, n_elems = vmstate_n_elems(opaque, field);
> int size = vmstate_size(opaque, field);
> + if (size < 0) {
> + error_setg(errp, "VMState field '%s': invalid size",
> + field->name);
> + return false;
> + }
>
> vmstate_handle_alloc(first_elem, field, opaque);
> if (field->flags & VMS_POINTER) {
> @@ -661,6 +680,12 @@ static bool vmstate_save_vmsd_v(QEMUFile *f, const
> VMStateDescription *vmsd,
> bool use_dynamic_array =
> field->flags & VMS_ARRAY_OF_POINTER_AUTO_ALLOC;
>
> + if (size < 0) {
> + error_setg(errp, "VMState field '%s': invalid size",
> + field->name);
> + ok = false;
> + goto out;
> + }
> trace_vmstate_save_state_loop(vmsd->name, field->name,
> n_elems);
> if (field->flags & VMS_POINTER) {
> first_elem = *(void **)first_elem;
> --
> MST
>
>
next prev parent reply other threads:[~2026-07-27 8:53 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-26 21:28 [PULL 00/30] pci, vhost, virtio, iommu: bugfixes Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 01/30] virtio: use masked features with set_features_ex Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 02/30] virtio-net: fix OOB read in RSC receive path Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 03/30] virtio-net: fix short frame OOB read in receive_filter() Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 04/30] libvhost-user: protect against OOB writes in vu_set_inflight_fd Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 05/30] libvhost-user: protect against OOB vring queue access Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 06/30] hw/virtio: reject zero-length packed indirect descriptor table Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 07/30] vhost: do not crash on ring map failure Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 08/30] virtio-scsi: fix SCSIRequest leak on a bad request Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 09/30] virtio-mmio: fix QUEUE_NUM_MAX Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 10/30] virtio: fix queue size validation against allocated maximum Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 11/30] virtio: stop migrating num_default, validate vring.num on load Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 12/30] virtio: fail early on bad config_len in migration Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 13/30] vhost-user: assert nregions within limit Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 14/30] virtio-pmem: wait for flush requests on unrealize Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 15/30] libvhost-user: validate last_batch_head in vu_check_queue_inflights Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 16/30] libvhost-user: fix heap overflow " Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 17/30] vmstate: fix type confusion in vmstate_size() for VMSTATE_VBUFFER_UINT64 Michael S. Tsirkin
2026-07-27 0:31 ` Peter Xu
2026-07-27 8:53 ` Michael S. Tsirkin [this message]
2026-07-27 12:49 ` Peter Xu
2026-07-27 13:17 ` Michael S. Tsirkin
2026-07-27 14:12 ` Peter Xu
2026-07-27 19:06 ` Michael S. Tsirkin
2026-07-27 20:29 ` Peter Xu
2026-07-27 20:49 ` Michael S. Tsirkin
2026-07-27 22:19 ` Fabiano Rosas
2026-07-27 22:36 ` Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 18/30] libvduse: validate vq size Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 19/30] virtio-iommu: fix OOM due to unbounded call_rcu Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 20/30] virtio-snd: check rx buffer descriptor size Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 21/30] virtio-snd: check for overflow before g_malloc0 Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 22/30] hw/pci-host/q35.c: Always initialize smram-region even if SMM disabled Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 23/30] hw/pci-host/q35.c: Factor out creation of SMRAM MRs Michael S. Tsirkin
2026-07-26 21:29 ` [PULL 24/30] hw/pci-host/q35.c: Avoid early return in mch_write_config() Michael S. Tsirkin
2026-07-26 21:30 ` [PULL 25/30] hw/virtio/vdpa-dev: pass set_config buffer to vhost backend Michael S. Tsirkin
2026-07-26 21:30 ` [PULL 26/30] hw/cxl: fix OOB access in cxl_doe_cdat_rsp via entry_handle Michael S. Tsirkin
2026-07-26 21:30 ` [PULL 27/30] intel_iommu: Check address mask before using it in pasid-based iotlb invalidation Michael S. Tsirkin
2026-07-26 21:30 ` [PULL 28/30] hw/net/virtio-net: Protect from DMA re-entrancy bugs Michael S. Tsirkin
2026-07-26 21:30 ` [PULL 29/30] hw/virtio-rng: Fix host use-after-free (CVE-2026-50624) Michael S. Tsirkin
2026-07-26 21:30 ` [PULL 30/30] backends/rng: cap request size to avoid oversized allocation Michael S. Tsirkin
2026-07-27 8:55 ` [PULL 00/30] pci, vhost, virtio, iommu: bugfixes Michael S. Tsirkin
2026-07-27 9:05 ` Marc-André Lureau
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=20260727045220-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=dtalexundeer@yandex-team.ru \
--cc=farosas@suse.de \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
/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.