mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yuansheng Yang <0xbeac@gmail.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH net] vxlan: fix out-of-bounds read in DF inherit path
Date: Thu, 26 Nov 2026 11:44:12 +0800	[thread overview]
Message-ID: <20261126034412.2799912-1-0xbeac@gmail.com> (raw)

vxlan_xmit_one() calls skb_vlan_inet_prepare() to pull the inner network
header into linear memory before assigning old_iph = ip_hdr(skb).  That
helper checks skb->protocol (skipping VLAN tags) and only pulls an IPv4 or
IPv6 header when the inner protocol is ETH_P_IP or ETH_P_IPV6.

However, the VXLAN_DF_INHERIT branch inspects eth_hdr(skb)->h_proto
before reading old_iph->frag_off.  With AF_PACKET/SOCK_RAW, eth->h_proto
and skb->protocol are independent: a 14-byte Ethernet frame with
h_proto set to ETH_P_IP and sll_protocol set to ETH_P_ARP passes
skb_vlan_inet_prepare() with only ETH_HLEN bytes pulled, leaving old_iph
pointing at skb->tail.  Reading old_iph->frag_off then accesses 6 bytes
past skb->tail in uninitialized tailroom and copies one bit into the
outer IPv4 DF bit.

Using eth_hdr(skb)->h_proto also fails to inherit DF for VLAN-tagged
packets and reads past the nonexistent Ethernet header on VXLAN-GPE
packets without Ethernet encapsulation.

Use skb_protocol(skb, true) to match skb_vlan_inet_prepare(), as the
TTL, DSCP and flowlabel inheritance helpers already do.

Discovered by manual code inspection following the sibling geneve
DF-inherit fix, with Gemini assisting in path verification and preparing
this patch and changelog.  Verified by static analysis and compile
testing only; the out-of-bounds read was not triggered or tested at
runtime.

Fixes: b4d3069783bc ("vxlan: Allow configuration of DF behaviour")
Cc: stable@vger.kernel.org
Signed-off-by: Yuansheng Yang <0xbeac@gmail.com>
---
Sibling geneve fix on netdev/lkml:
  https://lore.kernel.org/lkml/20261125235524.4139551-1-xmei5@asu.edu/

Testing: drivers/net/vxlan/vxlan_core.o compiled with W=1 on x86_64
(GCC 15.2.0, CONFIG_VXLAN=y, CONFIG_KASAN=y) with no warnings or errors;
git apply --check passes.  Not dynamically tested; no runtime reproducer
was executed.

Checked against net.git HEAD ef3e21c61baa (whose vxlan_core.c matches
the base-commit blob below).

 drivers/net/vxlan/vxlan_core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c
index d11028b37472..76a1828111ea 100644
--- a/drivers/net/vxlan/vxlan_core.c
+++ b/drivers/net/vxlan/vxlan_core.c
@@ -2551,10 +2551,10 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 			if (cfg->df == VXLAN_DF_SET) {
 				df = htons(IP_DF);
 			} else if (cfg->df == VXLAN_DF_INHERIT) {
-				struct ethhdr *eth = eth_hdr(skb);
+				__be16 inner_proto = skb_protocol(skb, true);
 
-				if (ntohs(eth->h_proto) == ETH_P_IPV6 ||
-				    (ntohs(eth->h_proto) == ETH_P_IP &&
+				if (inner_proto == htons(ETH_P_IPV6) ||
+				    (inner_proto == htons(ETH_P_IP) &&
 				     old_iph->frag_off & htons(IP_DF)))
 					df = htons(IP_DF);
 			}
-- 
2.43.0

base-commit: c710c654b8a3c92b34e38740dc17c29daf5b222e

                 reply	other threads:[~2026-11-26  3:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126034412.2799912-1-0xbeac@gmail.com \
    --to=0xbeac@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®