🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
3 messages
3 total messages Started by Xin Long Wed, 25 Nov 2026 15:17
[PATCH net v2] sctp: unshare GSO skb frag_list members instead of linearizing
#22616
Author: Xin Long
Date: Wed, 25 Nov 2026 15:17
107 lines
14256 bytes
When the iptables TEE target copies an SCTP GSO packet with pskb_copy(),
the frag_list skbs are shared by reference via skb_clone_fraglist().
The SCTP receive path then races on shared sk_buff headers in
sctp_inq_pop(), and can hit a BUG_ON in __pskb_pull_tail().

Commit fd60d8a08619 ("sctp: linearize cloned gso packets in sctp_rcv")
tried to fix this by checking skb_cloned() on the outer skb, but
pskb_copy() gives the outer skb a private head without marking it
cloned, so that check never fires for the TEE case. The frag_list
members stay shared regardless. Even when linearization does trigger
(e.g. for AF_PACKET clones), it destroys per-segment boundaries,
breaking AUTH: the HMAC is computed per segment on transmit, but after
linearization the receive side hashes across all concatenated segments
and the digest never matches.

Fix by avoiding linearization for GSO packets entirely. Add
sctp_gso_unshare() which:

 1. Calls skb_unclone() on the outer skb to privatize the head data
    buffer when it is marked cloned (e.g. from AF_PACKET's
    skb_clone()). For the TEE/pskb_copy() case this is a no-op since
    the head is already private.

 2. Walks all frag_list members and replaces any shared member with a
    private pskb_copy(), giving SCTP exclusive ownership of both the
    sk_buff headers and the linear data buffer. Data ownership is
    needed because AUTH verification (sctp_sf_authenticate) zeroes the
    on-wire digest and writes the computed HMAC back in place; with
    skb_clone() the data buffer stays shared, which could let a
    crafted packet pass AUTH on a second copy or corrupt data visible
    to AF_PACKET readers.

Fixes: 90017accff61 ("sctp: Add GSO support")
Reported-by: syzbot+f15a6eff7a53f6eb7dc3@syzkaller.appspotmail.com
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
v2:
  - Use a proper Fixes tag and refine the commit message.
  - Use pskb_copy() instead of skb_clone() for shared skbs in frag_list.
---
 net/sctp/input.c | 43 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 41 insertions(+), 2 deletions(-)

diff --git a/net/sctp/input.c b/net/sctp/input.c
index 9494cfa51106..f993191ee1ea 100644
--- a/net/sctp/input.c
+++ b/net/sctp/input.c
@@ -82,6 +82,39 @@ static inline int sctp_rcv_checksum(struct net *net, struct sk_buff *skb)
 	return 0;
 }
 
+/* Ensure exclusive ownership of frag_list members for GSO skbs.
+ * pskb_copy() shares them by reference; unshare with private copies
+ * so AUTH verification can safely modify the digest in place.
+ */
+static int sctp_gso_unshare(struct sk_buff *skb)
+{
+	struct sk_buff **pp, *p;
+
+	if (skb_unclone(skb, GFP_ATOMIC))
+		return -ENOMEM;
+
+	if (!skb_has_frag_list(skb))
+		return 0;
+
+	pp = &skb_shinfo(skb)->frag_list;
+	skb_walk_frags(skb, p) {
+		if (skb_shared(p)) {
+			struct sk_buff *copy;
+
+			copy = pskb_copy(p, GFP_ATOMIC);
+			if (!copy)
+				return -ENOMEM;
+			copy->next = p->next;
+			consume_skb(p);
+			p = copy;
+			*pp = p;
+		}
+		pp = &p->next;
+	}
+
+	return 0;
+}
+
 /*
  * This is the routine which IP calls when receiving an SCTP packet.
  */
@@ -117,8 +150,14 @@ int sctp_rcv(struct sk_buff *skb)
 	 * it's better to just linearize it otherwise crc computing
 	 * takes longer.
 	 */
-	if (((!is_gso || skb_cloned(skb)) && skb_linearize(skb)) ||
-	    !pskb_may_pull(skb, sizeof(struct sctphdr)))
+	if (!is_gso) {
+		if (skb_linearize(skb))
+			goto discard_it;
+	} else if (sctp_gso_unshare(skb)) {
+		goto discard_it;
+	}
+
+	if (!pskb_may_pull(skb, sizeof(struct sctphdr)))
 		goto discard_it;
 
 	/* Pull up the IP header. */
-- 
2.47.1
Re: [PATCH net v2] sctp: unshare GSO skb frag_list members instead of linearizing
#23165
Author: netdev-bot+sashiko
Date: Thu, 26 Nov 2026 16:17
132 lines
12500 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 0

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

- [High] In net/sctp/input.c, sctp_gso_unshare() does not give SCTP
  exclusive ownership of the frag_list data buffers, although the commit…

--

sctp: unshare GSO skb frag_list members instead of linearizing

This patch stops linearizing SCTP GSO packets in sctp_rcv(). It adds
sctp_gso_unshare() instead, which unclones the outer skb and replaces
each shared frag_list member with a private pskb_copy(). The intent is to
give SCTP exclusive ownership of both the member headers and their data,
so that AUTH verification can rewrite the digest in place safely.

> diff --git a/net/sctp/input.c b/net/sctp/input.c
> index 9494cfa51106c..f993191ee1ea1 100644
> --- a/net/sctp/input.c
> +++ b/net/sctp/input.c
> @@ -82,6 +82,39 @@ static inline int sctp_rcv_checksum(struct net *net, struct sk_buff *skb)
>  	return 0;
>  }
>  
> +/* Ensure exclusive ownership of frag_list members for GSO skbs.
> + * pskb_copy() shares them by reference; unshare with private copies
> + * so AUTH verification can safely modify the digest in place.
> + */
> +static int sctp_gso_unshare(struct sk_buff *skb)
> +{
> +	struct sk_buff **pp, *p;
> +
> +	if (skb_unclone(skb, GFP_ATOMIC))
> +		return -ENOMEM;
> +
> +	if (!skb_has_frag_list(skb))
> +		return 0;
> +
> +	pp = &skb_shinfo(skb)->frag_list;
> +	skb_walk_frags(skb, p) {
> +		if (skb_shared(p)) {

[Severity: High]

Does this check catch members whose data buffer is shared while their
users count is 1?

skb_shared() only tests refcount_read(&p->users) != 1. A frag_list member
can have users == 1 and still have skb_cloned(p) true (dataref > 1). The
skb_unclone() on the outer skb doesn't help here, because by this point
the outer head is already private.

Core skb code produces this state. ___pskb_trim() forks shared members
like this:

net/core/skbuff.c:___pskb_trim() {
    ...
		if (skb_shared(frag)) {
			struct sk_buff *nfrag;

			nfrag = skb_clone(frag, GFP_ATOMIC);
			...
			consume_skb(frag);
    ...
}

__pskb_pull_tail() forks shared members with skb_clone() in the same way.
In both cases, the member left behind in the other skb has users == 1 and
shares its data with the clone.

One path that appears to reach this is an SCTP GSO skb looped over lo,
with a non-mmap AF_PACKET socket attached whose BPF filter returns a
snaplen:

packet_rcv()
  pskb_trim(skb, snaplen)
    ___pskb_trim()
      pskb_expand_head()   /* skb_clone_fraglist(), members users == 2 */
      skb_clone(frag) + consume_skb(frag)   /* SCTP side users == 1 */

The original skb then reaches sctp_rcv()->sctp_gso_unshare(). There,
skb_unclone() does nothing and skb_shared(p) is false for every forked
member, so nothing gets copied.

skb_condense() only undoes the sharing when the trimmed data_len fits in
the head's tailroom. Any snaplen larger than that keeps the sharing.

Later, sctp_inq_pop() passes the member to sctp_sf_authenticate(), which
does:

	memset(digest, 0, sig_len);

	if (sctp_auth_calculate_hmac(asoc, chunk->skb,
				     (struct sctp_auth_chunk *)chunk->chunk_hdr,
				     sh_key, GFP_ATOMIC)) {

Wouldn't this zero the digest and then overwrite it inside a buffer that
the nfrag clones queued on the packet socket still share? The AF_PACKET
reader would then copy out modified data.

That appears to be the case the commit message says pskb_copy() prevents:

    with skb_clone() the data buffer stays shared, which could let a
    crafted packet pass AUTH on a second copy or corrupt data visible
    to AF_PACKET readers.

A similar fork could happen through __pskb_pull_tail() on one of two
copies that both reach SCTP, for example a TEE duplicate plus a rule that
pulls past the head. Two SCTP receivers could then write the same digest
bytes at the same time. That variant is more speculative.

Would checking skb_shared(p) || skb_cloned(p) here, or calling
skb_unclone(p) when users == 1, give the exclusive data ownership that
the comment above sctp_gso_unshare() describes?

> +			struct sk_buff *copy;
> +
> +			copy = pskb_copy(p, GFP_ATOMIC);

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/739a5caed11c49ce53078747c43ea8cec5076d50.1795619846.git.lucien.xin%40gmail.com
Re: [PATCH net v2] sctp: unshare GSO skb frag_list members instead of linearizing
#23231
Author: Xin Long
Date: Thu, 26 Nov 2026 19:53
156 lines
17053 bytes
On Thu, Nov 26, 2026 at 11:17 AM <netdev-bot+sashiko@kernel.org> wrote:
>
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 1 · Medium: 0 · Low: 0
>
> 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).
>
> - [High] In net/sctp/input.c, sctp_gso_unshare() does not give SCTP
>   exclusive ownership of the frag_list data buffers, although the commit…
>
> --
>
> sctp: unshare GSO skb frag_list members instead of linearizing
>
> This patch stops linearizing SCTP GSO packets in sctp_rcv(). It adds
> sctp_gso_unshare() instead, which unclones the outer skb and replaces
> each shared frag_list member with a private pskb_copy(). The intent is to
> give SCTP exclusive ownership of both the member headers and their data,
> so that AUTH verification can rewrite the digest in place safely.
>
> > diff --git a/net/sctp/input.c b/net/sctp/input.c
> > index 9494cfa51106c..f993191ee1ea1 100644
> > --- a/net/sctp/input.c
> > +++ b/net/sctp/input.c
> > @@ -82,6 +82,39 @@ static inline int sctp_rcv_checksum(struct net *net, struct sk_buff *skb)
> >       return 0;
> >  }
> >
> > +/* Ensure exclusive ownership of frag_list members for GSO skbs.
> > + * pskb_copy() shares them by reference; unshare with private copies
> > + * so AUTH verification can safely modify the digest in place.
> > + */
> > +static int sctp_gso_unshare(struct sk_buff *skb)
> > +{
> > +     struct sk_buff **pp, *p;
> > +
> > +     if (skb_unclone(skb, GFP_ATOMIC))
> > +             return -ENOMEM;
> > +
> > +     if (!skb_has_frag_list(skb))
> > +             return 0;
> > +
> > +     pp = &skb_shinfo(skb)->frag_list;
> > +     skb_walk_frags(skb, p) {
> > +             if (skb_shared(p)) {
>
> [Severity: High]
>
> Does this check catch members whose data buffer is shared while their
> users count is 1?
>
> skb_shared() only tests refcount_read(&p->users) != 1. A frag_list member
> can have users == 1 and still have skb_cloned(p) true (dataref > 1). The
> skb_unclone() on the outer skb doesn't help here, because by this point
> the outer head is already private.
>
> Core skb code produces this state. ___pskb_trim() forks shared members
> like this:
>
> net/core/skbuff.c:___pskb_trim() {
>     ...
>                 if (skb_shared(frag)) {
>                         struct sk_buff *nfrag;
>
>                         nfrag = skb_clone(frag, GFP_ATOMIC);
>                         ...
>                         consume_skb(frag);
>     ...
> }
Didn't expect cloned skb existing in the frag_list.

I will fix it by doing skb_unclone() for that case in sctp_gso_unshare().

Thanks.

pw-bot: cr

>
> __pskb_pull_tail() forks shared members with skb_clone() in the same way.
> In both cases, the member left behind in the other skb has users == 1 and
> shares its data with the clone.
>
> One path that appears to reach this is an SCTP GSO skb looped over lo,
> with a non-mmap AF_PACKET socket attached whose BPF filter returns a
> snaplen:
>
> packet_rcv()
>   pskb_trim(skb, snaplen)
>     ___pskb_trim()
>       pskb_expand_head()   /* skb_clone_fraglist(), members users == 2 */
>       skb_clone(frag) + consume_skb(frag)   /* SCTP side users == 1 */
>
> The original skb then reaches sctp_rcv()->sctp_gso_unshare(). There,
> skb_unclone() does nothing and skb_shared(p) is false for every forked
> member, so nothing gets copied.
>
> skb_condense() only undoes the sharing when the trimmed data_len fits in
> the head's tailroom. Any snaplen larger than that keeps the sharing.
>
> Later, sctp_inq_pop() passes the member to sctp_sf_authenticate(), which
> does:
>
>         memset(digest, 0, sig_len);
>
>         if (sctp_auth_calculate_hmac(asoc, chunk->skb,
>                                      (struct sctp_auth_chunk *)chunk->chunk_hdr,
>                                      sh_key, GFP_ATOMIC)) {
>
> Wouldn't this zero the digest and then overwrite it inside a buffer that
> the nfrag clones queued on the packet socket still share? The AF_PACKET
> reader would then copy out modified data.
>
> That appears to be the case the commit message says pskb_copy() prevents:
>
>     with skb_clone() the data buffer stays shared, which could let a
>     crafted packet pass AUTH on a second copy or corrupt data visible
>     to AF_PACKET readers.
>
> A similar fork could happen through __pskb_pull_tail() on one of two
> copies that both reach SCTP, for example a TEE duplicate plus a rule that
> pulls past the head. Two SCTP receivers could then write the same digest
> bytes at the same time. That variant is more speculative.
>
> Would checking skb_shared(p) || skb_cloned(p) here, or calling
> skb_unclone(p) when users == 1, give the exclusive data ownership that
> the comment above sctp_gso_unshare() describes?
>
> > +                     struct sk_buff *copy;
> > +
> > +                     copy = pskb_copy(p, GFP_ATOMIC);
>
> [ ... ]
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/739a5caed11c49ce53078747c43ea8cec5076d50.1795619846.git.lucien.xin%40gmail.com
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads