* [PATCH net] sctp: unshare GSO skb frag_list members instead of linearizing
@ 2026-11-22 23:02 Xin Long
2026-11-23 23:45 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Xin Long @ 2026-11-22 23:02 UTC (permalink / raw)
To: network dev, linux-sctp
Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Simon Horman,
Marcelo Ricardo Leitner
When the iptables TEE target copies an SCTP GSO packet with pskb_copy(),
the frag_list skbs are shared by reference. 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().
The previous fix in commit fd60d8a08619 ("sctp: linearize cloned gso
packets in sctp_rcv") checked skb_cloned() on the outer skb and
linearized the entire GSO packet. This is insufficient for two reasons:
- A partial pull into the frag_list can privatize the head while later
members stay shared.
- Linearizing 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() to unshare the outer skb header without
flattening the frag_list.
2. Walks all frag_list members and replaces any shared member with a
private skb_clone(), giving SCTP exclusive headers (data, len,
cb[]) while still sharing the underlying data buffers.
Fixes: fd60d8a08619 ("sctp: linearize cloned gso packets in sctp_rcv")
Reported-by: syzbot+f15a6eff7a53f6eb7dc3@syzkaller.appspotmail.com
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
net/sctp/input.c | 42 ++++++++++++++++++++++++++++++++++++++++--
1 file changed, 40 insertions(+), 2 deletions(-)
diff --git a/net/sctp/input.c b/net/sctp/input.c
index 9494cfa51106..cd84ee44b9f2 100644
--- a/net/sctp/input.c
+++ b/net/sctp/input.c
@@ -82,6 +82,38 @@ 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 by cloning 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 *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;
+}
+
/*
* This is the routine which IP calls when receiving an SCTP packet.
*/
@@ -117,8 +149,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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] sctp: unshare GSO skb frag_list members instead of linearizing
2026-11-22 23:02 [PATCH net] sctp: unshare GSO skb frag_list members instead of linearizing Xin Long
@ 2026-11-23 23:45 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 23:45 UTC (permalink / raw)
To: lucien.xin
Cc: netdev, linux-sctp, davem, kuba, edumazet, pabeni, horms,
marcelo.leitner
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] sctp_gso_unshare() (net/sctp/input.c) does not give SCTP
exclusive ownership of frag_list members, even though its comment says…
- [Medium] sctp_rcv() now skips skb_linearize() for every GSO-SCTP skb,
including nonlinear ones that have no frag_list.
- [Low] The commit message misstates the history and the mechanism.
--
sctp: unshare GSO skb frag_list members instead of linearizing
This patch stops sctp_rcv() from linearizing cloned SCTP GSO skbs. It adds
sctp_gso_unshare() instead. That helper calls skb_unclone() on the outer
skb and replaces each shared frag_list member with a private skb_clone().
The aim is to avoid races on shared frag_list headers after a TEE
pskb_copy(), and to keep per-segment boundaries so that SCTP-AUTH works.
> The previous fix in commit fd60d8a08619 ("sctp: linearize cloned gso
> packets in sctp_rcv") checked skb_cloned() on the outer skb and
> linearized the entire GSO packet. This is insufficient for two reasons:
>
> - A partial pull into the frag_list can privatize the head while later
> members stay shared.
[Severity: Low]
Does this match the TEE case? The TEE target goes through
nf_dup_ipv4()/nf_dup_ipv6() and pskb_copy(). __pskb_copy_fclone() gives
the new skb a private head and shares the frag_list:
net/core/skbuff.c:__pskb_copy_fclone() {
...
if (skb_has_frag_list(skb)) {
skb_shinfo(n)->frag_list = skb_shinfo(skb)->frag_list;
skb_clone_fraglist(n);
}
...
}
Neither skb is marked cloned. So the skb_cloned() check added by
fd60d8a08619 never fired here, and no partial pull is involved.
If that's right, the bug goes back to commit 90017accff61 ("sctp: Add GSO
support"). Should the Fixes: tag point there instead of fd60d8a08619?
> 1. Calls skb_unclone() to unshare the outer skb header without
> flattening the frag_list.
skb_unclone() only acts when skb_cloned() is true. It then calls
pskb_expand_head(), which reallocates the data head and shared info. The
sk_buff header is already private at that point.
For the pskb_copy()/TEE skb, skb_cloned() is false, so skb_unclone() does
nothing. Could this step be described more precisely?
> diff --git a/net/sctp/input.c b/net/sctp/input.c
> index 9494cfa51106c..cd84ee44b9f24 100644
> --- a/net/sctp/input.c
> +++ b/net/sctp/input.c
> @@ -82,6 +82,38 @@ 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 by cloning 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 *clone;
> +
> + clone = skb_clone(p, GFP_ATOMIC);
[Severity: High]
Does this give SCTP exclusive ownership of the frag_list member, as the
comment above says? skb_clone() makes the sk_buff private. The data buffer
stays shared: dataref is bumped and both skbs are marked cloned.
The SCTP receive path then writes into that shared data. For a
cover-letter GSO skb, sctp_inq_pop() points chunk->skb at the frag_list
member:
net/sctp/inqueue.c:sctp_inq_pop() {
...
if (chunk->head_skb && chunk->skb->data_len == chunk->skb->len) {
...
chunk->skb = skb_shinfo(chunk->skb)->frag_list;
...
}
sctp_sf_authenticate() then changes the digest in place:
net/sctp/sm_statefuns.c:sctp_sf_authenticate() {
...
save_digest = kmemdup(digest, sig_len, GFP_ATOMIC);
...
memset(digest, 0, sig_len);
if (sctp_auth_calculate_hmac(asoc, chunk->skb,
(struct sctp_auth_chunk *)chunk->chunk_hdr,
sh_key, GFP_ATOMIC)) {
...
}
sctp_auth_calculate_hmac() writes the HMAC it computes back into the same
digest location in the packet.
In the TEE scenario from the commit message, both copies share the same
frag_list data. Can this sequence let an unauthenticated packet through
on the second copy?
receiver A (first copy, on-wire digest D does not match)
sctp_sf_authenticate()
save_digest = D
memset(digest, 0, sig_len)
sctp_auth_calculate_hmac() writes valid H into the shared bytes
compare fails -> BAD_SIG
receiver B (second copy)
sctp_sf_authenticate()
save_digest = H <- read from the shared bytes
memset, then recompute H
compare(H, H) succeeds -> chunk->auth = 1
If the two copies are processed at the same time, can valid packets also
fail verification? The HMAC input would include the other receiver's
partial writes.
The cloned-outer case looks affected too, for example an AF_PACKET tap on
lo. packet_rcv() clones the skb, and then
skb_unclone()->pskb_expand_head()->skb_clone_fraglist() leaves the members
shared. Before this patch, skb_linearize() gave SCTP a private copy of the
data.
With this patch, don't the memset() and the HMAC write land in data the
tap's queued clone still references? The packet socket reader would then
see zeroed or recomputed digest bytes instead of the bytes received on the
wire.
Would it work to make the data private for the members SCTP writes to?
That could be skb_copy() or pskb_expand_head() on shared or cloned members,
at least those carrying AUTH. Another option is to compute the HMAC into a
private buffer instead of the packet.
> + if (!clone)
> + return -ENOMEM;
> + clone->next = p->next;
> + consume_skb(p);
> + p = clone;
> + *pp = p;
> + }
> + pp = &p->next;
> + }
> +
> + return 0;
> +}
> +
[ ... ]
> @@ -117,8 +149,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;
> + }
[Severity: Medium]
What happens to a nonlinear GSO-SCTP skb that has page frags but no
frag_list? sctp_gso_unshare() returns early for it:
if (!skb_has_frag_list(skb))
return 0;
So it reaches sctp_inq_pop() still nonlinear. There, head_skb is only set
when frag_list is non-NULL. Otherwise chunks are bounded by
skb_tail_pointer(), which covers only the linear area:
} else if (chunk->chunk_end > skb_tail_pointer(chunk->skb)) {
/* Discard inside state machine. */
chunk->pdiscard = 1;
Such skbs can come from generic XDP with a frags-capable program:
netif_receive_generic_xdp()
netif_skb_check_for_xdp()
skb_cow_data_for_xdp()
skb_pp_cow_data()
veth native XDP can produce them as well. skb_copy_header() keeps gso_type
as SKB_GSO_SCTP, and the payload ends up in page frags with no frag_list.
If an AF_PACKET tap then clones the skb, the old skb_cloned() condition
linearized it. With this change, are the chunks past the linear head now
pdiscarded?
The AUTH reasoning in the commit message only applies when a frag_list
exists. Could the code still linearize when !skb_has_frag_list(skb)?
> +
> + if (!pskb_may_pull(skb, sizeof(struct sctphdr)))
> goto discard_it;
>
> /* Pull up the IP header. */
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20e1d469385153bcfa766080453e8d9c1d64c339.1795388574.git.lucien.xin%40gmail.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-23 23:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 23:02 [PATCH net] sctp: unshare GSO skb frag_list members instead of linearizing Xin Long
2026-11-23 23:45 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox