Commit fda35a236c for qemu.org
commit fda35a236c96ee08e10481f585aa6bd841968395
Author: Peter Maydell <peter.maydell@linaro.org>
Date: Mon Nov 9 14:23:58 2026 +0900
hw/net/net_tx_pkt: Sanity check L2+L3 header len in net_tx_pkt_parse_headers()
In net_tx_pkt_parse_headers() we examine the L2 and L3 headers one
after the other. Add a sanity check that the two together don't
exceed the packet length or the maximum IP packet size. This
shouldn't happen if the L3 parsing was done right, but is worth doing
for defence-in-depth.
Cc: qemu-stable@nongnu.org
Fixes: e263cd49c73c595 ("Packet abstraction for VMWARE network devices")
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Message-id: 20261109-eth-v2-13-334cc08e2f2e@rsg.ci.i.u-tokyo.ac.jp
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
diff --git a/hw/net/net_tx_pkt.c b/hw/net/net_tx_pkt.c
index dc2563721e..c331628134 100644
--- a/hw/net/net_tx_pkt.c
+++ b/hw/net/net_tx_pkt.c
@@ -267,6 +267,14 @@ static bool net_tx_pkt_parse_headers(struct NetTxPkt *pkt)
break;
}
+ if (l2_hdr->iov_len + l3_hdr->iov_len > ETH_MAX_IP_DGRAM_LEN ||
+ l2_hdr->iov_len + l3_hdr->iov_len >
+ iov_size(pkt->raw, pkt->raw_frags)) {
+ l2_hdr->iov_len = 0;
+ l3_hdr->iov_len = 0;
+ return false;
+ }
+
net_tx_pkt_calculate_hdr_len(pkt);
return true;
}