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