Netdev List
 help / color / mirror / Atom feed
From: Aviral Srivastava <aviralyash27@gmail.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, willemb@google.com, horms@kernel.org,
	Aviral Srivastava <aviralyash27@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH net v2] udp: gro: do not match tunnel-processed and plain packets
Date: Mon, 23 Nov 2026 17:38:23 -0800	[thread overview]
Message-ID: <20261124013823.96835-1-aviralyash27@gmail.com> (raw)

udp_gro_receive_segment() matches an incoming UDP packet against the
held packets using udp_hdr(p), while every other GRO layer compares at
p->data + off. When an inner network header was parsed for p (vxlan,
geneve, or IPIP/SIT/GRE carried over FOU/GUE), the transport header of
p points at the inner L4 header. The port check then compares the ports
of an incoming plain UDP datagram with the inner TCP/UDP ports of the
tunnelled flow, and on a match the datagram is handled as the next
segment of that flow.

This needs both packets in the same GRO bucket with the same outer
addresses (no RX hash, or an equal one), a UDP tunnel GRO socket on the
receiver, and a UDP_GRO socket on the port, rx-udp-gro-forwarding or
rx-gro-list. Plain and tunnelled TCP cannot meet this way, their outer
IP protocols differ.

Since commit e20cf8d3f1f7 ("udp: implement GRO for plain UDP sockets.")
the datagram can be merged into the tunnelled aggregate. On v6.6.162 a
plain datagram with ordinary outer header values (same TTL, TOS and DF
as the vxlan packet) is appended to the inner TCP segment and never
reaches the UDP socket.

Since commit 4b0ebbca3e16 ("net: gro: move L3 flush checks to
tcp_gro_receive and udp_gro_receive_segment")
gro_receive_network_flush() also derives the network header of the
incoming skb from p's offsets (outer network header to inner transport
header: 70 bytes for vxlan over IPv4, more with larger inner headers)
and reads before the incoming skb's network header, out of bounds on
skbs with small headroom:

  BUG: KASAN: slab-out-of-bounds in __gro_receive_network_flush
  Read of size 1 ...
   udp_gro_receive <- udp4_gro_receive <- inet_gro_receive <- dev_gro_receive

The merge then depends on the bytes read there. When it happens with
rx-gro-list and forwarding, the datagram is forwarded as part of the
inner flow's aggregate, so netfilter rules matching the datagram itself
are not applied to it. Without a merge, the wrong comparison still
flushes the tunnelled flow on every such datagram.

When udp_gro_receive_segment() runs, NAPI_GRO_CB()->encap_mark is set
only if an inner network header was parsed for the packet, which is
also the only case where the transport header is past the first UDP
header. FOU and GUE clear encap_mark, but when they carry an L4
protocol directly the transport header and network offsets still
describe the outer headers, the same layer as for plain UDP; when they
carry IPIP, SIT or GRE the inner handler sets it again. Skip held
packets whose encap_mark differs from the incoming packet: both are 0
or both are 1 within one flow, so legitimate aggregation is unchanged.

Found by an AI code review agent (Claude) reviewing the UDP GRO code.
Confirmed with reproducers on unmodified kernels (arm64 QEMU with
KASAN, network namespaces over veth), and the fix was tested there:
- torvalds/master 4843f6873f7c, vxlan, geneve, and FOU/GUE carrying
  IPIP, SIT, GRE and vxlan: KASAN reports on every run before, none
  after; forced merge of 98% of the datagrams before, none after.
- v6.6.162 with this change backported, vxlan and geneve: 2000 of 2000
  datagrams merged before, none after; no KASAN report either way.
- Plain UDP GRO, UDP and TCP in vxlan, UDP in geneve and UDP in
  FOU/GUE + IPIP/GRE still aggregate.
Not tested: x86_64, real NICs, vxlan-gpe.

Fixes: e20cf8d3f1f7 ("udp: implement GRO for plain UDP sockets.")
Fixes: 4b0ebbca3e16 ("net: gro: move L3 flush checks to tcp_gro_receive and udp_gro_receive_segment")
Cc: stable@vger.kernel.org
Signed-off-by: Aviral Srivastava <aviralyash27@gmail.com>
---

Notes:
    v2:
    - Add Fixes: e20cf8d3f1f7 and Cc: stable. The merge without the
      out-of-bounds read is reproduced on v6.6.162 (Sashiko).
    - Reword the comment and changelog on what encap_mark means with
      FOU/GUE. No functional change: FOU/GUE carrying L4 directly keep the
      transport header at the outer UDP header (Sashiko).
    - Changelog: state the preconditions, correct the netfilter sentence
      (the hooks see the aggregate, not the datagram), move discovery and
      testing into the changelog, add geneve, FOU/GUE and v6.6 results.
    - v1 reported "28 and 29" KASAN reports; that was the dmesg ring
      limit. The console logs of those runs hold 1023 and 308 reports.
    v1: https://lore.kernel.org/netdev/20261122183951.73210-1-aviralyash27@gmail.com/
    
    The analysis, reproducers, fix and changelog were drafted with an LLM
    coding assistant (Claude). I reviewed them before sending. Reproducers
    and logs are available on request.

 net/ipv4/udp_offload.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c
index b77ae2f00c62..a9368a6abde2 100644
--- a/net/ipv4/udp_offload.c
+++ b/net/ipv4/udp_offload.c
@@ -723,6 +723,19 @@ static struct sk_buff *udp_gro_receive_segment(struct list_head *head,
 		if (!NAPI_GRO_CB(p)->same_flow)
 			continue;
 
+		/* encap_mark is set here only if an inner network header
+		 * was parsed (UDP tunnels, IPIP, SIT, GRE, also when carried
+		 * over FOU/GUE). udp_hdr() then points at the inner L4
+		 * header and the network offsets describe the inner packet.
+		 * FOU/GUE carrying an L4 protocol directly clear it and
+		 * leave udp_hdr() at the outer UDP header, as for plain UDP.
+		 * Never match packets across the two cases.
+		 */
+		if (NAPI_GRO_CB(p)->encap_mark != NAPI_GRO_CB(skb)->encap_mark) {
+			NAPI_GRO_CB(p)->same_flow = 0;
+			continue;
+		}
+
 		uh2 = udp_hdr(p);
 
 		/* Match ports only, as csum is always non zero */
-- 
2.55.0


                 reply	other threads:[~2026-11-24  1:38 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=20261124013823.96835-1-aviralyash27@gmail.com \
    --to=aviralyash27@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=willemb@google.com \
    /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