net: Update MemReentrancyGuard for NIC
Subsystems (4)
v2 cover net: Update MemReentrancyGuard for NIC
Recently MemReentrancyGuard was added to DeviceState to record that the device is engaging in I/O. The network device backend needs to update it when delivering a packet to a device.
This implementation follows what bottom half does, but it does not add a tracepoint for the case that the network device backend started delivering a packet to a device which is already engaging in I/O. This is because such reentrancy frequently happens for qemu_flush_queued_packets() and is insignificant.
This series consists of two patches. The first patch makes a bulk change to add a new parameter to qemu_new_nic() and does not contain behavioral changes. The second patch actually implements MemReentrancyGuard update.
V1 -> V2: Added the 'Fixes: CVE-2023-3019' tag
Akihiko Odaki (2):
net: Provide MemReentrancyGuard * to qemu_new_nic()
net: Update MemReentrancyGuard for NIC
include/net/net.h | 2 ++ hw/net/allwinner-sun8i-emac.c | 3 ++- hw/net/allwinner_emac.c | 3 ++- hw/net/cadence_gem.c | 3 ++- hw/net/dp8393x.c | 3 ++- hw/net/e1000.c | 3 ++- hw/net/e1000e.c | 2 +- hw/net/eepro100.c | 4 +++- hw/net/etraxfs_eth.c | 3 ++- hw/net/fsl_etsec/etsec.c | 3 ++- hw/net/ftgmac100.c | 3 ++- hw/net/i82596.c | 2 +- hw/net/igb.c | 2 +- hw/net/imx_fec.c | 2 +- hw/net/lan9118.c | 3 ++- hw/net/mcf_fec.c | 3 ++- hw/net/mipsnet.c | 3 ++- hw/net/msf2-emac.c | 3 ++- hw/net/mv88w8618_eth.c | 3 ++- hw/net/ne2000-isa.c | 3 ++- hw/net/ne2000-pci.c | 3 ++- hw/net/npcm7xx_emc.c | 3 ++- hw/net/opencores_eth.c | 3 ++- hw/net/pcnet.c | 3 ++- hw/net/rocker/rocker_fp.c | 4 ++-- hw/net/rtl8139.c | 3 ++- hw/net/smc91c111.c | 3 ++- hw/net/spapr_llan.c | 3 ++- hw/net/stellaris_enet.c | 3 ++- hw/net/sungem.c | 2 +- hw/net/sunhme.c | 3 ++- hw/net/tulip.c | 3 ++- hw/net/virtio-net.c | 6 ++++-- hw/net/vmxnet3.c | 2 +- hw/net/xen_nic.c | 4 ++-- hw/net/xgmac.c | 3 ++- hw/net/xilinx_axienet.c | 3 ++- hw/net/xilinx_ethlite.c | 3 ++- hw/usb/dev-network.c | 3 ++- net/net.c | 15 +++++++++++++++ 40 files changed, 90 insertions(+), 41 deletions(-)
Signature · 1 line
2.40.1
PATCH v2 1/2 net: Provide MemReentrancyGuard * to qemu_new_nic()
Recently MemReentrancyGuard was added to DeviceState to record that the device is engaging in I/O. The network device backend needs to update it when delivering a packet to a device.
In preparation for such a change, add MemReentrancyGuard * as a parameter of qemu_new_nic().
--- include/net/net.h | 1 + hw/net/allwinner-sun8i-emac.c | 3 ++- hw/net/allwinner_emac.c | 3 ++- hw/net/cadence_gem.c | 3 ++- hw/net/dp8393x.c | 3 ++- hw/net/e1000.c | 3 ++- hw/net/e1000e.c | 2 +- hw/net/eepro100.c | 4 +++- hw/net/etraxfs_eth.c | 3 ++- hw/net/fsl_etsec/etsec.c | 3 ++- hw/net/ftgmac100.c | 3 ++- hw/net/i82596.c | 2 +- hw/net/igb.c | 2 +- hw/net/imx_fec.c | 2 +- hw/net/lan9118.c | 3 ++- hw/net/mcf_fec.c | 3 ++- hw/net/mipsnet.c | 3 ++- hw/net/msf2-emac.c | 3 ++- hw/net/mv88w8618_eth.c | 3 ++- hw/net/ne2000-isa.c | 3 ++- hw/net/ne2000-pci.c | 3 ++- hw/net/npcm7xx_emc.c | 3 ++- hw/net/opencores_eth.c | 3 ++- hw/net/pcnet.c | 3 ++- hw/net/rocker/rocker_fp.c | 4 ++-- hw/net/rtl8139.c | 3 ++- hw/net/smc91c111.c | 3 ++- hw/net/spapr_llan.c | 3 ++- hw/net/stellaris_enet.c | 3 ++- hw/net/sungem.c | 2 +- hw/net/sunhme.c | 3 ++- hw/net/tulip.c | 3 ++- hw/net/virtio-net.c | 6 ++++-- hw/net/vmxnet3.c | 2 +- hw/net/xen_nic.c | 4 ++-- hw/net/xgmac.c | 3 ++- hw/net/xilinx_axienet.c | 3 ++- hw/net/xilinx_ethlite.c | 3 ++- hw/usb/dev-network.c | 3 ++- net/net.c | 1 + 40 files changed, 75 insertions(+), 41 deletions(-)
include/net/net.h +1 -0
@@ -157,6 +157,7 @@ NICState *qemu_new_nic(NetClientInfo *info,NICConf *conf, const char *model, const char *name, + MemReentrancyGuard *reentrancy_guard, void *opaque);void qemu_del_nic (NICState *nic);NetClientState *qemu_get_subqueue (NICState *nic,int queue_index);
hw/net/allwinner-sun8i-emac.c +2 -1
@@ -824,7 +824,8 @@ static void allwinner_sun8i_emac_realize(DeviceState *dev, Error **errp)qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic =qemu_new_nic (&net_allwinner_sun8i_emac_info, &s->conf, -object_get_typename (OBJECT (dev)), dev->id, s); +object_get_typename (OBJECT (dev)), dev->id, + &dev->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a); }
hw/net/allwinner_emac.c +2 -1
@@ -453,7 +453,8 @@ static void aw_emac_realize(DeviceState *dev, Error **errp)qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic =qemu_new_nic (&net_aw_emac_info, &s->conf, -object_get_typename (OBJECT (dev)), dev->id, s); +object_get_typename (OBJECT (dev)), dev->id, + &dev->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a);fifo8_create (&s->rx_fifo,RX_FIFO_SIZE );
hw/net/cadence_gem.c +2 -1
@@ -1633,7 +1633,8 @@ static void gem_realize(DeviceState *dev, Error **errp)qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic =qemu_new_nic (&net_gem_info, &s->conf, -object_get_typename (OBJECT (dev)), dev->id, s); +object_get_typename (OBJECT (dev)), dev->id, + &dev->mem_reentrancy_guard, s);if (s->jumbo_max_len >MAX_FRAME_SIZE ) { error_setg(errp, "jumbo-max-len is greater than %d",
hw/net/dp8393x.c +2 -1
@@ -943,7 +943,8 @@ static void dp8393x_realize(DeviceState *dev, Error **errp) "dp8393x-regs", SONIC_REG_COUNT << s->it_shift); s->nic =qemu_new_nic (&net_dp83932_info, &s->conf, -object_get_typename (OBJECT (dev)), dev->id, s); +object_get_typename (OBJECT (dev)), dev->id, + &dev->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a); s->watchdog =timer_new_ns (QEMU_CLOCK_VIRTUAL , dp8393x_watchdog, s);
hw/net/e1000.c +2 -1
@@ -1696,7 +1696,8 @@ static void pci_e1000_realize(PCIDevice *pci_dev, Error **errp) macaddr); d->nic =qemu_new_nic (&net_e1000_info, &d->conf, -object_get_typename (OBJECT (d)), dev->id, d); +object_get_typename (OBJECT (d)), dev->id, + &dev->mem_reentrancy_guard, d);qemu_format_nic_info_str (qemu_get_queue (d->nic), macaddr);
hw/net/e1000e.c +1 -1
@@ -320,7 +320,7 @@ e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev, uint8_t *macaddr)int i; s->nic =qemu_new_nic (&net_e1000e_info, &s->conf, -object_get_typename (OBJECT (s)), dev->id, s); +object_get_typename (OBJECT (s)), dev->id, &dev->mem_reentrancy_guard, s); s->core.max_queue_num = s->conf.peers.queues ? s->conf.peers.queues -1 :0 ;
hw/net/eepro100.c +3 -1
@@ -1874,7 +1874,9 @@ static void e100_nic_realize(PCIDevice *pci_dev, Error **errp)nic_reset (s); s->nic =qemu_new_nic (&net_eepro100_info, &s->conf, -object_get_typename (OBJECT (pci_dev)), pci_dev->qdev.id, s); +object_get_typename (OBJECT (pci_dev)), + pci_dev->qdev.id, + &pci_dev->qdev.mem_reentrancy_guard, s);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));
hw/net/etraxfs_eth.c +2 -1
@@ -618,7 +618,8 @@ static void etraxfs_eth_realize(DeviceState *dev, Error **errp)qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic =qemu_new_nic (&net_etraxfs_info, &s->conf, -object_get_typename (OBJECT (s)), dev->id, s); +object_get_typename (OBJECT (s)), dev->id, + &dev->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a); s->phy.read = tdk_read;
hw/net/fsl_etsec/etsec.c +2 -1
@@ -391,7 +391,8 @@ static void etsec_realize(DeviceState *dev, Error **errp)eTSEC *etsec =ETSEC_COMMON (dev); etsec->nic =qemu_new_nic (&net_etsec_info, &etsec->conf, -object_get_typename (OBJECT (dev)), dev->id, etsec); +object_get_typename (OBJECT (dev)), dev->id, + &dev->mem_reentrancy_guard, etsec);qemu_format_nic_info_str (qemu_get_queue (etsec->nic), etsec->conf.macaddr.a); etsec->ptimer =ptimer_init (etsec_timer_hit, etsec,PTIMER_POLICY_LEGACY );
hw/net/ftgmac100.c +2 -1
@@ -1118,7 +1118,8 @@ static void ftgmac100_realize(DeviceState *dev, Error **errp)qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic =qemu_new_nic (&net_ftgmac100_info, &s->conf, -object_get_typename (OBJECT (dev)), dev->id, s); +object_get_typename (OBJECT (dev)), dev->id, + &dev->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a); }
hw/net/i82596.c +1 -1
@@ -743,7 +743,7 @@ void i82596_common_init(DeviceState *dev, I82596State *s, NetClientInfo *info)qemu_macaddr_default_if_unset (&s->conf.macaddr); } s->nic =qemu_new_nic (info, &s->conf,object_get_typename (OBJECT (dev)), - dev->id, s); + dev->id, &dev->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a);if (USE_TIMER ) {
hw/net/igb.c +1 -1
@@ -315,7 +315,7 @@ igb_init_net_peer(IGBState *s, PCIDevice *pci_dev, uint8_t *macaddr)int i; s->nic =qemu_new_nic (&net_igb_info, &s->conf, -object_get_typename (OBJECT (s)), dev->id, s); +object_get_typename (OBJECT (s)), dev->id, &dev->mem_reentrancy_guard, s); s->core.max_queue_num = s->conf.peers.queues ? s->conf.peers.queues -1 :0 ;
hw/net/imx_fec.c +1 -1
@@ -1334,7 +1334,7 @@ static void imx_eth_realize(DeviceState *dev, Error **errp) s->nic =qemu_new_nic (&imx_eth_net_info, &s->conf,object_get_typename (OBJECT (dev)), - dev->id, s); + dev->id, &dev->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a); }
hw/net/lan9118.c +2 -1
@@ -1361,7 +1361,8 @@ static void lan9118_realize(DeviceState *dev, Error **errp)qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic =qemu_new_nic (&net_lan9118_info, &s->conf, -object_get_typename (OBJECT (dev)), dev->id, s); +object_get_typename (OBJECT (dev)), dev->id, + &dev->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a); s->eeprom[0 ] =0xa5 ;for (i =0 ; i <6 ; i++) {
hw/net/mcf_fec.c +2 -1
@@ -643,7 +643,8 @@ static void mcf_fec_realize(DeviceState *dev, Error **errp)mcf_fec_state *s =MCF_FEC_NET (dev); s->nic =qemu_new_nic (&net_mcf_fec_info, &s->conf, -object_get_typename (OBJECT (dev)), dev->id, s); +object_get_typename (OBJECT (dev)), dev->id, + &dev->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a); }
hw/net/mipsnet.c +2 -1
@@ -255,7 +255,8 @@ static void mipsnet_realize(DeviceState *dev, Error **errp)sysbus_init_irq (sbd, &s->irq); s->nic =qemu_new_nic (&net_mipsnet_info, &s->conf, -object_get_typename (OBJECT (dev)), dev->id, s); +object_get_typename (OBJECT (dev)), dev->id, + &dev->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a); }
hw/net/msf2-emac.c +2 -1
@@ -530,7 +530,8 @@ static void msf2_emac_realize(DeviceState *dev, Error **errp)qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic =qemu_new_nic (&net_msf2_emac_info, &s->conf, -object_get_typename (OBJECT (dev)), dev->id, s); +object_get_typename (OBJECT (dev)), dev->id, + &dev->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a); }
hw/net/mv88w8618_eth.c +2 -1
@@ -350,7 +350,8 @@ static void mv88w8618_eth_realize(DeviceState *dev, Error **errp)address_space_init (&s->dma_as, s->dma_mr,"emac-dma" ); s->nic =qemu_new_nic (&net_mv88w8618_info, &s->conf, -object_get_typename (OBJECT (dev)), dev->id, s); +object_get_typename (OBJECT (dev)), dev->id, + &dev->mem_reentrancy_guard, s); }static const VMStateDescription mv88w8618_eth_vmsd = {
hw/net/ne2000-isa.c +2 -1
@@ -74,7 +74,8 @@ static void isa_ne2000_realizefn(DeviceState *dev, Error **errp)ne2000_reset (s); s->nic =qemu_new_nic (&net_ne2000_isa_info, &s->c, -object_get_typename (OBJECT (dev)), dev->id, s); +object_get_typename (OBJECT (dev)), dev->id, + &dev->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->c.macaddr.a); }
hw/net/ne2000-pci.c +2 -1
@@ -71,7 +71,8 @@ static void pci_ne2000_realize(PCIDevice *pci_dev, Error **errp) s->nic =qemu_new_nic (&net_ne2000_info, &s->c,object_get_typename (OBJECT (pci_dev)), - pci_dev->qdev.id, s); + pci_dev->qdev.id, + &pci_dev->qdev.mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->c.macaddr.a); }
hw/net/npcm7xx_emc.c +2 -1
@@ -821,7 +821,8 @@ static void npcm7xx_emc_realize(DeviceState *dev, Error **errp)qemu_macaddr_default_if_unset (&emc->conf.macaddr); emc->nic =qemu_new_nic (&net_npcm7xx_emc_info, &emc->conf, -object_get_typename (OBJECT (dev)), dev->id, emc); +object_get_typename (OBJECT (dev)), dev->id, + &dev->mem_reentrancy_guard, emc);qemu_format_nic_info_str (qemu_get_queue (emc->nic), emc->conf.macaddr.a); }
hw/net/opencores_eth.c +2 -1
@@ -732,7 +732,8 @@ static void sysbus_open_eth_realize(DeviceState *dev, Error **errp)sysbus_init_irq (sbd, &s->irq); s->nic =qemu_new_nic (&net_open_eth_info, &s->conf, -object_get_typename (OBJECT (s)), dev->id, s); +object_get_typename (OBJECT (s)), dev->id, + &dev->mem_reentrancy_guard, s); }static void qdev_open_eth_reset (DeviceState *dev)
hw/net/pcnet.c +2 -1
@@ -1718,7 +1718,8 @@ void pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info) s->poll_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , pcnet_poll_timer, s);qemu_macaddr_default_if_unset (&s->conf.macaddr); - s->nic =qemu_new_nic (info, &s->conf,object_get_typename (OBJECT (dev)), dev->id, s); + s->nic =qemu_new_nic (info, &s->conf,object_get_typename (OBJECT (dev)), + dev->id, &dev->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a);/* Initialize the PROM */
hw/net/rocker/rocker_fp.c +2 -2
@@ -241,8 +241,8 @@ FpPort *fp_port_alloc(Rocker *r, char *sw_name, port->conf.bootindex =-1 ; port->conf.peers = *peers; - port->nic =qemu_new_nic (&fp_port_info, &port->conf, - sw_name,NULL , port); + port->nic =qemu_new_nic (&fp_port_info, &port->conf, sw_name,NULL , + &DEVICE (r)->mem_reentrancy_guard, port);qemu_format_nic_info_str (qemu_get_queue (port->nic), port->conf.macaddr.a);
hw/net/rtl8139.c +2 -1
@@ -3397,7 +3397,8 @@ static void pci_rtl8139_realize(PCIDevice *dev, Error **errp) s->eeprom.contents[9 ] = s->conf.macaddr.a[4 ] | s->conf.macaddr.a[5 ] <<8 ; s->nic =qemu_new_nic (&net_rtl8139_info, &s->conf, -object_get_typename (OBJECT (dev)), d->id, s); +object_get_typename (OBJECT (dev)), d->id, + &d->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a); s->cplus_txbuffer =NULL ;
hw/net/smc91c111.c +2 -1
@@ -783,7 +783,8 @@ static void smc91c111_realize(DeviceState *dev, Error **errp)sysbus_init_irq (sbd, &s->irq);qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic =qemu_new_nic (&net_smc91c111_info, &s->conf, -object_get_typename (OBJECT (dev)), dev->id, s); +object_get_typename (OBJECT (dev)), dev->id, + &dev->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a);/* ??? Save/restore. */ }
hw/net/spapr_llan.c +2 -1
@@ -325,7 +325,8 @@ static void spapr_vlan_realize(SpaprVioDevice *sdev, Error **errp)memcpy (&dev->perm_mac.a, &dev->nicconf.macaddr.a,sizeof (dev->perm_mac.a)); dev->nic =qemu_new_nic (&net_spapr_vlan_info, &dev->nicconf, -object_get_typename (OBJECT (sdev)), sdev->qdev.id, dev); +object_get_typename (OBJECT (sdev)), sdev->qdev.id, + &sdev->qdev.mem_reentrancy_guard, dev);qemu_format_nic_info_str (qemu_get_queue (dev->nic), dev->nicconf.macaddr.a); dev->rxp_timer = timer_new_us(QEMU_CLOCK_VIRTUAL, spapr_vlan_flush_rx_queue,
hw/net/stellaris_enet.c +2 -1
@@ -492,7 +492,8 @@ static void stellaris_enet_realize(DeviceState *dev, Error **errp)qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic =qemu_new_nic (&net_stellaris_enet_info, &s->conf, -object_get_typename (OBJECT (dev)), dev->id, s); +object_get_typename (OBJECT (dev)), dev->id, + &dev->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a); }
hw/net/sungem.c +1 -1
@@ -1361,7 +1361,7 @@ static void sungem_realize(PCIDevice *pci_dev, Error **errp)qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic =qemu_new_nic (&net_sungem_info, &s->conf,object_get_typename (OBJECT (dev)), - dev->id, s); + dev->id, &dev->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a); }
hw/net/sunhme.c +2 -1
@@ -892,7 +892,8 @@ static void sunhme_realize(PCIDevice *pci_dev, Error **errp)qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic =qemu_new_nic (&net_sunhme_info, &s->conf, -object_get_typename (OBJECT (d)), d->id, s); +object_get_typename (OBJECT (d)), d->id, + &d->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a); }
hw/net/tulip.c +2 -1
@@ -983,7 +983,8 @@ static void pci_tulip_realize(PCIDevice *pci_dev, Error **errp) s->nic =qemu_new_nic (&net_tulip_info, &s->c,object_get_typename (OBJECT (pci_dev)), - pci_dev->qdev.id, s); + pci_dev->qdev.id, + &pci_dev->qdev.mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->c.macaddr.a); }
hw/net/virtio-net.c +4 -2
@@ -3696,10 +3696,12 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)* Happen when virtio_net_set_netclient_name has been called. */ n->nic =qemu_new_nic (&net_virtio_info, &n->nic_conf, - n->netclient_type, n->netclient_name, n); + n->netclient_type, n->netclient_name, + &dev->mem_reentrancy_guard, n); }else { n->nic =qemu_new_nic (&net_virtio_info, &n->nic_conf, -object_get_typename (OBJECT (dev)), dev->id, n); +object_get_typename (OBJECT (dev)), dev->id, + &dev->mem_reentrancy_guard, n); }for (i =0 ; i < n->max_queue_pairs; i++) {
hw/net/vmxnet3.c +1 -1
@@ -2083,7 +2083,7 @@ static void vmxnet3_net_init(VMXNET3State *s) s->nic =qemu_new_nic (&net_vmxnet3_info, &s->conf,object_get_typename (OBJECT (s)), - d->id, s); + d->id, &d->mem_reentrancy_guard, s); s->peer_has_vhdr =vmxnet3_peer_has_vnet_hdr (s); s->tx_sop = true;
hw/net/xen_nic.c +2 -2
@@ -293,8 +293,8 @@ static int net_init(struct XenLegacyDevice *xendev)return -1 ; } - netdev->nic =qemu_new_nic (&net_xen_info, &netdev->conf, -"xen" ,NULL , netdev); + netdev->nic =qemu_new_nic (&net_xen_info, &netdev->conf,"xen" ,NULL , + &xendev->qdev.mem_reentrancy_guard, netdev);qemu_set_info_str (qemu_get_queue (netdev->nic),"nic: xenbus vif macaddr=%s" , netdev->mac);
hw/net/xgmac.c +2 -1
@@ -402,7 +402,8 @@ static void xgmac_enet_realize(DeviceState *dev, Error **errp)qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic =qemu_new_nic (&net_xgmac_enet_info, &s->conf, -object_get_typename (OBJECT (dev)), dev->id, s); +object_get_typename (OBJECT (dev)), dev->id, + &dev->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a); s->regs[XGMAC_ADDR_HIGH(0)] = (s->conf.macaddr.a[5] << 8) |
hw/net/xilinx_axienet.c +2 -1
@@ -967,7 +967,8 @@ static void xilinx_enet_realize(DeviceState *dev, Error **errp)qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic =qemu_new_nic (&net_xilinx_enet_info, &s->conf, -object_get_typename (OBJECT (dev)), dev->id, s); +object_get_typename (OBJECT (dev)), dev->id, + &dev->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a);tdk_init (&s->TEMAC.phy);
hw/net/xilinx_ethlite.c +2 -1
@@ -235,7 +235,8 @@ static void xilinx_ethlite_realize(DeviceState *dev, Error **errp)qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic =qemu_new_nic (&net_xilinx_ethlite_info, &s->conf, -object_get_typename (OBJECT (dev)), dev->id, s); +object_get_typename (OBJECT (dev)), dev->id, + &dev->mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a); }
hw/usb/dev-network.c +2 -1
@@ -1386,7 +1386,8 @@ static void usb_net_realize(USBDevice *dev, Error **errp)qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic =qemu_new_nic (&net_usbnet_info, &s->conf, -object_get_typename (OBJECT (s)), s->dev.qdev.id, s); +object_get_typename (OBJECT (s)), s->dev.qdev.id, + &s->dev.qdev.mem_reentrancy_guard, s);qemu_format_nic_info_str (qemu_get_queue (s->nic), s->conf.macaddr.a); snprintf(s->usbstring_mac, sizeof(s->usbstring_mac), "%02x%02x%02x%02x%02x%02x",
net/net.c +1 -0
@@ -319,6 +319,7 @@ NICState *qemu_new_nic(NetClientInfo *info,NICConf *conf, const char *model, const char *name, + MemReentrancyGuard *reentrancy_guard, void *opaque) { NetClientState **peers = conf->peers.ncs;
Signature · 1 line
2.40.1
Re: [PATCH v2 1/2] net: Provide MemReentrancyGuard * to qemu_new_nic()
Quoted 8 lines · Akihiko Odaki
Recently MemReentrancyGuard was added to DeviceState to record that the device is engaging in I/O. The network device backend needs to update it when delivering a packet to a device.
In preparation for such a change, add MemReentrancyGuard * as a parameter of
qemu_new_nic().Signed-off-by Akihiko Odaki <[email protected]>
One minor comment below.
Quoted 48 lines
--- include/net/net.h | 1 + hw/net/allwinner-sun8i-emac.c | 3 ++- hw/net/allwinner_emac.c | 3 ++- hw/net/cadence_gem.c | 3 ++- hw/net/dp8393x.c | 3 ++- hw/net/e1000.c | 3 ++- hw/net/e1000e.c | 2 +- hw/net/eepro100.c | 4 +++- hw/net/etraxfs_eth.c | 3 ++- hw/net/fsl_etsec/etsec.c | 3 ++- hw/net/ftgmac100.c | 3 ++- hw/net/i82596.c | 2 +- hw/net/igb.c | 2 +- hw/net/imx_fec.c | 2 +- hw/net/lan9118.c | 3 ++- hw/net/mcf_fec.c | 3 ++- hw/net/mipsnet.c | 3 ++- hw/net/msf2-emac.c | 3 ++- hw/net/mv88w8618_eth.c | 3 ++- hw/net/ne2000-isa.c | 3 ++- hw/net/ne2000-pci.c | 3 ++- hw/net/npcm7xx_emc.c | 3 ++- hw/net/opencores_eth.c | 3 ++- hw/net/pcnet.c | 3 ++- hw/net/rocker/rocker_fp.c | 4 ++-- hw/net/rtl8139.c | 3 ++- hw/net/smc91c111.c | 3 ++- hw/net/spapr_llan.c | 3 ++- hw/net/stellaris_enet.c | 3 ++- hw/net/sungem.c | 2 +- hw/net/sunhme.c | 3 ++- hw/net/tulip.c | 3 ++- hw/net/virtio-net.c | 6 ++++-- hw/net/vmxnet3.c | 2 +- hw/net/xen_nic.c | 4 ++-- hw/net/xgmac.c | 3 ++- hw/net/xilinx_axienet.c | 3 ++- hw/net/xilinx_ethlite.c | 3 ++- hw/usb/dev-network.c | 3 ++- net/net.c | 1 + 40 files changed, 75 insertions(+), 41 deletions(-)include/net/net.h +0
-0
include/net/net.h NICState *qemu_new_nic(NetClientInfo *info, · line 161
Quoted 5 lines
include/net/net.h +1
-0@@ -157,6 +157,7 @@ NICState *qemu_new_nic(NetClientInfo *info,NICConf *conf, const char *model, const char *name, + MemReentrancyGuard *reentrancy_guard, void *opaque);
Does it make sense to roll *reentrancy_guard into NICConf here?
Re: [PATCH v2 1/2] net: Provide MemReentrancyGuard * to qemu_new_nic()
Quoted 58 lines · Alexander Bulekov
Quoted 8 lines · Akihiko Odaki
Recently MemReentrancyGuard was added to DeviceState to record that the device is engaging in I/O. The network device backend needs to update it when delivering a packet to a device.
In preparation for such a change, add MemReentrancyGuard * as a parameter of
qemu_new_nic().Signed-off-by Akihiko Odaki <[email protected]>Reviewed-by Alexander Bulekov <[email protected]>One minor comment below.
Quoted 43 lines
--- include/net/net.h | 1 + hw/net/allwinner-sun8i-emac.c | 3 ++- hw/net/allwinner_emac.c | 3 ++- hw/net/cadence_gem.c | 3 ++- hw/net/dp8393x.c | 3 ++- hw/net/e1000.c | 3 ++- hw/net/e1000e.c | 2 +- hw/net/eepro100.c | 4 +++- hw/net/etraxfs_eth.c | 3 ++- hw/net/fsl_etsec/etsec.c | 3 ++- hw/net/ftgmac100.c | 3 ++- hw/net/i82596.c | 2 +- hw/net/igb.c | 2 +- hw/net/imx_fec.c | 2 +- hw/net/lan9118.c | 3 ++- hw/net/mcf_fec.c | 3 ++- hw/net/mipsnet.c | 3 ++- hw/net/msf2-emac.c | 3 ++- hw/net/mv88w8618_eth.c | 3 ++- hw/net/ne2000-isa.c | 3 ++- hw/net/ne2000-pci.c | 3 ++- hw/net/npcm7xx_emc.c | 3 ++- hw/net/opencores_eth.c | 3 ++- hw/net/pcnet.c | 3 ++- hw/net/rocker/rocker_fp.c | 4 ++-- hw/net/rtl8139.c | 3 ++- hw/net/smc91c111.c | 3 ++- hw/net/spapr_llan.c | 3 ++- hw/net/stellaris_enet.c | 3 ++- hw/net/sungem.c | 2 +- hw/net/sunhme.c | 3 ++- hw/net/tulip.c | 3 ++- hw/net/virtio-net.c | 6 ++++-- hw/net/vmxnet3.c | 2 +- hw/net/xen_nic.c | 4 ++-- hw/net/xgmac.c | 3 ++- hw/net/xilinx_axienet.c | 3 ++- hw/net/xilinx_ethlite.c | 3 ++- hw/usb/dev-network.c | 3 ++- net/net.c | 1 + 40 files changed, 75 insertions(+), 41 deletions(-)
Quoted 12 lines
include/net/net.h NICState *qemu_new_nic(NetClientInfo *info, · line 161
Quoted 10 lines
include/net/net.h +1
-0@@ -157,6 +157,7 @@ NICState *qemu_new_nic(NetClientInfo *info,NICConf *conf, const char *model, const char *name, + MemReentrancyGuard *reentrancy_guard, void *opaque);Does it make sense to roll
*reentrancy_guardinto NICConf here?
Probably no. All members of NICConf are device properties the user configure, but reentrancy_guard is an internal state. Similarly, the opaque parameter is an internal state and not included in NICConf.
Re: [PATCH v2 1/2] net: Provide MemReentrancyGuard * to qemu_new_nic()
In reply to Akihiko OdakiHi,
Quoted 6 lines · Akihiko Odaki
Recently MemReentrancyGuard was added to DeviceState to record that the device is engaging in I/O. The network device backend needs to update it when delivering a packet to a device.
In preparation for such a change, add MemReentrancyGuard * as a parameter of
qemu_new_nic().
An user on IRC asked if this patch is related/fixing CVE-2021-20255, any clue?
Quoted 43 lines
Signed-off-by Akihiko Odaki <[email protected]>--- include/net/net.h | 1 + hw/net/allwinner-sun8i-emac.c | 3 ++- hw/net/allwinner_emac.c | 3 ++- hw/net/cadence_gem.c | 3 ++- hw/net/dp8393x.c | 3 ++- hw/net/e1000.c | 3 ++- hw/net/e1000e.c | 2 +- hw/net/eepro100.c | 4 +++- hw/net/etraxfs_eth.c | 3 ++- hw/net/fsl_etsec/etsec.c | 3 ++- hw/net/ftgmac100.c | 3 ++- hw/net/i82596.c | 2 +- hw/net/igb.c | 2 +- hw/net/imx_fec.c | 2 +- hw/net/lan9118.c | 3 ++- hw/net/mcf_fec.c | 3 ++- hw/net/mipsnet.c | 3 ++- hw/net/msf2-emac.c | 3 ++- hw/net/mv88w8618_eth.c | 3 ++- hw/net/ne2000-isa.c | 3 ++- hw/net/ne2000-pci.c | 3 ++- hw/net/npcm7xx_emc.c | 3 ++- hw/net/opencores_eth.c | 3 ++- hw/net/pcnet.c | 3 ++- hw/net/rocker/rocker_fp.c | 4 ++-- hw/net/rtl8139.c | 3 ++- hw/net/smc91c111.c | 3 ++- hw/net/spapr_llan.c | 3 ++- hw/net/stellaris_enet.c | 3 ++- hw/net/sungem.c | 2 +- hw/net/sunhme.c | 3 ++- hw/net/tulip.c | 3 ++- hw/net/virtio-net.c | 6 ++++-- hw/net/vmxnet3.c | 2 +- hw/net/xen_nic.c | 4 ++-- hw/net/xgmac.c | 3 ++- hw/net/xilinx_axienet.c | 3 ++- hw/net/xilinx_ethlite.c | 3 ++- hw/usb/dev-network.c | 3 ++- net/net.c | 1 + 40 files changed, 75 insertions(+), 41 deletions(-)
Re: [PATCH v2 1/2] net: Provide MemReentrancyGuard * to qemu_new_nic()
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Akihiko Odaki
Recently MemReentrancyGuard was added to DeviceState to record that the device is engaging in I/O. The network device backend needs to update it when delivering a packet to a device.
In preparation for such a change, add MemReentrancyGuard * as a parameter ofqemu_new_nic().An user on IRC asked if this patch is related/fixing CVE-2021-20255, any clue?
* CVE-2021-20255 bug: infinite recursion is pointing at a different fix patch. -> https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2021-20255
* And the this patch below has different issue tagged
-> https://lists.nongnu.org/archive/html/qemu-devel/2023-05/msg08312.html
Fixes: CVE-2023-3019
* They look different, former is an infinite recursion issue and the latter is a use-after-free one.
Thank you.
---
-Prasad
Re: [PATCH v2 1/2] net: Provide MemReentrancyGuard * to qemu_new_nic()
Quoted 15 lines · Prasad Pandit
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Akihiko Odaki
Recently MemReentrancyGuard was added to DeviceState to record that the device is engaging in I/O. The network device backend needs to update it when delivering a packet to a device.
In preparation for such a change, add MemReentrancyGuard * as a parameter of
qemu_new_nic().An user on IRC asked if this patch is related/fixing CVE-2021-20255, any clue?
* CVE-2021-20255 bug: infinite recursion is pointing at a different fix patch. -> https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2021-20255
Quoted 6 lines
* And the this patch below has different issue tagged
-> https://lists.nongnu.org/archive/html/qemu-devel/2023-05/msg08312.html
Fixes: CVE-2023-3019* They look different, former is an infinite recursion issue and the latter is a use-after-free one.
I assume the eepro reentrancy issue has been fixed with:
https://gitlab.com/qemu-project/qemu/-/issues/556
i.e.:
https://gitlab.com/qemu-project/qemu/-/commit/c40ca2301c7603524eaddb5308a3
HTH,
Thomas
Re: [PATCH v2 1/2] net: Provide MemReentrancyGuard * to qemu_new_nic()
Quoted 21 lines · Thomas Huth
Quoted 20 lines · Prasad Pandit
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Akihiko Odaki
Recently MemReentrancyGuard was added to DeviceState to record that the device is engaging in I/O. The network device backend needs to update it when delivering a packet to a device.
In preparation for such a change, add MemReentrancyGuard * as a parameter ofqemu_new_nic().An user on IRC asked if this patch is related/fixing CVE-2021-20255, any clue?
* CVE-2021-20255 bug: infinite recursion is pointing at a different fix patch. -> https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2021-20255
* And the this patch below has different issue tagged
-> https://lists.nongnu.org/archive/html/qemu-devel/2023-05/msg08312.html
Fixes: CVE-2023-3019
Quoted 7 lines
Quoted 1 line
* They look different, former is an infinite recursion issue and the latter is a use-after-free one.
I assume the eepro reentrancy issue has been fixed with:
https://gitlab.com/qemu-project/qemu/-/issues/556
i.e.:
https://gitlab.com/qemu-project/qemu/-/commit/c40ca2301c7603524eaddb5308a3
I agree. Commit c40ca2301c7603524eaddb5308a3 should be what fixed CVE-2021-20255, not this patch.
Regards,
Akihiko Odaki
Re: [PATCH v2 1/2] net: Provide MemReentrancyGuard * to qemu_new_nic()
Quoted 23 lines · Akihiko Odaki
Quoted 22 lines · Thomas Huth
Quoted 20 lines · Prasad Pandit
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Akihiko Odaki
Recently MemReentrancyGuard was added to DeviceState to record that the device is engaging in I/O. The network device backend needs to update it when delivering a packet to a device.
In preparation for such a change, add MemReentrancyGuard * as a parameter ofqemu_new_nic().An user on IRC asked if this patch is related/fixing CVE-2021-20255, any clue?
* CVE-2021-20255 bug: infinite recursion is pointing at a different fix patch. -> https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2021-20255
* And the this patch below has different issue tagged
-> https://lists.nongnu.org/archive/html/qemu-devel/2023-05/msg08312.html
Fixes: CVE-2023-3019* They look different, former is an infinite recursion issue and the latter is a use-after-free one.
Quoted 7 lines
Quoted 5 lines
I assume the eepro reentrancy issue has been fixed with:
https://gitlab.com/qemu-project/qemu/-/issues/556
i.e.:
https://gitlab.com/qemu-project/qemu/-/commit/c40ca2301c7603524eaddb5308a3I agree. Commit
c40ca2301c7603524eaddb5308a3should be what fixed CVE-2021-20255, not this patch.
Thank you all for clarifying!
Re: [PATCH v2 1/2] net: Provide MemReentrancyGuard * to qemu_new_nic()
Quoted 26 lines · Philippe Mathieu-Daudé
Quoted 25 lines · Akihiko Odaki
Quoted 24 lines · Thomas Huth
Quoted 14 lines · Prasad Pandit
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Akihiko Odaki
Recently MemReentrancyGuard was added to DeviceState to record that the device is engaging in I/O. The network device backend needs to update it when delivering a packet to a device.
In preparation for such a change, add MemReentrancyGuard * as a parameter ofqemu_new_nic().An user on IRC asked if this patch is related/fixing CVE-2021-20255, any clue?
* CVE-2021-20255 bug: infinite recursion is pointing at a different fix patch. -> https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2021-20255
Quoted 6 lines
* And the this patch below has different issue tagged
-> https://lists.nongnu.org/archive/html/qemu-devel/2023-05/msg08312.html
Fixes: CVE-2023-3019* They look different, former is an infinite recursion issue and the latter is a use-after-free one.
I assume the eepro reentrancy issue has been fixed with:
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
https://gitlab.com/qemu-project/qemu/-/issues/556
i.e.:
https://gitlab.com/qemu-project/qemu/-/commit/c40ca2301c7603524eaddb5308a3I agree. Commit
c40ca2301c7603524eaddb5308a3should be what fixed CVE-2021-20255, not this patch.Thank you all for clarifying!
$ git log -p c40ca2301c7603524eaddb5308a3 -- fatal: bad revision 'c40ca2301c7603524eaddb5308a3'
It seems to actually be commit a2e1753b8054344f32cf94f31c6399a58794a380
Regards,
BALATON Zoltan
PATCH v2 2/2 net: Update MemReentrancyGuard for NIC
In reply to Akihiko OdakiRecently MemReentrancyGuard was added to DeviceState to record that the device is engaging in I/O. The network device backend needs to update it when delivering a packet to a device.
This implementation follows what bottom half does, but it does not add a tracepoint for the case that the network device backend started delivering a packet to a device which is already engaging in I/O. This is because such reentrancy frequently happens for qemu_flush_queued_packets() and is insignificant.
--- include/net/net.h | 1 + net/net.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+)
include/net/net.h +1 -0
@@ -124,6 +124,7 @@ typedef QTAILQ_HEAD(NetClientStateList, NetClientState) NetClientStateList;typedef struct NICState {NetClientState *ncs;NICConf *conf; +MemReentrancyGuard *reentrancy_guard;void *opaque;bool peer_deleted; }NICState ;
net/net.c +14 -0
@@ -332,6 +332,7 @@ NICState *qemu_new_nic(NetClientInfo *info, nic =g_malloc0 (info->size +sizeof (NetClientState) * queues); nic->ncs = (void *)nic + info->size; nic->conf = conf; + nic->reentrancy_guard = reentrancy_guard, nic->opaque = opaque;for (i =0 ; i < queues; i++) {
@@ -805,6 +806,7 @@ static ssize_t qemu_deliver_packet_iov(NetClientState *sender,int iovcnt, void *opaque) { + MemReentrancyGuard *owned_reentrancy_guard;NetClientState *nc = opaque;int ret;
@@ -817,12 +819,24 @@ static ssize_t qemu_deliver_packet_iov(NetClientState *sender,return 0 ; } +if (nc->info->type !=NET_CLIENT_DRIVER_NIC || +qemu_get_nic (nc)->reentrancy_guard->engaged_in_io) { + owned_reentrancy_guard =NULL ; + }else { + owned_reentrancy_guard =qemu_get_nic (nc)->reentrancy_guard; + owned_reentrancy_guard->engaged_in_io = true; + } +if (nc->info->receive_iov && !(flags &QEMU_NET_PACKET_FLAG_RAW )) { ret = nc->info->receive_iov (nc, iov, iovcnt); }else { ret =nc_sendv_compat (nc, iov, iovcnt, flags); } +if (owned_reentrancy_guard) { + owned_reentrancy_guard->engaged_in_io = false; + } +if (ret ==0 ) { nc->receive_disabled =1 ; }
Signature · 1 line
2.40.1
Quoted 10 lines · Akihiko Odaki
Recently MemReentrancyGuard was added to DeviceState to record that the device is engaging in I/O. The network device backend needs to update it when delivering a packet to a device.
This implementation follows what bottom half does, but it does not add a tracepoint for the case that the network device backend started delivering a packet to a device which is already engaging in I/O. This is because such reentrancy frequently happens for
qemu_flush_queued_packets()and is insignificant.
Quoted 3 lines
Fixes CVE-2023-3019Reported-by Alexander Bulekov <[email protected]>Signed-off-by Akihiko Odaki <[email protected]>
Quoted 65 lines
--- include/net/net.h | 1 + net/net.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+)include/net/net.h +1
-0@@ -124,6 +124,7 @@ typedef QTAILQ_HEAD(NetClientStateList, NetClientState) NetClientStateList;typedef struct NICState {NetClientState *ncs;NICConf *conf; +MemReentrancyGuard *reentrancy_guard;void *opaque;bool peer_deleted; }NICState ;net/net.c +14
-0@@ -332,6 +332,7 @@ NICState *qemu_new_nic(NetClientInfo *info, nic =g_malloc0 (info->size +sizeof (NetClientState) * queues); nic->ncs = (void *)nic + info->size; nic->conf = conf; + nic->reentrancy_guard = reentrancy_guard, nic->opaque = opaque;for (i =0 ; i < queues; i++) {@@ -805,6 +806,7 @@ static ssize_t qemu_deliver_packet_iov(NetClientState *sender,int iovcnt, void *opaque) { + MemReentrancyGuard *owned_reentrancy_guard;NetClientState *nc = opaque;int ret;@@ -817,12 +819,24 @@ static ssize_t qemu_deliver_packet_iov(NetClientState *sender,return 0 ; } +if (nc->info->type !=NET_CLIENT_DRIVER_NIC || +qemu_get_nic (nc)->reentrancy_guard->engaged_in_io) { + owned_reentrancy_guard =NULL ; + }else { + owned_reentrancy_guard =qemu_get_nic (nc)->reentrancy_guard; + owned_reentrancy_guard->engaged_in_io = true; + } +if (nc->info->receive_iov && !(flags &QEMU_NET_PACKET_FLAG_RAW )) { ret = nc->info->receive_iov (nc, iov, iovcnt); }else { ret =nc_sendv_compat (nc, iov, iovcnt, flags); } +if (owned_reentrancy_guard) { + owned_reentrancy_guard->engaged_in_io = false; + } +if (ret ==0 ) { nc->receive_disabled =1 ; }Signature · 1 line
2.40.1
Quoted 10 lines · Akihiko Odaki
Recently MemReentrancyGuard was added to DeviceState to record that the device is engaging in I/O. The network device backend needs to update it when delivering a packet to a device.
This implementation follows what bottom half does, but it does not add a tracepoint for the case that the network device backend started delivering a packet to a device which is already engaging in I/O. This is because such reentrancy frequently happens for
qemu_flush_queued_packets()and is insignificant.
Quoted 3 lines
This series consists of two patches. The first patch makes a bulk change to add a new parameter to
qemu_new_nic()and does not contain behavioral changes. The second patch actually implements MemReentrancyGuard update.
/me look at the 'net' API.
So the NetReceive* handlers from NetClientInfo process the HW NIC data flow, independently from the CPUs.
IIUC MemReentrancyGuard is supposed to protect reentrancy abuse from CPUs.
NetReceive* handlers aren't restricted to any particular API, they just consume blob of data. Looking at e1000_receive_iov(), this data is filled into memory using the pci_dma_rw() API. pci_dma_rw() gets the AddressSpace to use calling pci_get_address_space(), which returns PCIDevice::bus_master_as. Then we use the dma_memory_rw(), followed by address_space_rw(). Beh, I fail to see why there is reentrancy checks from this NIC DMA HW path.
Maybe the MemoryRegion API isn't the correct place to check for reentrancy abuse and we should do that at the AddressSpace level, keeping DMA ASes clear and only protecting CPU ASes?
Quoted 31 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Akihiko Odaki
Recently MemReentrancyGuard was added to DeviceState to record that the device is engaging in I/O. The network device backend needs to update it when delivering a packet to a device.
This implementation follows what bottom half does, but it does not add a tracepoint for the case that the network device backend started delivering a packet to a device which is already engaging in I/O. This is because such reentrancy frequently happens for
qemu_flush_queued_packets()and is insignificant.Quoted 3 lines
This series consists of two patches. The first patch makes a bulk change to add a new parameter to
qemu_new_nic()and does not contain behavioral changes. The second patch actually implements MemReentrancyGuard update./me look at the 'net' API.
So the NetReceive* handlers from NetClientInfo process the HW NIC data flow, independently from the CPUs.
IIUC MemReentrancyGuard is supposed to protect reentrancy abuse from CPUs.
NetReceive* handlers aren't restricted to any particular API, they just consume blob of data. Looking at
e1000_receive_iov(), this data is filled into memory using thepci_dma_rw()API.pci_dma_rw()gets the AddressSpace to use callingpci_get_address_space(), which returnsPCIDevice::bus_master_as. Then we use thedma_memory_rw(), followed byaddress_space_rw(). Beh, I fail to see why there is reentrancy checks from this NIC DMA HW path.
Quoted 3 lines
Maybe the MemoryRegion API isn't the correct place to check for reentrancy abuse and we should do that at the AddressSpace level, keeping DMA ASes clear and only protecting CPU ASes?
The involvement of CPU is not essential in my understanding. A typical scenario of DMA reentrancy is like the following:
1) The guest configures the DMA destination address register the device has to the address of another device register.
2) The DMA gets triggered.
3) The device performs the DMA, writing its own register.
4) The write causes reentrancy.
5) The re-entered device code corrupts the device state.
I guess 2) is done by CPU in most cases, but sometimes it happen with another cause. In fact, the current reentrancy protection code covers the case that bottom half handlers triggers DMA. The intention of this series is to extend the coverage and handles the case that incoming network traffic triggers DMA.
The essence of DMA reentrancy is in 3). This happens when the DMA address space contains the MMIO region of the device and there is no involvement of CPU here.
Quoted 43 lines · Akihiko Odaki
Quoted 31 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Akihiko Odaki
Recently MemReentrancyGuard was added to DeviceState to record that the device is engaging in I/O. The network device backend needs to update it when delivering a packet to a device.
This implementation follows what bottom half does, but it does not add a tracepoint for the case that the network device backend started delivering a packet to a device which is already engaging in I/O. This is because such reentrancy frequently happens for
qemu_flush_queued_packets()and is insignificant.Quoted 3 lines
This series consists of two patches. The first patch makes a bulk change to add a new parameter to
qemu_new_nic()and does not contain behavioral changes. The second patch actually implements MemReentrancyGuard update./me look at the 'net' API.
So the NetReceive* handlers from NetClientInfo process the HW NIC data flow, independently from the CPUs.
IIUC MemReentrancyGuard is supposed to protect reentrancy abuse from CPUs.
NetReceive* handlers aren't restricted to any particular API, they just consume blob of data. Looking at
e1000_receive_iov(), this data is filled into memory using thepci_dma_rw()API.pci_dma_rw()gets the AddressSpace to use callingpci_get_address_space(), which returnsPCIDevice::bus_master_as. Then we use thedma_memory_rw(), followed byaddress_space_rw(). Beh, I fail to see why there is reentrancy checks from this NIC DMA HW path.Quoted 3 lines
Maybe the MemoryRegion API isn't the correct place to check for reentrancy abuse and we should do that at the AddressSpace level, keeping DMA ASes clear and only protecting CPU ASes?
The involvement of CPU is not essential in my understanding. A typical scenario of DMA reentrancy is like the following:
1) The guest configures the DMA destination address register the device has to the address of another device register.
2) The DMA gets triggered.
3) The device performs the DMA, writing its own register.
4) The write causes reentrancy.
5) The re-entered device code corrupts the device state.
Quoted 3 lines
I guess 2) is done by CPU in most cases, but sometimes it happen with another cause. In fact, the current reentrancy protection code covers the case that bottom half handlers triggers DMA. The intention of this series is to extend the coverage and handles the case that incoming network traffic triggers DMA.
The essence of DMA reentrancy is in 3). This happens when the DMA address space contains the MMIO region of the device and there is no involvement of CPU here.
OK, thanks for the explanation.
Quoted 53 lines · Akihiko Odaki
Recently MemReentrancyGuard was added to DeviceState to record that the device is engaging in I/O. The network device backend needs to update it when delivering a packet to a device.
This implementation follows what bottom half does, but it does not add a tracepoint for the case that the network device backend started delivering a packet to a device which is already engaging in I/O. This is because such reentrancy frequently happens for
qemu_flush_queued_packets()and is insignificant.This series consists of two patches. The first patch makes a bulk change to add a new parameter to
qemu_new_nic()and does not contain behavioral changes. The second patch actually implements MemReentrancyGuard update.V1 -> V2: Added the 'Fixes: CVE-2023-3019' tag
Akihiko Odaki (2):
net: Provide MemReentrancyGuard * toqemu_new_nic()
net: Update MemReentrancyGuard for NICinclude/net/net.h | 2 ++ hw/net/allwinner-sun8i-emac.c | 3 ++- hw/net/allwinner_emac.c | 3 ++- hw/net/cadence_gem.c | 3 ++- hw/net/dp8393x.c | 3 ++- hw/net/e1000.c | 3 ++- hw/net/e1000e.c | 2 +- hw/net/eepro100.c | 4 +++- hw/net/etraxfs_eth.c | 3 ++- hw/net/fsl_etsec/etsec.c | 3 ++- hw/net/ftgmac100.c | 3 ++- hw/net/i82596.c | 2 +- hw/net/igb.c | 2 +- hw/net/imx_fec.c | 2 +- hw/net/lan9118.c | 3 ++- hw/net/mcf_fec.c | 3 ++- hw/net/mipsnet.c | 3 ++- hw/net/msf2-emac.c | 3 ++- hw/net/mv88w8618_eth.c | 3 ++- hw/net/ne2000-isa.c | 3 ++- hw/net/ne2000-pci.c | 3 ++- hw/net/npcm7xx_emc.c | 3 ++- hw/net/opencores_eth.c | 3 ++- hw/net/pcnet.c | 3 ++- hw/net/rocker/rocker_fp.c | 4 ++-- hw/net/rtl8139.c | 3 ++- hw/net/smc91c111.c | 3 ++- hw/net/spapr_llan.c | 3 ++- hw/net/stellaris_enet.c | 3 ++- hw/net/sungem.c | 2 +- hw/net/sunhme.c | 3 ++- hw/net/tulip.c | 3 ++- hw/net/virtio-net.c | 6 ++++--
Quoted 9 lines
hw/net/vmxnet3.c | 2 +- hw/net/xen_nic.c | 4 ++-- hw/net/xgmac.c | 3 ++- hw/net/xilinx_axienet.c | 3 ++- hw/net/xilinx_ethlite.c | 3 ++- hw/usb/dev-network.c | 3 ++- net/net.c | 15 +++++++++++++++ 40 files changed, 90 insertions(+), 41 deletions(-)
Hi Jason,
Can you review this series?
Regards,
Akihiko Odaki
Quoted 65 lines · Akihiko Odaki
Quoted 53 lines · Akihiko Odaki
Recently MemReentrancyGuard was added to DeviceState to record that the device is engaging in I/O. The network device backend needs to update it when delivering a packet to a device.
This implementation follows what bottom half does, but it does not add a tracepoint for the case that the network device backend started delivering a packet to a device which is already engaging in I/O. This is because such reentrancy frequently happens for
qemu_flush_queued_packets()and is insignificant.This series consists of two patches. The first patch makes a bulk change to add a new parameter to
qemu_new_nic()and does not contain behavioral changes. The second patch actually implements MemReentrancyGuard update.V1 -> V2: Added the 'Fixes: CVE-2023-3019' tag
Akihiko Odaki (2):
net: Provide MemReentrancyGuard * toqemu_new_nic()
net: Update MemReentrancyGuard for NICinclude/net/net.h | 2 ++ hw/net/allwinner-sun8i-emac.c | 3 ++- hw/net/allwinner_emac.c | 3 ++- hw/net/cadence_gem.c | 3 ++- hw/net/dp8393x.c | 3 ++- hw/net/e1000.c | 3 ++- hw/net/e1000e.c | 2 +- hw/net/eepro100.c | 4 +++- hw/net/etraxfs_eth.c | 3 ++- hw/net/fsl_etsec/etsec.c | 3 ++- hw/net/ftgmac100.c | 3 ++- hw/net/i82596.c | 2 +- hw/net/igb.c | 2 +- hw/net/imx_fec.c | 2 +- hw/net/lan9118.c | 3 ++- hw/net/mcf_fec.c | 3 ++- hw/net/mipsnet.c | 3 ++- hw/net/msf2-emac.c | 3 ++- hw/net/mv88w8618_eth.c | 3 ++- hw/net/ne2000-isa.c | 3 ++- hw/net/ne2000-pci.c | 3 ++- hw/net/npcm7xx_emc.c | 3 ++- hw/net/opencores_eth.c | 3 ++- hw/net/pcnet.c | 3 ++- hw/net/rocker/rocker_fp.c | 4 ++-- hw/net/rtl8139.c | 3 ++- hw/net/smc91c111.c | 3 ++- hw/net/spapr_llan.c | 3 ++- hw/net/stellaris_enet.c | 3 ++- hw/net/sungem.c | 2 +- hw/net/sunhme.c | 3 ++- hw/net/tulip.c | 3 ++- hw/net/virtio-net.c | 6 ++++--Quoted 9 lines
hw/net/vmxnet3.c | 2 +- hw/net/xen_nic.c | 4 ++-- hw/net/xgmac.c | 3 ++- hw/net/xilinx_axienet.c | 3 ++- hw/net/xilinx_ethlite.c | 3 ++- hw/usb/dev-network.c | 3 ++- net/net.c | 15 +++++++++++++++ 40 files changed, 90 insertions(+), 41 deletions(-)
Quoted 3 lines
Hi Jason,
Can you review this series?
For some reason it falls through the cracks.
I've queued this for rc1.
Thanks
Quoted 4 lines
Regards,
Akihiko Odaki