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 --- 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