Article View: linux.kernel.netdev
Article #24879Re: [PATCH net] tcp: drop skb extensions before queueing a received skb
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 00:55
Date: Tue, 01 Dec 2026 00:55
220 lines
15804 bytes
15804 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 ยท High: 2 ยท Medium: 0 ยท 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] On IPv6 TCP sockets, TCP still keeps a clone of the received skb
that pins the xfrm states, so the fix does not release them.
- [High] On MPTCP subflows, and on any skb carrying SKB_EXT_PSP,
tcp_cleanup_skb() still calls only secpath_reset().
- [Low] The new comment in tcp_add_backlog() gives the wrong reason for
skipping tcp_cleanup_skb().
--
tcp: drop skb extensions before queueing a received skb
This patch changes tcp_cleanup_skb() so that it drops all skb extensions
before a received skb is queued, instead of only the secpath. The aim is
to stop a queued skb from keeping an IPv6 tunnel xfrm state alive past
its netns. MPTCP sockets and skbs with a PSP extension keep the old
secpath_reset()-only behaviour, and tcp_add_backlog() now drops the dst
and calls secpath_reset() directly.
> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index 869e780fcb482..3f14ea632486e 100644
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h
> @@ -829,10 +829,32 @@ static inline void tcp_check_space(struct sock *sk)
>
> void tcp_sack_compress_send_ack(struct sock *sk);
>
> -static inline void tcp_cleanup_skb(struct sk_buff *skb)
> +/* Drop what the receive queue does not need, here on the RX CPU: dst and
> + * skb extensions. MPTCP may just have attached its own extension, and PSP
> + * checks queued skbs against a new association (psp_sock_set_tx_key()),
> + * so with either one only the secpath goes.
> + */
> +static inline bool tcp_skb_keep_ext(const struct sk_buff *skb,
> + const struct sock *sk)
> +{
> + if (sk_is_mptcp(sk))
> + return true;
[Severity: High]
Can MPTCP subflows still hit the leak described in the commit message?
This check looks at the socket type, not at whether the skb actually
carries SKB_EXT_MPTCP. When it returns true, tcp_cleanup_skb() only calls
secpath_reset(), which ends up here:
net/core/skbuff.c:__skb_ext_del() {
...
if (refcount_read(&ext->refcnt) > 1)
return;
#ifdef CONFIG_XFRM
if (id == SKB_EXT_SEC_PATH)
skb_ext_put_sp(skb_ext_get_ptr(ext, SKB_EXT_SEC_PATH));
#endif
...
}
The comment's reason ("MPTCP may just have attached its own extension")
only makes the block private when mptcp_incoming_options() reaches
skb_ext_add(), because skb_ext_maybe_cow() copies the block on add. But
there are early returns that the peer controls and that add no extension:
net/mptcp/options.c:mptcp_incoming_options() {
...
if (__mptcp_check_fallback(msk)) {
...
return !mptcp_over_limit(subflow->conn, sk, skb);
}
...
if (!(mp_opt.suboptions & OPTION_MPTCP_DSS))
return true;
...
mpext = skb_ext_add(skb, SKB_EXT_MPTCP);
...
}
In those cases, under the commit's own precondition (another extension
active and the block shared with a clone), the secpath and its xfrm_state
references stay with the skb queued on the subflow sk_receive_queue or
out_of_order_queue. mptcp_init_skb() only resets them later. That can take
a long time if the msk receive buffer is full or a sequence hole is never
filled.
tcp_fastopen_add_skb() always passes a fresh skb_clone() to
tcp_cleanup_skb(), so MPTCP children take this path with a shared block
too.
The PSP branch below has the same gap if a PSP skb also carries a shared
secpath, though that case is more speculative.
Would it work to test skb_ext_exist(skb, SKB_EXT_MPTCP) instead of
sk_is_mptcp(sk)? Other options are to unshare the block before deleting
SKB_EXT_SEC_PATH, or to drop everything except the MPTCP/PSP extensions,
similar to what skb_ext_scrub() does for PSP.
> +#if IS_ENABLED(CONFIG_INET_PSP)
> + if (skb_ext_exist(skb, SKB_EXT_PSP))
> + return true;
> +#endif
> + return false;
> +}
> +
> +static inline void tcp_cleanup_skb(struct sk_buff *skb, const struct sock *sk)
> {
> skb_dst_drop(skb);
> - secpath_reset(skb);
> + if (unlikely(skb_has_extensions(skb))) {
> + if (tcp_skb_keep_ext(skb, sk))
> + secpath_reset(skb);
> + else
> + skb_ext_reset(skb);
[Severity: High]
Does this actually release the xfrm states on IPv6 sockets that have rx
options set?
In tcp_v6_do_rcv(), the skb is cloned before tcp_rcv_established() or
tcp_rcv_state_process() runs, and the clone is later stored on the
socket:
net/ipv6/tcp_ipv6.c:tcp_v6_do_rcv() {
...
if (np->rxopt.all &&
!((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)))
opt_skb = skb_clone_and_charge_r(skb, sk);
...
if (ipv6_opt_accepted(sk, opt_skb, &TCP_SKB_CB(opt_skb)->header.h6)) {
tcp_v6_restore_cb(opt_skb);
opt_skb = xchg(&np->pktoptions, opt_skb);
...
}
Through __copy_skb_header()->__skb_ext_copy(), the clone shares
skb->extensions, secpath included. The skb_ext_reset() here only drops
the original's reference. The block and its xfrm_state references then
stay alive through np->pktoptions, and nothing resets its extensions.
The listener path looks similar. When rxinfo, rxoinfo, rxhlim, rxohlim or
REPFLOW is set, tcp_v6_init_req() keeps the SYN itself:
refcount_inc(&skb->users);
ireq->pktopts = skb;
and tcp_v6_syn_recv_sock() clones it into the child:
newnp->pktoptions = skb_clone_and_charge_r(ireq->pktopts, newsk);
No secpath_reset() ever runs on that SYN. The child keeps the SYN's
sec_path until pktoptions is replaced or cleared, or until the socket is
destroyed.
Suppose the packet was decapsulated by an xfrm6 tunnel or IPcomp state in
another netns. Destroying that netns would then seem to give the same
xfrm6_tunnel_net_exit() warning and xfrm6_tunnel_destroy() use-after-free
quoted in the commit message.
Storing skbs in pktoptions is older than this patch, but it is the same
class of problem this commit is meant to close. The opt_skb clone is also
one source of the shared-extension condition the fix relies on.
> + }
> }
>
> static inline void tcp_add_receive_queue(struct sock *sk, struct sk_buff *skb)
[ ... ]
> diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
> index 2fc92a7884fc8..014364828e0cf 100644
> --- a/net/ipv4/tcp_ipv4.c
> +++ b/net/ipv4/tcp_ipv4.c
> @@ -1926,7 +1926,11 @@ enum skb_drop_reason tcp_add_backlog(struct sock *sk, struct sk_buff *skb)
> */
> skb_condense(skb);
>
> - tcp_cleanup_skb(skb);
> + /* Only the secpath: PSP needs its extension until tcp_v4_do_rcv(),
> + * and the full cleanup runs when the backlog is processed.
> + */
> + skb_dst_drop(skb);
> + secpath_reset(skb);
[Severity: Low]
This isn't a bug, but is the reason given in this comment accurate?
tcp_skb_keep_ext() already returns true when skb_ext_exist(skb,
SKB_EXT_PSP) is true, and tcp_cleanup_skb() then only calls
secpath_reset(). Calling tcp_cleanup_skb(skb, sk) here would therefore
also leave the PSP extension in place for psp_skb_coalesce_diff() and
__psp_sk_rx_policy_check().
The commit message uses the same reasoning:
"tcp_add_backlog() keeps secpath_reset(), as PSP needs its extension
until tcp_v{4,6}_do_rcv()."
The code itself works, because backlog skbs are cleaned up again in
tcp_rcv_established() or tcp_data_queue().
Could the comment and the changelog be updated to give the actual reason
this cleanup is done by hand here?
>
> if (unlikely(tcp_checksum_complete(skb))) {
> bh_unlock_sock(sk);
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/bd169df0-f88c-417b-91aa-c9b0f11a28b8%40mid.andrii.net
Technical Details
Message-ID:
<179608651264.3146.13590410168903598099@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374571-linux-kernel-netdev=dewy.ruReferences:
<bd169df0-f88c-417b-91aa-c9b0f11a28b8@mid.andrii.net>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374571-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] tcp: drop skb extensions before queueing a received skb Date: Tue, 01 Dec 2026 00:55:12 +0000 Organization: Usenet Network Message-ID: <179608651264.3146.13590410168903598099@kernel.org> References: <bd169df0-f88c-417b-91aa-c9b0f11a28b8@mid.andrii.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1578621"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:wWGPz86ePhTDKfcYNPqz+3WMTpg= sha256:k1SjO9+4hJsdL25ZIBvl9iteqpbWY1HtTIOuTHG2IDc= sha1:7JibfLHsbmMKN3XC/UJFBUNfwgI= sha256:IOWzxbs+J0rIf45yWSGJI7krjzuMXVzJwSTwSb4rKf0= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 16046126017; Tue, 1 Dec 2026 03:55:30 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.5 X-Spam-Status: No, score=-3.5 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oT9199gCx2J1; Tue, 1 Dec 2026 03:55:26 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-374571-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id D061212600C; Tue, 1 Dec 2026 03:55:17 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id A6A96259FF; Tue, 1 Dec 2026 00:55:16 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796086515; b=pLJa6a4hlzuUyyyrwPpBDDHtJ5/8YuJyTJcQA5P+7QTtSyyJ2UQO12Bnr/rY1TLv5YJ/ PLXdqPTHcnD/FFfabUQcdKkv7TuBQfDVUabn+oWjYVAggIr4uscNHebv0W8UTMBGpW4W9 kWMwURI0X/O8j0nBybHJhUfkbYFpSuADjEkV5dc1R0x2qCMIPlOWKwZmZ6ywc9d2yJ7XB nZ8W6fBdC6rDHBMl6u7aaXGxnmbz44+ImrDZqAyrJevYTNWm2+qAhFX/L8nmkDt7AVTPs wQPs5Cfqxfb166giVCecPSiqPKU6ZNF9yjH2EQSo/yj7C3pcKlV3Inr2auBqFeyXkQw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796086515; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=aYuBvF2MKG9S7piySlHFutLUQpwyM5FiIZbZvDP1qlg=; b=Gdpl0xjs7/rT2L5pCD6RuSacF9TNmCz5eKSRAdOIK45kD48XqOVy2DimC5VEve2IUteU aFfJn5z+meWWGmdPB8R+YGJ+OlF27+VKuXT1qCJ2eDNOdM9WyBxLOooAT9SgkCYlZ9VFO V1n6XwrRNMQ9LdFmco8bMUTuzlBzX2YWbVF7CON1rFWHnzW5MnpXOp2tTHmDNoArlacxT /5g3MN7ZOkkbrR4PB4wTX6QsayA7vR1qkLJ4uFkpDzS2zy7ejblwH0eeaB2JpGi36hQf2 v8tCUnuXJkbys3fG3tQmlh93zAsLBvUgdGBJt8Wo2gpCidmUrmC/xU9hEbDVq2oB+jg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=k+fSEroh; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 965D3606A32F; Tue, 1 Dec 2026 00:55:15 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=k+fSEroh X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796086514; b=Ss6OFJT+Ty3equz9D9ZRrHeEHWA4g0n0A3R3ZJ2trFiOdvqVfIZ0r96o4Sg2nd6YEi84 IZhw9UIEN7NXKVmeDshkjeLH78KEKx1LGNdVFnbzhXfD37p5Q0lp662hnzaboL0HLFCYo 3Wuqkcs+4/NtQYoj2U4hgGSwM2xBE1BSzHCHS7JZmZdnCuBkpm1pWEV3cgYrYJn3zmb8D HfPNFvQJr2GgbaUphgRIJUMlVbL3Y4ifMHUKP7iI5lk6FbmiBmQ4wULjQnmu47KEflAFB jFxfKsA4KGt4FlmpIyzVNzu3ybQzuNrqJXU0SLKx1LY8eWqkXAU5pgZN+uIHE0nE2/A== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796086514; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=aYuBvF2MKG9S7piySlHFutLUQpwyM5FiIZbZvDP1qlg=; b=j2Fsmy88W4Ruq55whFt24IC9imz+rfXvfRjBuu76r3ZsfoQt3P+cmsbBPBegVuOWqabc 19dZdkVW5VHWxM1K+7sIBeCAo36Nyl2EYC++Y5/n8t5bX7BQNOJLkrXOv2OwFPUvkbEX3 R4qp6J9weUWHqaawGisAhItscgGwg3+F39k6ujgchmrlSmwpYFXL3KuuC4NvshAdZhjcX FWXzqY5mRpmAHTtDuC2SecjOEmhftBB4sGRTAVcE7r4P0V9lj5RzivDSDN7IwTxgIxnX7 pa7E7qCzN8x3gjQmhX6fbJjp+BU6Y5oV27Fd8t2xsTVuWcyGkEzOdABlOYIEcS9b1ig== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=k+fSEroh; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB10B606A31A; Tue, 1 Dec 2026 00:55:14 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C0441F000C1; Tue, 1 Dec 2026 00:55:13 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796086514; bh=aYuBvF2MKG9S7piySlHFutLUQpwyM5FiIZbZvDP1qlg=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=k+fSEroheCGul6CI/HpZp4ZzoQ72PYZeKJlyduPtympUATGf9wZE7cRNFWS8YQsIS lFl79c+4+yMv8Mgvi7iPiCVPTYt9UNiT3Zl/nBtVgt87qJbvGFdtTTKc14wYF1Nmfk 7KCP3Dj/slWNL7fsid4ExazdAMbUcCk0Um0JvKhZWVSBPlqLmCzfKlMnFEMgYVJhRj 0NVzTERQAx2mGT7eK9qcBaCfJO/gP8Pvgmi2A/9XKsNh0tk3LIwT3WYSKknVeddycd 0Xbd5pz8AHLW99xsPamsrnLnB3f3C7luiaFVmtbt/7RZysnaDRrf2/0/tMvk9pNxPw cTNJuQzbwFqyQ== X-Cc: edumazet@kernel.org, ncardwell@google.com, kuniyu@google.com, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, horms@kernel.org, sd@queasysnail.net, steffen.klassert@secunet.com, herbert@gondor.apana.org.au, matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org, fw@strlen.de, netdev@vger.kernel.org, stable@vger.kernel.org X-In-Reply-To: <bd169df0-f88c-417b-91aa-c9b0f11a28b8@mid.andrii.net> X-sashiko-severity: High X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list