From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796365788; b=21vvWw+L9oVN1S7LzWuLseT53azlZq6mPJ9za4oa85/HNQjvhEbGvnYwzmNNTTjbFPD2 hoW+12KMw44HENrGKDTB1IYL8uf+wUvtx9nNqGAHk8d3lg8Y7AS+9xBRLkszDiwy5bs4m wfjwCcPSHNTBS3odf3CObBUmk5ozl6jE6yDiqlB2FtGnstwrzTh+mmtvtA7WG6vPt8j3Q ZZAx3LMhGTJvcUpAUq2UW8SN1zBB70zRYs/0JZuArDNHAc4aQ4uJR2k43dYJOT1w+RkYy UAXsUe+Hpz5JiZVUBwkes7beAwGCWeF2eZkqbue0cCTDhDMiWSvbPQisOOw9Ot6CaUQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796365788; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=I0rZFnYjazkkLxEzIdFFIQ+InYe1NqODolhUlpGcdLM=; b=4aqNgimazzykVq0xbxnjgWrtcMXdV4esZax8LZj40N5Nt032bGWiRWtHq9YAJ8XfI9fZ Q6wQqPg9H+vR9cHd5hFLkBHome78ZFk/ecQaSg7Hm5lPy9LauhD0bmDyIa0YwYLP6aW21 7UmNNHYtej/7cCfhGHpAFBsRmXpnaY/W1cl4MvtunFYC1aiAQ1CJCPHJHcpTsgmYeLwOK 2QfYUtScfm8f6krkSIwQheqTbBG5iZgd9ZNcKoANdfjP9rlBcS2AfFXuXDHjw5X0vBpDP Vw5ihk0dzHHvYALurzA78h9IxQSpkKiDrnLKDhGiOtqlb6unw5pZ1f9by8JnCXf5OVQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Hv4G+DWQ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07FDA606A322 for ; Fri, 4 Dec 2026 06:29:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Hv4G+DWQ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 839691F000C2; Fri, 4 Dec 2026 06:29:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796365787; bh=I0rZFnYjazkkLxEzIdFFIQ+InYe1NqODolhUlpGcdLM=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=Hv4G+DWQFSXuRsZFTYMNXknT+HPkA2NLDLTpCZcCuDiGtt6+ebDivVA6Pur7aJZoy gB4y7oMkzFIRHpG3Tkn4gE4GFP2fI192R/DqveLVEqwyiz4Chg7IOKRKHSfn/Hd4O3 Sn5ysYerojbKSarHf/sMVNv/cMSjhGc2HipiTiHyFs2bqfLOM9Gn1AC1ewSoPHDQpb 3iOzEZi66IHDM2+kulMpB/T4VGDAvqReEIMFc8fKM5TqqWEsQLBpWbk/giHpvcrW4E En+X7NDK5PF68N/D6NHgbuJ/UtpeHKWDIgfSm+E84e2Sk/zpzLq3YmlRAkoEAV7LVA hshhY0WkCV4MQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH bpf v2 2/2] selftests/bpf: Expect TCP_ULP to fail on a socket in a sockmap Reply-To: sashiko-reviews@lists.linux.dev To: "Sechang Lim" , bpf@vger.kernel.org In-Reply-To: <20261204061110.1929596-3-rhkrqnwk98@gmail.com> References: <20261204061110.1929596-1-rhkrqnwk98@gmail.com> <20261204061110.1929596-3-rhkrqnwk98@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 06:29:47 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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_updat= e(), 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 str= uct tcp_ulp_ops *ulp_ops) > if (!ulp_ops->clone && sk->sk_state =3D=3D TCP_LISTEN) > goto out_err; > =20 > - err =3D 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 =3D -EBUSY; > + write_lock_bh(&sk->sk_callback_lock); > + rcu_read_lock(); > + if (!sk_psock(sk)) { > + icsk->icsk_ulp_ops =3D ulp_ops; > + err =3D 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 point= er 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 () __tcp_set_ulp() icsk->icsk_ulp_ops =3D 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 =3D 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 =3D ulp_ops; > + err =3D ulp_ops->init(sk); > + if (err) { > + icsk->icsk_ulp_ops =3D 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_loc= k, 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 =3D ulp_ops if (!icsk->icsk_ulp_ops) /* false */ copy_to_sockptr(optlen, ...) tls_init() -> -ENOTCONN icsk->icsk_ulp_ops =3D 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 =3D ulp_ops ulp_ops =3D icsk->icsk_ulp_ops tls_init() -> -ENOTCONN icsk->icsk_ulp_ops =3D 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 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 exp= ect setsockopt(TCP_ULP) to fail directly instead of setsockopt(TLS_TX). > diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_ktls.c b/tool= s/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_s= ockmap(int family, int map) > if (!ASSERT_OK(err, "sockmap update elem")) > goto close; > =20 > - /* Installing the TLS ULP is allowed, it does not touch the datapath. */ > err =3D 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 =3D 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 =3D=3D 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 pso= ck check. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204061110.1929= 596-1-rhkrqnwk98@gmail.com?part=3D2