hw/net/xilinx_ethlite: Check for oversized TX packets
PATCH 1/1 hw/net/xilinx_ethlite: Check for oversized TX packets
The xilinx_ethlite network device wasn't checking that the TX packet size set by the guest was within the size of its dual port RAM, with the effect that the guest could get it to read off the end of the RAM block.
Check the length. There is no provision in this very simple device for reporting errors, so as with various RX errors we just report via tracepoint.
This lack of length check has been present since the device was first introduced, though the code implementing the tx path has changed somewhat since then.
Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3317
--- hw/net/trace-events | 1 + hw/net/xilinx_ethlite.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-)
hw/net/trace-events +1 -0
@@ -527,3 +527,4 @@ xen_netdev_rx(int dev, int idx, int status, int flags) "vif%u idx %d status %d f # xilinx_ethlite.c ethlite_pkt_lost(uint32_t rx_ctrl) "rx_ctrl:0x%" PRIx32 ethlite_pkt_size_too_big(uint64_t size) "size:0x%" PRIx64 +ethlite_pkt_tx_size_too_big(uint64_t size) "size:0x%" PRIx64
hw/net/xilinx_ethlite.c +9 -3
@@ -162,9 +162,15 @@ static void port_tx_write(void *opaque, hwaddr addr, uint64_t value,break ;case TX_CTRL :if ((value & (CTRL_P |CTRL_S )) ==CTRL_S ) { -qemu_send_packet (qemu_get_queue (s->nic), -txbuf_ptr (s, port_index), - s->port[port_index].reg.tx_len); +uint32_t size = s->port[port_index].reg.tx_len; + +if (size >=BUFSZ_MAX ) { +trace_ethlite_pkt_tx_size_too_big (size); + }else { +qemu_send_packet (qemu_get_queue (s->nic), +txbuf_ptr (s, port_index), + size); + }if (s->port[port_index].reg.tx_ctrl &CTRL_I ) {eth_pulse_irq (s); }
Signature · 1 line
2.43.0
Quoted 9 lines · Peter Maydell
The
xilinx_ethlitenetwork device wasn't checking that the TX packet size set by the guest was within the size of its dual port RAM, with the effect that the guest could get it to read off the end of the RAM block.Check the length. There is no provision in this very simple device for reporting errors, so as with various RX errors we just report via tracepoint.
Quoted 8 lines
This lack of length check has been present since the device was first introduced, though the code implementing the tx path has changed somewhat since then.
Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3317Fixes b43848a1005ce ("xilinx: Add ethlite emulation")Signed-off-by Peter Maydell <[email protected]>
Quoted 40 lines
--- hw/net/trace-events | 1 + hw/net/xilinx_ethlite.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-)hw/net/trace-events +1
-0@@ -527,3 +527,4 @@ xen_netdev_rx(int dev, int idx, int status, int flags) "vif%u idx %d status %d f # xilinx_ethlite.c ethlite_pkt_lost(uint32_t rx_ctrl) "rx_ctrl:0x%" PRIx32 ethlite_pkt_size_too_big(uint64_t size) "size:0x%" PRIx64 +ethlite_pkt_tx_size_too_big(uint64_t size) "size:0x%" PRIx64hw/net/xilinx_ethlite.c +9
-3@@ -162,9 +162,15 @@ static void port_tx_write(void *opaque, hwaddr addr, uint64_t value,break ;case TX_CTRL :if ((value & (CTRL_P |CTRL_S )) ==CTRL_S ) { -qemu_send_packet (qemu_get_queue (s->nic), -txbuf_ptr (s, port_index), - s->port[port_index].reg.tx_len); +uint32_t size = s->port[port_index].reg.tx_len; + +if (size >=BUFSZ_MAX ) { +trace_ethlite_pkt_tx_size_too_big (size); + }else { +qemu_send_packet (qemu_get_queue (s->nic), +txbuf_ptr (s, port_index), + size); + }if (s->port[port_index].reg.tx_ctrl &CTRL_I ) {eth_pulse_irq (s); }Signature · 1 line
2.43.0
Quoted 10 lines · Peter Maydell
The
xilinx_ethlitenetwork device wasn't checking that the TX packet size set by the guest was within the size of its dual port RAM, with the effect that the guest could get it to read off the end of the RAM block.Check the length. There is no provision in this very simple device for reporting errors, so as with various RX errors we just report via tracepoint.
Quoted 8 lines
This lack of length check has been present since the device was first introduced, though the code implementing the tx path has changed somewhat since then.
Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3317Fixes b43848a1005ce ("xilinx: Add ethlite emulation")Signed-off-by Peter Maydell <[email protected]>
Alistair
Quoted 41 lines
--- hw/net/trace-events | 1 + hw/net/xilinx_ethlite.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-)hw/net/trace-events +1
-0@@ -527,3 +527,4 @@ xen_netdev_rx(int dev, int idx, int status, int flags) "vif%u idx %d status %d f # xilinx_ethlite.c ethlite_pkt_lost(uint32_t rx_ctrl) "rx_ctrl:0x%" PRIx32 ethlite_pkt_size_too_big(uint64_t size) "size:0x%" PRIx64 +ethlite_pkt_tx_size_too_big(uint64_t size) "size:0x%" PRIx64hw/net/xilinx_ethlite.c +9
-4@@ -162,9 +162,15 @@ static void port_tx_write(void *opaque, hwaddr addr, uint64_t value,break ;case TX_CTRL :if ((value & (CTRL_P |CTRL_S )) ==CTRL_S ) { -qemu_send_packet (qemu_get_queue (s->nic), -txbuf_ptr (s, port_index), - s->port[port_index].reg.tx_len); +uint32_t size = s->port[port_index].reg.tx_len; + +if (size >=BUFSZ_MAX ) { +trace_ethlite_pkt_tx_size_too_big (size); + }else { +qemu_send_packet (qemu_get_queue (s->nic), +txbuf_ptr (s, port_index), + size); + }if (s->port[port_index].reg.tx_ctrl &CTRL_I ) {eth_pulse_irq (s); } --2.43.0
Quoted 36 lines · Peter Maydell
The
xilinx_ethlitenetwork device wasn't checking that the TX packet size set by the guest was within the size of its dual port RAM, with the effect that the guest could get it to read off the end of the RAM block.Check the length. There is no provision in this very simple device for reporting errors, so as with various RX errors we just report via tracepoint.
This lack of length check has been present since the device was first introduced, though the code implementing the tx path has changed somewhat since then.
Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3317Fixes b43848a1005ce ("xilinx: Add ethlite emulation")Signed-off-by Peter Maydell <[email protected]>--- hw/net/trace-events | 1 + hw/net/xilinx_ethlite.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-)hw/net/xilinx_ethlite.c +2
-3@@ -162,9 +162,15 @@ static void port_tx_write(void *opaque, hwaddr addr, uint64_t value,break ;case TX_CTRL :if ((value & (CTRL_P |CTRL_S )) ==CTRL_S ) { -qemu_send_packet (qemu_get_queue (s->nic), -txbuf_ptr (s, port_index), - s->port[port_index].reg.tx_len); +uint32_t size = s->port[port_index].reg.tx_len; +
hw/net/xilinx_ethlite.c static void port_tx_write(void *opaque, hwaddr addr, uint64_t value, · line 176
Quoted 10 lines
hw/net/xilinx_ethlite.c +7
-0+if (size >=BUFSZ_MAX ) { +trace_ethlite_pkt_tx_size_too_big (size); + }else { +qemu_send_packet (qemu_get_queue (s->nic), +txbuf_ptr (s, port_index), + size); + }if (s->port[port_index].reg.tx_ctrl &CTRL_I ) {eth_pulse_irq (s); }
Patch queued renaming @size -> @tx_size to prevent:
../hw/net/xilinx_ethlite.c: In function ‘port_tx_write’:../hw/net/xilinx_ethlite.c:165:22: error: declaration of ‘size’ shadows a parameter [-Werror=shadow=compatible-local]
165 | uint32_t size = s->port[port_index].reg.tx_len;
| ^~~~../hw/net/xilinx_ethlite.c:151:40: note: shadowed declaration is here
151 | unsigned int size)
| ~~~~~~~~~~~~~^~~~