From: sashiko-bot@kernel.org
To: "Sechang Lim" <rhkrqnwk98@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf v2 1/2] bpf, sockmap: Reject a ULP on a socket with a psock
Date: Fri, 04 Dec 2026 06:32:25 +0000 [thread overview]
Message-ID: <sashiko-outbox-249231@kernel.org> (raw)
In-Reply-To: <20261204061110.1929596-2-rhkrqnwk98@gmail.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Critical] tcp: premature icsk_ulp_ops publish crashes
subflow_ulp_clone() on listeners
- [Critical] tcp: icsk_ulp_ops rollback causes NULL deref and UAF in
do_tcp_getsockopt()
- [Medium] tcp: early icsk_ulp_ops publish causes module UAF and stale
state in tcp_diag
- [Medium] tcp: unlocked icsk_ulp_ops reset in __tcp_set_ulp() races
with sk_psock_init()
- [Low] bpf, sockmap: Fixes tag cites e34a07c0ae39 instead of
460e6486617c
--
commit 465bb4ab46ca075f14fde9c7bc7c50ceeb8bf320
Author: Sechang Lim <rhkrqnwk98@gmail.com>
> bpf, sockmap: Reject a ULP on a socket with a psock
>
> A socket in a sockmap can't get TLS keys since commit 460e6486617c
> ("tls: reject the combination of TLS and sockmap"), but it can still
> get the TLS ULP. When the socket then leaves the map, sk_write_space
> is not restored. If the map has an sk_skb program, sk_prot isn't
> either, and close() spins in sock_map_close() forever.
>
> Reject the ULP with -EBUSY on a socket with a psock. A BPF program can
> add the socket to a sockmap without lock_sock(), so set icsk_ulp_ops
> before ->init(), under sk_callback_lock and only if there is no psock.
> sk_psock_init() checks for a ULP under the same lock.
>
> Remove tls_update(), tcp_update_ulp() and the psock check in TLS,
> which are now dead.
>
> Fixes: e34a07c0ae39 ("sock: redo the psock vs ULP protection check")
> Suggested-by: Alexei Starovoitov <ast@kernel.org>
> Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
[Severity: Low]
Should the Fixes tag reference 460e6486617c ("tls: reject the combination of
TLS and sockmap") instead of e34a07c0ae39 ("sock: redo the psock vs ULP
protection check")?
That 2022 commit only moved the inet_csk_has_ulp() check back into
sk_psock_init(). This patch replaces the sk_psock() check added by
460e6486617c ("tls: reject the combination of TLS and sockmap") and removes
tls_update() and tcp_update_ulp(), so citing the older commit queues it for
stable branches where TLS and sockmap are still allowed together.
[ ... ]
> diff --git a/net/ipv4/tcp_ulp.c b/net/ipv4/tcp_ulp.c
> index b58045df101e5..b50ca05763525 100644
> --- a/net/ipv4/tcp_ulp.c
> +++ b/net/ipv4/tcp_ulp.c
[ ... ]
> @@ -147,11 +139,26 @@ static int __tcp_set_ulp(struct sock *sk, const struct tcp_ulp_ops *ulp_ops)
> if (!ulp_ops->clone && sk->sk_state == TCP_LISTEN)
> goto out_err;
>
> - err = ulp_ops->init(sk);
> + /* A ULP and a psock exclude each other. sk_psock_init() checks
> + * icsk_ulp_ops and sets the psock under the same lock.
> + */
> + err = -EBUSY;
> + write_lock_bh(&sk->sk_callback_lock);
> + rcu_read_lock();
> + if (!sk_psock(sk)) {
> + icsk->icsk_ulp_ops = ulp_ops;
> + err = 0;
> + }
> + rcu_read_unlock();
> + write_unlock_bh(&sk->sk_callback_lock);
> if (err)
> goto out_err;
[Severity: Critical]
Can publishing icsk->icsk_ulp_ops before ulp_ops->init() crash
subflow_ulp_clone() with a NULL pointer dereference on a listening socket?
subflow_ulp_ops ("mptcp") sets .clone = subflow_ulp_clone, so
setsockopt(TCP_ULP, "mptcp") on an ordinary userspace TCP_LISTEN socket
passes the TCP_LISTEN check and publishes icsk->icsk_ulp_ops with
icsk->icsk_ulp_data still NULL before subflow_ulp_init() rejects
!sk->sk_kern_sock. Handshake completion runs locklessly in softirq:
CPU0 CPU1 (<softirq>)
__tcp_set_ulp()
icsk->icsk_ulp_ops = &subflow_ulp_ops
tcp_v4_rcv() -> ...
inet_csk_clone_lock()
sk_clone_lock()
inet_clone_ulp()
subflow_ulp_clone()
mptcp_subflow_tcp_fallback()
ctx->tcp_state_change
<-- NULL pointer dereference
subflow_ulp_init() -> -EOPNOTSUPP
Because CONFIG_MPTCP is built in by default, an unprivileged local user can
trigger this Oops in softirq context.
> - icsk->icsk_ulp_ops = ulp_ops;
> + err = ulp_ops->init(sk);
> + if (err) {
> + icsk->icsk_ulp_ops = NULL;
> + goto out_err;
> + }
[Severity: Medium]
Should resetting icsk->icsk_ulp_ops to NULL also hold sk->sk_callback_lock?
sk_psock_init() runs without lock_sock(sk) and reads icsk->icsk_ulp_ops via
inet_csk_has_ulp(sk) under write_lock_bh(&sk->sk_callback_lock). This
unlocked plain store races with that read, breaking the sk_callback_lock
synchronization added above.
> return 0;
> out_err:
> module_put(ulp_ops->owner);
[Severity: Critical]
Can rolling back icsk->icsk_ulp_ops on init() failure cause a NULL pointer
dereference or use-after-free in do_tcp_getsockopt(TCP_ULP)?
tcp_getsockopt() calls do_tcp_getsockopt() without lock_sock(sk),
sk_callback_lock, or rcu_read_lock(). Previously, icsk->icsk_ulp_ops never
transitioned from non-NULL back to NULL on a live socket, nor dropped its
module reference before socket destruction.
CPU0 CPU1
__tcp_set_ulp()
icsk->icsk_ulp_ops = ulp_ops
do_tcp_getsockopt(TCP_ULP)
if (!icsk->icsk_ulp_ops) // false
copy_to_sockptr(optlen, ...) // blocks
ulp_ops->init(sk) -> -ENOTCONN
icsk->icsk_ulp_ops = NULL
module_put(ulp_ops->owner)
copy_to_sockptr(...,
icsk->icsk_ulp_ops->name, len)
<-- NULL pointer dereference
An unprivileged local user can hit this on an unconnected TCP socket; on
architectures without exception fixups on kernel-source loads in
copy_to_user() (such as arm64), or under KASAN/HARDENED_USERCOPY, passing
NULL->name causes an unhandled kernel Oops. Even if icsk_ulp_ops were
loaded once, module_put(ulp_ops->owner) allows a modular ULP such as tls.ko
to be unloaded while CPU1 is blocked, causing a use-after-free.
[Severity: Medium]
Does early publication of icsk->icsk_ulp_ops followed by module_put() on
init() failure also cause a module use-after-free in tcp_diag?
tcp_diag_dump_one() and tcp_diag_dump() call tcp_diag_get_aux() and
tcp_diag_get_aux_size() without lock_sock(sk), sk_callback_lock, or
rcu_read_lock(). Because tcp_unregister_ulp()'s synchronize_rcu() does not
wait for these readers, a concurrent rmmod tls after a failing
setsockopt(TCP_ULP, "tls") on a hashed socket can free tcp_tls_ulp_ops and
module text while tcp_diag is still using them:
CPU0 CPU1
__tcp_set_ulp()
icsk->icsk_ulp_ops = ulp_ops
tcp_diag_dump_one() -> ...
tcp_diag_get_aux()
ulp_ops = icsk->icsk_ulp_ops
tls_init(sk) -> -ENOTCONN
icsk->icsk_ulp_ops = NULL
module_put(ulp_ops->owner)
rmmod tls (frees tls.ko)
ulp_ops->get_info(sk, ...)
<-- use-after-free
Even without module unload, tls_ctx_create() sets icsk_ulp_data before
tls_init() initializes ctx->tx_conf, ctx->rx_conf, and
ctx->tx_max_payload_len, so concurrent tls_get_info() can export those
fields as 0.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204061110.1929596-1-rhkrqnwk98@gmail.com?part=1
next prev parent reply other threads:[~2026-12-04 6:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 6:11 [PATCH bpf v2 0/2] bpf, sockmap: Reject a ULP on a socket with a psock Sechang Lim
2026-12-04 6:11 ` [PATCH bpf v2 1/2] " Sechang Lim
2026-12-04 6:32 ` sashiko-bot [this message]
2026-12-04 6:11 ` [PATCH bpf v2 2/2] selftests/bpf: Expect TCP_ULP to fail on a socket in a sockmap Sechang Lim
2026-12-04 6:29 ` sashiko-bot
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-249231@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