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>
Subject: [PATCH net] udp: gro: do not match tunnel-processed and plain packets
Date: Sun, 22 Nov 2026 10:39:51 -0800	[thread overview]
Message-ID: <20261122183951.73210-1-aviralyash27@gmail.com> (raw)

udp_gro_receive_segment() matches an incoming UDP packet against the
held packets using udp_hdr(p). When p went through a UDP tunnel GRO
handler (vxlan, geneve), its transport header points at the inner L4
header, so the port check compares the incoming UDP ports with the
inner TCP/UDP ports of the tunnelled flow. gro_receive_network_flush()
then derives the network header of the incoming skb from p's offsets
(outer network header to inner transport header, 70 bytes or more for
vxlan) and reads before the incoming skb's network header, past its
head on small-headroom skbs.

A remote sender can trigger this on a host with a vxlan or geneve
socket plus a UDP_GRO socket, rx-udp-gro-forwarding or rx-gro-list by
sending a vxlan-encapsulated TCP segment followed by a plain UDP
datagram whose ports equal the inner TCP ports. Reproduced with KASAN
on arm64 QEMU over veth:

  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

When the bytes read happen to match, the UDP payload is merged into the
tunnelled TCP aggregate. With rx-gro-list and forwarding the datagram
is then segmented and sent out with the inner flow's addresses, without
having been seen by the forward or egress netfilter hooks.

NAPI_GRO_CB()->encap_mark records whether a packet has been through a
tunnel GRO handler. Skip held packets whose encap_mark differs from the
incoming packet: both are 0 for plain UDP aggregation and both are 1
for UDP inside a tunnel, so legitimate aggregation is unchanged.

Fixes: 4b0ebbca3e16 ("net: gro: move L3 flush checks to tcp_gro_receive and udp_gro_receive_segment")
Signed-off-by: Aviral Srivastava <aviralyash27@gmail.com>
---

Notes:
    How this patch was made: the bug was found and the fix drafted with an
    LLM coding assistant (Claude) during a review of the UDP GRO code. I
    reviewed the analysis and the change before sending.
    
    Testing (arm64 QEMU, KASAN, two netns over veth, torvalds/master
    4843f6873f7c, unpatched vs patched; netdev/net has no change to these
    files since then):
    - KASAN slab-out-of-bounds in __gro_receive_network_flush: 28 and 29
      reports in two trigger variants before, 0 and 0 after.
    - Forced UDP-into-TCP merge: 97.6% of datagrams merged before, 0 after.
    - rx-gro-list forwarding: 1995 datagrams sent out under the inner flow's
      addresses before, 0 after.
    - Regression: plain UDP GRO, UDP-in-vxlan and TCP-in-vxlan traffic still
      aggregate (recvmsg calls / frames within a few percent of unpatched).
    Not tested: x86_64, real NIC hardware, an IPv6 outer header (IPv6
    UDP GRO shares udp_gro_receive_segment(), so the fix covers it).
    On virtio_net the comparison runs but the out-of-bounds read lands
    in rx headroom, so KASAN stays silent.
    Reproducer available on request.

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

diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c
index b77ae2f00c62..160b60005a1b 100644
--- a/net/ipv4/udp_offload.c
+++ b/net/ipv4/udp_offload.c
@@ -723,6 +723,17 @@ static struct sk_buff *udp_gro_receive_segment(struct list_head *head,
 		if (!NAPI_GRO_CB(p)->same_flow)
 			continue;
 
+		/* encap_mark is set once a packet has been through a tunnel
+		 * GRO handler (vxlan, geneve, ...). For such a packet
+		 * udp_hdr() points at the inner L4 header and its network
+		 * offsets describe the inner packet, so it must not be
+		 * compared with a packet that has not been through one.
+		 */
+		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-22 18:39 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=20261122183951.73210-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=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