* [PATCH bpf] bpf, sockmap: Don't replace a ULP's sk_prot when leaving a sockmap
@ 2026-11-30 5:56 Sechang Lim
2026-11-30 6:17 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Sechang Lim @ 2026-11-30 5:56 UTC (permalink / raw)
To: bpf
Cc: netdev, edumazet, ncardwell, kuniyu, john.fastabend, jakub,
jiayuan.chen, davem, kuba, pabeni, horms
A socket can get the TLS ULP after it was added to a sockmap. If the
map has an sk_skb program, removing the socket from it calls
tcp_bpf_update_proto() with restore=false, which puts a tcp_bpf proto
in sk->sk_prot over the TLS one.
When the psock is dropped, the restore path sees the ULP and only calls
tcp_update_ulp(), which updates the TLS context but leaves sk->sk_prot
alone. close() then enters sock_map_close() with no psock, reads
sock_map_close() again from sk->sk_prot->close and retries forever. The
task can't be killed and the socket is never freed.
Don't replace sk->sk_prot when a ULP is installed.
Fixes: e34a07c0ae39 ("sock: redo the psock vs ULP protection check")
Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
---
net/ipv4/tcp_bpf.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
index 788ce08eef4d..035894e5d923 100644
--- a/net/ipv4/tcp_bpf.c
+++ b/net/ipv4/tcp_bpf.c
@@ -810,6 +810,9 @@ int tcp_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore)
return 0;
}
+ if (inet_csk_has_ulp(sk))
+ return -EINVAL;
+
if (sk->sk_family == AF_INET6) {
if (tcp_bpf_assert_proto_ops(psock->sk_proto))
return -EINVAL;
--
2.56.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf] bpf, sockmap: Don't replace a ULP's sk_prot when leaving a sockmap
2026-11-30 5:56 [PATCH bpf] bpf, sockmap: Don't replace a ULP's sk_prot when leaving a sockmap Sechang Lim
@ 2026-11-30 6:17 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-30 6:17 UTC (permalink / raw)
To: Sechang Lim, bpf
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] bpf, sockmap: unrestored sk_write_space and tls_prots
pollution on ULP socket
--
commit 73c8b9838a60a20d7579f5fb528badbe18cba8d1
Author: Sechang Lim <rhkrqnwk98@gmail.com>
bpf, sockmap: Don't replace a ULP's sk_prot when leaving a sockmap
This commit makes tcp_bpf_update_proto() return -EINVAL when restore is
false and the socket has a ULP installed, preventing it from overwriting
the ULP's sk->sk_prot when a socket is removed from a sockmap.
> diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
> index 788ce08eef4d7..035894e5d9235 100644
> --- a/net/ipv4/tcp_bpf.c
> +++ b/net/ipv4/tcp_bpf.c
> @@ -810,6 +810,9 @@ int tcp_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore)
> return 0;
> }
>
> + if (inet_csk_has_ulp(sk))
> + return -EINVAL;
> +
> if (sk->sk_family == AF_INET6) {
> if (tcp_bpf_assert_proto_ops(psock->sk_proto))
> return -EINVAL;
[Severity: Medium]
Does allowing a socket in a sockmap to attach the TLS ULP still leave
sk->sk_write_space and tls_prots corrupted when the socket leaves the
map?
When a socket is added to a sockmap with a verdict or stream parser
program, sk->sk_write_space is set to sk_psock_write_space and
sk->sk_prot is set to tcp_bpf_prots. Attaching the TLS ULP via
tls_init() leaves tx_conf at TLS_BASE (do_tls_setsockopt_conf() rejects
sockets while sk_psock(sk) is set), so sk->sk_write_space stays
sk_psock_write_space. When the psock is later dropped, the restore path
in tcp_bpf_update_proto() calls tcp_update_ulp() -> tls_update(), which
only writes ctx->sk_write_space = psock->saved_write_space and never
restores sk->sk_write_space. Once sk->sk_user_data is cleared,
sk->sk_write_space remains sk_psock_write_space with no psock, turning
write-space wakeups into a permanent no-op.
In addition, tls_init() calls tls_build_proto() while sk->sk_prot points
to tcp_bpf_prots, which rebuilds the global tls_prots[ip_ver] table from
tcp_bpf_prots and overwrites its callbacks with tcp_bpf_recvmsg_parser,
sk_msg_is_readable, sock_map_destroy and tcp_bpf_ioctl. And if the
socket was in two sockmaps (one with an sk_skb program and one without)
before attaching TLS, removing it from the first map stops the verdict
program via sk_psock_stop_verdict() and calls tcp_bpf_update_proto() with
restore=false; returning -EINVAL here leaves ctx->sk_proto and tls_prots
using tcp_bpf_recvmsg_parser without a verdict program, causing
subsequent recvmsg() calls to fail with -EAGAIN.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130055650.686483-1-rhkrqnwk98@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 6:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 5:56 [PATCH bpf] bpf, sockmap: Don't replace a ULP's sk_prot when leaving a sockmap Sechang Lim
2026-11-30 6:17 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox