🚀 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 Thu, 05 Nov 2026 18:21
[PATCH net] sctp: linearize GSO skb when frag_list skbs are shared
#11835
Author: Xin Long
Date: Thu, 05 Nov 2026 18:21
42 lines
12224 bytes
When the iptables TEE target copies an SCTP GSO packet with pskb_copy(),
the new skb shares the frag_list skbs by reference (their refcounts are
bumped but they are not deep-copied). The SCTP receive path skips
linearization for uncloned GSO packets, so it later operates directly on
the shared frag_list entries. If skb_copy_bits() encounters a length
discrepancy or invalid offset in such a shared frag_list skb, it returns
-EFAULT, which triggers a BUG_ON in __pskb_pull_tail().

Extend the linearization condition to also cover GSO packets whose
frag_list head is shared, so SCTP obtains an exclusive, contiguous
copy of the data before processing it.

Fixes: 4c2f24549644 ("sctp: linearize early if it's not GSO")
Reported-by: syzbot+f15a6eff7a53f6eb7dc3@syzkaller.appspotmail.com
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/sctp/input.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/net/sctp/input.c b/net/sctp/input.c
index 9494cfa51106..db3c7818724b 100644
--- a/net/sctp/input.c
+++ b/net/sctp/input.c
@@ -117,8 +117,13 @@ 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 || skb_cloned(skb) ||
+	    (skb_has_frag_list(skb) && skb_shared(skb_shinfo(skb)->frag_list))) {
+		if (skb_linearize(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] sctp: linearize GSO skb when frag_list skbs are shared
#12841
Author: netdev-bot+sashiko
Date: Sun, 08 Nov 2026 21:01
197 lines
15106 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 1 · 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).

- [High] The fix is incomplete because sctp_rcv() only tests the first
  frag_list member for sharing.
- [Medium] sctp: skb_linearize() on GSO skb in sctp_rcv() breaks SCTP-
  AUTH verification
- [Low] The comment above the changed condition in sctp_rcv()
  (net/sctp/input.c:116-119, from 4c2f24549644) gives CRC cost as the…

--

sctp: linearize GSO skb when frag_list skbs are shared

This patch widens the linearization condition in sctp_rcv(). GSO packets
whose frag_list head skb is shared are now linearized as well. The aim is
to stop SCTP from working in place on frag_list skbs shared through
pskb_copy() (for example by the TEE target), which can end in a BUG_ON in
__pskb_pull_tail().

> diff --git a/net/sctp/input.c b/net/sctp/input.c
> index 9494cfa51106c..db3c7818724b8 100644
> --- a/net/sctp/input.c
> +++ b/net/sctp/input.c
> @@ -117,8 +117,13 @@ int sctp_rcv(struct sk_buff *skb)
>  	 * it's better to just linearize it otherwise crc computing
>  	 * takes longer.
>  	 */

[Severity: Low]
This isn't a bug, but the comment above this block still gives CRC cost
as the only reason to linearize:

    /* If the packet is fragmented and we need to do crc checking,
     * it's better to just linearize it otherwise crc computing
     * takes longer.
     */

The new frag_list clause only matters when is_gso is true. In that case
sctp_rcv_checksum() is skipped anyway. The clause is there for
correctness, not for CRC speed.

Could the comment be updated to say that GSO packets with shared frag_list
skbs must be linearized?

> -	if (((!is_gso || skb_cloned(skb)) && skb_linearize(skb)) ||
> -	    !pskb_may_pull(skb, sizeof(struct sctphdr)))
> +	if (!is_gso || skb_cloned(skb) ||
> +	    (skb_has_frag_list(skb) && skb_shared(skb_shinfo(skb)->frag_list))) {

[Severity: High]
Is it enough to check only the first frag_list member here?

pskb_copy() goes through __pskb_copy_fclone()->skb_clone_fraglist(),
which takes a reference on every member of the chain:

net/core/skbuff.c:skb_clone_fraglist() {
	skb_walk_frags(skb, list)
		skb_get(list);
}

So after nf_dup_ipv4()->pskb_copy() in the TEE target, every frag_list
member is shared, not only the head.

Something may pull into the frag_list before sctp_rcv() runs. Examples
are nft_payload_set_eval() or tcf_pedit_act() through
skb_ensure_writable(), and bpf_skb_pull_data(). In that case
__pskb_pull_tail() forks a partially eaten shared head:

net/core/skbuff.c:__pskb_pull_tail() {
    ...
				if (skb_shared(list)) {
					/* Sucks! We need to fork list. :-( */
					clone = skb_clone(list, GFP_ATOMIC);
					...
					insp = list->next;
					list = clone;
				}
    ...
		/* Free pulled out fragments. */
		while ((list = skb_shinfo(skb)->frag_list) != insp) {
			skb_shinfo(skb)->frag_list = list->next;
			consume_skb(list);
		}
		/* And insert new clone at head. */
		if (clone) {
			clone->next = list;
			skb_shinfo(skb)->frag_list = clone;
		}
    ...
}

The pulled copy then has a private clone at the head of its frag_list,
while the later members still have users == 2. Because consume_skb() drops
a reference on the old head, the twin skb's head also goes back to
users == 1. An eat that consumes whole leading members ends in the same
state.

Both outer skbs stay uncloned with is_gso true. The new check therefore
returns false in both of them and skb_linearize() is skipped.

sctp_inq_pop() then walks the chain and calls skb_pull() on each member:

net/sctp/inqueue.c:sctp_inq_pop() {
    ...
			if (chunk->skb->next) {
				chunk->skb = chunk->skb->next;
				goto new_skb;
			}
    ...
			skb_pull(chunk->skb, chunk->chunk_end - chunk->skb->data);
    ...
	skb_pull(chunk->skb, sizeof(*ch));
    ...
}

It also writes SCTP_INPUT_CB() into those members. Can the two SCTP
receive paths, possibly on different CPUs, end up changing data, len and
cb of the same shared sk_buff structs?

Suppose either copy is linearized later, for example because a tap made
it skb_cloned(), or because of another pull into the frag_list. Then
__pskb_pull_tail()->skb_copy_bits() walks members whose len has already
been reduced. Would that still return -EFAULT and hit
BUG_ON(skb_copy_bits(...)), the same panic this patch is meant to fix?

The commit message talks about sharing of "the frag_list skbs" in general,
but the check only looks at the head. Should this walk every member with
skb_walk_frags() and linearize if any of them is skb_shared()?

> +		if (skb_linearize(skb))
> +			goto discard_it;
> +	}
> +
> +	if (!pskb_may_pull(skb, sizeof(struct sctphdr)))
>  		goto discard_it;
>  
>  	/* Pull up the IP header. */

[Severity: Medium]
Does linearizing an SCTP GSO skb here lose the per-segment boundaries
that the SCTP-AUTH check depends on?

On transmit, sctp_packet_pack() builds each GSO segment in its own nskb
and appends it to skb_shinfo(head)->frag_list. When the association
uses AUTH, the HMAC is computed over that single nskb only:

net/sctp/output.c:sctp_packet_pack() {
    ...
		if (auth) {
			if (sctp_auth_calculate_hmac(tp->asoc, nskb, auth,
						     packet->auth->shkey, gfp)) {
    ...
}

After skb_linearize() the frag_list is gone. sctp_inq_pop() then no
longer sets chunk->head_skb, and it treats all the concatenated
segments as one SCTP packet. When sctp_sf_authenticate() checks the
first AUTH chunk, it passes chunk->skb to sctp_auth_calculate_hmac(),
which hashes up to the tail of the whole linear buffer:

net/sctp/auth.c:sctp_auth_calculate_hmac() {
    ...
	data_len = skb_tail_pointer(skb) - (unsigned char *)auth;
    ...
}

That range now covers every following segment as well, so the digest
cannot match. sctp_sf_authenticate() returns SCTP_IERROR_BAD_SIG, and
sctp_sf_pdiscard() discards the remaining chunks, which now means all
segments of the GSO packet.

The existing skb_cloned() leg already behaves this way. The new clause
extends it to every GSO packet whose frag_list was shared by
pskb_copy(). If I read nf_dup_ipv4() right, with the TEE target that
includes the original skb that keeps going to the local socket, not
only the duplicate. skb_clone_fraglist() takes a reference on members
that both skbs point to, so both see a shared frag_list head. On
loopback or veth with AUTH enabled, a TEE rule would then turn the
BUG_ON into silent drops of authenticated traffic.

Would it be better to unshare the frag_list members instead, for
example by replacing each shared member with a private copy, so the
segments stay separate? Or is there another way to get an exclusive
copy without merging the segments into one SCTP packet?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/9997493edadfe9faa713c73de9c70e36cee9ffea.1793902911.git.lucien.xin%40gmail.com
Re: [PATCH net] sctp: linearize GSO skb when frag_list skbs are shared
#13558
Author: Xin Long
Date: Tue, 10 Nov 2026 01:49
248 lines
21375 bytes
On Sun, Nov 8, 2026 at 4:01 PM <netdev-bot+sashiko@kernel.org> wrote:
>
> Thank you for your contribution! Sashiko AI review found 3 potential
> issue(s) to consider.
>
> Critical: 0 · High: 1 · 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).
>
> - [High] The fix is incomplete because sctp_rcv() only tests the first
>   frag_list member for sharing.
> - [Medium] sctp: skb_linearize() on GSO skb in sctp_rcv() breaks SCTP-
>   AUTH verification
> - [Low] The comment above the changed condition in sctp_rcv()
>   (net/sctp/input.c:116-119, from 4c2f24549644) gives CRC cost as the…
>
> --
>
> sctp: linearize GSO skb when frag_list skbs are shared
>
> This patch widens the linearization condition in sctp_rcv(). GSO packets
> whose frag_list head skb is shared are now linearized as well. The aim is
> to stop SCTP from working in place on frag_list skbs shared through
> pskb_copy() (for example by the TEE target), which can end in a BUG_ON in
> __pskb_pull_tail().
>
> > diff --git a/net/sctp/input.c b/net/sctp/input.c
> > index 9494cfa51106c..db3c7818724b8 100644
> > --- a/net/sctp/input.c
> > +++ b/net/sctp/input.c
> > @@ -117,8 +117,13 @@ int sctp_rcv(struct sk_buff *skb)
> >        * it's better to just linearize it otherwise crc computing
> >        * takes longer.
> >        */
>
> [Severity: Low]
> This isn't a bug, but the comment above this block still gives CRC cost
> as the only reason to linearize:
>
>     /* If the packet is fragmented and we need to do crc checking,
>      * it's better to just linearize it otherwise crc computing
>      * takes longer.
>      */
>
> The new frag_list clause only matters when is_gso is true. In that case
> sctp_rcv_checksum() is skipped anyway. The clause is there for
> correctness, not for CRC speed.
>
> Could the comment be updated to say that GSO packets with shared frag_list
> skbs must be linearized?
>
> > -     if (((!is_gso || skb_cloned(skb)) && skb_linearize(skb)) ||
> > -         !pskb_may_pull(skb, sizeof(struct sctphdr)))
> > +     if (!is_gso || skb_cloned(skb) ||
> > +         (skb_has_frag_list(skb) && skb_shared(skb_shinfo(skb)->frag_list))) {
>
> [Severity: High]
> Is it enough to check only the first frag_list member here?
>
> pskb_copy() goes through __pskb_copy_fclone()->skb_clone_fraglist(),
> which takes a reference on every member of the chain:
>
> net/core/skbuff.c:skb_clone_fraglist() {
>         skb_walk_frags(skb, list)
>                 skb_get(list);
> }
>
> So after nf_dup_ipv4()->pskb_copy() in the TEE target, every frag_list
> member is shared, not only the head.
>
> Something may pull into the frag_list before sctp_rcv() runs. Examples
> are nft_payload_set_eval() or tcf_pedit_act() through
> skb_ensure_writable(), and bpf_skb_pull_data(). In that case
> __pskb_pull_tail() forks a partially eaten shared head:
>
> net/core/skbuff.c:__pskb_pull_tail() {
>     ...
>                                 if (skb_shared(list)) {
>                                         /* Sucks! We need to fork list. :-( */
>                                         clone = skb_clone(list, GFP_ATOMIC);
>                                         ...
>                                         insp = list->next;
>                                         list = clone;
>                                 }
>     ...
>                 /* Free pulled out fragments. */
>                 while ((list = skb_shinfo(skb)->frag_list) != insp) {
>                         skb_shinfo(skb)->frag_list = list->next;
>                         consume_skb(list);
>                 }
>                 /* And insert new clone at head. */
>                 if (clone) {
>                         clone->next = list;
>                         skb_shinfo(skb)->frag_list = clone;
>                 }
>     ...
> }
>
> The pulled copy then has a private clone at the head of its frag_list,
> while the later members still have users == 2. Because consume_skb() drops
> a reference on the old head, the twin skb's head also goes back to
> users == 1. An eat that consumes whole leading members ends in the same
> state.
>
> Both outer skbs stay uncloned with is_gso true. The new check therefore
> returns false in both of them and skb_linearize() is skipped.
>
> sctp_inq_pop() then walks the chain and calls skb_pull() on each member:
>
> net/sctp/inqueue.c:sctp_inq_pop() {
>     ...
>                         if (chunk->skb->next) {
>                                 chunk->skb = chunk->skb->next;
>                                 goto new_skb;
>                         }
>     ...
>                         skb_pull(chunk->skb, chunk->chunk_end - chunk->skb->data);
>     ...
>         skb_pull(chunk->skb, sizeof(*ch));
>     ...
> }
>
> It also writes SCTP_INPUT_CB() into those members. Can the two SCTP
> receive paths, possibly on different CPUs, end up changing data, len and
> cb of the same shared sk_buff structs?
>
> Suppose either copy is linearized later, for example because a tap made
> it skb_cloned(), or because of another pull into the frag_list. Then
> __pskb_pull_tail()->skb_copy_bits() walks members whose len has already
> been reduced. Would that still return -EFAULT and hit
> BUG_ON(skb_copy_bits(...)), the same panic this patch is meant to fix?
>
> The commit message talks about sharing of "the frag_list skbs" in general,
> but the check only looks at the head. Should this walk every member with
> skb_walk_frags() and linearize if any of them is skb_shared()?
>
> > +             if (skb_linearize(skb))
> > +                     goto discard_it;
> > +     }
> > +
> > +     if (!pskb_may_pull(skb, sizeof(struct sctphdr)))
> >               goto discard_it;
> >
> >       /* Pull up the IP header. */
>
> [Severity: Medium]
> Does linearizing an SCTP GSO skb here lose the per-segment boundaries
> that the SCTP-AUTH check depends on?
>
> On transmit, sctp_packet_pack() builds each GSO segment in its own nskb
> and appends it to skb_shinfo(head)->frag_list. When the association
> uses AUTH, the HMAC is computed over that single nskb only:
>
> net/sctp/output.c:sctp_packet_pack() {
>     ...
>                 if (auth) {
>                         if (sctp_auth_calculate_hmac(tp->asoc, nskb, auth,
>                                                      packet->auth->shkey, gfp)) {
>     ...
> }
>
> After skb_linearize() the frag_list is gone. sctp_inq_pop() then no
> longer sets chunk->head_skb, and it treats all the concatenated
> segments as one SCTP packet. When sctp_sf_authenticate() checks the
> first AUTH chunk, it passes chunk->skb to sctp_auth_calculate_hmac(),
> which hashes up to the tail of the whole linear buffer:
>
> net/sctp/auth.c:sctp_auth_calculate_hmac() {
>     ...
>         data_len = skb_tail_pointer(skb) - (unsigned char *)auth;
>     ...
> }
>
> That range now covers every following segment as well, so the digest
> cannot match. sctp_sf_authenticate() returns SCTP_IERROR_BAD_SIG, and
> sctp_sf_pdiscard() discards the remaining chunks, which now means all
> segments of the GSO packet.
>
> The existing skb_cloned() leg already behaves this way. The new clause
> extends it to every GSO packet whose frag_list was shared by
> pskb_copy(). If I read nf_dup_ipv4() right, with the TEE target that
> includes the original skb that keeps going to the local socket, not
> only the duplicate. skb_clone_fraglist() takes a reference on members
> that both skbs point to, so both see a shared frag_list head. On
> loopback or veth with AUTH enabled, a TEE rule would then turn the
> BUG_ON into silent drops of authenticated traffic.
>
> Would it be better to unshare the frag_list members instead, for
> example by replacing each shared member with a private copy, so the
> segments stay separate? Or is there another way to get an exclusive
> copy without merging the segments into one SCTP packet?
>
The issues reported are valid, we should never linearize a SCTP GSO
packet, even prior to this patch.

I will try to fix it by adding a new helper for this in SCTP, like:

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 *clone;

                        clone = skb_clone(p, GFP_ATOMIC);
                        if (!clone)
                                return -ENOMEM;
                        clone->next = p->next;
                        consume_skb(p);
                        p = clone;
                        *pp = p;
                }
                pp = &p->next;
        }

        return 0;
}

Thanks.

pw-bot: cr
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