* [PATCH net] tls: restore sk_prot before calling original destructor
@ 2026-06-05 12:57 Geliang Tang
2026-06-05 14:09 ` MPTCP CI
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Geliang Tang @ 2026-06-05 12:57 UTC (permalink / raw)
To: John Fastabend, Jakub Kicinski, Sabrina Dubroca, David S. Miller,
Eric Dumazet, Paolo Abeni, Simon Horman, Atul Gupta
Cc: Geliang Tang, netdev, mptcp, Gang Yan
From: Geliang Tang <tanggeliang@kylinos.cn>
When a TLS socket is offloaded to a TOE device, tls_toe_bypass() replaces
sk->sk_prot with a TLS-specific protocol table. On socket destruction,
tls_toe_sk_destruct() calls the original sk_destruct callback
(ctx->sk_destruct), which may rely on the original sk_prot (e.g., for
memory accounting or close handling). Without restoring sk->sk_prot
before calling ctx->sk_destruct, the destructor may access stale or
incorrect protocol functions, leading to use-after-free or kernel panic.
Add WRITE_ONCE(sk->sk_prot, ctx->sk_proto) before invoking
ctx->sk_destruct to restore the original protocol pointer. This mirrors
the restoration already done in tls_sk_proto_close() for the software
and device offload paths.
Fixes: 76f7164d02d4 ("net/tls: free ctx in sock destruct")
Co-developed-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
Hi,
This bug was identified by Sashiko during my development of "MPTCP KTLS
support" [1]. I am sending this fix separately for now.
Thanks,
-Geliang
[1]
https://patchwork.kernel.org/project/mptcp/cover/cover.1780621326.git.tanggeliang@kylinos.cn/
---
net/tls/tls_toe.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/tls/tls_toe.c b/net/tls/tls_toe.c
index 825669e1ab47..c9c1a0952f4b 100644
--- a/net/tls/tls_toe.c
+++ b/net/tls/tls_toe.c
@@ -48,6 +48,8 @@ static void tls_toe_sk_destruct(struct sock *sk)
struct inet_connection_sock *icsk = inet_csk(sk);
struct tls_context *ctx = tls_get_ctx(sk);
+ WRITE_ONCE(sk->sk_prot, ctx->sk_proto);
+
ctx->sk_destruct(sk);
/* Free ctx */
rcu_assign_pointer(icsk->icsk_ulp_data, NULL);
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net] tls: restore sk_prot before calling original destructor
2026-06-05 12:57 [PATCH net] tls: restore sk_prot before calling original destructor Geliang Tang
@ 2026-06-05 14:09 ` MPTCP CI
2026-06-08 3:24 ` Geliang Tang
2026-06-08 8:28 ` Sabrina Dubroca
2 siblings, 0 replies; 5+ messages in thread
From: MPTCP CI @ 2026-06-05 14:09 UTC (permalink / raw)
To: Geliang Tang; +Cc: mptcp
Hi Geliang,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal (except selftest_mptcp_join): Success! ✅
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Success! ✅
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/27017157085
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/854fb4e76a75
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1106620
If there are some issues, you can reproduce them using the same environment as
the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normal
For more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a
stable tests suite when executed on a public CI like here, it is possible some
reported issues are not due to your modifications. Still, do not hesitate to
help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] tls: restore sk_prot before calling original destructor
2026-06-05 12:57 [PATCH net] tls: restore sk_prot before calling original destructor Geliang Tang
2026-06-05 14:09 ` MPTCP CI
@ 2026-06-08 3:24 ` Geliang Tang
2026-06-08 8:28 ` Sabrina Dubroca
2 siblings, 0 replies; 5+ messages in thread
From: Geliang Tang @ 2026-06-08 3:24 UTC (permalink / raw)
To: John Fastabend, Jakub Kicinski, Sabrina Dubroca, David S. Miller,
Eric Dumazet, Paolo Abeni, Simon Horman, Atul Gupta
Cc: Geliang Tang, netdev, mptcp, Gang Yan
On Fri, 2026-06-05 at 20:57 +0800, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> When a TLS socket is offloaded to a TOE device, tls_toe_bypass()
> replaces
> sk->sk_prot with a TLS-specific protocol table. On socket
> destruction,
> tls_toe_sk_destruct() calls the original sk_destruct callback
> (ctx->sk_destruct), which may rely on the original sk_prot (e.g., for
> memory accounting or close handling). Without restoring sk->sk_prot
> before calling ctx->sk_destruct, the destructor may access stale or
> incorrect protocol functions, leading to use-after-free or kernel
> panic.
>
> Add WRITE_ONCE(sk->sk_prot, ctx->sk_proto) before invoking
> ctx->sk_destruct to restore the original protocol pointer. This
> mirrors
> the restoration already done in tls_sk_proto_close() for the software
> and device offload paths.
>
> Fixes: 76f7164d02d4 ("net/tls: free ctx in sock destruct")
Sorry, this "Fixes" tag is not accurate. sk_proto was only added to
struct tls_context in commit 32857cf57f92, so it would be better to
update the "Fixes" tag as follows:
Fixes: 32857cf57f92 ("net/tls: fix transition through disconnect with
close")
If needed, I can send a v2.
Thanks,
-Geliang
> Co-developed-by: Gang Yan <yangang@kylinos.cn>
> Signed-off-by: Gang Yan <yangang@kylinos.cn>
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
> Hi,
>
> This bug was identified by Sashiko during my development of "MPTCP
> KTLS
> support" [1]. I am sending this fix separately for now.
>
> Thanks,
> -Geliang
>
> [1]
> https://patchwork.kernel.org/project/mptcp/cover/cover.1780621326.git.tanggeliang@kylinos.cn/
> ---
> net/tls/tls_toe.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/net/tls/tls_toe.c b/net/tls/tls_toe.c
> index 825669e1ab47..c9c1a0952f4b 100644
> --- a/net/tls/tls_toe.c
> +++ b/net/tls/tls_toe.c
> @@ -48,6 +48,8 @@ static void tls_toe_sk_destruct(struct sock *sk)
> struct inet_connection_sock *icsk = inet_csk(sk);
> struct tls_context *ctx = tls_get_ctx(sk);
>
> + WRITE_ONCE(sk->sk_prot, ctx->sk_proto);
> +
> ctx->sk_destruct(sk);
> /* Free ctx */
> rcu_assign_pointer(icsk->icsk_ulp_data, NULL);
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] tls: restore sk_prot before calling original destructor
2026-06-05 12:57 [PATCH net] tls: restore sk_prot before calling original destructor Geliang Tang
2026-06-05 14:09 ` MPTCP CI
2026-06-08 3:24 ` Geliang Tang
@ 2026-06-08 8:28 ` Sabrina Dubroca
2026-06-09 3:02 ` Jakub Kicinski
2 siblings, 1 reply; 5+ messages in thread
From: Sabrina Dubroca @ 2026-06-08 8:28 UTC (permalink / raw)
To: Geliang Tang, John Fastabend, Jakub Kicinski
Cc: David S. Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Atul Gupta, Geliang Tang, netdev, mptcp, Gang Yan
2026-06-05, 20:57:07 +0800, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> When a TLS socket is offloaded to a TOE device, tls_toe_bypass() replaces
Or maybe it's time to simply drop tls_toe? There's only one driver
that uses it (chelsio/chtls), and it hasn't been touched by someone at
chelsio since 2021 (2355a6773a2c [1]). Since then, there have been a
few fixes by people who I doubt are actually using this (Eric, Dan
Carpenter), everything else is treewide/refactoring patches.
[1] the author of this commit, and current maintainer for
drivers/crypto/chelsio and drivers/net/ethernet/chelsio/inline_crypto,
hasn't been around since 2022
--
Sabrina
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] tls: restore sk_prot before calling original destructor
2026-06-08 8:28 ` Sabrina Dubroca
@ 2026-06-09 3:02 ` Jakub Kicinski
0 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2026-06-09 3:02 UTC (permalink / raw)
To: Sabrina Dubroca
Cc: Geliang Tang, John Fastabend, David S. Miller, Eric Dumazet,
Paolo Abeni, Simon Horman, Atul Gupta, Geliang Tang, netdev,
mptcp, Gang Yan
On Mon, 8 Jun 2026 10:28:45 +0200 Sabrina Dubroca wrote:
> 2026-06-05, 20:57:07 +0800, Geliang Tang wrote:
> > From: Geliang Tang <tanggeliang@kylinos.cn>
> >
> > When a TLS socket is offloaded to a TOE device, tls_toe_bypass() replaces
>
> Or maybe it's time to simply drop tls_toe? There's only one driver
> that uses it (chelsio/chtls), and it hasn't been touched by someone at
> chelsio since 2021 (2355a6773a2c [1]). Since then, there have been a
> few fixes by people who I doubt are actually using this (Eric, Dan
> Carpenter), everything else is treewide/refactoring patches.
Yup, tls_toe is unsalvageable. Sabrina, could you float a net-next
patch to nuke it?
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-06-09 3:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-05 12:57 [PATCH net] tls: restore sk_prot before calling original destructor Geliang Tang
2026-06-05 14:09 ` MPTCP CI
2026-06-08 3:24 ` Geliang Tang
2026-06-08 8:28 ` Sabrina Dubroca
2026-06-09 3:02 ` Jakub Kicinski
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.