Skip to content

net, hw/net: Harden common code against bogus offsets

Peter Maydell qemu-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest11 patches 5 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/11hw/net/net_rx_pkt: Handle bogus l4hdr_off when validating SCTP checksumhw/net/net_rx_pkt.c+8 -40 replies
2/11net/eth.c: In eth_parse_ipv6_hdr(), fix check of input sizenet/eth.c+4 -41 reply
3/11net/eth.c: In eth_get_protocols(), don't report SCTP header off end of packetinclude/net/eth.h net/eth.c+10 -14 replies
4/11net/eth.c: Check for undersized IPv4 headers in eth_get_protocols()net/eth.c+2 -00 replies
5/11net/eth.c: Harden _eth_tcp_has_data() against short lengthsnet/eth.c+12 -20 replies
6/11net/eth.c: Tighten size checks in eth_get_l3_proto()net/eth.c+4 -20 replies
7/11include/net/eth.h: Make eth_get_l2_hdr_length_iov() check protocolinclude/net/eth.h+1 -10 replies
8/11hw/net/net_tx_pkt: Sanity check GSO headers in net_tx_pkt_build_vheader()hw/net/net_tx_pkt.c+9 -10 replies
9/11hw/net/net_tx_pkt: Sanity check virt hdr len in net_tx_tcp_fragment_inithw/net/net_tx_pkt.c+1 -10 replies
10/11hw/net/net_tx_pkt: Sanity check L2+L3 header len in net_tx_pkt_parse_headers()hw/net/net_tx_pkt.c+8 -00 replies
11/11hw/net/net_rx_pkt: Check for overflow in _net_rx_pkt_calc_l4_csum()hw/net/net_rx_pkt.c+6 -40 replies

Reviews trailers per patch

1 of 11 patches has a Reviewed-by or Acked-by.

PatchPhilippe Mathieu-Daudé
1/11
2/11
3/11R-b
4/11
5/11
6/11
7/11
8/11
9/11
10/11
11/11

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 00/11] net, hw/net: Harden common code against bogus offsets

This patchset is a set of patches which try to make the common code in net/eth.c and hw/net/net_{tx,rx}_pkt.c a bit more robust against malicious packets with bogus offsets and similar problems. In theory if other parts of the code are correctly checking offsets and sizes to ensure they're within the packet before relying on them, this should make no difference. But a defence-in-depth approach seems like a good idea.

Two things in this are fixing demonstrable bugs:
* the "igb" network device's use of the SCTP checksum validation function allowed a malicious packet to trigger a read off the end of an iovec, likely triggering a segfault (patch 1, issue #4138)
* net_tx_pkt_build_vheader() could overflow a 16-bit field when calculating the virt header length, and net_tx_tcp_fragment_init() would trust that and attempt an extremely large allocation as a result, triggering an abort() (patches 8 and 9, issue #3648)

Neither of those are security issues from QEMU's point of view, because "igb" isn't covered under the virtualization use case and "guest root can trigger self-denial-of-service" is also excluded.

The rest are just sanity-checking, mostly based on suggestions from issue #4156.

The disclaimer here is that this hasn't had much testing beyond "make check" and "make check-functional" plus "make sure virtio-net isn't obviously completely broken", which I am pretty sure do not exercise much of this code at all, especially not the stuff about L3 and L4 and segment-offload. So I'm trusting the net maintainers to have a more extensive testsuite.

thanks
-- PMM

Peter Maydell (11):
hw/net/net_rx_pkt: Handle bogus l4hdr_off when validating SCTP
checksum
net/eth.c: In eth_parse_ipv6_hdr(), fix check of input size net/eth.c: In eth_get_protocols(), don't report SCTP header off end of
packet
net/eth.c: Check for undersized IPv4 headers in eth_get_protocols() 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()

 include/net/eth.h   |  4 +++-
 hw/net/net_rx_pkt.c | 22 ++++++++++++++--------
 hw/net/net_tx_pkt.c | 20 ++++++++++++++++++--
 net/eth.c           | 39 ++++++++++++++++++++++++++++++---------
 4 files changed, 65 insertions(+), 20 deletions(-)
Signature · 1 line
2.43.0