Skip to contentSkip to conversation

target-arm queue

GIT PULL Applied Peter Maydell 2 participants 35 messages Nov 16

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

Hi; this is quite a large pullreq, but it's all bug fixes aimed at rc1 (both arm-specific and otherwise). Notably, there are a set of patches in here which fix various problems with handling of packets in the net/ code.

thanks
-- PMM

The following changes since commit e9fa1f66f0d47c74b6766e1b8b87ad7c2a9394d5:

Merge tag 'pull-nbd-2026-11-10-v2' of https://gitlab.com/ebblake/qemu into staging (2026-11-13 08:44:16 -0700)

are available in the Git repository at:

https://gitlab.com/pm215/qemu.git tags/pull-target-arm-20261116

for you to fetch changes up to 7d8fc59308ce20661515555855af4e01ac9bab77:

hw/arm/virt-acpi-build: test vms->acpi_dev before building HEST (2026-11-16 11:09:47 +0000)

----------------------------------------------------------------
target/arm queue:
* hw/ssi/stm32f2xx_spi: avoid transferring data on DR reads
* hw/arm/bcm2838: Route SPI0 interrupt to GIC
* hw/intc/arm_gicv5: Various minor bug fixes
* hw/core/qdev-properties-system.c: Don't leak str in set_drive_helper()
* hw/watchdog/wdt_imx2: Set vmstate minimum_version_id to 1
* include/hw/core/ptimer.h: Fix 'version' argument of VMSTATE_PTIMER
* net: Tighten various size/offset checks in packet parsing functions
* net: Pad short packets regardless of network backend
* hw/net/eepro100: fix use-after-free on reset after hot-unplug
* hw/arm: Deprecate Nuvoton quanta-gsj board model
* Revert ".dir-locals: include QEMU code in PYTHONPATH"
* docs/about/deprecated: Add missing "since" marker for OABI/NWFPE
* docs/about/deprecated: Fix heading level for AF_ALG heading
* hw/net: cadence: Honor subword lanes in the GEM registers
* hw/arm/virt-acpi-build: test vms->acpi_dev before building HEST

----------------------------------------------------------------
Akihiko Odaki (4):
net/eth.c: Check for undersized L2 headers in eth_get_protocols() net/eth.c: In eth_get_protocols(), don't report TCP data offset off end of packet net/eth.c: In eth_parse_ipv6_hdr(), fix check of input size net/eth.c: Move the Routing Header Hdr Ext Len check

Alex Bennée (1):
Revert ".dir-locals: include QEMU code in PYTHONPATH"

Bin Meng (1):
hw/net: cadence: Honor subword lanes in the GEM registers

Hanyu (1):
hw/arm/bcm2838: Route SPI0 interrupt to GIC

Manuele Conti (1):
hw/ssi/stm32f2xx_spi: avoid transferring data on DR reads

Peter Maydell (23):
hw/intc/arm_gicv5: Use cached IRS_IST_BASER.VALID state hw/intc/arm_gicv5: Free memory in finalize
target/arm: Only allow GICv5 on CPUs without AArch32 at EL1..3 hw/intc/arm_gicv5: Use correct type for value in lpi_cache_get_hppi() hw/core/qdev-properties-system.c: Don't leak str in set_drive_helper() hw/watchdog/wdt_imx2: Set vmstate minimum_version_id to 1 include/hw/core/ptimer.h: Fix 'version' argument of VMSTATE_PTIMER hw/net/net_rx_pkt: Handle bogus l4hdr_off when validating SCTP checksum net/eth.c: Check for undersized IPv4 headers in eth_get_protocols() net/eth.c: In eth_get_protocols(), don't report SCTP header off end of packet net/eth.c: Harden _eth_tcp_has_data() against short lengths net/eth.c: Tighten size checks in eth_get_l3_proto() include/net/eth.h: Make eth_get_l2_hdr_length_iov() check protocol hw/net/net_tx_pkt: Sanity check GSO headers in net_tx_pkt_build_vheader() hw/net/net_tx_pkt: Sanity check virt hdr len in net_tx_tcp_fragment_init hw/net/net_tx_pkt: Sanity check L2+L3 header len in net_tx_pkt_parse_headers() hw/net/net_rx_pkt: Check for overflow in _net_rx_pkt_calc_l4_csum() tests/qtest: Make netfilter tests accept padded ethernet packets
net: Pad short packets consistently regardless of backend
net: Remove padding code from net backends
hw/arm: Deprecate Nuvoton quanta-gsj board model docs/about/deprecated: Add missing "since" marker for OABI/NWFPE docs/about/deprecated: Fix heading level for AF_ALG heading

Ren Yanyi (1):

      hw/arm/virt-acpi-build: test vms->acpi_dev before building HEST

Stefan Weil (1):
hw/net/eepro100: fix use-after-free on reset after hot-unplug

 MAINTAINERS                          |   1 +
 docs/about/deprecated.rst            |  16 +++-
 include/hw/arm/bcm2835_peripherals.h |   1 +
 include/hw/arm/bcm2838_peripherals.h |   1 +
 include/hw/core/ptimer.h             |   2 +-
 include/net/eth.h                    |  26 ++++++-
 include/net/net.h                    |   3 +-
 target/arm/cpu-features.h            |   8 ++
 hw/arm/bcm2835_peripherals.c         |  14 +++-
 hw/arm/bcm2838.c                     |   4 +
 hw/arm/npcm7xx_boards.c              |   1 +
 hw/arm/virt-acpi-build.c             |  25 +++---
 hw/core/qdev-properties-system.c     |   5 +-
 hw/dma/xlnx_csu_dma.c                |   4 +-
 hw/intc/arm_gicv5.c                  |  20 +++--
 hw/intc/arm_gicv5_common.c           |   3 +
 hw/net/cadence_gem.c                 |  55 +++++++++-----
 hw/net/eepro100.c                    |  13 +++-
 hw/net/net_rx_pkt.c                  |  22 ++++--
 hw/net/net_tx_pkt.c                  |  20 ++++-
 hw/ssi/stm32f2xx_spi.c               |   1 -
 hw/watchdog/k230_wdt.c               |   2 +
 hw/watchdog/wdt_imx2.c               |   1 +
 net/eth.c                            | 143 +++++++++++++++++++++++++++++------
 net/net.c                            |  32 +++++++-
 net/slirp.c                          |   9 ---
 net/tap-win32.c                      |  15 +---
 net/tap.c                            |  11 +--
 target/arm/cpu.c                     |  37 ++-------
 tests/qtest/stm32f2xx-spi-test.c     |  50 ++++++++++++
 tests/qtest/test-filter-buffer.c     |   4 +-
 tests/qtest/test-filter-mirror.c     |   4 +-
 tests/qtest/test-filter-redirector.c |   4 +-
 .dir-locals.el                       |   8 +-
 net/vmnet-common.m                   |  11 ---
 tests/qtest/meson.build              |   2 +
 36 files changed, 399 insertions(+), 179 deletions(-)
 create mode 100644 tests/qtest/stm32f2xx-spi-test.c
#1 lore raw

[PULL 13/33] net/eth.c: In eth_get_protocols(), don't report TCP data offset off end of packet

From: Akihiko Odaki <[email protected]>

eth_get_protocols() already rejects some out-of-bounds offsets found in packets. Add a missing check for TCP data offset.

Fixes eb700029c783 ("net_pkt: Extend packet abstraction as required by e1000e functionality")

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4155

Message-id: [email protected]

---
 net/eth.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/eth.c +2 -1
index 038f7d889c3..a444377fd0a 100644
@@ -197,7 +197,8 @@ void eth_get_protocols(const struct iovec *iov, size_t iovcnt, size_t iovoff,
         if (_eth_copy_chunk(input_size,
                             iov, iovcnt,
                             *l4hdr_off, sizeof(l4hdr_info->hdr.tcp),
-                            &l4hdr_info->hdr.tcp)) {
+                            &l4hdr_info->hdr.tcp) &&
+            input_size - *l4hdr_off >= TCP_HEADER_DATA_OFFSET(&l4hdr_info->hdr.tcp)) {
             l4hdr_info->proto = ETH_L4_HDR_PROTO_TCP;
             *l5hdr_off = *l4hdr_off +
                 TCP_HEADER_DATA_OFFSET(&l4hdr_info->hdr.tcp);
Signature · 1 line
2.43.0
#2 lore raw

[PULL 17/33] net/eth.c: Harden _eth_tcp_has_data() against short lengths

In reply to Peter Maydell

In _eth_tcp_has_data() we calculate the length of the rest of the packet after the ipv4 header by subtracting the header offset from the packet length. If this subtraction underflows we'll return the wrong answer. This shouldn't cause any problems if other layers of the code are checking lengths and offsets, but defence-in-depth suggests doing a checked-subtraction and returning "has no data" if the subtraction underflows.

Fixes eb700029c783 ("net_pkt: Extend packet abstraction as required by e1000e functionality")

Message-id: [email protected]

---
 net/eth.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
net/eth.c +12 -2
index 54b0a77fa0a..74a705a2679 100644
@@ -118,10 +118,20 @@ _eth_tcp_has_data(bool is_ip4,
     uint32_t l4len;
 
     if (is_ip4) {
-        l4len = be16_to_cpu(ip4_hdr->ip_len) - IP_HDR_GET_LEN(ip4_hdr);
+        if (usub32_overflow(be16_to_cpu(ip4_hdr->ip_len),
+                            IP_HDR_GET_LEN(ip4_hdr), &l4len)) {
+            /* packet too short for claimed IP header: no data */
+            return false;
+        }
     } else {
         size_t opts_len = full_ip6hdr_len - sizeof(struct ip6_header);
-        l4len = be16_to_cpu(ip6_hdr->ip6_ctlun.ip6_un1.ip6_un1_plen) - opts_len;
+        uint64_t l4len_64;
+        if (usub64_overflow(be16_to_cpu(ip6_hdr->ip6_ctlun.ip6_un1.ip6_un1_plen),
+                            opts_len, &l4len_64)) {
+            /* packet too short for claimed IP header: no data */
+            return false;
+        }
+        l4len = l4len_64;
     }
 
     return l4len > TCP_HEADER_DATA_OFFSET(tcp);
Signature · 1 line
2.43.0
#3 lore raw

[PULL 02/33] hw/arm/bcm2838: Route SPI0 interrupt to GIC

In reply to Peter Maydell

From: Hanyu <[email protected]>

On raspi4b, SPI0's interrupt is connected only to the legacy interrupt controller. Linux guests whose device trees use the GIC therefore can't detect an SPI0 interrupt.

This patch adds a two-output IRQ splitter to deliver SPI0's interrupt to both the legacy controller and GIC SPI 118. This follows commit fb3e0557a4cb ("hw/arm/bcm2838: Route I2C interrupts to GIC").

Testing

Add these options to the QEMU invocation:

  -device m25p80,bus=spi,drive=flash0 \
  -blockdev node-name=flash0,driver=file,filename=flash.bin

Before the change, probing fails and /proc/mtd contains no devices:

spi-nor spi0.0: SPI transfer timed out spi_master spi0: failed to transfer one message from queue
spi-nor: probe of spi0.0 failed with error -2

After the change, the flash is detected:

spi-nor spi0.0: m25p80 (1024 Kbytes)

  # cat /proc/mtd
  dev:    size   erasesize  name
  mtd0: 00100000 00010000 "spi0.0"

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3013

Message-id: [email protected]

---
 include/hw/arm/bcm2835_peripherals.h |  1 +
 include/hw/arm/bcm2838_peripherals.h |  1 +
 hw/arm/bcm2835_peripherals.c         | 14 +++++++++++---
 hw/arm/bcm2838.c                     |  4 ++++
 4 files changed, 17 insertions(+), 3 deletions(-)
include/hw/arm/bcm2835_peripherals.h +1 -0
index 4f356f46435..cd66a734e7c 100644
@@ -71,6 +71,7 @@ struct BCMSocPeripheralBaseState {
     BCM2835SDHostState sdhost;
     UnimplementedDeviceState i2s;
     BCM2835SPIState spi[1];
+    SplitIRQ spi_irq_splitter;
     BCM2835I2CState i2c[3];
     OrIRQState orgated_i2c_irq;
     SplitIRQ orgated_i2c_irq_splitter;
include/hw/arm/bcm2838_peripherals.h +1 -0
index 60bfacdce49..f9279daa4d0 100644
@@ -27,6 +27,7 @@
 #define GIC_SPI_INTERRUPT_DMA_9_10     88
 #define GIC_SPI_INTERRUPT_AUX_UART1    93
 #define GIC_SPI_INTERRUPT_I2C          117
+#define GIC_SPI_INTERRUPT_SPI          118
 #define GIC_SPI_INTERRUPT_SDHOST       120
 #define GIC_SPI_INTERRUPT_UART0        121
 #define GIC_SPI_INTERRUPT_RNG200       125
hw/arm/bcm2835_peripherals.c +11 -3
index 558c180df9f..be40c6b92a4 100644
@@ -166,6 +166,8 @@ static void raspi_peripherals_base_init(Object *obj)
     /* SPI */
     object_initialize_child(obj, "bcm2835-spi0", &s->spi[0],
                             TYPE_BCM2835_SPI);
+    object_initialize_child(obj, "spi-irq-splitter",
+                            &s->spi_irq_splitter, TYPE_SPLIT_IRQ);
 
     /* I2C */
     object_initialize_child(obj, "bcm2835-i2c0", &s->i2c[0],
@@ -480,10 +482,16 @@ void bcm_soc_peripherals_common_realize(DeviceState *dev, Error **errp)
 
     memory_region_add_subregion(&s->peri_mr, SPI0_OFFSET,
                 sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->spi[0]), 0));
+    qdev_prop_set_uint32(DEVICE(&s->spi_irq_splitter), "num-lines", 2);
+    if (!qdev_realize(DEVICE(&s->spi_irq_splitter), NULL, errp)) {
+        return;
+    }
     sysbus_connect_irq(SYS_BUS_DEVICE(&s->spi[0]), 0,
-                       qdev_get_gpio_in_named(DEVICE(&s->ic),
-                                              BCM2835_IC_GPU_IRQ,
-                                              INTERRUPT_SPI));
+                       qdev_get_gpio_in(DEVICE(&s->spi_irq_splitter), 0));
+    qdev_connect_gpio_out(DEVICE(&s->spi_irq_splitter), 0,
+                          qdev_get_gpio_in_named(DEVICE(&s->ic),
+                                                 BCM2835_IC_GPU_IRQ,
+                                                 INTERRUPT_SPI));
 
     /* I2C */
     for (n = 0; n < 3; n++) {
hw/arm/bcm2838.c +4 -0
index 650b1fe8f44..1bde9e68af9 100644
@@ -188,6 +188,10 @@ static void bcm2838_realize(DeviceState *dev, Error **errp)
     qdev_connect_gpio_out(DEVICE(&ps_base->orgated_i2c_irq_splitter), 1,
                           qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_I2C));
 
+    /* Connect the SPI interrupt to the interrupt controller */
+    qdev_connect_gpio_out(DEVICE(&ps_base->spi_irq_splitter), 1,
+                          qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_SPI));
+
     /* Connect VC mailbox to the interrupt controller */
     sysbus_connect_irq(SYS_BUS_DEVICE(&ps_base->mboxes), 0,
                        qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_MBOX));
Signature · 1 line
2.43.0
#4 lore raw

[PULL 14/33] net/eth.c: In eth_get_protocols(), don't report SCTP header off end of packet

In reply to Peter Maydell

eth_get_protocols() parses an ethernet packet and tells the caller about various offsets into it and other properties of the packet. For the L4 protocol, in both the IP_PROTO_TCP and IP_PROTO_UDP branches we implicitly check that the packet does contain a whole TCP or UDP header at the l4hdr_off offset, because _eth_copy_chunk() will fail if the input packet size isn't big enough for the whole header we are copying out of it. But for IP_PROTO_SCTP we don't copy the SCTP common header. In this case we should still do the length check, so we don't set l4hdr_info->proto to say there's an SCTP header present when there isn't.

This shouldn't have any visible effects if the downstream consumers of the l4hdr_info are conservative about checking before they access into the packet, but checking here too adds defence in depth, hence the cc to stable.

Fixes 907209e3111d ("igb: Implement Rx SCTP CSO")

Message-id: [email protected]

[Reversed the condition and changed it to use input_size - *l4hdr_off]
---
 include/net/eth.h | 2 ++
 net/eth.c         | 9 ++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)
include/net/eth.h +2 -0
index 46dc9ed5acd..e10684ed923 100644
@@ -394,6 +394,8 @@ typedef struct eth_l4_hdr_info_st {
     bool has_tcp_data;
 } eth_l4_hdr_info;
 
+#define SCTP_COMMON_HEADER_LEN 12
+
 void eth_get_protocols(const struct iovec *iov, size_t iovcnt, size_t iovoff,
                        bool *hasip4, bool *hasip6,
                        size_t *l3hdr_off,
net/eth.c +8 -1
index a444377fd0a..55d85cecd1d 100644
@@ -223,7 +223,14 @@ void eth_get_protocols(const struct iovec *iov, size_t iovcnt, size_t iovoff,
         break;
 
     case IP_PROTO_SCTP:
-        l4hdr_info->proto = ETH_L4_HDR_PROTO_SCTP;
+        /*
+         * We don't copy the SCTP common header into l4hdr_info, but
+         * don't report SCTP as present if the packet isn't big enough
+         * to actually have an SCTP header.
+         */
+        if (input_size - *l4hdr_off >= SCTP_COMMON_HEADER_LEN) {
+            l4hdr_info->proto = ETH_L4_HDR_PROTO_SCTP;
+        }
         break;
     }
 }
Signature · 1 line
2.43.0
#5 lore raw

[PULL 27/33] hw/net/eepro100: fix use-after-free on reset after hot-unplug

In reply to Peter Maydell

From: Stefan Weil <[email protected]>

e100_nic_realize() registers a system reset handler via qemu_register_reset(nic_reset, s), but pci_nic_uninit() never unregisters it. After the device is hot-unplugged, the LegacyReset object stored in the root reset container still holds the raw pointer to the freed EEPRO100State, so the next system reset invokes nic_reset() on freed memory.

Instead, define a reset phase on the device itself: assign phases.hold in eepro100_class_init() to a wrapper around nic_reset(). The device is already part of the resettable tree via its parent bus (TYPE_DEVICE implements the Resettable interface), so no explicit registration is needed, and the reset state is automatically dropped when the device is unplugged. This follows the approach used by the e1000, e1000e and igb emulations.

Message-id: [email protected]

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4058
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4510

---
 hw/net/eepro100.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
hw/net/eepro100.c +9 -4
index aaa3eb60f8a..8fe7f31bd2f 100644
@@ -617,6 +617,13 @@ static void nic_reset(void *opaque)
     nic_selective_reset(s);
 }
 
+static void eepro100_reset_hold(Object *obj, ResetType type)
+{
+    EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, PCI_DEVICE(obj));
+
+    nic_reset(s);
+}
+
 #if defined(DEBUG_EEPRO100)
 static const char * const e100_reg[PCI_IO_SIZE / 4] = {
     "Command/Status",
@@ -1871,8 +1878,6 @@ static void e100_nic_realize(PCIDevice *pci_dev, Error **errp)
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
     logout("macaddr: %s\n", nic_dump(&s->conf.macaddr.a[0], 6));
 
-    nic_reset(s);
-
     s->nic = qemu_new_nic(&net_eepro100_info, &s->conf,
                           object_get_typename(OBJECT(pci_dev)),
                           pci_dev->qdev.id,
@@ -1881,8 +1886,6 @@ static void e100_nic_realize(PCIDevice *pci_dev, Error **errp)
     qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
     TRACE(OTHER, logout("%s\n", qemu_get_queue(s->nic)->info_str));
 
-    qemu_register_reset(nic_reset, s);
-
     s->vmstate = g_memdup(&vmstate_eepro100, sizeof(vmstate_eepro100));
     s->vmstate->name = qemu_get_queue(s->nic)->model;
     vmstate_register_any(VMSTATE_IF(&pci_dev->qdev), s->vmstate, s);
@@ -2064,6 +2067,7 @@ static void eepro100_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
     E100PCIDeviceInfo *info;
 
     info = eepro100_get_class_by_name(object_class_get_name(klass));
@@ -2080,6 +2084,7 @@ static void eepro100_class_init(ObjectClass *klass, const void *data)
     k->revision = info->revision;
     k->subsystem_vendor_id = info->subsystem_vendor_id;
     k->subsystem_id = info->subsystem_id;
+    rc->phases.hold = eepro100_reset_hold;
 }
 
 static void eepro100_register_types(void)
Signature · 1 line
2.43.0
#6 lore raw

[PULL 16/33] net/eth.c: Move the Routing Header Hdr Ext Len check

In reply to Peter Maydell

From: Akihiko Odaki <[email protected]>

RFC 8200 - Internet Protocol, Version 6 (IPv6) Specification section 4.4 [1] says the Routing Header length depends on the Routing Type, so place the checks of the Hdr Ext Len and the Routing Type together.

[1] https://datatracker.ietf.org/doc/html/rfc8200#section-4.4

Message-id: [email protected]

---
 net/eth.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
net/eth.c +6 -7
index 484f61ef31d..54b0a77fa0a 100644
@@ -407,7 +407,8 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags,
     bytes_read = iov_to_buf(pkt, pkt_frags, ext_hdr_offset,
                             &rt_hdr, sizeof(rt_hdr));
     assert(bytes_read == sizeof(rt_hdr));
-    if ((rt_hdr.rtype != 2) || (rt_hdr.segleft != 1)) {
+    if (rt_hdr.len != sizeof(struct in6_address) / 8 ||
+        rt_hdr.rtype != 2 || rt_hdr.segleft != 1) {
         return false;
     }
     bytes_read = iov_to_buf(pkt, pkt_frags, ext_hdr_offset + sizeof(rt_hdr),
@@ -518,12 +519,10 @@ bool eth_parse_ipv6_hdr(const struct iovec *pkt, int pkt_frags,
 
         switch (curr_ext_hdr_type) {
         case IP6_ROUTING:
-            if (ext_hdr.ip6r_len == sizeof(struct in6_address) / 8) {
-                info->rss_ex_dst_valid =
-                    _eth_get_rss_ex_dst_addr(pkt, pkt_frags,
-                                             ip6hdr_off + info->full_hdr_len,
-                                             &ext_hdr, &info->rss_ex_dst);
-            }
+            info->rss_ex_dst_valid =
+                _eth_get_rss_ex_dst_addr(pkt, pkt_frags,
+                                         ip6hdr_off + info->full_hdr_len,
+                                         &ext_hdr, &info->rss_ex_dst);
             info->full_hdr_len += (ext_hdr.ip6r_len + 1) * IP6_EXT_GRANULARITY;
             break;
 
Signature · 1 line
2.43.0
#7 lore raw

[PULL 31/33] docs/about/deprecated: Fix heading level for AF_ALG heading

In reply to Peter Maydell

rST heading levels are marked by using different underline levels. In commit 00e70abb8500a979 we added what was intended to be a new section "Build features" with one sub-section "Crypto AF_ALG backend", but because the same underline character is used in both cases they ended up both as sections at the same level. Fix the underline for the AF_ALG heading.

Fixes 00e70abb8500a9 ("crypto: deprecate the AF_ALG crypto backend")

Message-id: [email protected]

---
 docs/about/deprecated.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
docs/about/deprecated.rst +1 -1
index 4188445ed45..3362dbf0acd 100644
@@ -476,7 +476,7 @@ Build features
 --------------
 
 Crypto AF_ALG backend (since 11.2)
-----------------------------------
+''''''''''''''''''''''''''''''''''
 
 The use of the AF_ALG backend for cryptography has been deprecated
 with no replacement.
Signature · 1 line
2.43.0
#8 lore raw

[PULL 08/33] hw/watchdog/wdt_imx2: Set vmstate minimum_version_id to 1

In reply to Peter Maydell

In commit d9abd0253be90 we made a non-compatible migration state change, and set version_id to 1. However we forgot to also set minimum_version_id to 1, so the state struct now incorrectly claims it can accept migrations from the old version 0 format.

Bump minimum_version_id also to 1, so that attempted migrations from the old QEMU fail cleanly.

Fixes d9abd0253be90280 ("hw/watchdog/wdt_imx2: Remove redundant attributes")

Message-id: [email protected]

---
 hw/watchdog/wdt_imx2.c | 1 +
 1 file changed, 1 insertion(+)
hw/watchdog/wdt_imx2.c +1 -0
index f8129625e58..abb8edfae25 100644
@@ -224,6 +224,7 @@ static const MemoryRegionOps imx2_wdt_ops = {
 static const VMStateDescription vmstate_imx2_wdt = {
     .name = "imx2.wdt",
     .version_id = 1,
+    .minimum_version_id = 1,
     .fields = (const VMStateField[]) {
         VMSTATE_PTIMER(timer, IMX2WdtState),
         VMSTATE_PTIMER(itimer, IMX2WdtState),
Signature · 1 line
2.43.0
#9 lore raw

[PULL 04/33] hw/intc/arm_gicv5: Free memory in finalize

In reply to Peter Maydell

The GICv5 allocates memory and creates hashtables during realize and as part of its operation. Free those resources in finalize.

Since the GICv5 is created at QEMU startup and remains in existence for the lifetime of the process, this isn't an in-practice leak, only a theoretical one.

Message-id: [email protected]

---
 hw/intc/arm_gicv5.c        | 11 +++++++++++
 hw/intc/arm_gicv5_common.c |  3 +++
 2 files changed, 14 insertions(+)
hw/intc/arm_gicv5.c +11 -0
index d0a8574916b..fd6456cd8aa 100644
@@ -1970,6 +1970,17 @@ static void gicv5_init(Object *obj)
 
 static void gicv5_finalize(Object *obj)
 {
+    GICv5 *s = ARM_GICV5(obj);
+
+    for (int i = 0; i < NUM_GICV5_DOMAINS; i++) {
+        GHashTable *ht = s->phys_lpi_config[i].lpi_cache;
+
+        if (ht) {
+            g_hash_table_destroy(ht);
+        }
+
+        g_free(s->hppi[i]);
+    }
 }
 
 static void gicv5_class_init(ObjectClass *oc, const void *data)
hw/intc/arm_gicv5_common.c +3 -0
index 2920b11cc39..cfadfee4f05 100644
@@ -112,6 +112,9 @@ static void gicv5_common_init(Object *obj)
 
 static void gicv5_common_finalize(Object *obj)
 {
+    GICv5Common *cs = ARM_GICV5_COMMON(obj);
+
+    g_free(cs->spi);
 }
 
 static void gicv5_common_realize(DeviceState *dev, Error **errp)
Signature · 1 line
2.43.0
#10 lore raw

[PULL 30/33] docs/about/deprecated: Add missing "since" marker for OABI/NWFPE

In reply to Peter Maydell

In 750c2d53ee4 we deprecated our linux-user support for the Arm OABI and NWFPE emulation; however we forgot to mark the text in deprecated.rst with the usual indication of what version it was deprecated in. We announced the deprecation of this feature in the 11.0 release, so note that.

Fixes 750c2d53ee48f1e ("docs: Deprecate Arm OABI and NWFPE support")

Message-id: [email protected]

---
 docs/about/deprecated.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
docs/about/deprecated.rst +2 -2
index de7d502babb..4188445ed45 100644
@@ -451,8 +451,8 @@ across versions).
 linux-user mode CPUs
 --------------------
 
-OABI and NWFPE support for Arm CPUs
-'''''''''''''''''''''''''''''''''''
+OABI and NWFPE support for Arm CPUs (since 11.0)
+''''''''''''''''''''''''''''''''''''''''''''''''
 
 Linux for 32-bit Arm has had two major ABIs: the original OABI and the
 more modern EABI. OABI support was marked as obsolete in GCC 4.7 and
Signature · 1 line
2.43.0
#11 lore raw

[PULL 19/33] include/net/eth.h: Make eth_get_l2_hdr_length_iov() check protocol

In reply to Peter Maydell

In eth_get_l2_hdr_length() we return sizeof(eth_header) for any protocol other than VLAN or DVLAN. However, in the iov version of this function, if the packet is larger than the ethernet header but not large enough for both the eth_header and the vlan_header we'll end up returning the actual packet size rather than the eth_header size. Fix the "not enough data" return case.

This will only cause issues if the caller isn't already checking offsets and sizes, so this is defence-in-depth. It also in theory corrects the result for the hypothetical case of an ethernet-level protocol that allows a payload of less than 4 bytes.

Fixes eb700029c783 ("net_pkt: Extend packet abstraction as required by e1000e functionality")

Message-id: [email protected]

---
 include/net/eth.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/eth.h +1 -1
index e10684ed923..3e83f5d68c0 100644
@@ -321,7 +321,7 @@ eth_get_l2_hdr_length_iov(const struct iovec *iov, size_t iovcnt, size_t iovoff)
     size_t copied = iov_to_buf(iov, iovcnt, iovoff, p, ARRAY_SIZE(p));
 
     if (copied < ARRAY_SIZE(p)) {
-        return copied;
+        return MIN(copied, sizeof(struct eth_header));
     }
 
     return eth_get_l2_hdr_length(p);
Signature · 1 line
2.43.0
#12 lore raw

[PULL 06/33] hw/intc/arm_gicv5: Use correct type for value in lpi_cache_get_hppi()

In reply to Peter Maydell

lpi_cache_get_hppi() is a function we pass to g_hash_table_foreach() to iterate over the LPI cache hashtable. This hash table has keys which are GINT_TO_POINTER(intid) and values which hold the L2 ISTE value, allocated as "hashvalue = g_new(uint32_t, 1)".

The function is passed the key and value as type 'gpointer' and has to cast them to the real types itself, but it incorrectly casts the value pointer to a uint64_t*. This works on little-endian hosts (since we only read specific fields of the L2 ISTE using bitmasking), but won't work on big-endian, and trips the clang sanitizer.

Fix the pointer type; for consistency we fix also the type of the local variable, though that was not producing any incorrect behaviour.

Fixes a0562ada75e ("hw/intc/arm_gicv5: Calculate HPPI in the IRS")

Message-id: [email protected]

---
 hw/intc/arm_gicv5.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/intc/arm_gicv5.c +1 -1
index fd6456cd8aa..26dcbc82ed4 100644
@@ -390,7 +390,7 @@ typedef struct GetHPPIUserData {
 static void lpi_cache_get_hppi(gpointer key, gpointer value, gpointer user_data)
 {
     uint64_t id = GPOINTER_TO_INT(key);
-    uint64_t l2_iste = *(uint64_t *)value;
+    uint32_t l2_iste = *(uint32_t *)value;
     uint32_t prio, iaffid;
     GetHPPIUserData *ud = user_data;
 
Signature · 1 line
2.43.0
#13 lore raw

[PULL 32/33] hw/net: cadence: Honor subword lanes in the GEM registers

In reply to Peter Maydell

From: Bin Meng <[email protected]>

The GEM MMIO callbacks ignored the low address bits and access size. Byte reads therefore always returned lane zero, causing guest driver that reads the station address byte by byte to turn four unique MAC addresses into the same value. Partial writes had the corresponding lane-selection problem.

Extract the requested little-endian read lane and merge partial writes with the current register value. Preserve the existing read-clear and write-clear behavior and dynamic queue pointer readback.

With this change, reset the TX queue pointers only when a write covers TX-enable and leaves it clear, and only start a PHY operation when a write covers the OP/ST fields in the PHY maintenance register.

Fixes e9f186e514a7 ("cadence_gem: initial version of device model")

Message-id: [email protected]

---
 hw/net/cadence_gem.c | 55 +++++++++++++++++++++++++++-----------------
 1 file changed, 34 insertions(+), 21 deletions(-)
hw/net/cadence_gem.c +34 -21
index 9a94b3b8ca4..7456f0e18e7 100644
@@ -1603,8 +1603,11 @@ static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size)
 {
     CadenceGEMState *s;
     uint32_t retval;
+    unsigned shift;
+
     s = opaque;
 
+    shift = (offset & 3) * 8;
     offset >>= 2;
     retval = s->regs[offset];
 
@@ -1638,7 +1641,7 @@ static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size)
 
     DB_PRINT("0x%08x\n", retval);
     gem_update_int_status(s);
-    return retval;
+    return extract32(retval, shift, size * 8);
 }
 
 /*
@@ -1649,35 +1652,43 @@ static void gem_write(void *opaque, hwaddr offset, uint64_t val,
         unsigned size)
 {
     CadenceGEMState *s = (CadenceGEMState *)opaque;
-    uint32_t readonly;
+    uint32_t access_mask;
+    uint32_t writable_mask;
+    uint32_t write_val;
+    unsigned shift;
     int i;
 
     DB_PRINT("offset: 0x%04x write: 0x%08x ", (unsigned)offset, (unsigned)val);
+    shift = (offset & 3) * 8;
+    access_mask = MAKE_64BIT_MASK(shift, size * 8);
+    write_val = (uint32_t)val << shift;
     offset >>= 2;
 
     /* Squash bits which are read only in write value */
-    val &= ~(s->regs_ro[offset]);
-    /* Preserve (only) bits which are read only and wtc in register */
-    readonly = s->regs[offset] & (s->regs_ro[offset] | s->regs_w1c[offset]);
+    write_val &= ~(s->regs_ro[offset]);
 
-    /* Copy register write to backing store */
-    s->regs[offset] = (val & ~s->regs_w1c[offset]) | readonly;
+    /* Copy writable bits in the accessed lanes to the backing store */
+    writable_mask = access_mask &
+                    ~(s->regs_ro[offset] | s->regs_w1c[offset]);
+    s->regs[offset] = (s->regs[offset] & ~writable_mask) |
+                      (write_val & writable_mask);
 
     /* do w1c */
-    s->regs[offset] &= ~(s->regs_w1c[offset] & val);
+    s->regs[offset] &= ~(s->regs_w1c[offset] & write_val);
 
     /* Handle register write side effects */
     switch (offset) {
     case R_NWCTRL:
-        if (FIELD_EX32(val, NWCTRL, ENABLE_RECEIVE)) {
+        if (FIELD_EX32(write_val, NWCTRL, ENABLE_RECEIVE)) {
             for (i = 0; i < s->num_priority_queues; ++i) {
                 gem_get_rx_desc(s, i);
             }
         }
-        if (FIELD_EX32(val, NWCTRL, TRANSMIT_START)) {
+        if (FIELD_EX32(write_val, NWCTRL, TRANSMIT_START)) {
             gem_transmit(s);
         }
-        if (!(FIELD_EX32(val, NWCTRL, ENABLE_TRANSMIT))) {
+        if ((access_mask & R_NWCTRL_ENABLE_TRANSMIT_MASK) &&
+            !(FIELD_EX32(s->regs[offset], NWCTRL, ENABLE_TRANSMIT))) {
             /* Reset to start of Q when transmit disabled. */
             for (i = 0; i < s->num_priority_queues; i++) {
                 s->tx_desc_addr[i] = gem_get_tx_queue_base_addr(s, i);
@@ -1692,37 +1703,37 @@ static void gem_write(void *opaque, hwaddr offset, uint64_t val,
         gem_update_int_status(s);
         break;
     case R_RXQBASE:
-        s->rx_desc_addr[0] = val;
+        s->rx_desc_addr[0] = s->regs[offset];
         break;
     case R_RECEIVE_Q1_PTR ... R_RECEIVE_Q7_PTR:
-        s->rx_desc_addr[offset - R_RECEIVE_Q1_PTR + 1] = val;
+        s->rx_desc_addr[offset - R_RECEIVE_Q1_PTR + 1] = s->regs[offset];
         break;
     case R_TXQBASE:
-        s->tx_desc_addr[0] = val;
+        s->tx_desc_addr[0] = s->regs[offset];
         break;
     case R_TRANSMIT_Q1_PTR ... R_TRANSMIT_Q7_PTR:
-        s->tx_desc_addr[offset - R_TRANSMIT_Q1_PTR + 1] = val;
+        s->tx_desc_addr[offset - R_TRANSMIT_Q1_PTR + 1] = s->regs[offset];
         break;
     case R_RXSTATUS:
         gem_update_int_status(s);
         break;
     case R_IER:
-        s->regs[R_IMR] &= ~val;
+        s->regs[R_IMR] &= ~write_val;
         gem_update_int_status(s);
         break;
     case R_JUMBO_MAX_LEN:
-        s->regs[R_JUMBO_MAX_LEN] = val & MAX_JUMBO_FRAME_SIZE_MASK;
+        s->regs[R_JUMBO_MAX_LEN] &= MAX_JUMBO_FRAME_SIZE_MASK;
         break;
     case R_INT_Q1_ENABLE ... R_INT_Q7_ENABLE:
-        s->regs[R_INT_Q1_MASK + offset - R_INT_Q1_ENABLE] &= ~val;
+        s->regs[R_INT_Q1_MASK + offset - R_INT_Q1_ENABLE] &= ~write_val;
         gem_update_int_status(s);
         break;
     case R_IDR:
-        s->regs[R_IMR] |= val;
+        s->regs[R_IMR] |= write_val;
         gem_update_int_status(s);
         break;
     case R_INT_Q1_DISABLE ... R_INT_Q7_DISABLE:
-        s->regs[R_INT_Q1_MASK + offset - R_INT_Q1_DISABLE] |= val;
+        s->regs[R_INT_Q1_MASK + offset - R_INT_Q1_DISABLE] |= write_val;
         gem_update_int_status(s);
         break;
     case R_SPADDR1LO:
@@ -1738,7 +1749,9 @@ static void gem_write(void *opaque, hwaddr offset, uint64_t val,
         s->sar_active[(offset - R_SPADDR1HI) / 2] = true;
         break;
     case R_PHYMNTNC:
-        gem_handle_phy_access(s);
+        if (access_mask & (R_PHYMNTNC_OP_MASK | R_PHYMNTNC_ST_MASK)) {
+            gem_handle_phy_access(s);
+        }
         break;
     }
 
Signature · 1 line
2.43.0
#14 lore raw

[PULL 12/33] net/eth.c: Check for undersized IPv4 headers in eth_get_protocols()

In reply to Peter Maydell

In the IPv6 path of eth_get_protocols(), eth_parse_ipv6_hdr() does various sanity checks on the packet's IPv6 header, so we won't tell the caller we have an IPv6 header when we have a malformed one. However for IPv4 we only check the version and that we have at least the minimum header size.

Harden this codepath by checking also that the header size declared in the packet's own headers is neither smaller than the minimum nor larger than the actual packet size.

Missing these checks shouldn't cause problems if the caller is validating all offsets and lengths before use, but checking here too is defence-in-depth, hence the cc to stable.

Fixes 69ff5ef847457555 ("net/eth: Report if headers are actually present")

Message-id: [email protected]

---
 net/eth.c | 2 ++
 1 file changed, 2 insertions(+)
net/eth.c +2 -0
index 59b278b887c..038f7d889c3 100644
@@ -163,6 +163,8 @@ void eth_get_protocols(const struct iovec *iov, size_t iovcnt, size_t iovoff,
 
         copied = iov_to_buf(iov, iovcnt, *l3hdr_off, iphdr, sizeof(*iphdr));
         if (copied < sizeof(*iphdr) ||
+            IP_HDR_GET_LEN(iphdr) < sizeof(*iphdr) ||
+            input_size - *l3hdr_off < IP_HDR_GET_LEN(iphdr) ||
             IP_HEADER_VERSION(iphdr) != IP_HEADER_VERSION_4) {
             return;
         }
Signature · 1 line
2.43.0
#15 lore raw

[PULL 18/33] net/eth.c: Tighten size checks in eth_get_l3_proto()

In reply to Peter Maydell

Currently eth_get_l3_proto() has a check that the offset of the protocol field is not off the end of the iovec; this is actually unnecessary because iov_to_buf() guarantees to return 0 for offsets off the end of the iovec. On the other hand, it assumes that the l2hdr_len it is passed is not so small that the protocol offset calculation underflows and it doesn't check that the packet is actually big enough for the l2hdr_len. This shouldn't matter if other parts of the code are checking, but for defence in depth we tighten this check.

Fixes eb700029c783 ("net_pkt: Extend packet abstraction as required by e1000e functionality")

Message-id: [email protected]

---
 net/eth.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
net/eth.c +4 -2
index 74a705a2679..33b61cac414 100644
@@ -75,11 +75,13 @@ eth_get_l3_proto(const struct iovec *l2hdr_iov, int iovcnt, size_t l2hdr_len)
     uint16_t proto;
     size_t copied;
     size_t size = iov_size(l2hdr_iov, iovcnt);
-    size_t proto_offset = l2hdr_len - sizeof(proto);
+    size_t proto_offset;
 
-    if (size < proto_offset) {
+    if (l2hdr_len < sizeof(struct eth_header) || size < l2hdr_len) {
+        /* We don't have a complete ethernet header */
         return ETH_P_UNKNOWN;
     }
+    proto_offset = l2hdr_len - sizeof(proto);
 
     copied = iov_to_buf(l2hdr_iov, iovcnt, proto_offset,
                         &proto, sizeof(proto));
Signature · 1 line
2.43.0
#16 lore raw

[PULL 11/33] net/eth.c: Check for undersized L2 headers in eth_get_protocols()

In reply to Peter Maydell

From: Akihiko Odaki <[email protected]>

We already have some header bounds checks. Add a missing check for L2 headers.

Message-id: [email protected]

---
 net/eth.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
net/eth.c +12 -5
index 12ec316e240..59b278b887c 100644
@@ -139,21 +139,28 @@ void eth_get_protocols(const struct iovec *iov, size_t iovcnt, size_t iovoff,
     bool fragment = false;
     size_t input_size = iov_size(iov, iovcnt);
     size_t copied;
+    uint32_t hdr_size;
     uint8_t ip_p;
 
     *hasip4 = *hasip6 = false;
-    *l3hdr_off = iovoff + eth_get_l2_hdr_length_iov(iov, iovcnt, iovoff);
     l4hdr_info->proto = ETH_L4_HDR_PROTO_INVALID;
 
+    if (input_size < iovoff) {
+        return;
+    }
+
+    hdr_size = eth_get_l2_hdr_length_iov(iov, iovcnt, iovoff);
+    if (input_size - iovoff < hdr_size) {
+        return;
+    }
+
+    *l3hdr_off = iovoff + hdr_size;
+
     proto = eth_get_l3_proto(iov, iovcnt, *l3hdr_off);
 
     if (proto == ETH_P_IP) {
         struct ip_header *iphdr = &ip4hdr_info->ip4_hdr;
 
-        if (input_size < *l3hdr_off) {
-            return;
-        }
-
         copied = iov_to_buf(iov, iovcnt, *l3hdr_off, iphdr, sizeof(*iphdr));
         if (copied < sizeof(*iphdr) ||
             IP_HEADER_VERSION(iphdr) != IP_HEADER_VERSION_4) {
Signature · 1 line
2.43.0
#17 lore raw

[PULL 21/33] hw/net/net_tx_pkt: Sanity check virt hdr len in net_tx_tcp_fragment_init

In reply to Peter Maydell

In net_tx_pkt_tcp_fragment_init() we calculate the l4 header size by subtracting the packet's virt_hdr.hdr_len from its overall length, and then we g_malloc() that many bytes. This shouldn't underflow if the caller has been sanity checking sizes and offsets, but as defence-in-depth, check again here before relying on it for the malloc size.

This change would suffice to avoid the guest self-denial-of-service via overflowing the virt_hdr.hdr_len calculation in net_tx_pkt_tcp_fragment_init() which we fixed in the preceding commit.

Fixes 02ef5fdc092bd4 ("hw/net/net_tx_pkt: Implement TCP segmentation")

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3648

Message-id: [email protected]

---
 hw/net/net_tx_pkt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/net_tx_pkt.c +1 -1
index b2935900fe7..dc2563721e8 100644
@@ -604,7 +604,7 @@ static bool net_tx_pkt_tcp_fragment_init(struct NetTxPkt *pkt,
     size_t bytes_read = 0;
     struct tcp_hdr *th;
 
-    if (!pkt->payload_frags) {
+    if (!pkt->payload_frags || pkt->virt_hdr.hdr_len <= pkt->hdr_len) {
         return false;
     }
 
Signature · 1 line
2.43.0
#18 lore raw

[PULL 01/33] hw/ssi/stm32f2xx_spi: avoid transferring data on DR reads

In reply to Peter Maydell

From: Manuele Conti <[email protected]>

Writing SPI_DR already performs the synchronous SSI transfer and stores its response in spi_dr. Reading SPI_DR performs another transfer, using the previous response as transmit data, and returns the new response. Consequently a normal write/read pair clocks two frames on the bus and can skip bytes in a peripheral's response.

Return the response saved by the write and clear RXNE without starting another transfer. Repeated reads then leave the peripheral state alone.

Add a qtest using the upstream netduino2 machine and an M25P80 flash. Check the JEDEC ID, RXNE clearing, and repeated DR reads. The test requires no board changes and reproduces the unwanted extra transfers before the fix.

Fixes 5ae74402d1f ("STM32F2xx: Add the SPI device")

Message-id: [email protected]

---
 MAINTAINERS                      |  1 +
 hw/ssi/stm32f2xx_spi.c           |  1 -
 tests/qtest/stm32f2xx-spi-test.c | 50 ++++++++++++++++++++++++++++++++
 tests/qtest/meson.build          |  2 ++
 4 files changed, 53 insertions(+), 1 deletion(-)
 create mode 100644 tests/qtest/stm32f2xx-spi-test.c
MAINTAINERS +1 -0
index 3d53e104c5b..15942aaba3a 100644
@@ -1225,6 +1225,7 @@ F: hw/char/stm32f2xx_usart.c
 F: hw/timer/stm32f2xx_timer.c
 F: hw/adc/*
 F: hw/ssi/stm32f2xx_spi.c
+F: tests/qtest/stm32f2xx-spi-test.c
 F: include/hw/*/stm32*.h
 
 STM32F405
hw/ssi/stm32f2xx_spi.c +0 -1
index 871d57324d1..da1dbb7bd7a 100644
@@ -82,7 +82,6 @@ static uint64_t stm32f2xx_spi_read(void *opaque, hwaddr addr,
     case STM_SPI_SR:
         return s->spi_sr;
     case STM_SPI_DR:
-        stm32f2xx_spi_transfer(s);
         s->spi_sr &= ~STM_SPI_SR_RXNE;
         return s->spi_dr;
     case STM_SPI_CRCPR:
tests/qtest/stm32f2xx-spi-test.c new file +50 -0

50 lines not on this page · raw message

tests/qtest/meson.build +2 -0
index 79946960869..626791d1eb4 100644
@@ -258,6 +258,8 @@ qtests_exynos4210 = \
 qtests_arm = \
   (config_all_devices.has_key('CONFIG_OLIMEX_STM32_H405') ? \
    ['stm32f405-timer-test', 'stm32f405-rcc-test'] : []) + \
+  (config_all_devices.has_key('CONFIG_NETDUINO2') and
+   config_all_devices.has_key('CONFIG_SSI_M25P80') ? ['stm32f2xx-spi-test'] : []) + \
   (config_all_devices.has_key('CONFIG_MPS2') ? ['sse-timer-test'] : []) + \
   (config_all_devices.has_key('CONFIG_CMSDK_APB_DUALTIMER') ? ['cmsdk-apb-dualtimer-test'] : []) + \
   (config_all_devices.has_key('CONFIG_CMSDK_APB_TIMER') ? ['cmsdk-apb-timer-test'] : []) + \
Signature · 1 line
2.43.0
#19 lore raw

[PULL 10/33] hw/net/net_rx_pkt: Handle bogus l4hdr_off when validating SCTP checksum

In reply to Peter Maydell

In _net_rx_pkt_validate_sctp_sum() we calculate a checksum that starts at the NetRxPkt::l4hdr_off offset. If this offset (which might be guest controlled) is larger than the size of the packet, the loop that walks through the iovec can walk off the end of it. The resulting out-of-bounds read in attempting to convert the iov to a buffer might cause a segfault.

We also weren't correctly checking the return values of iov_to_buf() and iov_from_buf() when reading and writing the checksum word: if the l4hdr_off claims the checksum word is half off the end of the packet these functions will return the count of how much data they were able to access, and we should fail if they don't write the entire 4 byte word.

Return "checksum not valid" if the l4hdr_off is too large or the iov accesses don't do the full read/write.

Note that this affects only the igb network device; the other user of this function (e1000e) does its own check on the l4 header and won't calculate a checksum if it's out of range.

Fixes 907209e3111dd62 ("igb: Implement Rx SCTP CSO")

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4138

Message-id: [email protected]

---
 hw/net/net_rx_pkt.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
hw/net/net_rx_pkt.c +8 -4
index f87b6f046cc..03a35f03154 100644
@@ -549,19 +549,23 @@ _net_rx_pkt_validate_sctp_sum(struct NetRxPkt *pkt)
     uint32_t original;
     bool valid;
 
-    for (vec = pkt->vec; vec->iov_len < off; vec++) {
+    for (vec = pkt->vec; vec_len > 0 && vec->iov_len < off; vec++) {
         off -= vec->iov_len;
         vec_len--;
     }
+    if (vec_len == 0) {
+        return false;
+    }
 
     csum_off = off + 8;
 
-    if (!iov_to_buf(vec, vec_len, csum_off, &original, sizeof(original))) {
+    if (iov_to_buf(vec, vec_len, csum_off,
+                   &original, sizeof(original)) != sizeof(original)) {
         return false;
     }
 
-    if (!iov_from_buf(vec, vec_len, csum_off,
-                      &calculated, sizeof(calculated))) {
+    if (iov_from_buf(vec, vec_len, csum_off,
+                     &calculated, sizeof(calculated)) != sizeof(calculated)) {
         return false;
     }
 
Signature · 1 line
2.43.0
#20 lore raw

[PULL 23/33] hw/net/net_rx_pkt: Check for overflow in _net_rx_pkt_calc_l4_csum()

In reply to Peter Maydell

In _net_rx_pkt_calc_l4_csum() we calculate the number of bytes to run the checksum over by subtracting the IP header length from the total IP packet size. This shouldn't underflow if other parts of the code have been correctly checking and calculating sizes and offsets, but for defence in depth check here, and don't checksum any bytes if we would otherwise underflow.

Fixes eb700029c783 ("net_pkt: Extend packet abstraction as required by e1000e functionality")

Message-id: [email protected]

---
 hw/net/net_rx_pkt.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
hw/net/net_rx_pkt.c +6 -4
index 03a35f03154..110496e9c81 100644
@@ -501,8 +501,10 @@ _net_rx_pkt_calc_l4_csum(struct NetRxPkt *pkt)
             csl = be16_to_cpu(pkt->l4hdr_info.hdr.udp.uh_ulen);
             trace_net_rx_pkt_l4_csum_calc_ip4_udp();
         } else {
-            csl = be16_to_cpu(pkt->ip4hdr_info.ip4_hdr.ip_len) -
-                  IP_HDR_GET_LEN(&pkt->ip4hdr_info.ip4_hdr);
+            uint16_t iplen = be16_to_cpu(pkt->ip4hdr_info.ip4_hdr.ip_len);
+            uint16_t iphdr_len = IP_HDR_GET_LEN(&pkt->ip4hdr_info.ip4_hdr);
+
+            csl = (iplen >= iphdr_len) ? (iplen - iphdr_len) : 0;
             trace_net_rx_pkt_l4_csum_calc_ip4_tcp();
         }
 
@@ -517,9 +519,9 @@ _net_rx_pkt_calc_l4_csum(struct NetRxPkt *pkt)
             struct ip6_header *ip6hdr = &pkt->ip6hdr_info.ip6_hdr;
             size_t full_ip6hdr_len = pkt->l4hdr_off - pkt->l3hdr_off;
             size_t ip6opts_len = full_ip6hdr_len - sizeof(struct ip6_header);
+            uint16_t plen = be16_to_cpu(ip6hdr->ip6_ctlun.ip6_un1.ip6_un1_plen);
 
-            csl = be16_to_cpu(ip6hdr->ip6_ctlun.ip6_un1.ip6_un1_plen) -
-                  ip6opts_len;
+            csl = (plen >= ip6opts_len) ? (plen - ip6opts_len) : 0;
             trace_net_rx_pkt_l4_csum_calc_ip6_tcp();
         }
 
Signature · 1 line
2.43.0
#21 lore raw

[PULL 29/33] Revert ".dir-locals: include QEMU code in PYTHONPATH"

In reply to Peter Maydell

From: Alex Bennée <[email protected]>

Unfortunately this relied on trusting the source tree via the safe-local-variable-directories otherwise users keep being prompted that ".dir-locals.el contains values that may not be safe".

An alternative is for the user to add something like this to their local emacs config:

(defun my-return-source-if-in-qemu-tree()
"Return the root of source when in QEMU code."
(when-let ((src (expand-file-name (locate-dominating-file default-directory ".git"))))
(if (file-exists-p (concat src "/qemu-options.hx"))
src)))

(defun my-set-qemu-python-path()
"Set local python environment for QEMU."
(when-let ((root (my-return-source-if-in-qemu-tree)))
(setq-local process-environment (copy-sequence process-environment)) (setenv "PYTHONPATH" (concat (expand-file-name "python" root) ":"
(expand-file-name "tests/functional" root)))))

(use-package python
:hook ((python-mode python-ts-mode) . my-set-qemu-python-path))

This reverts commit 3112269be3ac92343a5f0e5d9eae919edd176a35.

Message-id: [email protected]

---
 .dir-locals.el | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
.dir-locals.el +1 -7
index 51871619422..3ac0cfc6f0d 100644
@@ -1,8 +1,2 @@
 ((c-mode . ((c-file-style . "stroustrup")
-	    (indent-tabs-mode . nil)))
- (python-mode .
-              ((eval . (when-let* ((root (locate-dominating-file default-directory ".dir-locals.el")))
-                         (setq-local process-environment (copy-sequence process-environment))
-                         (setenv "PYTHONPATH"
-                                 (concat (expand-file-name "python" root) ":"
-                                         (expand-file-name "tests/functional" root))))))))
+	    (indent-tabs-mode . nil))))
Signature · 1 line
2.43.0
#22 lore raw

[PULL 09/33] include/hw/core/ptimer.h: Fix 'version' argument of VMSTATE_PTIMER

In reply to Peter Maydell

The VMSTATE_PTIMER macro is defined to pass a 'version' argument of 1 to VMSTATE_STRUCT_POINTER_TEST_V. This means that the field will only be used in migration when the vmstate struct that uses VMSTATE_PTIMER has a version_id of at least 1. This doesn't match how we define other VMSTATE_FOO which don't take an explicit version_id, which is to use a version argument of 0 (e.g. all the common macros like VMSTATE_UINT32 are written to pass 0 to their VMSTATE_UINT32_V counterparts, and so on). It also doesn't match how we define VMSTATE_PTIMER_ARRAY.

The practical effect of this is that users of VMSTATE_PTIMER in vmstate structs which explicitly or implicitly have a version_id of 0 were actually not getting their ptimers migrated.

This affects:
vmstate_xlnx_csu_dma in wh/dma/xlnx_csu_dma.c
vmstate_k230_wdt in hw/watchdog/k230_wdt.c

which are used in:
* Arm Xilinx versal and zynq machines
* RISC-V K230 machine

Most ptimer users are unaffected because they took the usual approach of explicitly setting their starting version_id to 1.

Fix the version_id in this field. This is a migration compatibility break for all the above listed devices/machines. Since the timers involved are in devices where the timer is usually stopped (e.g. the watchdogs only have the timer active when the watchdog is enabled and counting down), the consequences of the bug are likely not visible to most users.

We could perhaps attempt to preserve migration compatibility here, but none of the affected machine types are versioned and so we do not promise cross-version compatibility, so do the simple thing. Bump the version_id and version_id on the two affected vmstate structs so that attempted migration between old and new QEMU fails cleanly.

Fixes 852f771ec9e5c ("vmstate: port pmtimer")

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4705

Message-id: [email protected]

---
 include/hw/core/ptimer.h | 2 +-
 hw/dma/xlnx_csu_dma.c    | 4 ++--
 hw/watchdog/k230_wdt.c   | 2 ++
 3 files changed, 5 insertions(+), 3 deletions(-)
include/hw/core/ptimer.h +1 -1
index 4dc02b0de47..8513f8917e3 100644
@@ -300,7 +300,7 @@ void ptimer_stop(ptimer_state *s);
 extern const VMStateDescription vmstate_ptimer;
 
 #define VMSTATE_PTIMER(_field, _state) \
-    VMSTATE_STRUCT_POINTER_V(_field, _state, 1, vmstate_ptimer, ptimer_state)
+    VMSTATE_STRUCT_POINTER_V(_field, _state, 0, vmstate_ptimer, ptimer_state)
 
 #define VMSTATE_PTIMER_ARRAY(_f, _s, _n)                                \
     VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(_f, _s, _n, 0,                   \
hw/dma/xlnx_csu_dma.c +2 -2
index 436f9915e02..ea703dc00ce 100644
@@ -679,8 +679,8 @@ static void xlnx_csu_dma_realize(DeviceState *dev, Error **errp)
 
 static const VMStateDescription vmstate_xlnx_csu_dma = {
     .name = TYPE_XLNX_CSU_DMA,
-    .version_id = 0,
-    .minimum_version_id = 0,
+    .version_id = 1,
+    .minimum_version_id = 1,
     .fields = (const VMStateField[]) {
         VMSTATE_PTIMER(src_timer, XlnxCSUDMA),
         VMSTATE_UINT16(width, XlnxCSUDMA),
hw/watchdog/k230_wdt.c +2 -0
index 1f83b499e82..fba2013b8f3 100644
@@ -234,6 +234,8 @@ static const MemoryRegionOps k230_wdt_ops = {
 
 static const VMStateDescription vmstate_k230_wdt = {
     .name = "k230.wdt",
+    .version_id = 1,
+    .minimum_version_id = 1,
     .fields = (const VMStateField[]) {
         VMSTATE_PTIMER(timer, K230WdtState),
         VMSTATE_UINT32(cr, K230WdtState),
Signature · 1 line
2.43.0
#23 lore raw

[PULL 25/33] net: Pad short packets consistently regardless of backend

In reply to Peter Maydell

Currently our handling of short network packets (i.e. those which are smaller than the minimum ethernet frame size of 60 bytes) is a little confused. The intention is that we allow network device models to transmit short packets, but we protect them from having to deal with receiving short packets unless they explicitly opt into it. This means we don't have to have a lot of code in each network device to try to handle the short packet size -- historically that code was untested, and often a source of "carefully crafted packet can cause an out-of-bounds memory access" bugs.

Our implementation of the padding is currently done when each network backend feeds a packet into the system via one of the qemu_send_packet family of functions. This mostly works, except that we missed some of the more obscure backends (e.g. the socket backend), and it means code duplication in each backend. We'd like to switch to making qemu_send_packet do the padding itself. To do that, we first need to make sure that all the NetClientState implementations which do not want padding set the do_not_pad flag. We do this by setting the flag for NetClientState instances created by qemu_new_net_client() and qemu_new_net_control_client(). Emulated network devices use qemu_new_nic(), which does not set the flag.

Note that this also causes the net/hub client to request no padding. This is the right behaviour: we want the hub to accept short packets and forward them on to all destinations. Each destination then gets to choose whether it sees a padded packet or the short one. The hub.c code is length-agnostic and doesn't look inside the packets it is passing on, so it has no issues with short packets.

That change means we can rely on do_not_pad being correct for all NetClientInfo structs, and so we can pad short packets in the qemu_send_packet() and qemu_sendv_packet() family of functions.

If the callsite is already padding, then this will have no effect, but callsites like the socket and dgram backends will now correctly add padding. This fixes the bug where when two QEMU instances are connected via one of those backends a short ARP packet transmitted by one is not correctly padded by the other and gets dropped.

Note that if we pad a packet, our return value on success will be the size of the padded packet, not the original. This is OK because this function (like the NetQueueDeliverFunc function type documented in include/net/queue.h and which we will eventually end up calling and returning the return value of) returns

Quoted 1 line

0 - success

0 - queue packet for future redelivery
<0 - failure (discard packet)
and doesn't guarantee to return exactly the size of the packet sent. None of the callers try to use the return value as an exact size.

Cc: [email protected]
Fixes: CVE-2026-118490
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2362

Message-id: [email protected]

---
 include/net/eth.h | 22 ++++++++++++++++++++++
 include/net/net.h |  3 ++-
 net/eth.c         | 18 ++++++++++++++++++
 net/net.c         | 32 ++++++++++++++++++++++++++++----
 net/tap.c         |  2 +-
 5 files changed, 71 insertions(+), 6 deletions(-)
include/net/eth.h +22 -0
index 3e83f5d68c0..a1bc0c2fd58 100644
@@ -439,4 +439,26 @@ eth_parse_ipv6_hdr(const struct iovec *pkt, int pkt_frags,
 bool eth_pad_short_frame(uint8_t *padded_pkt, size_t *padded_buflen,
                          const void *pkt, size_t pkt_size);
 
+/**
+ * eth_pad_short_frame_iov - pad a short frame, iovec version
+ *
+ * This is equivalent to eth_pad_short_frame(), except that it works
+ * on a packet stored in a struct iovec.
+ *
+ * If the Ethernet frame size is shorter than 60 bytes, it will be padded to
+ * 60 bytes at the address @padded_pkt (and the caller will need to handle
+ * it as a not-in-an-iovec packet).
+ *
+ * @padded_pkt: buffer address to hold the padded frame
+ * @padded_buflen: pointer holding length of @padded_pkt. If the frame is
+ *                 padded, the length will be updated to the padded one.
+ * @iov: iovec holding the original Ethernet frame
+ * @iovcnt: number of elements in @iov
+ * @pkt_size: size of the original Ethernet frame (i.e. iov_size(iov, iovcnt))
+ * @return true if the frame is padded, otherwise false
+ */
+bool eth_pad_short_frame_iov(uint8_t *padded_pkt, size_t *padded_buflen,
+                             const struct iovec *iov, int iovcnt,
+                             size_t pkt_size);
+
 #endif
include/net/net.h +2 -1
index de4f03c3013..c2fd451f17e 100644
@@ -171,7 +171,8 @@ void qemu_net_client_setup(NetClientState *nc,
                            const char *model,
                            const char *name,
                            NetClientDestructor *destructor,
-                           bool is_datapath);
+                           bool is_datapath,
+                           bool do_not_pad);
 NetClientState *qemu_new_net_client(NetClientInfo *info,
                                     NetClientState *peer,
                                     const char *model,
net/eth.c +18 -0
index 33b61cac414..d5590bb671e 100644
@@ -615,3 +615,21 @@ bool eth_pad_short_frame(uint8_t *padded_pkt, size_t *padded_buflen,
 
     return true;
 }
+
+bool eth_pad_short_frame_iov(uint8_t *padded_pkt, size_t *padded_buflen,
+                             const struct iovec *iov, int iovcnt,
+                             size_t pkt_size)
+{
+    assert(padded_buflen && *padded_buflen >= ETH_ZLEN);
+
+    if (pkt_size >= ETH_ZLEN) {
+        return false;
+    }
+
+    /* pad to minimum Ethernet frame length */
+    iov_to_buf(iov, iovcnt, 0, padded_pkt, pkt_size);
+    memset(&padded_pkt[pkt_size], 0, ETH_ZLEN - pkt_size);
+    *padded_buflen = ETH_ZLEN;
+
+    return true;
+}
net/net.c +28 -4
index bf7e5d9b125..7c7fb4bd30e 100644
@@ -267,7 +267,8 @@ void qemu_net_client_setup(NetClientState *nc,
                            const char *model,
                            const char *name,
                            NetClientDestructor *destructor,
-                           bool is_datapath)
+                           bool is_datapath,
+                           bool do_not_pad)
 {
     nc->info = info;
     nc->model = g_strdup(model);
@@ -287,6 +288,7 @@ void qemu_net_client_setup(NetClientState *nc,
     nc->incoming_queue = qemu_new_net_queue(qemu_deliver_packet_iov, nc);
     nc->destructor = destructor;
     nc->is_datapath = is_datapath;
+    nc->do_not_pad = do_not_pad;
     QTAILQ_INIT(&nc->filters);
 }
 
@@ -301,7 +303,7 @@ NetClientState *qemu_new_net_client(NetClientInfo *info,
 
     nc = g_malloc0(info->size);
     qemu_net_client_setup(nc, info, peer, model, name,
-                          qemu_net_client_destructor, true);
+                          qemu_net_client_destructor, true, true);
 
     return nc;
 }
@@ -317,7 +319,7 @@ NetClientState *qemu_new_net_control_client(NetClientInfo *info,
 
     nc = g_malloc0(info->size);
     qemu_net_client_setup(nc, info, peer, model, name,
-                          qemu_net_client_destructor, false);
+                          qemu_net_client_destructor, false, true);
 
     return nc;
 }
@@ -344,7 +346,7 @@ NICState *qemu_new_nic(NetClientInfo *info,
 
     for (i = 0; i < queues; i++) {
         qemu_net_client_setup(&nic->ncs[i], info, peers[i], model, name,
-                              NULL, true);
+                              NULL, true, false);
         nic->ncs[i].queue_index = i;
     }
 
@@ -742,6 +744,8 @@ static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender,
 {
     NetQueue *queue;
     int ret;
+    uint8_t min_pkt[ETH_ZLEN];
+    size_t min_pktsz = sizeof(min_pkt);
 
 #ifdef DEBUG_NET
     printf("qemu_send_packet_async:\n");
@@ -752,6 +756,13 @@ static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender,
         return size;
     }
 
+    if (net_peer_needs_padding(sender)) {
+        if (eth_pad_short_frame(min_pkt, &min_pktsz, buf, size)) {
+            buf = min_pkt;
+            size = min_pktsz;
+        }
+    }
+
     /* Let filters handle the packet first */
     ret = filter_receive(sender, NET_FILTER_DIRECTION_TX,
                          sender, flags, buf, size, sent_cb);
@@ -906,6 +917,19 @@ ssize_t qemu_sendv_packet_async(NetClientState *sender,
         return size;
     }
 
+    if (net_peer_needs_padding(sender)) {
+        uint8_t min_pkt[ETH_ZLEN];
+        size_t min_pktsz = sizeof(min_pkt);
+
+        /*
+         * If we pad the packet, we get back a simple buffer, so handle
+         * it by sending it to the non-iov qemu_send_packet function
+         */
+        if (eth_pad_short_frame_iov(min_pkt, &min_pktsz, iov, iovcnt, size)) {
+            return qemu_send_packet_async(sender, min_pkt, min_pktsz, sent_cb);
+        }
+    }
+
     /* Let filters handle the packet first */
     ret = filter_receive_iov(sender, NET_FILTER_DIRECTION_TX, sender,
                              QEMU_NET_PACKET_FLAG_NONE, iov, iovcnt, sent_cb);
net/tap.c +1 -1
index 9bce0d088f9..ee6430d34a5 100644
@@ -627,7 +627,7 @@ static TAPState *new_tap(NetClientState *peer,
     TAPState *s = TAP_NETDEV(object_new(TYPE_TAP_NETDEV));
 
     qemu_net_client_setup(&s->nc, &net_tap_info, peer, model, name,
-                          tap_net_client_destructor, true);
+                          tap_net_client_destructor, true, true);
 
     s->queue_index = queue_index;
 
Signature · 1 line
2.43.0
#24 lore raw

[PULL 26/33] net: Remove padding code from net backends

In reply to Peter Maydell

We can remove the short-frame padding code from the net backends that were previously doing it, because the qemu_send_packet and qemu_sendv_packet calls they use now do the padding for them.

Message-id: [email protected]

---
 net/slirp.c        |  9 ---------
 net/tap-win32.c    | 15 ++-------------
 net/tap.c          |  9 ---------
 net/vmnet-common.m | 11 -----------
 4 files changed, 2 insertions(+), 42 deletions(-)
net/slirp.c +0 -9
index 451c0fd1ba4..eea12e79816 100644
@@ -120,15 +120,6 @@ static ssize_t net_slirp_send_packet(const void *pkt, size_t pkt_len,
                                      void *opaque)
 {
     SlirpState *s = opaque;
-    uint8_t min_pkt[ETH_ZLEN];
-    size_t min_pktsz = sizeof(min_pkt);
-
-    if (net_peer_needs_padding(&s->nc)) {
-        if (eth_pad_short_frame(min_pkt, &min_pktsz, pkt, pkt_len)) {
-            pkt = min_pkt;
-            pkt_len = min_pktsz;
-        }
-    }
 
     return qemu_send_packet(&s->nc, pkt, pkt_len);
 }
net/tap-win32.c +2 -13
index 38baf90e0b3..2fccfdbaacf 100644
@@ -682,25 +682,14 @@ static ssize_t tap_receive(NetClientState *nc, const uint8_t *buf, size_t size)
 static void tap_win32_send(void *opaque)
 {
     TAPState *s = opaque;
-    uint8_t *buf, *orig_buf;
+    uint8_t *buf;
     int max_size = 4096;
     int size;
-    uint8_t min_pkt[ETH_ZLEN];
-    size_t min_pktsz = sizeof(min_pkt);
 
     size = tap_win32_read(s->handle, &buf, max_size);
     if (size > 0) {
-        orig_buf = buf;
-
-        if (net_peer_needs_padding(&s->nc)) {
-            if (eth_pad_short_frame(min_pkt, &min_pktsz, buf, size)) {
-                buf = min_pkt;
-                size = min_pktsz;
-            }
-        }
-
         qemu_send_packet(&s->nc, buf, size);
-        tap_win32_free_buffer(s->handle, orig_buf);
+        tap_win32_free_buffer(s->handle, buf);
     }
 }
 
net/tap.c +0 -9
index ee6430d34a5..9f3d0b08ab7 100644
@@ -261,8 +261,6 @@ static void tap_send(void *opaque)
 
     while (true) {
         uint8_t *buf = s->buf;
-        uint8_t min_pkt[ETH_ZLEN];
-        size_t min_pktsz = sizeof(min_pkt);
 
         size = tap_read_packet(s->fd, s->buf, sizeof(s->buf));
         if (size <= 0) {
@@ -279,13 +277,6 @@ static void tap_send(void *opaque)
             size -= s->host_vnet_hdr_len;
         }
 
-        if (net_peer_needs_padding(&s->nc)) {
-            if (eth_pad_short_frame(min_pkt, &min_pktsz, buf, size)) {
-                buf = min_pkt;
-                size = min_pktsz;
-            }
-        }
-
         size = qemu_send_packet_async(&s->nc, buf, size, tap_send_completed);
         if (size == 0) {
             tap_read_poll(s, false);
net/vmnet-common.m +0 -11
index ab33ce2b0c2..4dfc8abbc15 100644
@@ -150,23 +150,12 @@ static void vmnet_write_packets_to_qemu(VmnetState *s)
 {
     uint8_t *pkt;
     size_t pktsz;
-    uint8_t min_pkt[ETH_ZLEN];
-    size_t min_pktsz;
     ssize_t size;
 
     while (s->packets_send_current_pos < s->packets_send_end_pos) {
         pkt = s->iov_buf[s->packets_send_current_pos].iov_base;
         pktsz = s->packets_buf[s->packets_send_current_pos].vm_pkt_size;
 
-        if (net_peer_needs_padding(&s->nc)) {
-            min_pktsz = sizeof(min_pkt);
-
-            if (eth_pad_short_frame(min_pkt, &min_pktsz, pkt, pktsz)) {
-                pkt = min_pkt;
-                pktsz = min_pktsz;
-            }
-        }
-
         size = qemu_send_packet_async(&s->nc, pkt, pktsz,
                                       vmnet_send_completed);
 
Signature · 1 line
2.43.0
#25 lore raw

[PULL 03/33] hw/intc/arm_gicv5: Use cached IRS_IST_BASER.VALID state

In reply to Peter Maydell

When the guest writes to IRS_IST_BASER we effectively cache the value of the VALID bit in the GICv5ISTConfig valid field entry. In a few places we check whether the IST is valid by doing a bit extract on the register value; switch those to look at cfg->structure instead.

Message-id: [email protected]

---
 hw/intc/arm_gicv5.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
hw/intc/arm_gicv5.c +3 -4
index 5d0a50ab6aa..d0a8574916b 100644
@@ -1222,8 +1222,7 @@ static void irs_map_l2_istr_write(GICv5 *s, GICv5Domain domain, uint64_t value)
     uint64_t l1_iste;
     MemTxResult res;
 
-    if (!FIELD_EX64(cs->irs_ist_baser[domain], IRS_IST_BASER, VALID) ||
-        !cfg->structure) {
+    if (!cfg->valid || !cfg->structure) {
         /* WI if no IST set up or it is not 2-level */
         return;
     }
@@ -1293,7 +1292,7 @@ static void irs_ist_baser_write(GICv5 *s, GICv5Domain domain, uint64_t value)
 {
     GICv5Common *cs = ARM_GICV5_COMMON(s);
 
-    if (FIELD_EX64(cs->irs_ist_baser[domain], IRS_IST_BASER, VALID)) {
+    if (s->phys_lpi_config[domain].valid) {
         /* If VALID is set, ADDR is RO and we can only update VALID */
         bool valid = FIELD_EX64(value, IRS_IST_BASER, VALID);
         if (valid) {
@@ -1604,7 +1603,7 @@ static bool config_writel(GICv5 *s, GICv5Domain domain, hwaddr offset,
                             deposit64(cs->irs_ist_baser[domain], 32, 32, data));
         return true;
     case A_IRS_IST_CFGR:
-        if (FIELD_EX64(cs->irs_ist_baser[domain], IRS_IST_BASER, VALID)) {
+        if (s->phys_lpi_config[domain].valid) {
             qemu_log_mask(LOG_GUEST_ERROR,
                           "guest tried to write IRS_IST_CFGR for %s config frame "
                           "while IST_BASER.VALID set\n", domain_name[domain]);
Signature · 1 line
2.43.0
#26 lore raw

[PULL 15/33] net/eth.c: In eth_parse_ipv6_hdr(), fix check of input size

In reply to Peter Maydell

From: Akihiko Odaki <[email protected]>

We already have some L4/L5 header bound checks. Add the missing coverage for IPv6.

The IPv6 header parser incorrectly derives L4 offsets greater than actual values. Adding a bound check without fixing it would reject valid packets while fixing it without adding a bound check can result in an out-of-bounds access, so fix it along with the bound check addition.

One fixed problem of the parser is that extension header size is not properly computed for the Fragment Header and the IP Authentication Header.

RFC 8200 "Internet Protocol, Version 6 (IPv6) Specification" section 4.5. "Fragment Header" says the Fragment Header has a fixed size. The byte represented by ext_hdr.ip6r_len is reserved and "ignored on reception".

RFC 4302 "IP Authentication Header" section 2.2. "Payload Length" says it specifies the length of AH in 32-bit words (4-byte units), minus "2".

Another fixed problem is that the parser continues parsing extensions in noninitial fragments.

RFC 8200 "Internet Protocol, Version 6 (IPv6) Specification" section 4.5 "Fragment Header" says the noninitial fragment packets have the Fragment Header containing "the Next Header value that identifies the first header after the Per-Fragment headers of the original packet" followed by "the fragment itself."

Therefore, the data following the Fragment Header in the noninitial fragment packet must be treated as a fragment instead of another extension header, regardless of the Next Header value the Fragment Header contains.

Fixes eb700029c783 ("net_pkt: Extend packet abstraction as required by e1000e functionality")
Fixes 75020a702151 ("Common definitions for VMWARE devices")

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4155

Message-id: [email protected]

[PMM: fixed typo in comment]
---
 net/eth.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 56 insertions(+), 5 deletions(-)
net/eth.c +56 -5
index 55d85cecd1d..484f61ef31d 100644
@@ -16,6 +16,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/bitops.h"
 #include "qemu/log.h"
 #include "net/eth.h"
 #include "net/checksum.h"
@@ -473,7 +474,9 @@ bool eth_parse_ipv6_hdr(const struct iovec *pkt, int pkt_frags,
     struct ip6_ext_hdr ext_hdr;
     size_t bytes_read;
     uint8_t curr_ext_hdr_type;
+    uint16_t buf;
     size_t input_size = iov_size(pkt, pkt_frags);
+    bool subsequent = false;
 
     info->rss_ex_dst_valid = false;
     info->rss_ex_src_valid = false;
@@ -513,25 +516,73 @@ bool eth_parse_ipv6_hdr(const struct iovec *pkt, int pkt_frags,
             return false;
         }
 
-        if (curr_ext_hdr_type == IP6_ROUTING) {
+        switch (curr_ext_hdr_type) {
+        case IP6_ROUTING:
             if (ext_hdr.ip6r_len == sizeof(struct in6_address) / 8) {
                 info->rss_ex_dst_valid =
                     _eth_get_rss_ex_dst_addr(pkt, pkt_frags,
                                              ip6hdr_off + info->full_hdr_len,
                                              &ext_hdr, &info->rss_ex_dst);
             }
-        } else if (curr_ext_hdr_type == IP6_DESTINATON) {
+            info->full_hdr_len += (ext_hdr.ip6r_len + 1) * IP6_EXT_GRANULARITY;
+            break;
+
+        case IP6_DESTINATON:
             info->rss_ex_src_valid =
                 _eth_get_rss_ex_src_addr(pkt, pkt_frags,
                                          ip6hdr_off + info->full_hdr_len,
                                          &ext_hdr, &info->rss_ex_src);
-        } else if (curr_ext_hdr_type == IP6_FRAGMENT) {
+            info->full_hdr_len += (ext_hdr.ip6r_len + 1) * IP6_EXT_GRANULARITY;
+            break;
+
+        case IP6_FRAGMENT:
+            bytes_read = iov_to_buf(pkt, pkt_frags,
+                                    ip6hdr_off + info->full_hdr_len + 2,
+                                    &buf, sizeof(buf));
+            if (bytes_read < sizeof(buf)) {
+                return false;
+            }
+
+            /*
+             * Per RFC 8200, the Fragment header does not have the Hdr Ext Len.
+             */
+            info->full_hdr_len += 8;
+
             info->fragment = true;
+
+            /*
+             * Detect a subsequent fragment per RFC 8200.
+             *
+             * A subsequent fragment contains no extension headers while the
+             * Next Header value identifies the first header after the
+             * Per-Fragment headers of the original packet.
+             *
+             * The subsequent fragment is detected by checking if the Fragment
+             * Offset is nonzero.
+             */
+            subsequent = extract16(be16_to_cpu(buf), 3, 13);
+            break;
+
+        case IP6_AUTHENTICATION:
+            /*
+             * Per RFC 4302, the Authentication Header has the Payload Len
+             * instead of the Hdr Ext Len. The Payload Len specifies the length
+             * of AH in 4-byte units.
+             */
+            info->full_hdr_len += (ext_hdr.ip6r_len + 2) * 4;
+            break;
+
+        default:
+            info->full_hdr_len += (ext_hdr.ip6r_len + 1) * IP6_EXT_GRANULARITY;
         }
 
-        info->full_hdr_len += (ext_hdr.ip6r_len + 1) * IP6_EXT_GRANULARITY;
         curr_ext_hdr_type = ext_hdr.ip6r_nxt;
-    } while (eth_is_ip6_extension_header_type(curr_ext_hdr_type));
+    } while (!subsequent &&
+             eth_is_ip6_extension_header_type(curr_ext_hdr_type));
+
+    if (input_size < ip6hdr_off + info->full_hdr_len) {
+        return false;
+    }
 
     info->l4proto = ext_hdr.ip6r_nxt;
     return true;
Signature · 1 line
2.43.0
#27 lore raw

[PULL 28/33] hw/arm: Deprecate Nuvoton quanta-gsj board model

In reply to Peter Maydell

The latest OpenBMC release as of June 2026 no longer supports the quanta-gsj board model (as noted in docs/system/arm/nuvoton.rst); support was removed by OpenBMC back in 2023:
https://github.com/openbmc/openbmc/commit/ab5062cf6f562ad0c844570ba1ea0089961848ca

If OpenBMC don't care about this model any more, it's unlikely to have many users. Deprecate it, with the intention of deletion after the usual two-release period.

Message-id: [email protected]

---
 docs/about/deprecated.rst | 10 ++++++++++
 hw/arm/npcm7xx_boards.c   |  1 +
 2 files changed, 11 insertions(+)
docs/about/deprecated.rst +10 -0
index 0891bbc44de..de7d502babb 100644
@@ -287,6 +287,16 @@ The machine never got fully implemented and can only show the firmware prompt.
 Given the incomplete state and slow progress on improvements, it might get
 removed again without replacement.
 
+``quanta-gsj`` Arm machine (since 11.2)
+'''''''''''''''''''''''''''''''''''''''
+
+The ``quanta-gsj`` machine models a system with a Nuvoton SoC
+intended for use as a baseband management controller in a server.
+Support for this machine type was dropped from the OpenBMC project
+in 2023. If OpenBMC no longer care about this hardware, the QEMU
+model is unlikely to have many users, so we are deprecating it.
+Users should consider one of the other Nuvoton-based board models.
+
 
 Backend options
 ---------------
hw/arm/npcm7xx_boards.c +1 -0
index 9c526a26839..ec4b530986b 100644
@@ -496,6 +496,7 @@ static void gsj_machine_class_init(ObjectClass *oc, const void *data)
     mc->init = quanta_gsj_init;
     mc->auto_create_sdcard = true;
     mc->default_ram_size = 512 * MiB;
+    mc->deprecation_reason = "No longer supported by OpenBMC";
 };
 
 static void gbs_bmc_machine_class_init(ObjectClass *oc, const void *data)
Signature · 1 line
2.43.0
#28 lore raw

[PULL 22/33] hw/net/net_tx_pkt: Sanity check L2+L3 header len in net_tx_pkt_parse_headers()

In reply to Peter Maydell

In net_tx_pkt_parse_headers() we examine the L2 and L3 headers one after the other. Add a sanity check that the two together don't exceed the packet length or the maximum IP packet size. This shouldn't happen if the L3 parsing was done right, but is worth doing for defence-in-depth.

Fixes e263cd49c73c595 ("Packet abstraction for VMWARE network devices")

Message-id: [email protected]

---
 hw/net/net_tx_pkt.c | 8 ++++++++
 1 file changed, 8 insertions(+)
hw/net/net_tx_pkt.c +8 -0
index dc2563721e8..c331628134e 100644
@@ -267,6 +267,14 @@ static bool net_tx_pkt_parse_headers(struct NetTxPkt *pkt)
         break;
     }
 
+    if (l2_hdr->iov_len + l3_hdr->iov_len > ETH_MAX_IP_DGRAM_LEN ||
+        l2_hdr->iov_len + l3_hdr->iov_len >
+        iov_size(pkt->raw, pkt->raw_frags)) {
+        l2_hdr->iov_len = 0;
+        l3_hdr->iov_len = 0;
+        return false;
+    }
+
     net_tx_pkt_calculate_hdr_len(pkt);
     return true;
 }
Signature · 1 line
2.43.0
#29 lore raw

[PULL 33/33] hw/arm/virt-acpi-build: test vms->acpi_dev before building HEST

In reply to Peter Maydell

From: Ren Yanyi <[email protected]>

virt_acpi_build() gates HEST table construction on:

    acpi_ged_state = ACPI_GED(vms->acpi_dev);
    ags = &acpi_ged_state->ghes_state;
    if (ags) {

ags is the address of the ghes_state member of AcpiGedState and can never be NULL, so the check always passes. Whether the GED device exists is a separate condition (has_ged also depends on firmware being loaded and on ACPI being enabled), so a machine started with ras=on but without a GED device reaches this code with a NULL acpi_ged_state; ags then holds a bogus non-NULL pointer and acpi_build_hest() dereferences it.

Test vms->acpi_dev in the enclosing condition instead, so the HEST table is only built when the GED device exists and the ACPI_GED() cast is always valid.

Fixes 2e9c5c5bc85a ("acpi/ghes: prepare to change the way HEST offsets are calculated")
---
 hw/arm/virt-acpi-build.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
hw/arm/virt-acpi-build.c +12 -13
index d368913e766..5670d1eca71 100644
@@ -1406,7 +1406,7 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)
     acpi_add_table(table_offsets, tables_blob);
     build_dbg2(tables_blob, tables->linker, vms);
 
-    if (vms->ras) {
+    if (vms->ras && vms->acpi_dev) {
         AcpiGedState *acpi_ged_state;
         static const AcpiNotificationSourceId *notify;
         unsigned int notify_sz;
@@ -1414,21 +1414,20 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)
 
         acpi_ged_state = ACPI_GED(vms->acpi_dev);
         ags = &acpi_ged_state->ghes_state;
-        if (ags) {
-            acpi_add_table(table_offsets, tables_blob);
 
-            if (!ags->use_hest_addr) {
-                notify = hest_ghes_notify_10_0;
-                notify_sz = ARRAY_SIZE(hest_ghes_notify_10_0);
-            } else {
-                notify = hest_ghes_notify;
-                notify_sz = ARRAY_SIZE(hest_ghes_notify);
-            }
+        acpi_add_table(table_offsets, tables_blob);
 
-            acpi_build_hest(ags, tables_blob, tables->hardware_errors,
-                            tables->linker, notify, notify_sz,
-                            vms->oem_id, vms->oem_table_id);
+        if (!ags->use_hest_addr) {
+            notify = hest_ghes_notify_10_0;
+            notify_sz = ARRAY_SIZE(hest_ghes_notify_10_0);
+        } else {
+            notify = hest_ghes_notify;
+            notify_sz = ARRAY_SIZE(hest_ghes_notify);
         }
+
+        acpi_build_hest(ags, tables_blob, tables->hardware_errors,
+                        tables->linker, notify, notify_sz,
+                        vms->oem_id, vms->oem_table_id);
     }
 
     if (ms->numa_state->num_nodes > 0) {
Signature · 1 line
2.43.0
#30 lore raw

[PULL 24/33] tests/qtest: Make netfilter tests accept padded ethernet packets

In reply to Peter Maydell

Currently the various netfilter tests assume and assert that the data they get from the filter is an exact match for the data that they send in to it via the net socket backend. This happens to be the case currently because the net socket backend fails to pad frames to the ethernet minimum when the device expects that (unlike e.g. the tap backend). When we fix the socket backend to honour the device's request for padding, the netfilter will see padded packets for devices that require them (which is most of them), and not for those that don't (notably virtio-net).

This seems best considered as a test error: if you're using netfilter to look at what a particular network device is receiving, you want to actually see what it is receiving. And most real-world users of filtering will be doing it with the backends like TAP that were already doing pad-before-filter; it's only the oddball backends like 'socket' that forgot to pad.

Make the test cases accept as valid both padded and unpadded frames.

Message-id: [email protected]

---
 tests/qtest/test-filter-buffer.c     | 4 +++-
 tests/qtest/test-filter-mirror.c     | 4 +++-
 tests/qtest/test-filter-redirector.c | 4 +++-
 3 files changed, 9 insertions(+), 3 deletions(-)
tests/qtest/test-filter-buffer.c +3 -1
index 441cbb975ca..418caccf00a 100644
@@ -11,6 +11,7 @@
 #include "qobject/qdict.h"
 #include "qemu/iov.h"
 #include "qemu/sockets.h"
+#include "net/eth.h"
 
 /*
  * Test that changing interval at runtime affects packet release timing.
@@ -148,7 +149,8 @@ static void test_change_interval_timer(void)
     ret = recv(recv_sock, &len, sizeof(len), 0);
     g_assert_cmpint(ret, ==, sizeof(len));
     len = ntohl(len);
-    g_assert_cmpint(len, ==, sizeof(send_buf));
+    /* The snooped network device might or might not have asked for padding */
+    g_assert(len == sizeof(send_buf) || len == MAX(sizeof(send_buf), ETH_ZLEN));
 
     ret = recv(recv_sock, recv_buf, len, 0);
     g_assert_cmpint(ret, ==, len);
tests/qtest/test-filter-mirror.c +3 -1
index 723d2c2f291..9972712cb49 100644
@@ -15,6 +15,7 @@
 #include "qemu/sockets.h"
 #include "qemu/error-report.h"
 #include "qemu/main-loop.h"
+#include "net/eth.h"
 
 static void test_mirror(void)
 {
@@ -58,7 +59,8 @@ static void test_mirror(void)
     g_assert_cmpint(ret, ==, sizeof(len));
     len = ntohl(len);
 
-    g_assert_cmpint(len, ==, sizeof(send_buf));
+    /* The snooped network device might or might not have asked for padding */
+    g_assert(len == sizeof(send_buf) || len == MAX(sizeof(send_buf), ETH_ZLEN));
     recv_buf = g_malloc(len);
     ret = recv(recv_sock[0], recv_buf, len, 0);
     g_assert_cmpint(ret, ==, len);
tests/qtest/test-filter-redirector.c +3 -1
index 5540c232c0b..a4f9b73c72a 100644
@@ -57,6 +57,7 @@
 #include "qemu/sockets.h"
 #include "qemu/error-report.h"
 #include "qemu/main-loop.h"
+#include "net/eth.h"
 
 static void test_redirector_tx(void)
 {
@@ -115,7 +116,8 @@ static void test_redirector_tx(void)
     g_assert_cmpint(ret, ==, sizeof(len));
     len = ntohl(len);
 
-    g_assert_cmpint(len, ==, sizeof(send_buf));
+    /* The snooped network device might or might not have asked for padding */
+    g_assert(len == sizeof(send_buf) || len == MAX(sizeof(send_buf), ETH_ZLEN));
     recv_buf = g_malloc(len);
     ret = recv(recv_sock, recv_buf, len, 0);
     g_assert_cmpint(ret, ==, len);
Signature · 1 line
2.43.0
#31 lore raw

[PULL 20/33] hw/net/net_tx_pkt: Sanity check GSO headers in net_tx_pkt_build_vheader()

In reply to Peter Maydell

In net_tx_pkt_build_vheader(), we are insufficiently cautious about headers from the packet from the guest. Add more checking:
* that the segment offload payload gso_size isn't 0
* that the packet is not too small
* that the TCP th_off is inside the payload
* that we aren't going to overflow in our header length calculation

Of these, the most significant extra check is in calculation of the virt_hdr length. We calculate this with
pkt->virt_hdr.hdr_len = pkt->hdr_len + l4hdr.th_off * sizeof(uint32_t);

The struct field is 16 bits, and so this can overflow if the guest hands us a packet of close to 64K in size and an appropriate l4hdr.th_off. The effect is that we record a bogus virt_hdr.hdr_len, and later on in net_tx_pkt_tcp_fragment_init() this will cause us to make a very large allocation that causes g_malloc() to abort.

This is a hardening issue rather than a security issue, because the amount of guest control over the allocation size is such that it can only generate allocations very close to SIZE_MAX which always make g_malloc() abort, and so it's a guest self-denial-of-service only.

Fixes e263cd49c73c595 ("Packet abstraction for VMWARE network devices")

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3648

Message-id: [email protected]

---
 hw/net/net_tx_pkt.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
hw/net/net_tx_pkt.c +9 -1
index b134348fe80..b2935900fe7 100644
@@ -335,6 +335,11 @@ bool net_tx_pkt_build_vheader(struct NetTxPkt *pkt, bool tso_enable,
         break;
 
     case VIRTIO_NET_HDR_GSO_UDP:
+        if (IP_FRAG_ALIGN_SIZE(gso_size) == 0 ||
+            pkt->payload_len < sizeof(struct udp_header) ||
+            pkt->hdr_len + sizeof(struct udp_header) > UINT16_MAX) {
+            return false;
+        }
         pkt->virt_hdr.gso_size = gso_size;
         pkt->virt_hdr.hdr_len = pkt->hdr_len + sizeof(struct udp_header);
         break;
@@ -344,7 +349,10 @@ bool net_tx_pkt_build_vheader(struct NetTxPkt *pkt, bool tso_enable,
         bytes_read = iov_to_buf(&pkt->vec[NET_TX_PKT_PL_START_FRAG],
                                 pkt->payload_frags, 0, &l4hdr, sizeof(l4hdr));
         if (bytes_read < sizeof(l4hdr) ||
-            l4hdr.th_off * sizeof(uint32_t) < sizeof(l4hdr)) {
+            gso_size == 0 ||
+            l4hdr.th_off * sizeof(uint32_t) < sizeof(l4hdr) ||
+            l4hdr.th_off * sizeof(uint32_t) > pkt->payload_len ||
+            pkt->hdr_len + l4hdr.th_off * sizeof(uint32_t) > UINT16_MAX) {
             return false;
         }
 
Signature · 1 line
2.43.0
#32 lore raw

[PULL 07/33] hw/core/qdev-properties-system.c: Don't leak str in set_drive_helper()

In reply to Peter Maydell

In set_drive_helper(), we call visit_type_str() to get the value being set as a string. This is an allocated string, and we're supposed to free it, but not all paths out of this function do so. In particular, the "block backend already exists, change the attached node" code path does not free the string. This shows up as a memory leak under the newly added virtio-scsi-tests/replaced-node-size qtest:

$ UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 \
  QTEST_QEMU_BINARY=./qemu-system-i386 \
  ASAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 \
  ./tests/qtest/qos-test --tap -k \
  -p /i386/pc/i440FX-pcihost/pci-bus-pc/pci-bus/virtio-scsi-pci/virtio-scsi/virtio-scsi-tests/replaced-node-size
[...]
Direct leak of 4 byte(s) in 1 object(s) allocated from:
    #0 0x55f7744155e3 in malloc (/home/pm215/qemu/build/x86-tgt-san-dbg/qemu-system-i386+0x20115e3) (BuildId: 271ffb42d2e322de7813813d8c6cc85351e48a4f)
    #1 0x713dbd345b79 in g_malloc /usr/src/glib2.0-2.80.0-6ubuntu3.10/debian/build/deb/../../../glib/gmem.c:100:13
    #2 0x713dbd35b988 in g_strdup /usr/src/glib2.0-2.80.0-6ubuntu3.10/debian/build/deb/../../../glib/gstrfuncs.c:323:17
    #3 0x55f777208021 in g_strdup_inline /usr/include/glib-2.0/glib/gstrfuncs.h:321:10
    #4 0x55f777208021 in qobject_input_type_str /home/pm215/qemu/build/x86-tgt-san-dbg/../../qapi/qobject-input-visitor.c:542:12
    #5 0x55f777204d1c in visit_type_str /home/pm215/qemu/build/x86-tgt-san-dbg/../../qapi/qapi-visit-core.c:349:10
    #6 0x55f774df80d1 in set_drive_helper /home/pm215/qemu/build/x86-tgt-san-dbg/../../hw/core/qdev-properties-system.c:129:10
    #7 0x55f774dee9fa in set_drive_iothread /home/pm215/qemu/build/x86-tgt-san-dbg/../../hw/core/qdev-properties-system.c:224:5
    #8 0x55f7767cc5c8 in field_prop_set /home/pm215/qemu/build/x86-tgt-san-dbg/../../hw/core/qdev-properties.c:89:12
    #9 0x55f7767ec12b in object_property_set /home/pm215/qemu/build/x86-tgt-san-dbg/../../qom/object.c:1562:5

Switch to using g_autofree so that the string is properly freed all all exit paths.

Fixes d1a58c176a11b ("qdev: allow setting drive property for realized device")

Message-id: [email protected]

---
 hw/core/qdev-properties-system.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
hw/core/qdev-properties-system.c +1 -4
index 4d605c20561..d5b227dbecb 100644
@@ -120,7 +120,7 @@ static void set_drive_helper(Object *obj, Visitor *v, const char *name,
     DeviceState *dev = DEVICE(obj);
     const Property *prop = opaque;
     void **ptr = object_field_prop_ptr(obj, prop);
-    char *str;
+    g_autofree char *str = NULL;
     BlockBackend *blk;
     bool blk_created = false;
     int ret;
@@ -155,7 +155,6 @@ static void set_drive_helper(Object *obj, Visitor *v, const char *name,
     }
 
     if (!*str) {
-        g_free(str);
         *ptr = NULL;
         return;
     }
@@ -209,8 +208,6 @@ fail:
         /* If we need to keep a reference, blk_attach_dev() took it */
         blk_unref(blk);
     }
-
-    g_free(str);
 }
 
 static void set_drive(Object *obj, Visitor *v, const char *name, void *opaque,
Signature · 1 line
2.43.0
#33 lore raw

[PULL 05/33] target/arm: Only allow GICv5 on CPUs without AArch32 at EL1..3

In reply to Peter Maydell

We previously allowed the GICv5 on any 64-bit CPU, with a hack where enabling the GICv5 silently disabled AArch32 for EL1..3.

Now that we have a separate 'max-v8' and 'max-v9' where max-v9 correctly doesn't implement AArch32 at EL1..3, we can fix the "when do we expose the has_gcie property" condition so that we only allow the GICv5 when AArch32 doesn't exist above EL0, and remove the hack disabling AArch32.

We could instead have defined a new ARM_FEATURE_V9, but "allow the feature to be present on CPUs where it doesn't actively break anything" fits the way we've generally handled things in QEMU, and it avoids having a new V9 feature bit that we only use for this one thing and where it's not clear when we should be setting it for KVM, hvf, etc accelerators.

In practice the only CPUs which will allow GICv5 now are max, max-v9 and a64fx.

Message-id: [email protected]

---
 target/arm/cpu-features.h |  8 ++++++++
 target/arm/cpu.c          | 37 +++++++------------------------------
 2 files changed, 15 insertions(+), 30 deletions(-)
target/arm/cpu-features.h +8 -0
index 96ec12f64f4..b0edec28378 100644
@@ -1130,6 +1130,14 @@ static inline bool isar_feature_aa64_aa32_el3(const ARMISARegisters *id)
     return FIELD_EX64_IDREG(id, ID_AA64PFR0, EL3) >= 2;
 }
 
+static inline bool isar_feature_aa64_aa32_above_el0(const ARMISARegisters *id)
+{
+    /* True if any EL above EL0 has AArch32 support */
+    return isar_feature_aa64_aa32_el1(id) ||
+        isar_feature_aa64_aa32_el2(id) ||
+        isar_feature_aa64_aa32_el3(id);
+}
+
 static inline bool isar_feature_aa64_ras(const ARMISARegisters *id)
 {
     return FIELD_EX64_IDREG(id, ID_AA64PFR0, RAS) != 0;
target/arm/cpu.c +7 -30
index 71681447b21..dde03ffdd6f 100644
@@ -1596,8 +1596,13 @@ static void arm_cpu_post_init(Object *obj)
                                        &cpu->rvbar_prop,
                                        OBJ_PROP_FLAG_READWRITE);
 
-        /* We only allow GICv5 on a 64-bit v8 CPU */
-        if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
+        /*
+         * We only allow GICv5 on a CPU with no AArch32 support above EL0
+         * (which is typically a v9 CPU), because GICv5 defines no AArch32
+         * system registers to control it.
+         */
+        if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64) &&
+            !cpu_isar_feature(aa64_aa32_above_el0, cpu)) {
             qdev_property_add_static(DEVICE(obj), &arm_cpu_has_gcie_property);
         }
     }
@@ -2274,34 +2279,6 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
 
     /* Report FEAT_GCIE in our ID registers if property was set */
     FIELD_DP64_IDREG(isar, ID_AA64PFR2, GCIE, cpu->has_gcie);
-    if (cpu_isar_feature(aa64_gcie, cpu)) {
-        if (!arm_feature(env, ARM_FEATURE_AARCH64)) {
-            /*
-             * We only create the have_gcie property for AArch64 CPUs,
-             * but the user might have tried aarch64=off with has_gcie=on.
-             */
-            error_setg(errp, "Cannot both enable has_gcie and disable aarch64");
-            return;
-        }
-
-        /*
-         * FEAT_GCIE implies Armv9, which implies no AArch32 above EL0.
-         * Usually we don't strictly insist on this kind of feature
-         * dependency, but in this case we enforce it, because the
-         * GICv5 CPU interface has no AArch32 versions of its system
-         * registers, so interrupts wouldn't work if we allowed AArch32
-         * in EL1 or above. Downgrade "AArch32 and AArch64" to "AArch64".
-         */
-        if (cpu_isar_feature(aa64_aa32_el3, cpu)) {
-            FIELD_DP64_IDREG(isar, ID_AA64PFR0, EL3, 1);
-        }
-        if (cpu_isar_feature(aa64_aa32_el2, cpu)) {
-            FIELD_DP64_IDREG(isar, ID_AA64PFR0, EL2, 1);
-        }
-        if (cpu_isar_feature(aa64_aa32_el1, cpu)) {
-            FIELD_DP64_IDREG(isar, ID_AA64PFR0, EL1, 1);
-        }
-    }
 
     if (cpu_isar_feature(aa64_mte, cpu)) {
         /*
Signature · 1 line
2.43.0
#34 lore raw
In reply to Peter Maydell
Quoted 29 lines · Peter Maydell

Hi; this is quite a large pullreq, but it's all bug fixes aimed at rc1 (both arm-specific and otherwise). Notably, there are a set of patches in here which fix various problems with handling of packets in the net/ code.

thanks
-- PMM

The following changes since commit e9fa1f66f0d47c74b6766e1b8b87ad7c2a9394d5:

   Merge tag 'pull-nbd-2026-11-10-v2' ofhttps://gitlab.com/ebblake/qemu into staging (2026-11-13 08:44:16 -0700)

are available in the Git repository at:

   https://gitlab.com/pm215/qemu.git tags/pull-target-arm-20261116

for you to fetch changes up to 7d8fc59308ce20661515555855af4e01ac9bab77:

   hw/arm/virt-acpi-build: test vms->acpi_dev before building HEST (2026-11-16 11:09:47 +0000)

----------------------------------------------------------------
target/arm queue:
* hw/ssi/stm32f2xx_spi: avoid transferring data on DR reads
* hw/arm/bcm2838: Route SPI0 interrupt to GIC
* hw/intc/arm_gicv5: Various minor bug fixes
* hw/core/qdev-properties-system.c: Don't leak str in set_drive_helper()
* hw/watchdog/wdt_imx2: Set vmstate minimum_version_id to 1
* include/hw/core/ptimer.h: Fix 'version' argument of VMSTATE_PTIMER
* net: Tighten various size/offset checks in packet parsing functions

Quoted 8 lines

* net: Pad short packets regardless of network backend
* hw/net/eepro100: fix use-after-free on reset after hot-unplug
* hw/arm: Deprecate Nuvoton quanta-gsj board model
* Revert ".dir-locals: include QEMU code in PYTHONPATH"
* docs/about/deprecated: Add missing "since" marker for OABI/NWFPE
* docs/about/deprecated: Fix heading level for AF_ALG heading
* hw/net: cadence: Honor subword lanes in the GEM registers
* hw/arm/virt-acpi-build: test vms->acpi_dev before building HEST

Applied, thanks.

r~