qemu/hw/net
Peter Maydell 700d3d6dd4 hw/net/smc91c111: Don't allow data register access to overrun buffer
For accesses to the 91c111 data register, the address within the
packet's data frame is determined by a combination of the pointer
register and the offset used to access the data register, so that you
can access data at effectively wider than byte width.  The pointer
register's pointer field is 11 bits wide, which is exactly the size
to index a 2048-byte data frame.

We weren't quite getting the logic right for ensuring that we end up
with a pointer value to use in the s->data[][] array that isn't out
of bounds:

 * we correctly mask when getting the initial pointer value
 * for the "autoincrement the pointer register" case, we
   correctly mask after adding 1 so that the pointer register
   wraps back around at the 2048 byte mark
 * but for the non-autoincrement case where we have to add the
   low 2 bits of the data register offset, we don't account
   for the possibility that the pointer register is 0x7ff
   and the addition should wrap

Fix this bug by factoring out the "get the p value to use as an array
index" into a function, making it use FIELD macro names rather than
hard-coded constants, and having a utility function that does "add a
value and wrap it" that we can use both for the "autoincrement" and
"add the offset bits" codepaths.

Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2758
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20250228191652.1957208-1-peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
2025-03-11 20:03:24 +01:00
..
can include/hw/qdev-properties: Remove DEFINE_PROP_END_OF_LIST 2024-12-19 19:36:37 +01:00
fsl_etsec hw/net/fsl_etsec: Set eTSEC device description and category 2025-03-04 14:45:34 +01:00
rocker qapi: Move include/qapi/qmp/ to include/qobject/ 2025-02-10 15:33:16 +01:00
allwinner-sun8i-emac.c hw/arm: Mark Allwinner Technology devices as little-endian 2025-02-16 14:41:46 +01:00
allwinner_emac.c hw/arm: Mark Allwinner Technology devices as little-endian 2025-02-16 14:41:46 +01:00
cadence_gem.c hw/net/cadence_gem: Fix the mask/compare/disable-mask logic 2025-02-07 16:09:20 +00:00
dp8393x.c include/hw/qdev-properties: Remove DEFINE_PROP_END_OF_LIST 2024-12-19 19:36:37 +01:00
e1000.c Accel & Exec patch queue 2024-12-21 11:07:00 -05:00
e1000_common.h e1000: Split header files 2023-03-10 15:35:38 +08:00
e1000_regs.h hw/net: spelling fixes 2023-09-20 07:54:34 +03:00
e1000e.c pci: Use PCI PM capability initializer 2025-03-06 06:47:33 +01:00
e1000e_core.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
e1000e_core.h e1000e: fix link state on resume 2024-03-12 19:28:32 +08:00
e1000x_common.c e1000x: Take CRC into consideration for size check 2023-05-23 15:20:15 +08:00
e1000x_common.h e1000x: Share more Rx filtering logic 2023-05-23 15:20:15 +08:00
e1000x_regs.h hw/net: spelling fixes 2023-09-20 07:54:34 +03:00
eepro100.c pci: Use PCI PM capability initializer 2025-03-06 06:47:33 +01:00
ftgmac100.c Accel & Exec patch queue 2024-12-21 11:07:00 -05:00
i82596.c * Convert more Avocado tests to the new functional test framework 2024-09-28 12:34:38 +01:00
i82596.h hw/net: Make NetCanReceive() return a boolean 2020-03-31 21:14:35 +08:00
igb.c pci: Use PCI PM capability initializer 2025-03-06 06:47:33 +01:00
igb_common.h igb: Add a VF reset handler 2023-11-13 15:33:37 +08:00
igb_core.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
igb_core.h igb: fix link state on resume 2024-03-12 19:28:31 +08:00
igb_regs.h license: Update deprecated SPDX tag GPL-2.0 to GPL-2.0-only 2024-09-20 10:11:59 +03:00
igbvf.c hw, target: Add ResetType argument to hold and exit phase methods 2024-04-25 10:21:06 +01:00
imx_fec.c Accel & Exec patch queue 2024-12-21 11:07:00 -05:00
Kconfig hw/net/lan9118_phy: Reuse in imx_fec and consolidate implementations 2024-12-11 15:30:51 +00:00
lan9118.c include/hw/qdev-properties: Remove DEFINE_PROP_END_OF_LIST 2024-12-19 19:36:37 +01:00
lan9118_phy.c hw/net/lan9118_phy: Add missing 100 mbps full duplex advertisement 2024-12-11 15:30:52 +00:00
lance.c Accel & Exec patch queue 2024-12-21 11:07:00 -05:00
lasi_i82596.c Accel & Exec patch queue 2024-12-21 11:07:00 -05:00
mcf_fec.c include/hw/qdev-properties: Remove DEFINE_PROP_END_OF_LIST 2024-12-19 19:36:37 +01:00
meson.build hw/net: Add NPCM8XX PCS Module 2025-02-20 15:22:22 +00:00
mipsnet.c include/hw/qdev-properties: Remove DEFINE_PROP_END_OF_LIST 2024-12-19 19:36:37 +01:00
msf2-emac.c include/hw/qdev-properties: Remove DEFINE_PROP_END_OF_LIST 2024-12-19 19:36:37 +01:00
mv88w8618_eth.c Accel & Exec patch queue 2024-12-21 11:07:00 -05:00
ne2000-isa.c Accel & Exec patch queue 2024-12-21 11:07:00 -05:00
ne2000-pci.c Accel & Exec patch queue 2024-12-21 11:07:00 -05:00
ne2000.c hw/net: Constify VMState 2023-12-30 07:38:06 +11:00
ne2000.h Include hw/hw.h exactly where needed 2019-08-16 13:31:52 +02:00
net_rx_pkt.c hw/net/net_rx_pkt: Remove deadcode 2024-10-03 17:26:05 +03:00
net_rx_pkt.h hw/net/net_rx_pkt: Remove deadcode 2024-10-03 17:26:05 +03:00
net_tx_pkt.c Revert "hw/net/net_tx_pkt: Fix overrun in update_sctp_checksum()" 2025-03-10 17:07:16 +08:00
net_tx_pkt.h igb: Implement Tx SCTP CSO 2023-05-23 15:20:15 +08:00
npcm7xx_emc.c Accel & Exec patch queue 2024-12-21 11:07:00 -05:00
npcm_gmac.c Accel & Exec patch queue 2024-12-21 11:07:00 -05:00
npcm_pcs.c hw/net: Add NPCM8XX PCS Module 2025-02-20 15:22:22 +00:00
opencores_eth.c include/hw/qdev-properties: Remove DEFINE_PROP_END_OF_LIST 2024-12-19 19:36:37 +01:00
pcnet-pci.c Accel & Exec patch queue 2024-12-21 11:07:00 -05:00
pcnet.c Avoid unaligned fetch in ladr_match() 2024-03-12 19:28:32 +08:00
pcnet.h net: Replace TAB indentations with spaces 2022-11-11 09:39:03 +01:00
rtl8139.c Accel & Exec patch queue 2024-12-21 11:07:00 -05:00
smc91c111.c hw/net/smc91c111: Don't allow data register access to overrun buffer 2025-03-11 20:03:24 +01:00
spapr_llan.c Accel & Exec patch queue 2024-12-21 11:07:00 -05:00
stellaris_enet.c include/hw/qdev-properties: Remove DEFINE_PROP_END_OF_LIST 2024-12-19 19:36:37 +01:00
sungem.c Accel & Exec patch queue 2024-12-21 11:07:00 -05:00
sunhme.c Accel & Exec patch queue 2024-12-21 11:07:00 -05:00
trace-events hw/net: Add NPCM8XX PCS Module 2025-02-20 15:22:22 +00:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00
tulip.c Accel & Exec patch queue 2024-12-21 11:07:00 -05:00
tulip.h Use OBJECT_DECLARE_SIMPLE_TYPE when possible 2020-09-18 14:12:32 -04:00
vhost_net-stub.c virtio-net: add support for configure interrupt 2023-01-08 01:54:22 -05:00
vhost_net.c vhost_net: fix assertion triggered by batch of host notifiers processing 2024-11-26 16:35:51 -05:00
virtio-net.c virtio,pc,pci: features, fixes, cleanups 2025-02-22 05:06:39 +08:00
vmware_utils.h hw/net/vmxnet3: Fix code to work on big endian hosts, too 2017-11-20 11:08:00 +08:00
vmxnet3.c Accel & Exec patch queue 2024-12-21 11:07:00 -05:00
vmxnet3.h hw/net: spelling fixes 2023-09-20 07:54:34 +03:00
vmxnet3_defs.h include/hw/pci: Split pci_device.h off pci.h 2023-01-08 01:54:22 -05:00
vmxnet_debug.h Clean up ill-advised or unusual header guards 2016-07-12 16:20:46 +02:00
xen_nic.c qapi: Move include/qapi/qmp/ to include/qobject/ 2025-02-10 15:33:16 +01:00
xgmac.c include/hw/qdev-properties: Remove DEFINE_PROP_END_OF_LIST 2024-12-19 19:36:37 +01:00
xilinx_axienet.c include/hw/qdev-properties: Remove DEFINE_PROP_END_OF_LIST 2024-12-19 19:36:37 +01:00
xilinx_ethlite.c hw/net/xilinx_ethlite: Make device endianness configurable 2025-02-16 14:34:16 +01:00