hw/net/opencores_eth: clamp MII register read to local PHY array
PATCH 1/1 hw/net/opencores_eth: clamp MII register read to local PHY array
mii_read_host() uses the guest-supplied register index directly to read from Mii.regs[], which has only MII_REG_MAX (16) entries. The adjacent mii_write_host() already rejects idx >= MII_REG_MAX, but the read path did not, so a guest writing MIIADDRESS.RGAD to 16..31 and then setting MIICOMMAND.RSTAT caused a host-side out-of-bounds read.
Return 0xffff for out-of-range indices; this matches the value already used for reads with FIAD != DEFAULT_PHY and is the conventional value for unimplemented MII registers.
Add a qtest on the lx60 board that programs RGAD == 16 and triggers the read command, verifying MIIRX_DATA reads 0xffff instead of crashing or tripping sanitizer checks.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4364
--- hw/net/opencores_eth.c | 3 ++ tests/qtest/meson.build | 3 ++ tests/qtest/opencores-eth-test.c | 66 ++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 tests/qtest/opencores-eth-test.c
hw/net/opencores_eth.c +3 -0
@@ -130,6 +130,9 @@ static void mii_write_host(Mii *s, unsigned idx, uint16_t v)static uint16_t mii_read_host (Mii *s,unsigned idx) { +if (idx >=MII_REG_MAX ) { +return 0xffff ; + }trace_open_eth_mii_read (idx, s->regs[idx]);return s->regs[idx]; }
tests/qtest/meson.build +3 -0
@@ -217,6 +217,9 @@ qtests_sparc64 = \ qtests_filter + \ ['prom-env-test', 'boot-serial-test'] +qtests_xtensa = \ + (config_all_devices.has_key('CONFIG_OPENCORES_ETH') ? ['opencores-eth-test'] : []) + qtests_npcm7xx = \ ['npcm7xx_adc-test', 'npcm7xx_gpio-test',
tests/qtest/opencores-eth-test.c new file +66 -0
66 lines not on this page · raw message
Signature · 1 line
2.50.1 (Apple Git-155)