Netdev List
 help / color / mirror / Atom feed
From: Xingwang Xiang <v3rdant.xiang@gmail.com>
To: john.fastabend@gmail.com
Cc: kuba@kernel.org, jakub@cloudflare.com, sd@queasysnail.net,
	davem@davemloft.net, pabeni@redhat.com, horms@kernel.org,
	netdev@vger.kernel.org, mrpre@163.com,
	Xingwang Xiang <v3rdant.xiang@gmail.com>
Subject: [PATCH net v4 1/2] net/tls: reject TLS_RX setsockopt on psock-owned sockets
Date: Tue, 12 May 2026 00:52:08 +0900	[thread overview]
Message-ID: <20260511155210.32926-2-v3rdant.xiang@gmail.com> (raw)
In-Reply-To: <20260511155210.32926-1-v3rdant.xiang@gmail.com>

When a TCP socket is inserted into a sockmap before TLS RX is
configured, tls_sw_strparser_arm() saves sk_psock_verdict_data_ready
as rx_ctx->saved_data_ready.  On data arrival tls_rx_msg_ready()
calls saved_data_ready(), which is sk_psock_verdict_data_ready().
That calls tcp_read_skb(), draining sk_receive_queue via
__skb_unlink() without advancing copied_seq, because SK_PASS through
sk_psock_verdict_recv() does not call tcp_eat_skb().

tls_strp_msg_load() then sees tcp_inq() >= full_len (stale), calls
tcp_recv_skb() on an empty queue, triggers WARN_ON_ONCE(!first), and
returns with rx_ctx->strp.anchor.frag_list still pointing at a
psock-owned (potentially freed) skb.  tls_decrypt_sg() subsequently
walks that frag_list, yielding a use-after-free.

The existing guard only covers the reverse order: a sockmap update
already fails with EBUSY when the socket has TLS ULP set
(tcp_bpf_check_ulp).  Add the symmetric check: if a psock is already
attached to the socket, reject setsockopt(TLS_RX) with EBUSY before
any strparser state is modified.

Signed-off-by: Xingwang Xiang <v3rdant.xiang@gmail.com>
---
 net/tls/tls_main.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c
index fd39acf41..46cdd38ae 100644
--- a/net/tls/tls_main.c
+++ b/net/tls/tls_main.c
@@ -648,6 +648,15 @@ static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval,
 	if (sockptr_is_null(optval) || (optlen < sizeof(*crypto_info)))
 		return -EINVAL;
 
+	if (!tx) {
+		struct sk_psock *psock = sk_psock_get(sk);
+
+		if (psock) {
+			sk_psock_put(sk, psock);
+			return -EBUSY;
+		}
+	}
+
 	if (tx) {
 		crypto_ctx = &ctx->crypto_send;
 		alt_crypto_info = &ctx->crypto_recv.info;
-- 
2.54.0


  reply	other threads:[~2026-05-11 15:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-11 15:52 [PATCH net v4 0/2] net/tls: fix UAF when TLS_RX is set on sockmap socket Xingwang Xiang
2026-05-11 15:52 ` Xingwang Xiang [this message]
2026-05-11 15:52 ` [PATCH net v4 2/2] selftests: bpf: add test for KTLS+sockmap reverse-order UAF Xingwang Xiang
2026-05-11 23:13 ` [PATCH net v4 0/2] net/tls: fix UAF when TLS_RX is set on sockmap socket Jakub Kicinski
     [not found]   ` <CAFFJMPzw8pcwX9g7iv3F=FpHQyovUgZZ28P7XfH3gmiay-JfpA@mail.gmail.com>
2026-05-12  0:10     ` xw x
2026-05-12  2:06       ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260511155210.32926-2-v3rdant.xiang@gmail.com \
    --to=v3rdant.xiang@gmail.com \
    --cc=davem@davemloft.net \
    --cc=horms@kernel.org \
    --cc=jakub@cloudflare.com \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=mrpre@163.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sd@queasysnail.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox