Netdev List
 help / color / mirror / Atom feed
* [PATCH net v3] sctp: unshare GSO skb frag_list members instead of linearizing
@ 2026-11-27 14:26 Xin Long
  2026-11-28 15:11 ` netdev-bot+sashiko
  0 siblings, 1 reply; 2+ messages in thread
From: Xin Long @ 2026-11-27 14:26 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 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 walks the frag_list and ensures exclusive
ownership of each member:

 - skb_unclone() on the outer skb to privatize the head when cloned.

 - For shared members (users > 1): replace with a pskb_copy() to get
   a private sk_buff and data buffer.

 - For non-shared members: skb_unclone() to handle the case where
   users == 1 but the data buffer is still shared (dataref > 1). This
   state arises when a cloned GSO skb is trimmed via ___pskb_trim() or
   __pskb_pull_tail(), e.g. an AF_PACKET socket with a BPF snaplen on
   loopback trims a clone from dev_queue_xmit_nit(), leaving the
   original's frag_list members with privately-owned sk_buff headers
   but shared data.

Data exclusivity matters because sctp_sf_authenticate() zeroes the
digest and writes the computed HMAC in place; shared data would corrupt
AF_PACKET readers or let a crafted packet pass AUTH on a second copy.

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
    (noted by Sashiko AI review).
v3:
  - Call skb_unclone() on the skbs in frag_list that are not shared in
    sctp_gso_unshare() (noted by Sashiko AI review).
---
 net/sctp/input.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/net/sctp/input.c b/net/sctp/input.c
index 9494cfa51106..89599fe4c2f1 100644
--- a/net/sctp/input.c
+++ b/net/sctp/input.c
@@ -82,6 +82,42 @@ static inline int sctp_rcv_checksum(struct net *net, struct sk_buff *skb)
 	return 0;
 }
 
+/* Ensure exclusive ownership of head and frag_list data for GSO skbs.
+ * pskb_copy() shares frag_list via skb_clone_fraglist(): copy shared
+ * members and unclone shared data so sctp_sf_authenticate() can safely
+ * zero and rewrite the HMAC 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;
+		} else if (skb_unclone(p, GFP_ATOMIC)) {
+			return -ENOMEM;
+		}
+		pp = &p->next;
+	}
+
+	return 0;
+}
+
 /*
  * This is the routine which IP calls when receiving an SCTP packet.
  */
@@ -117,8 +153,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

end of thread, other threads:[~2026-11-28 15:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 14:26 [PATCH net v3] sctp: unshare GSO skb frag_list members instead of linearizing Xin Long
2026-11-28 15:11 ` 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