Skip to content

migration/vmstate: Add VMState support to safely migrate GByteArray

Arun Menon qemu-devel 4 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest2 patches 0 repliesNew
  2. v32 patches 4 repliesSuperseded
  3. v22 patches 3 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v12 patches3 repliesSuperseded

Changes in v4 from the cover letter

- Applied Peter Xu's feedback: unwrapped GByteArray pointer immediately.
- Removed redundant assert() and ternary logic.
- Removed unneeded len>0 check around qemu_get_buffer and qemu_put_buffer.

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2migration/vmstate: Add VMState support for GByteArrayinclude/migration/vmstate.h migration/vmstate-types.c+38 -00 replies
2/2ui/vdagent: Use VMSTATE_GBYTEARRAY to safely migrate outbufui/vdagent.c+1 -120 replies

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchMarc-André LureauPeter Xu
1/2R-b R-b
2/2R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 0/2] migration/vmstate: Add VMState support to safely migrate GByteArray

In GLib, GByteArray is an object managed by the library. Currently, migrating a GByteArray requires treating it as a raw C struct and using VMSTATE_VBUFFER_ALLOC_UINT32. For example, see vmstate_vdba in ui/vdagent.c

QEMU cannot pretend that GByteArray is a C struct and simply use VMS_ALLOC to g_malloc() the buffer. This is because, VMS_ALLOC blindly overwrites the data pointer with a newly allocated buffer, thereby leaking the previous memory. Besides, GLib tracks the array's capacity in a hidden alloc field. Bypassing GLib APIs leave this capacity out of sync with the newly allocated buffer, potentially leading to heap buffer overflows during subsequent g_byte_array_append() calls.

This series adds a new VMState called VMSTATE_GBYTEARRAY, which will directly use GLib library API calls to create, or resize the object. This is then used in ui/vdaagent.c replacing the use of VMSTATE_VBUFFER_ALLOC_UINT32.

Changes in v4:
- Applied Peter Xu's feedback: unwrapped GByteArray pointer immediately.
- Removed redundant assert() and ternary logic.
- Removed unneeded len>0 check around qemu_get_buffer and qemu_put_buffer.

Changes in v3:
- Add assert() checks to get and put functions to prevent NULL pointer dereferences, as suggested by Peter Xu.

Changes in v2:
- Marc-André pointed out the problem of not updating the device state itself. To do that we should essentially pass a pointer to the GByteArray pointer. Remove VMS_POINTER from VMSTATE_GBYTEARRAY. This changes 'pv' to be the address of the pointer field (GByteArray **) instead of the pointer's value.
- Update get_g_byte_array and put_g_byte_array to handle this additional level of indirection, allowing safe allocation and updating device state.
- Link to v1: https://lore.kernel.org/all/[email protected]/

Arun Menon (2):
migration/vmstate: Add VMState support for GByteArray ui/vdagent: Use VMSTATE_GBYTEARRAY to safely migrate outbuf

 include/migration/vmstate.h | 10 ++++++++++
 migration/vmstate-types.c   | 28 ++++++++++++++++++++++++++++
 ui/vdagent.c                | 13 +------------
 3 files changed, 39 insertions(+), 12 deletions(-)
Signature · 1 line
2.53.0