Commit 5251fee208 for qemu.org

commit 5251fee208ac4981dc5ac2e4438ed38955fdad43
Author: Peter Maydell <peter.maydell@linaro.org>
Date:   Mon Nov 9 14:23:55 2026 +0900

    include/net/eth.h: Make eth_get_l2_hdr_length_iov() check protocol

    In eth_get_l2_hdr_length() we return sizeof(eth_header) for
    any protocol other than VLAN or DVLAN. However, in the iov
    version of this function, if the packet is larger than
    the ethernet header but not large enough for both the eth_header
    and the vlan_header we'll end up returning the actual packet
    size rather than the eth_header size. Fix the "not enough
    data" return case.

    This will only cause issues if the caller isn't already checking
    offsets and sizes, so this is defence-in-depth.  It also in theory
    corrects the result for the hypothetical case of an ethernet-level
    protocol that allows a payload of less than 4 bytes.

    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-10-334cc08e2f2e@rsg.ci.i.u-tokyo.ac.jp
    Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

diff --git a/include/net/eth.h b/include/net/eth.h
index e10684ed92..3e83f5d68c 100644
--- a/include/net/eth.h
+++ b/include/net/eth.h
@@ -321,7 +321,7 @@ eth_get_l2_hdr_length_iov(const struct iovec *iov, size_t iovcnt, size_t iovoff)
     size_t copied = iov_to_buf(iov, iovcnt, iovoff, p, ARRAY_SIZE(p));

     if (copied < ARRAY_SIZE(p)) {
-        return copied;
+        return MIN(copied, sizeof(struct eth_header));
     }

     return eth_get_l2_hdr_length(p);