From: sashiko-bot@kernel.org
To: "Sechang Lim" <rhkrqnwk98@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf] bpf, sockmap: Don't replace a ULP's sk_prot when leaving a sockmap
Date: Mon, 30 Nov 2026 06:17:55 +0000 [thread overview]
Message-ID: <sashiko-outbox-240436@kernel.org> (raw)
In-Reply-To: <20261130055650.686483-1-rhkrqnwk98@gmail.com>
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
prev parent reply other threads:[~2026-11-30 6:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
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=sashiko-outbox-240436@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=rhkrqnwk98@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/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