gro: do not GRO GSO packets with inconsistent payload
Subsystems (3)
Eric Dumazet
maintainerPATCH 1/1 gro: do not GRO GSO packets with inconsistent payload
From: Kyle Zeng <[email protected]>
tcp_gro_receive() excludes empty non-GSO packets with the unsigned len - 1 check, but its GSO branch only checks that gso_size matches the held packet's MSS. A trusted TCP GSO skb can reach GRO again with no payload after TC pedit increases its TCP data offset.
If the skb is fully linear, skb_gro_receive() then enters its fragment transfer path with nr_frags == 0. The do-while loop copies skb_frag_t entries backwards beyond both fragment arrays. An unprivileged process using its own user and network namespaces can trigger a KASAN slab-out-of-bounds write and panic through veth, pedit and GRE.
More generally, the payload of such a packet can be shrunk to any value, making it inconsistent with its gso_segs, and a GSO packet with gso_segs == 0 contributes no segment to the GRO packet.
Do not aggregate GSO packets with gso_segs == 0, and require the payload of GSO packets to be consistent with gso_segs and gso_size, the last segment being allowed to be short. This rejects the empty skb before either TCP merge helper, and covers both IPv4 and IPv6.
--- net/core/gro.c | 5 +++-- net/ipv4/tcp_offload.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-)
net/core/gro.c +3 -2
@@ -513,9 +513,10 @@ static enum gro_result dev_gro_receive(struct gro_node *gro,NAPI_GRO_CB (skb)->count =1 ;if (unlikely (skb_is_gso (skb))) {NAPI_GRO_CB (skb)->count =skb_shinfo (skb)->gso_segs; -/* Only support TCP and non DODGY users. */ +/* Only support TCP and non DODGY users, with a sane gso_segs. */ if (!skb_is_gso_tcp (skb) || - (skb_shinfo (skb)->gso_type &SKB_GSO_DODGY )) + (skb_shinfo (skb)->gso_type &SKB_GSO_DODGY ) || + !NAPI_GRO_CB (skb)->count)NAPI_GRO_CB (skb)->flush =1 ; }
net/ipv4/tcp_offload.c +9 -3
@@ -315,14 +315,20 @@ struct sk_buff *tcp_gro_receive(struct list_head *head, struct sk_buff *skb, mss =skb_shinfo (p)->gso_size; -/* If skb is a GRO packet, make sure its gso_size matches prior packet mss. +/* If skb is a GRO packet, make sure its gso_size matches prior packet +* mss, and that its payload is consistent with its gso_segs +* (the last segment can be short). * If it is a single frame, do not aggregate it if its length * is bigger than our mss. */ -if (unlikely (skb_is_gso (skb))) +if (unlikely (skb_is_gso (skb))) { +unsigned int segs =NAPI_GRO_CB (skb)->count; + flush |= (mss !=skb_shinfo (skb)->gso_size); -else + flush |= len <= (segs -1 ) * mss || len > segs * mss; + }else { flush |= (len -1 ) >= mss; + } flush |= (ntohl (th2->seq) +skb_gro_len (p)) ^ntohl (th->seq); flush |=skb_cmp_decrypted (p, skb);
Signature · 1 line
2.53.0
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Quoted 36 lines · Eric Dumazet
From: Kyle Zeng <[email protected]>
tcp_gro_receive()excludes empty non-GSO packets with the unsigned len - 1 check, but its GSO branch only checks thatgso_sizematches the held packet's MSS. A trusted TCP GSO skb can reach GRO again with no payload after TC pedit increases its TCP data offset.If the skb is fully linear,
skb_gro_receive()then enters its fragment transfer path withnr_frags== 0. The do-while loop copiesskb_frag_tentries backwards beyond both fragment arrays. An unprivileged process using its own user and network namespaces can trigger a KASAN slab-out-of-bounds write and panic through veth, pedit and GRE.More generally, the payload of such a packet can be shrunk to any value, making it inconsistent with its
gso_segs, and a GSO packet withgso_segs== 0 contributes no segment to the GRO packet.Do not aggregate GSO packets with
gso_segs== 0, and require the payload of GSO packets to be consistent withgso_segsandgso_size, the last segment being allowed to be short. This rejects the empty skb before either TCP merge helper, and covers both IPv4 and IPv6.Fixes 5eddb24901ee ("gro: add support of (hw)gro packets to gro stack")Signed-off-by Kyle Zeng <[email protected]>[edumazet: check payload against gso_segs, refuse gso_segs == 0]Signed-off-by Eric Dumazet <[email protected]>--- net/core/gro.c | 5 +++-- net/ipv4/tcp_offload.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-)net/core/gro.c +0
-0
net/core/gro.c static enum gro_result dev_gro_receive(struct gro_node *gro, · line 519
Quoted 9 lines
net/core/gro.c +3
-2@@ -513,9 +513,10 @@ static enum gro_result dev_gro_receive(struct gro_node *gro,NAPI_GRO_CB (skb)->count =1 ;if (unlikely (skb_is_gso (skb))) {NAPI_GRO_CB (skb)->count =skb_shinfo (skb)->gso_segs; -/* Only support TCP and non DODGY users. */ +/* Only support TCP and non DODGY users, with a sane gso_segs. */ if (!skb_is_gso_tcp (skb) || - (skb_shinfo (skb)->gso_type &SKB_GSO_DODGY )) + (skb_shinfo (skb)->gso_type &SKB_GSO_DODGY ) || + !NAPI_GRO_CB (skb)->count)
Or make tc_pedit set SKB_GSO_DODGY? BPF already does.
In pedit_l4_skb_offset and pedit_l4_skb_offset.
Eric Dumazet
maintainerQuoted 50 lines · Willem de Bruijn
Quoted 36 lines · Eric Dumazet
From: Kyle Zeng <[email protected]>
tcp_gro_receive()excludes empty non-GSO packets with the unsigned len - 1 check, but its GSO branch only checks thatgso_sizematches the held packet's MSS. A trusted TCP GSO skb can reach GRO again with no payload after TC pedit increases its TCP data offset.If the skb is fully linear,
skb_gro_receive()then enters its fragment transfer path withnr_frags== 0. The do-while loop copiesskb_frag_tentries backwards beyond both fragment arrays. An unprivileged process using its own user and network namespaces can trigger a KASAN slab-out-of-bounds write and panic through veth, pedit and GRE.More generally, the payload of such a packet can be shrunk to any value, making it inconsistent with its
gso_segs, and a GSO packet withgso_segs== 0 contributes no segment to the GRO packet.Do not aggregate GSO packets with
gso_segs== 0, and require the payload of GSO packets to be consistent withgso_segsandgso_size, the last segment being allowed to be short. This rejects the empty skb before either TCP merge helper, and covers both IPv4 and IPv6.Fixes 5eddb24901ee ("gro: add support of (hw)gro packets to gro stack")Signed-off-by Kyle Zeng <[email protected]>[edumazet: check payload against gso_segs, refuse gso_segs == 0]Signed-off-by Eric Dumazet <[email protected]>--- net/core/gro.c | 5 +++-- net/ipv4/tcp_offload.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-)net/core/gro.c +0
-0net/core/gro.c static enum gro_result dev_gro_receive(struct gro_node *gro, · line 519
Quoted 9 lines
net/core/gro.c +3
-2@@ -513,9 +513,10 @@ static enum gro_result dev_gro_receive(struct gro_node *gro,NAPI_GRO_CB (skb)->count =1 ;if (unlikely (skb_is_gso (skb))) {NAPI_GRO_CB (skb)->count =skb_shinfo (skb)->gso_segs; -/* Only support TCP and non DODGY users. */ +/* Only support TCP and non DODGY users, with a sane gso_segs. */ if (!skb_is_gso_tcp (skb) || - (skb_shinfo (skb)->gso_type &SKB_GSO_DODGY )) + (skb_shinfo (skb)->gso_type &SKB_GSO_DODGY ) || + !NAPI_GRO_CB (skb)->count)Or make
tc_peditsetSKB_GSO_DODGY? BPF already does.
Quoted 1 line
In
pedit_l4_skb_offsetandpedit_l4_skb_offset.
Good idea, this would also make sure gso_segs is recomputed if such packets are later segmented.
I would still keep the !count check: ixgbe and libwx RSC packets reach GRO with gso_segs == 0, and the payload check in tcp_gro_receive() relies on count being non zero.
pedit is also not the only way to change the TCP header of a GSO packet (nft payload on older kernels, NFQUEUE with NFQA_CFG_F_GSO, bpf_skb_store_bytes()), so I prefer GRO to stay robust anyway.
pedit can be changed later in net-next to set SKB_GSO_DODGY on GSO packets it modifies. Note this needs skb_unclone(), which can fail. pedit does not drop packets on allocation errors today, so it would probably leave the packet unmarked, another reason for GRO to not trust these packets.
Thanks.
Willem de Bruijn
Reviewed-byQuoted 52 lines · Eric Dumazet
Quoted 50 lines · Willem de Bruijn
Quoted 36 lines · Eric Dumazet
From: Kyle Zeng <[email protected]>
tcp_gro_receive()excludes empty non-GSO packets with the unsigned len - 1 check, but its GSO branch only checks thatgso_sizematches the held packet's MSS. A trusted TCP GSO skb can reach GRO again with no payload after TC pedit increases its TCP data offset.If the skb is fully linear,
skb_gro_receive()then enters its fragment transfer path withnr_frags== 0. The do-while loop copiesskb_frag_tentries backwards beyond both fragment arrays. An unprivileged process using its own user and network namespaces can trigger a KASAN slab-out-of-bounds write and panic through veth, pedit and GRE.More generally, the payload of such a packet can be shrunk to any value, making it inconsistent with its
gso_segs, and a GSO packet withgso_segs== 0 contributes no segment to the GRO packet.Do not aggregate GSO packets with
gso_segs== 0, and require the payload of GSO packets to be consistent withgso_segsandgso_size, the last segment being allowed to be short. This rejects the empty skb before either TCP merge helper, and covers both IPv4 and IPv6.Fixes 5eddb24901ee ("gro: add support of (hw)gro packets to gro stack")Signed-off-by Kyle Zeng <[email protected]>[edumazet: check payload against gso_segs, refuse gso_segs == 0]Signed-off-by Eric Dumazet <[email protected]>--- net/core/gro.c | 5 +++-- net/ipv4/tcp_offload.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-)net/core/gro.c +0
-0net/core/gro.c static enum gro_result dev_gro_receive(struct gro_node *gro, · line 519
Quoted 9 lines
net/core/gro.c +3
-2@@ -513,9 +513,10 @@ static enum gro_result dev_gro_receive(struct gro_node *gro,NAPI_GRO_CB (skb)->count =1 ;if (unlikely (skb_is_gso (skb))) {NAPI_GRO_CB (skb)->count =skb_shinfo (skb)->gso_segs; -/* Only support TCP and non DODGY users. */ +/* Only support TCP and non DODGY users, with a sane gso_segs. */ if (!skb_is_gso_tcp (skb) || - (skb_shinfo (skb)->gso_type &SKB_GSO_DODGY )) + (skb_shinfo (skb)->gso_type &SKB_GSO_DODGY ) || + !NAPI_GRO_CB (skb)->count)Or make
tc_peditsetSKB_GSO_DODGY? BPF already does.
Quoted 8 lines
Quoted 1 line
In
pedit_l4_skb_offsetandpedit_l4_skb_offset.Good idea, this would also make sure
gso_segsis recomputed if such packets are later segmented.I would still keep the !count check: ixgbe and libwx RSC packets reach GRO with
gso_segs== 0, and the payload check intcp_gro_receive()relies on count being non zero.
Should those get fixed instead (eventually).
Quoted 4 lines
pedit is also not the only way to change the TCP header of a GSO packet (nft payload on older kernels, NFQUEUE with
NFQA_CFG_F_GSO,bpf_skb_store_bytes()), so I prefer GRO to stay robust anyway.
Argh. Good point. In that case:
Quoted 5 lines
pedit can be changed later in net-next to set
SKB_GSO_DODGYon GSO packets it modifies. Note this needsskb_unclone(), which can fail. pedit does not drop packets on allocation errors today, so it would probably leave the packet unmarked, another reason for GRO to not trust these packets.
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Wed, 28 Oct 2026 18:13:50 +0100 you wrote:
From: Kyle Zeng <[email protected]>
tcp_gro_receive()excludes empty non-GSO packets with the unsigned len - 1 check, but its GSO branch only checks thatgso_sizematches the held packet's MSS. A trusted TCP GSO skb can reach GRO again with no payload after TC pedit increases its TCP data offset.[...]
Here is the summary with links:
- [net] gro: do not GRO GSO packets with inconsistent payload
https://git.kernel.org/netdev/net/c/de788d8a7032
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html