* [PATCH net] udp: gro: do not match tunnel-processed and plain packets
@ 2026-11-22 18:39 Aviral Srivastava
2026-11-23 18:40 ` netdev-bot+sashiko
0 siblings, 1 reply; 3+ messages in thread
From: Aviral Srivastava @ 2026-11-22 18:39 UTC (permalink / raw)
To: netdev; +Cc: davem, edumazet, kuba, pabeni, willemb, horms, Aviral Srivastava
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] udp: gro: do not match tunnel-processed and plain packets
2026-11-22 18:39 [PATCH net] udp: gro: do not match tunnel-processed and plain packets Aviral Srivastava
@ 2026-11-23 18:40 ` netdev-bot+sashiko
2026-11-24 1:38 ` Aviral Srivastava
0 siblings, 1 reply; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 18:40 UTC (permalink / raw)
To: aviralyash27; +Cc: netdev, davem, edumazet, kuba, pabeni, willemb, horms
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The Fixes: tag covers only the out-of-bounds read, not the
older mis-merge bug.
- [Low] The new comment and the commit message both say encap_mark is set
for any tunnel-processed packet; FOU and GUE clear it.
--
udp: gro: do not match tunnel-processed and plain packets
With this patch, udp_gro_receive_segment() skips held packets whose
NAPI_GRO_CB()->encap_mark differs from the incoming skb. A plain UDP
datagram is then no longer compared against, or merged into, a held
packet that went through a vxlan/geneve GRO handler. For such a packet
udp_hdr(p) points at the inner L4 header.
> 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.
[ ... ]
> Fixes: 4b0ebbca3e16 ("net: gro: move L3 flush checks to tcp_gro_receive and udp_gro_receive_segment")
[Severity: Medium]
Does this Fixes: tag cover the whole bug?
4b0ebbca3e16 added the gro_receive_network_flush() call, and that call is
where the out-of-bounds read comes from. The port comparison against a
tunnel-processed held packet looks older:
net/ipv4/udp_offload.c:udp_gro_receive_segment() {
...
uh2 = udp_hdr(p);
/* Match ports only, as csum is always non zero */
if ((*(u32 *)&uh->source != *(u32 *)&uh2->source)) {
...
}
Blame traces these lines to e20cf8d3f1f7 ("udp: implement GRO for plain
UDP sockets.").
udp_hdr(p) points at the inner L4 header because the inner
inet_gro_receive() resets p's transport header:
net/ipv4/af_inet.c:inet_gro_receive() {
...
skb_set_transport_header(skb, skb_gro_offset(skb));
...
}
Before 4b0ebbca3e16, flush came from NAPI_GRO_CB(p)->flush/flush_id.
inet_gro_receive() computed these by comparing the outer IP headers (ttl,
tos, DF, id) at the same offset in both skbs. The remote sender controls
all of those fields. Before 5babae777c61 there was no flush check at all.
On those kernels, can a plain UDP datagram whose ports equal the inner TCP
ports of a held vxlan packet reach skb_gro_receive() through a UDP_GRO
socket or rx-udp-gro-forwarding, without reading any out-of-bounds bytes?
If so, "when the bytes read happen to match" is only true after
4b0ebbca3e16. Backporters who follow the current tag would skip 6.6, 6.1,
5.15 and 5.10, and those trees still have the cross-flow merge. The
rx-gro-list forwarding variant needs TCP fraglist GRO, so it does not apply
to those older trees.
encap_mark has existed since 2016, so the check should backport easily.
Would it make sense to add:
Fixes: e20cf8d3f1f7 ("udp: implement GRO for plain UDP sockets.")
and keep the current tag for the out-of-bounds read? The message could
then say that on older kernels the mis-merge does not need the
out-of-bounds read.
> diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c
> index b77ae2f00c626..160b60005a1b6 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) {
[Severity: Low]
Is this comment accurate for FOU and GUE? The commit message makes the same
claim:
NAPI_GRO_CB()->encap_mark records whether a packet has been through a
tunnel GRO handler.
fou_gro_receive() and gue_gro_receive() in net/ipv4/fou_core.c both clear
the mark after tunnel processing:
net/ipv4/fou_core.c:gue_gro_receive() {
...
NAPI_GRO_CB(skb)->encap_mark = 0;
/* Flag this frame as already having an outer encap header */
NAPI_GRO_CB(skb)->is_fou = 1;
ops = fou_gro_ops(sk, proto);
...
}
For GUE version 0, the sender chooses proto through guehdr->proto_ctype.
With IPPROTO_UDP, the packet reaches
udp4_gro_receive()->udp_gro_receive_segment() with encap_mark == 0. No
inner IP layer runs, so the transport header stays on the outer UDP
header.
Two such GUE-direct-UDP packets have equal encap_mark, but the headers
being compared are from different layers. uh from udp_gro_udphdr(skb) is
the inner UDP header. udp_hdr(p) is the outer GUE UDP header.
If the sender sets the inner ports equal to the GUE port, can the packet
match any held GUE-direct-UDP aggregate of the same outer flow, whatever
its inner ports are?
This path has no out-of-bounds read, because the offset difference is only
the outer IP header length. The cross-inner-flow merge also predates this
patch. Still, the invariant stated in the new comment and in the commit
message does not hold for FOU/GUE.
Could the comment say that encap_mark tracks whether an inner network layer
was processed, rather than tunnel processing in general? Alternatively,
could the check also compare is_fou?
> + NAPI_GRO_CB(p)->same_flow = 0;
> + continue;
> + }
> +
> uh2 = udp_hdr(p);
>
> /* Match ports only, as csum is always non zero */
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122183951.73210-1-aviralyash27%40gmail.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] udp: gro: do not match tunnel-processed and plain packets
2026-11-23 18:40 ` netdev-bot+sashiko
@ 2026-11-24 1:38 ` Aviral Srivastava
0 siblings, 0 replies; 3+ messages in thread
From: Aviral Srivastava @ 2026-11-24 1:38 UTC (permalink / raw)
To: netdev; +Cc: netdev-bot+sashiko, davem, edumazet, kuba, pabeni, willemb, horms
Thanks for the review. Both points lead to changes, I will send a v2.
[Medium] Fixes tag covers only the out-of-bounds read
Agreed. The port match through udp_hdr(p) dates from e20cf8d3f1f7 and
the merge does not depend on 4b0ebbca3e16. I checked it on v6.6.162,
which does not have 4b0ebbca3e16 (arm64 QEMU, KASAN, netns over veth):
- vxlan with inner TCP, UDP_GRO socket on the port, plain datagram
with the same outer TTL, TOS and DF as the vxlan packet: 2000 of
2000 datagrams end up inside the inner TCP segments on the vxlan
device, none reach the UDP socket. No KASAN report.
- Same with consecutive IP IDs and no DF: 2000 of 2000.
- Same with the plain datagram's TTL off by one: 0 merged. Differing
ports, no tunnel device, GRO off: 0 merged.
- With the v1 hunk applied to v6.6.162: 0 merged in every case, and
UDP in vxlan/geneve still aggregates.
On v6.6 the L3 gate is the flush/flush_id state from 5babae777c61,
computed on the two real outer headers, so ordinary header values are
enough there. v2 carries both tags, e20cf8d3f1f7 first, and Cc: stable.
The hunk applies to 6.6.y, 6.1.y, 5.15.y and 5.10.y as is.
[Low] encap_mark is cleared by FOU/GUE
The observation is right and the comment and changelog in v1 are wrong
on this. I do not think an is_fou comparison is needed, though:
- When FOU/GUE carry IPIP, SIT or GRE (or vxlan), the inner handler
sets encap_mark again and the transport header moves to the inner L4
header. Those are covered by the v1 check: they give the same KASAN
report against plain UDP before the patch and none after.
- When FOU/GUE carry UDP directly, encap_mark is 0, but nothing moves
the transport header or the network offsets, so udp_hdr(p) is the
outer UDP header, the same layer as for a plain packet. A plain
datagram with those ports resolves to the FOU socket itself in the
GRO lookup, so it does not reach udp_gro_receive_segment().
I ran held plain UDP followed by FOU/GUE-direct UDP with matching inner
ports, and the reverse order, with a wildcard, a single-tunnel and a
connected FOU socket, with a UDP_GRO socket, rx-udp-gro-forwarding and
rx-gro-list: no cross merge and no KASAN report, with or without the
patch. The only merge with differing is_fou I could produce needs the
FOU port to be deleted while a packet is held; it is at the same header
layer and in bounds.
v2 keeps the code and rewords the comment and changelog to say what
encap_mark guarantees at that point.
Separately, UDP carried directly in FOU/GUE never aggregates in
udp_gro_receive_segment(), because the inner header is compared with
the held packet's outer one. That is not a regression and not changed
by this patch.
The v1 notes also said "28 and 29" KASAN reports. That was the dmesg
ring limit, the console logs of those runs have 1023 and 308. And the
changelog said the merged datagram is not seen by the forward and
egress netfilter hooks; the hooks do see the aggregate, what is skipped
are rules matching the datagram itself. Both are corrected in v2.
pw-bot: cr
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-24 1:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 18:39 [PATCH net] udp: gro: do not match tunnel-processed and plain packets Aviral Srivastava
2026-11-23 18:40 ` netdev-bot+sashiko
2026-11-24 1:38 ` Aviral Srivastava
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox