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=1796365946; b=uYuxh2Uzbj/QxohxzVXd3wN6RaV+9T1NwSfTuKLhGlEa4hbq08m+/SXi9+tSBgozVkcE UMeUrJQ1dK7pmHWxItwRIZgTY6qMKQFDCT5oKv9eHNND4fGJGhXNfdNdcCjKSckP8nuTp Xn+FC7p4/jgqmsmXPGVL4AxsWP2tTS5Gnvyii9xJyJHRemBsAqI7nZa5ap6jE9HGnOeix hBORx+f2r10/DyDZLDGpGrPAeGmlpV/kwZOxvXtaPp1wVBiBIvY1LL6OJBCp4A2dTyAbP aSelq422nx+110x/IVdQCbUTlRzFbTF4a++YtVfDfANU55IZu3jvL4T8R+oTdfHOl7Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796365946; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=YVfRIDX3MRyBxTZx9jQhhx3xExa/++BxXzWkud68ISI=; b=4HfipnwWxbBhot+YzzPg6xnUACjZmZLH1H8LBWw/gouKFp3KI1s6ZLGMgKvBQZcsY6Au UQ/W5bqLvNrXgqIbfue+rCOfU/GNz75HoK3B86m6UOvGjHfoX+LLFqyQWcy3WLSl4NDtu S6lNfxwHTFjsWDosNk8hQFQPBA8PfNj4uf9x/nE3lXI/Ins/d1Xi3dwvjKK0EjXXrTHoP /Z6S4Wgl9r8dGv6jshRMl5AaGKuGnzYHXCPsTnhE6b2QOyBzxVadheTOHbY3hX3sqTg0X fS4siKWx52kY1oVxF8nqGbxuDVidGicnzk54EwN9Cel6YQJzY1HHRgCvkVXUvFBIpxg== 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=mG18NdwO; 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 3E6E4606A32C for ; Fri, 4 Dec 2026 06:32:26 +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=mG18NdwO Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4C5C1F000C2; Fri, 4 Dec 2026 06:32:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796365945; bh=YVfRIDX3MRyBxTZx9jQhhx3xExa/++BxXzWkud68ISI=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=mG18NdwOnr75dQ7hjd5XcZuwbCy/D9Wh24EEHmmwAyjqY+4vcCJLqkJ6pZrXL5q6W XzZC9PBYTdQhHAHKOzljg14WNqq10FA5zTneCxb4+reWGF4SGvCvqwI8i/tQNilugp BjdWHLIa8FrIaWrgQ1j3TrqK9GIKnP5lnxlpUYQTCkShiIgtX2azr5Y9K+BPB0cMOh 3f1gnEdb5tz5Sde6UnhIf9NESaCJ/oXsqOYTsBop+TMa+QZeUA//zf1iJen0l/8z4A EkiMg46Sxe+2SPljesvsrH66Oe9ZxnbylyqhEzb+gOxwN64o/jjFNOroQs/MF2EB+w 1dacBx9Dqnu5Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH bpf v2 1/2] bpf, sockmap: Reject a ULP on a socket with a psock Reply-To: sashiko-reviews@lists.linux.dev To: "Sechang Lim" , bpf@vger.kernel.org In-Reply-To: <20261204061110.1929596-2-rhkrqnwk98@gmail.com> References: <20261204061110.1929596-1-rhkrqnwk98@gmail.com> <20261204061110.1929596-2-rhkrqnwk98@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 06:32:25 +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 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 > 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 > Signed-off-by: Sechang Lim [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 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() crash subflow_ulp_clone() with a NULL pointer dereference on a listening socket? subflow_ulp_ops ("mptcp") sets .clone =3D 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 () __tcp_set_ulp() icsk->icsk_ulp_ops =3D &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 dereferen= ce 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 =3D ulp_ops; > + err =3D ulp_ops->init(sk); > + if (err) { > + icsk->icsk_ulp_ops =3D 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 =3D 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 =3D 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 =3D ulp_ops tcp_diag_dump_one() -> ... tcp_diag_get_aux() ulp_ops =3D icsk->icsk_ulp_ops tls_init(sk) -> -ENOTCONN icsk->icsk_ulp_ops =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204061110.1929= 596-1-rhkrqnwk98@gmail.com?part=3D1