From: sashiko-bot@kernel.org
To: "Sechang Lim" <rhkrqnwk98@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf v2 2/2] selftests/bpf: Expect TCP_ULP to fail on a socket in a sockmap
Date: Fri, 04 Dec 2026 06:29:47 +0000 [thread overview]
Message-ID: <sashiko-outbox-249226@kernel.org> (raw)
In-Reply-To: <20261204061110.1929596-3-rhkrqnwk98@gmail.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Critical] net: NULL dereference in mptcp_subflow_tcp_fallback() on
TCP_LISTEN ULP race
- [Critical] net: NULL dereference in do_tcp_getsockopt() on
__tcp_set_ulp() init failure
- [Medium] net: module UAF in tcp_diag and getsockopt after
__tcp_set_ulp() init failure
- [Low] selftests/bpf: missing EBUSY errno check on setsockopt(TCP_ULP)
failure
--
commit 465bb4ab46ca075f14fde9c7bc7c50ceeb8bf320
Author: Sechang Lim <rhkrqnwk98@gmail.com>
bpf, sockmap: Reject a ULP on a socket with a psock
This commit rejects setting a TCP ULP with -EBUSY when a psock is attached by
assigning icsk->icsk_ulp_ops under sk_callback_lock before calling
ulp_ops->init(). It also removes the now-unused tcp_update_ulp(), tls_update(),
and the psock check in TLS.
> 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() cause a NULL pointer
dereference in mptcp_subflow_tcp_fallback() on a listening socket?
Because subflow_ulp_ops defines .clone, an unprivileged
setsockopt(IPPROTO_TCP, TCP_ULP, "mptcp") on a TCP_LISTEN socket passes the
check above, publishes icsk->icsk_ulp_ops while icsk->icsk_ulp_data is still
NULL, and then fails in subflow_ulp_init() with -EOPNOTSUPP.
CPU0 CPU1 (<softirq>)
__tcp_set_ulp()
icsk->icsk_ulp_ops = ulp_ops
tcp_v4_rcv() -> ...
inet_csk_clone_lock()
sk_clone_lock()
inet_clone_ulp()
subflow_ulp_clone()
mptcp_subflow_tcp_fallback(NULL)
<-- NULL pointer dereference
subflow_ulp_init() -> err
icsk->icsk_ulp_ops = NULL
An incoming ACK completing a handshake clones the listener without taking
lock_sock() or sk_callback_lock, copies the transient subflow_ulp_ops with
NULL icsk_ulp_data, and panics the kernel in softirq when
mptcp_subflow_tcp_fallback() dereferences ctx->tcp_state_change.
> - icsk->icsk_ulp_ops = ulp_ops;
> + err = ulp_ops->init(sk);
> + if (err) {
> + icsk->icsk_ulp_ops = NULL;
> + goto out_err;
> + }
[Severity: Critical]
Can clearing icsk->icsk_ulp_ops to NULL on init failure cause a NULL pointer
dereference in do_tcp_getsockopt()?
do_tcp_getsockopt() for TCP_ULP runs without lock_sock() or sk_callback_lock,
checks icsk->icsk_ulp_ops, writes optlen to userspace (which can fault and
sleep), and then reloads icsk->icsk_ulp_ops->name.
CPU0 CPU1
__tcp_set_ulp() do_tcp_getsockopt(TCP_ULP)
icsk->icsk_ulp_ops = ulp_ops
if (!icsk->icsk_ulp_ops) /* false */
copy_to_sockptr(optlen, ...)
tls_init() -> -ENOTCONN
icsk->icsk_ulp_ops = NULL
copy_to_sockptr(optval,
icsk->icsk_ulp_ops->name, ...)
<-- NULL pointer dereference
An unprivileged user can trigger this by racing setsockopt(TCP_ULP, "tls") on
an unconnected socket against getsockopt(TCP_ULP), crashing the kernel.
Additionally, this plain store runs outside sk_callback_lock and without
WRITE_ONCE(), creating a data race with sk_psock_init() checking
inet_csk_has_ulp() under sk_callback_lock as well as lockless readers.
> return 0;
> out_err:
> module_put(ulp_ops->owner);
[Severity: Medium]
Can dropping the module reference immediately on init failure cause a
use-after-free in tcp_diag or do_tcp_getsockopt()?
tcp_diag_get_aux(), tcp_diag_get_aux_size(), and do_tcp_getsockopt(TCP_ULP)
read icsk->icsk_ulp_ops without lock_sock(), sk_callback_lock, a module
reference, or rcu_read_lock().
CPU0 CPU1
__tcp_set_ulp() tcp_diag_get_aux_size()
icsk->icsk_ulp_ops = ulp_ops
ulp_ops = icsk->icsk_ulp_ops
tls_init() -> -ENOTCONN
icsk->icsk_ulp_ops = NULL
module_put(ulp_ops->owner)
rmmod tls
tcp_unregister_ulp()
synchronize_rcu()
/* module text freed */
ulp_ops->get_info_size(...)
<-- use-after-free
Because these readers are not inside rcu_read_lock(), tcp_unregister_ulp()'s
synchronize_rcu() during rmmod does not wait for them, allowing the unloaded
module's rodata and callbacks to be freed while still in use.
commit 87d52e3d519ca688662dddf41b1acf31f697108b
Author: Sechang Lim <rhkrqnwk98@gmail.com>
selftests/bpf: Expect TCP_ULP to fail on a socket in a sockmap
This commit updates test_sockmap_ktls_enable_fails_when_in_sockmap() to expect
setsockopt(TCP_ULP) to fail directly instead of setsockopt(TLS_TX).
> diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c
> index 34737e8df6ea1..749b41b743df7 100644
> --- a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c
> +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c
[ ... ]
> @@ -165,14 +159,8 @@ static void test_sockmap_ktls_enable_fails_when_in_sockmap(int family, int map)
> if (!ASSERT_OK(err, "sockmap update elem"))
> goto close;
>
> - /* Installing the TLS ULP is allowed, it does not touch the datapath. */
> err = setsockopt(s, IPPROTO_TCP, TCP_ULP, "tls", strlen("tls"));
> - if (!ASSERT_OK(err, "setsockopt(TCP_ULP)"))
> - goto close;
> -
> - /* Enabling the TLS crypto datapath must be rejected. */
> - err = setsockopt(s, SOL_TLS, TLS_TX, &crypto, sizeof(crypto));
> - ASSERT_ERR(err, "setsockopt(TLS_TX)");
> + ASSERT_ERR(err, "setsockopt(TCP_ULP)");
[Severity: Low]
Should this also assert errno == EBUSY after setsockopt(TCP_ULP) fails?
When CONFIG_TLS is not enabled or the tls module cannot be loaded,
tcp_set_ulp() returns -ENOENT before reaching __tcp_set_ulp(), so a bare
ASSERT_ERR() silently passes without testing the psock rejection path.
Checking ASSERT_EQ(errno, EBUSY, ...) ensures the failure came from the psock
check.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204061110.1929596-1-rhkrqnwk98@gmail.com?part=2
prev parent reply other threads:[~2026-12-04 6:29 UTC|newest]
Thread overview: 7+ 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
2026-12-04 6:45 ` bot+bpf-ci
2026-12-05 4:19 ` Alexei Starovoitov
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 [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-249226@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 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.