qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/28] glib: Replace g_memdup() by g_memdup2_qemu()
@ 2021-09-03 11:06 Philippe Mathieu-Daudé
  2021-09-03 11:06 ` [PATCH 01/28] hw/hyperv/vmbus: Remove unused vmbus_load/save_req() Philippe Mathieu-Daudé
                   ` (27 more replies)
  0 siblings, 28 replies; 40+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-03 11:06 UTC (permalink / raw)
  To: qemu-devel
  Cc: Fam Zheng, Peter Maydell, Li Zhijian, Michael S. Tsirkin,
	Jason Wang, Christian Schoenebeck, Yuval Shaia, Peter Xu,
	Gerd Hoffmann, Alexandre Iooss, Eric Blake, qemu-block,
	Zhang Chen, Alex Bennée, Helge Deller, David Hildenbrand,
	Markus Armbruster, Gonglei (Arei),
	Stefan Weil, Philippe Mathieu-Daudé,
	Laurent Vivier, Thomas Huth, Eduardo Habkost, Michael Roth,
	Richard Henderson, Greg Kurz, Alex Williamson, qemu-arm,
	Paolo Bonzini, John Snow, David Gibson, Kevin Wolf,
	Vladimir Sementsov-Ogievskiy, Laurent Vivier, Shannon Zhao,
	Hanna Reitz, qemu-ppc, Igor Mammedov, Mahmoud Mandour

Per https://discourse.gnome.org/t/port-your-module-from-g-memdup-to-g-memdup2-now/5538

  The old API took the size of the memory to duplicate as a guint,
  whereas most memory functions take memory sizes as a gsize. This
  made it easy to accidentally pass a gsize to g_memdup(). For large
  values, that would lead to a silent truncation of the size from 64
  to 32 bits, and result in a heap area being returned which is
  significantly smaller than what the caller expects. This can likely
  be exploited in various modules to cause a heap buffer overflow.

g_memdup() as been deprecated in GLib 2.68. Since QEMU defines
GLIB_VERSION_MAX_ALLOWED to GLIB_VERSION_2_56, the deprecation
is not displayed (on GLib >= 2.68 such available on Fedora 34).
However the function is still unsafe, so it is better to avoid
its use.

This series provides the safely equivalent g_memdup2_qemu()
wrapper, and replace all g_memdup() calls by it.

The previous link recommend to audit the call sites. Most of the
calls use byte_size=sizeof(STRUCT), and no STRUCT appears to be
> 4GiB.  Few calls use unsigned/size_t/uint16_t. Where code is
doing multiplication, patches are sent as RFC. In particular:
    hw/net/virtio-net.c
    hw/virtio/virtio-crypto.c

Please review,

Phil.

Philippe Mathieu-Daudé (28):
  hw/hyperv/vmbus: Remove unused vmbus_load/save_req()
  glib-compat: Introduce g_memdup2() wrapper
  qapi: Replace g_memdup() by g_memdup2_qemu()
  accel/tcg: Replace g_memdup() by g_memdup2_qemu()
  block/qcow2-bitmap: Replace g_memdup() by g_memdup2_qemu()
  softmmu: Replace g_memdup() by g_memdup2_qemu()
  hw/9pfs: Replace g_memdup() by g_memdup2_qemu()
  hw/acpi: Avoid truncating acpi_data_len() to 32-bit
  hw/acpi: Replace g_memdup() by g_memdup2_qemu()
  hw/core/machine: Replace g_memdup() by g_memdup2_qemu()
  hw/hppa/machine: Replace g_memdup() by g_memdup2_qemu()
  hw/i386/multiboot: Replace g_memdup() by g_memdup2_qemu()
  hw/net/eepro100: Replace g_memdup() by g_memdup2_qemu()
  hw/nvram/fw_cfg: Replace g_memdup() by g_memdup2_qemu()
  hw/scsi/mptsas: Replace g_memdup() by g_memdup2_qemu()
  hw/ppc/spapr_pci: Replace g_memdup() by g_memdup2_qemu()
  hw/rdma: Replace g_memdup() by g_memdup2_qemu()
  hw/vfio/pci: Replace g_memdup() by g_memdup2_qemu()
  RFC hw/virtio: Replace g_memdup() by g_memdup2_qemu()
  net/colo: Replace g_memdup() by g_memdup2_qemu()
  RFC ui/clipboard: Replace g_memdup() by g_memdup2_qemu()
  RFC linux-user: Replace g_memdup() by g_memdup2_qemu()
  tests/unit: Replace g_memdup() by g_memdup2_qemu()
  tests/qtest: Replace g_memdup() by g_memdup2_qemu()
  target/arm: Replace g_memdup() by g_memdup2_qemu()
  target/ppc: Replace g_memdup() by g_memdup2_qemu()
  contrib: Replace g_memdup() by g_memdup2_qemu()
  checkpatch: Do not allow deprecated g_memdup()

 include/glib-compat.h       | 36 ++++++++++++++++++++++
 include/hw/hyperv/vmbus.h   |  3 --
 accel/tcg/cputlb.c          |  8 ++---
 block/qcow2-bitmap.c        |  2 +-
 contrib/plugins/lockstep.c  |  2 +-
 contrib/rdmacm-mux/main.c   | 10 +++----
 hw/9pfs/9p-synth.c          |  2 +-
 hw/9pfs/9p.c                |  2 +-
 hw/acpi/core.c              |  3 +-
 hw/arm/virt-acpi-build.c    |  2 +-
 hw/core/machine.c           |  4 +--
 hw/hppa/machine.c           |  8 ++---
 hw/hyperv/vmbus.c           | 59 -------------------------------------
 hw/i386/acpi-build.c        |  6 ++--
 hw/i386/multiboot.c         |  2 +-
 hw/net/eepro100.c           |  2 +-
 hw/net/virtio-net.c         |  3 +-
 hw/nvram/fw_cfg.c           |  9 +++---
 hw/ppc/spapr_pci.c          |  8 ++---
 hw/rdma/rdma_utils.c        |  2 +-
 hw/scsi/mptsas.c            |  5 ++--
 hw/vfio/pci.c               |  2 +-
 hw/virtio/virtio-crypto.c   |  7 +++--
 linux-user/syscall.c        |  2 +-
 linux-user/uaccess.c        |  2 +-
 net/colo.c                  |  4 +--
 qapi/qapi-clone-visitor.c   | 16 +++++-----
 qapi/qapi-visit-core.c      |  6 ++--
 softmmu/memory.c            |  2 +-
 softmmu/vl.c                |  2 +-
 target/arm/helper.c         |  7 +++--
 target/ppc/mmu-hash64.c     |  3 +-
 tests/qtest/libqos/ahci.c   |  6 ++--
 tests/qtest/libqos/qgraph.c |  2 +-
 tests/unit/ptimer-test.c    | 22 +++++++-------
 tests/unit/test-iov.c       | 26 ++++++++--------
 ui/clipboard.c              |  2 +-
 scripts/checkpatch.pl       |  5 ++++
 38 files changed, 141 insertions(+), 153 deletions(-)

-- 
2.31.1




^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2021-09-08  7:19 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-03 11:06 [PATCH 00/28] glib: Replace g_memdup() by g_memdup2_qemu() Philippe Mathieu-Daudé
2021-09-03 11:06 ` [PATCH 01/28] hw/hyperv/vmbus: Remove unused vmbus_load/save_req() Philippe Mathieu-Daudé
2021-09-03 11:06 ` [PATCH 02/28] glib-compat: Introduce g_memdup2() wrapper Philippe Mathieu-Daudé
2021-09-03 11:16   ` Daniel P. Berrangé
2021-09-03 11:51     ` Vladimir Sementsov-Ogievskiy
2021-09-03 11:56       ` Daniel P. Berrangé
2021-09-03 12:03         ` Vladimir Sementsov-Ogievskiy
2021-09-03 17:09     ` Philippe Mathieu-Daudé
2021-09-03 11:06 ` [PATCH 03/28] qapi: Replace g_memdup() by g_memdup2_qemu() Philippe Mathieu-Daudé
2021-09-03 11:18   ` Daniel P. Berrangé
2021-09-03 17:10     ` Philippe Mathieu-Daudé
2021-09-03 11:06 ` [PATCH 04/28] accel/tcg: " Philippe Mathieu-Daudé
2021-09-03 11:06 ` [PATCH 05/28] block/qcow2-bitmap: " Philippe Mathieu-Daudé
2021-09-03 11:06 ` [PATCH 06/28] softmmu: " Philippe Mathieu-Daudé
2021-09-03 11:06 ` [PATCH 07/28] hw/9pfs: " Philippe Mathieu-Daudé
2021-09-03 11:06 ` [PATCH 08/28] hw/acpi: Avoid truncating acpi_data_len() to 32-bit Philippe Mathieu-Daudé
2021-09-08  7:15   ` Igor Mammedov
2021-09-03 11:06 ` [PATCH 09/28] hw/acpi: Replace g_memdup() by g_memdup2_qemu() Philippe Mathieu-Daudé
2021-09-08  7:16   ` Igor Mammedov
2021-09-03 11:06 ` [PATCH 10/28] hw/core/machine: " Philippe Mathieu-Daudé
2021-09-03 11:06 ` [PATCH 11/28] hw/hppa/machine: " Philippe Mathieu-Daudé
2021-09-03 11:06 ` [PATCH 12/28] hw/i386/multiboot: " Philippe Mathieu-Daudé
2021-09-03 11:06 ` [PATCH 13/28] hw/net/eepro100: " Philippe Mathieu-Daudé
2021-09-03 11:06 ` [PATCH 14/28] hw/nvram/fw_cfg: " Philippe Mathieu-Daudé
2021-09-03 11:06 ` [PATCH 15/28] hw/scsi/mptsas: " Philippe Mathieu-Daudé
2021-09-03 11:06 ` [PATCH 16/28] hw/ppc/spapr_pci: " Philippe Mathieu-Daudé
2021-09-03 11:45   ` David Gibson
2021-09-03 11:06 ` [PATCH 17/28] hw/rdma: " Philippe Mathieu-Daudé
2021-09-03 11:06 ` [PATCH 18/28] hw/vfio/pci: " Philippe Mathieu-Daudé
2021-09-03 11:06 ` [RFC PATCH 19/28] hw/virtio: " Philippe Mathieu-Daudé
2021-09-03 11:06 ` [PATCH 20/28] net/colo: " Philippe Mathieu-Daudé
2021-09-03 11:06 ` [RFC PATCH 21/28] ui/clipboard: " Philippe Mathieu-Daudé
2021-09-03 11:06 ` [RFC PATCH 22/28] linux-user: " Philippe Mathieu-Daudé
2021-09-03 11:06 ` [PATCH 23/28] tests/unit: " Philippe Mathieu-Daudé
2021-09-03 11:06 ` [PATCH 24/28] tests/qtest: " Philippe Mathieu-Daudé
2021-09-03 11:06 ` [PATCH 25/28] target/arm: " Philippe Mathieu-Daudé
2021-09-03 11:07 ` [PATCH 26/28] target/ppc: " Philippe Mathieu-Daudé
2021-09-03 11:45   ` David Gibson
2021-09-03 11:07 ` [PATCH 27/28] contrib: " Philippe Mathieu-Daudé
2021-09-03 11:07 ` [PATCH 28/28] checkpatch: Do not allow deprecated g_memdup() Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).