Article View: linux.kernel.netdev
Article #26783Re: [PATCH bpf v2 1/2] bpf, sockmap: Reject a ULP on a socket with a psock
From: bot+bpf-ci
Date: Fri, 04 Dec 2026 06:45
Date: Fri, 04 Dec 2026 06:45
143 lines
13758 bytes
13758 bytes
--===============1441812569693825970==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
> bpf, sockmap: Reject a ULP on a socket with a psock
TL;DR:
- Publishing icsk_ulp_ops before init may let a listener clone of the mptcp
ULP hit a NULL pointer dereference in softirq
- Fixes: tag looks wrong
> diff --git a/net/ipv4/tcp_ulp.c b/net/ipv4/tcp_ulp.c
> --- 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;
>
> - icsk->icsk_ulp_ops = ulp_ops;
> + err = ulp_ops->init(sk);
> + if (err) {
> + icsk->icsk_ulp_ops = NULL;
> + goto out_err;
> + }
> return 0;
> out_err:
> module_put(ulp_ops->owner);
Can a listener clone observe icsk_ulp_ops while icsk_ulp_data is still
NULL here? icsk_ulp_ops is now published before ulp_ops->init() runs, and
it is cleared again if init fails. Previously it was only stored after a
successful init.
The listener clone path runs in softirq without taking any lock on the
listener:
tcp_v4_rcv() (TCP_NEW_SYN_RECV)
tcp_check_req()
tcp_v4_syn_recv_sock()
tcp_create_openreq_child()
inet_csk_clone_lock()
sk_clone() /* copies icsk_ulp_ops and icsk_ulp_data */
inet_clone_ulp():
if (!icsk->icsk_ulp_ops)
return;
icsk->icsk_ulp_ops->clone(req, newsk, priority);
This looks reachable with the built-in "mptcp" ULP. subflow_ulp_ops has
.clone, so the "!ulp_ops->clone && sk->sk_state == TCP_LISTEN" check lets
it through on a listening socket. subflow_ulp_init() then fails with
-EOPNOTSUPP because the socket is not a kernel socket:
if (!sk->sk_kern_sock)
In the window before that failure, icsk_ulp_ops == &subflow_ulp_ops while
icsk_ulp_data is NULL. A connection that completes on that listener in
the window gets a child with those values, and subflow_ulp_clone() runs:
struct mptcp_subflow_context *old_ctx = mptcp_subflow_ctx(newsk); /* NULL */
if (!tcp_rsk(req)->is_mptcp || ...) { /* is_mptcp = 0 from tcp_conn_request() */
subflow_ulp_fallback(newsk, old_ctx);
mptcp_subflow_tcp_fallback() then dereferences ctx->tcp_state_change, which
looks like a NULL pointer dereference in softirq context.
A possible trigger is, on a CONFIG_MPTCP=y kernel, looping
setsockopt(lfd, IPPROTO_TCP, TCP_ULP, "mptcp") on a userspace TCP listener
while connecting to it. The same clone happens for syncookie and TFO
children, and write_unlock_bh() can run pending NET_RX softirqs on the same
CPU inside the window. Before this patch, a failed init never made the
mptcp ops visible.
The commit message explains why the ops must be set before ->init(), but
other lockless readers of icsk_ulp_ops rely on a non-NULL ops implying an
initialized ULP. Would it work to refuse clone-capable ULPs on a listener
before publishing, to publish under sk_callback_lock only after init and
recheck for a psock there, or to make the clone path tolerate a NULL ctx?
The later commit 343621ae291f in this series only updates selftests and
does not address this.
> 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>
The Fixes: tag points at e34a07c0ae39 ("sock: redo the psock vs ULP
protection check"), but that commit added the inet_csk_has_ulp() check in
sk_psock_init() for the ULP-then-psock order, plus a WARN_ON_ONCE in
tls_update().
The bug fixed here is the opposite order, where a socket already has a
psock and then gets the TLS ULP via setsockopt(TCP_ULP). Was that path
introduced or changed by e34a07c0ae39?
The commit message ties the problem to 460e6486617c ("tls: reject the
combination of TLS and sockmap"), which also does not look like an obvious
Fixes: target. The tls_update() ctx branch appears to date to 95fa145479fb
("bpf: sockmap/tls, close can race with map free"). Could the Fixes: tag
be re-checked against the commit that introduced the psock-then-ULP
restore problem?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/47281082845
--===============1441812569693825970==--
Technical Details
Message-ID:
<825d2b9ca8c1b6d1d38c0f2e67577bbdc0800209b03e67abe36f765252200399@mail.kernel.org>Path:
mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377122-linux-kernel-netdev=dewy.ruReferences:
<20261204061110.1929596-2-rhkrqnwk98@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377122-linux-kernel-netdev=dewy.ru From: bot+bpf-ci@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH bpf v2 1/2] bpf, sockmap: Reject a ULP on a socket with a psock Date: Fri, 4 Dec 2026 06:45:08 +0000 (UTC) Organization: Usenet Network Message-ID: <825d2b9ca8c1b6d1d38c0f2e67577bbdc0800209b03e67abe36f765252200399@mail.kernel.org> References: <20261204061110.1929596-2-rhkrqnwk98@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1441812569693825970==" Injection-Info: usenet.network; logging-data="2695446"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:14958uePnP0QPzsTix2HjL93vwg= sha256:8BhainJlCpmegFcOvtTjIY+W96YC+/A1Jgzh4+qOMpw= sha1:ONRIOMopt56Sp+bVHPYyFKvuubc= sha256:0jvBZb3DhV+lh8+hx/Zh8j46/wozDqifEa89yM3S32Q= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 77DD8117B34; Fri, 4 Dec 2026 09:45:33 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.64 X-Spam-Status: No, score=-3.64 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5iYm4F-67rU8; Fri, 4 Dec 2026 09:45:26 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-377122-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id F1A71117B31; Fri, 4 Dec 2026 09:45:17 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 2A12F21B4C; Fri, 4 Dec 2026 06:45:15 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796366712; b=GJQfuvqC5CEBTKVTnLjycEzDxYFPIOqS7W69P6Z6Uf4Z0HKwNCc9PBaolS5Dz6ORb1Mg x2AJXpgMt+EDQ5Jw5uRFIEY8iphc4uR/Q+NBvO4yL8Arei7PqCYwt6pUnoz9v6UeVENqT 85XJcpq90iNtiMFTRObxcMvhUyoaCG3OdIGvdY+73E4yJM+bgbRs/lF1IaGai/qnkLtTD 19EopErPvuwIRfM+vIQwvhScV7puX5D8KWG30sz/wpy6CaLirpWVoGZOt7CXH+kC3DLI4 Lzf7FQiMH/4lU7jFRSdqtnBx2sIO5KS9ePD85Fg1u6ismT9UILTT7VAMw2RxgSAFPuA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796366712; h=X-Original-To:Received:Received:DKIM-Signature:Content-Type: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:Message-Id: In-Reply-To:References:Subject:From:To:Cc:Date; bh=nCiJKUwftFMZmCkJHDo/7Vhd/AhVQfvMYdGYJR+djjs=; b=u4EVBmli+qGADCbcCPgHxhrb7PrVW5iM2p2mucm2oWul9yNGJJcRm4NVVGqNngA55NNI OklQej82jzwPof9zCNwWITF1qWSHyIFbVhddml1bkBU+JEoQkNN3OREYvaz7LIEqLN0RG QF+0X9l2imr0v+FbcJYNAv5li+S3FvPTVhJNxCvbDG24K8wW3SaV0g0Luzk7CbCq1oXzy OjOjotrzQmB9auwfJvtTU4MbFw4cjd0c+EZ7brqhnN3we+E5+cL/k1Smk4HavShtqadib W+5o1mFSw5O9J8ITDfdGEfgZJdk64dY9PoUhpF3XGAubwnFD5tZuXKFbK0P95+4VyYw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Pvv2eQBu; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BD1F2606A32F; Fri, 4 Dec 2026 06:45:12 +0000 (UTC) X-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=Pvv2eQBu X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796366711; b=BnCTOm1IIFD2hY0FkCkmxefjNaJY8NT/biuIXZGmdop3T32YU1MqVqkQydPXWM/gv90a fEKYl1eP1Dk5MYjLgoYVjHrFq6MkSluL9Wghfx2wKeW5LMO8L7bk1AGSkNRmBMUrK/Bxt vz4VY13FiaK0PlYD/Mju/m6ILShXJ2jGU+UekyD9KUlFOte4W7S+XDYMepnoXcPD8uHnM l0a2f8GFdRMbtIVRGDso0mRGtLLocfvSNXjjnL307GNcuE79z9JZuX5E4b8MKBbCWp91+ eZcAZKD1wRZBvJTWPcg91A7qdStLz8j8BM+HheuqLkQmAi+T1TXS0SD16OImLjLQEFQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796366711; h=Received:DKIM-Signature:Content-Type:MIME-Version:Message-Id: In-Reply-To:References:Subject:From:To:Cc:Date; bh=nCiJKUwftFMZmCkJHDo/7Vhd/AhVQfvMYdGYJR+djjs=; b=U82qDsj56DPwu0rxzOnYDxJcnTVFeMhGkRbvpCd9lmoAaS59ffSPvQhRt/IK8TC2dVYZ lp5/Nd9j6wJPgLONW0Txo9PEH20nxeLURFqFSvqhA2dxnswNyWNnakzF0R8AcHx3nyCTw gOTQHGq0JSuWAp8ZEO5ljdTVhWGi2WZmU5lnBCadDw32NvKdBRCMXJcrWjBXVBCfKEkoD sQLbPeGpsBD2ASGIiQnxZk5QmsaaZWeGd4r1ZMNRrpyRYKVzxMTTwdTuurhGOsoGICR5G UCtSX75EAABdIE5Q8ilwoL0FUMCnF/De3apq1GYduCujnVH4ANNI6ByYcbD+C9HdIpQ== X-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=Pvv2eQBu; arc=none smtp.remote-ip=100.103.45.18 X-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) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D659D606A322; Fri, 4 Dec 2026 06:45:11 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E41CF1F00897; Fri, 4 Dec 2026 06:45:08 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796366711; bh=nCiJKUwftFMZmCkJHDo/7Vhd/AhVQfvMYdGYJR+djjs=; h=In-Reply-To:References:Subject:From:To:Cc:Date; b=Pvv2eQBuRykktwvgB/Ye9X4/1D0Bh0iYD40P7VAY5bvGRSwL1wveiJkInbfS4mftM Ovx408q5TDqSM/9H5IkvfIMVn4S6D5Ga9IMOr1/eG4N/02MgNTm3dUyN+lcOIBQW9z /3Tw1KpjoUkhauPFP9YxUOJWkpjmrzbGj6r6RxBg70mTJ87pICxsrDPJb+RZwgXPU7 rLmCCO4Keftwo7Z5dSd+shZx1j+Xakz9L3ATwdFFSNbL2p5oBZAbsX8tTxZiCFda4G VelP9RhhYcd7Dd8KCwk/O/zzdnbj1qCAM4gwtgwGzJxZ0a3lk9W4+evEDLC8KBozC8 3ZsPFxhJFlvyg== X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261204061110.1929596-2-rhkrqnwk98@gmail.com> X-Cc: ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,martin.lau@linux.dev,john.fastabend@gmail.com,jakub@cloudflare.com,jiayuan.chen@linux.dev,sd@queasysnail.net,kuba@kernel.org,edumazet@kernel.org,ncardwell@google.com,kuniyu@google.com,pabeni@redhat.com,davem@davemloft.net,horms@kernel.org,willemb@google.com,eddyz87@gmail.com,memxor@gmail.com,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,ihor.solodrai@linux.dev,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev