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