From: sashiko-bot@kernel.org
To: "Rosen Penev" <rosenp@gmail.com>
Cc: "open list:BPF [MISC]:Keyword:(?: b|_)bpf(?: b|_)" <bpf@vger.kernel.org>
Subject: Re: [PATCH net-next] net: gro: skip the checksum of fraglist GRO packets
Date: Tue, 24 Nov 2026 04:27:54 +0000 [thread overview]
Message-ID: <sashiko-outbox-230501@kernel.org> (raw)
In-Reply-To: <20261123042735.139550-1-rosenp@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] ipv6: gro: stale ipv6hdr pointer dereference in
tcp6_gro_receive()
- [High] net: gro: CHECKSUM_NONE fraglist GRO skbs break GSO on
NETIF_F_GSO_FRAGLIST devs
It also noticed 2 related pre-existing issues this patch does not
introduce:
- [High] tcp: missing protocol check in tcp_add_backlog() allows
cross-family coalesce [1]
- [High] tcp: gro: stale CHECKSUM_COMPLETE on fraglist in
tcp4/6_gro_complete() [2]
--
commit fa341d1e23410a4c1023b2a324454cb1f2e9afbb
Author: Rosen Penev <rosenp@gmail.com>
net: gro: skip the checksum of fraglist GRO packets
This commit skips software TCP checksum validation during fraglist GRO and
leaves the merged skb with CHECKSUM_NONE, teaching __skb_checksum_complete()
to verify each frag_list segment individually on demand and moving
tcp_add_backlog()'s checksum check ahead of skb_condense().
> diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
> index f2a5c8f3bf9d7..67897435291ae 100644
> --- a/net/ipv4/tcp_ipv4.c
> +++ b/net/ipv4/tcp_ipv4.c
> @@ -1919,14 +1919,6 @@ enum skb_drop_reason tcp_add_backlog(struct sock *sk, struct sk_buff *skb)
> int delta;
> int err;
>
> - /* In case all data was pulled from skb frags (in __pskb_pull_tail()),
> - * we can fix skb->truesize to its real value to avoid future drops.
> - * This is valid because skb is not yet charged to the socket.
> - * It has been noticed pure SACK packets were sometimes dropped
> - * (if cooked by drivers without copybreak feature).
> - */
> - skb_condense(skb);
> -
> tcp_cleanup_skb(skb);
>
> if (unlikely(tcp_checksum_complete(skb))) {
> @@ -1937,6 +1929,17 @@ enum skb_drop_reason tcp_add_backlog(struct sock *sk, struct sk_buff *skb)
> return SKB_DROP_REASON_TCP_CSUM;
> }
>
> + /* Verify the checksum first: a TCP fraglist GRO skb left unverified
> + * can only be checked while its packets are still on its frag_list.
> + *
> + * In case all data was pulled from skb frags (in __pskb_pull_tail()),
> + * we can fix skb->truesize to its real value to avoid future drops.
> + * This is valid because skb is not yet charged to the socket.
> + * It has been noticed pure SACK packets were sometimes dropped
> + * (if cooked by drivers without copybreak feature).
> + */
> + skb_condense(skb);
> +
> /* Attempt coalescing to last skb in backlog, even if we are
> * above the limits.
> * This is okay because skb capacity is limited to MAX_SKB_FRAGS.
[Severity: High]
This problem wasn't introduced by this patch, but can tcp_add_backlog()
coalesce ETH_P_IPV6 and ETH_P_IP packets together when an AF_INET6 socket
disconnects and reconnects to an IPv4-mapped peer [1]?
If tcp_v6_rcv() looks up the socket before userspace disconnects and
reconnects it to an IPv4-mapped address while holding the socket lock, both
the in-flight IPv6 packet and subsequent IPv4 packets are queued via
tcp_add_backlog(). Neither the checks right below nor
tcp_skb_can_collapse_rx() verify tail->protocol == skb->protocol before
skb_try_coalesce(). When __release_sock() drains the backlog into
tcp_v4_do_rcv(), a stale IPv6 packet coalesced onto an IPv4 tail bypasses
the skb->protocol check and injects stale payload, sequence numbers, or FIN
flags into the IPv4 stream, while an IPv4 packet coalesced onto a stale
IPv6 tail is dropped with it.
> diff --git a/net/ipv4/tcp_offload.c b/net/ipv4/tcp_offload.c
> index b84fcd07c7230..d38eaf24c3c58 100644
> --- a/net/ipv4/tcp_offload.c
> +++ b/net/ipv4/tcp_offload.c
[ ... ]
> @@ -465,7 +476,9 @@ INDIRECT_CALLABLE_SCOPE int tcp4_gro_complete(struct sk_buff *skb, int thoff)
> skb_shinfo(skb)->gso_type |= SKB_GSO_FRAGLIST | SKB_GSO_TCPV4;
> skb_shinfo(skb)->gso_segs = NAPI_GRO_CB(skb)->count;
>
> - __skb_incr_checksum_unnecessary(skb);
> + /* not verified, see skb_gro_flist_skip_csum() */
> + if (skb->ip_summed != CHECKSUM_NONE)
> + __skb_incr_checksum_unnecessary(skb);
>
> return 0;
> }
[Severity: High]
Does leaving SKB_GSO_FRAGLIST packets as CHECKSUM_NONE break GSO handling
on egress devices with NETIF_F_GSO_FRAGLIST (and similarly in
tcp6_gro_complete())?
include/linux/netdevice.h:netif_needs_gso() {
return skb_is_gso(skb) && (!skb_gso_ok(skb, features) ||
unlikely((skb->ip_summed != CHECKSUM_PARTIAL) &&
(skb->ip_summed != CHECKSUM_UNNECESSARY)));
}
Because netif_needs_gso() returns true for CHECKSUM_NONE even when
skb_gso_ok() is true, validate_xmit_skb() forces software GSO on virtual
devices advertising NETIF_F_GSO_FRAGLIST | NETIF_F_FRAGLIST (such as
bridges, veth, VLANs, or VRFs). In tcp4_gso_segment() (and
tcp6_gso_segment()):
net/ipv4/tcp_offload.c:tcp4_gso_segment() {
...
if (skb_shinfo(skb)->gso_type & SKB_GSO_FRAGLIST) {
struct tcphdr *th = tcp_hdr(skb);
if ((skb_pagelen(skb) - th->doff * 4 == skb_shinfo(skb)->gso_size) &&
!(skb_shinfo(skb)->gso_type & SKB_GSO_DODGY))
return __tcp4_gso_segment_list(skb, features);
skb->ip_summed = CHECKSUM_NONE;
}
if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) {
...
th->check = 0;
skb->ip_summed = CHECKSUM_PARTIAL;
__tcp_v4_send_check(skb, iph->saddr, iph->daddr);
}
return tcp_gso_segment(skb, features);
}
Unmodified fraglist GRO skbs are immediately split by
__tcp4_gso_segment_list() at the first virtual device instead of passing
through as a GSO aggregate. Worse, if the geometry was modified after GRO
(for example by bpf_skb_pull_data()), tcp4_gso_segment() overwrites
th->check with a pseudo-header checksum, sets CHECKSUM_PARTIAL, and calls
tcp_gso_segment(), which sees skb_gso_ok(skb, features |
NETIF_F_GSO_ROBUST) == true and returns NULL without segmenting the skb,
transmitting the broken fraglist skb unsegmented with an invalid
th->check.
[Severity: High]
This problem wasn't introduced by this patch, but when packets arrive with
CHECKSUM_COMPLETE, does __skb_incr_checksum_unnecessary() leave a stale
single-segment skb->csum on the coalesced fraglist skb (and similarly in
tcp6_gro_complete()) [2]?
Each segment was already validated by skb_gro_checksum_validate() in
tcp4_gro_receive(), which converted CHECKSUM_NONE to CHECKSUM_UNNECESSARY
but left CHECKSUM_COMPLETE intact. Because
__skb_incr_checksum_unnecessary() only acts on CHECKSUM_NONE and
CHECKSUM_UNNECESSARY, a CHECKSUM_COMPLETE fraglist skb keeps skb->csum from
the first segment while skb->len spans the entire aggregate, causing
later checksum checks in conntrack or local delivery to fail and drop the
packet.
> diff --git a/net/ipv6/tcpv6_offload.c b/net/ipv6/tcpv6_offload.c
> index eec3778855eb8..9c5709b2bf721 100644
> --- a/net/ipv6/tcpv6_offload.c
> +++ b/net/ipv6/tcpv6_offload.c
[ ... ]
> @@ -56,10 +59,23 @@ static void tcp6_check_fraglist_gro(struct list_head *head, struct sk_buff *skb,
> static __always_inline struct sk_buff *tcp6_gro_receive(struct list_head *head,
> struct sk_buff *skb)
> {
> + const struct ipv6hdr *iph = skb_gro_network_header(skb);
> + unsigned int off = skb_gro_offset(skb);
> struct tcphdr *th;
>
> - /* Don't bother verifying checksum if we're going to flush anyway. */
> + th = skb_gro_header(skb, off + sizeof(*th), off);
> + if (unlikely(!th))
> + goto flush;
> +
> + if (unlikely(skb->dev->features & NETIF_F_GRO_FRAGLIST))
> + tcp6_check_fraglist_gro(head, skb, th);
> +
> + /* Don't bother verifying checksum if we're going to flush anyway.
> + * __skb_checksum_complete() can only verify the packets of a fraglist
> + * skb without extension headers.
> + */
> if (!NAPI_GRO_CB(skb)->flush &&
> + !(skb_gro_flist_skip_csum(skb) && iph->nexthdr == IPPROTO_TCP) &&
> skb_gro_checksum_validate(skb, IPPROTO_TCP,
> ip6_gro_compute_pseudo))
> goto flush;
[Severity: High]
Can iph->nexthdr dereference freed memory after skb_gro_header()?
iph is loaded via skb_gro_network_header(skb) before skb_gro_header() pulls
the TCP header. If off + sizeof(*th) exceeds frag0_len, skb_gro_header()
falls back to skb_gro_header_slow() -> pskb_may_pull(), which can release
the frag0 page or reallocate skb->head, leaving iph dangling when
iph->nexthdr is read. Fetching skb_gro_network_header(skb) after
skb_gro_header() avoids the stale pointer.
[1] https://sashiko.dev/#/bug/linux-54f30cb5-2d86-46d9-b2c9-c25a0adaef88
[2] https://sashiko.dev/#/bug/linux-b1b0f506-a36b-4c96-bc55-812755610e6c
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123042735.139550-1-rosenp@gmail.com?part=1
next prev parent reply other threads:[~2026-11-24 4:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 4:27 [PATCH net-next] net: gro: skip the checksum of fraglist GRO packets Rosen Penev
2026-11-23 6:51 ` Alexei Starovoitov
2026-11-24 4:27 ` sashiko-bot [this message]
2026-11-24 4:47 ` netdev-bot+sashiko
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=sashiko-outbox-230501@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=rosenp@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/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