Commit 2dd4094cfb for qemu.org
commit 2dd4094cfb255b17839a28990eb9145b9b4fe8ae
Author: Peter Maydell <peter.maydell@linaro.org>
Date: Mon Nov 9 14:23:54 2026 +0900
net/eth.c: Tighten size checks in eth_get_l3_proto()
Currently eth_get_l3_proto() has a check that the offset of the
protocol field is not off the end of the iovec; this is actually
unnecessary because iov_to_buf() guarantees to return 0 for offsets
off the end of the iovec. On the other hand, it assumes that the
l2hdr_len it is passed is not so small that the protocol offset
calculation underflows and it doesn't check that the packet is
actually big enough for the l2hdr_len. This shouldn't matter
if other parts of the code are checking, but for defence in
depth we tighten this check.
Cc: qemu-stable@nongnu.org
Fixes: eb700029c783 ("net_pkt: Extend packet abstraction as required by e1000e functionality")
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-9-334cc08e2f2e@rsg.ci.i.u-tokyo.ac.jp
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
diff --git a/net/eth.c b/net/eth.c
index 74a705a267..33b61cac41 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -75,11 +75,13 @@ eth_get_l3_proto(const struct iovec *l2hdr_iov, int iovcnt, size_t l2hdr_len)
uint16_t proto;
size_t copied;
size_t size = iov_size(l2hdr_iov, iovcnt);
- size_t proto_offset = l2hdr_len - sizeof(proto);
+ size_t proto_offset;
- if (size < proto_offset) {
+ if (l2hdr_len < sizeof(struct eth_header) || size < l2hdr_len) {
+ /* We don't have a complete ethernet header */
return ETH_P_UNKNOWN;
}
+ proto_offset = l2hdr_len - sizeof(proto);
copied = iov_to_buf(l2hdr_iov, iovcnt, proto_offset,
&proto, sizeof(proto));