From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Stanislav Fomichev" <sdf.kernel@gmail.com>,
"Jiayuan Chen" <jiayuan.chen@linux.dev>
Cc: <bpf@vger.kernel.org>, <kpsingh@kernel.org>, <matt@bobrowski.net>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"John Fastabend" <john.fastabend@gmail.com>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"Jiri Olsa" <jolsa@kernel.org>,
"Emil Tsalapatis" <emil@etsalapatis.com>,
"Ihor Solodrai" <ihor.solodrai@linux.dev>,
"Stanislav Fomichev" <sdf@fomichev.me>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@kernel.org>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@kernel.org>,
"Shuah Khan" <shuah@kernel.org>,
"Xu Kuohai" <xukuohai@huawei.com>, <netdev@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH bpf v2 1/2] bpf, lsm: fix bpf_setsockopt() on a half set up child in inet_csk_clone
Date: Sat, 28 Nov 2026 00:31:11 +0000 [thread overview]
Message-ID: <DN6F54C8AZSE.3QLYZS0114Q5L@gmail.com> (raw)
In-Reply-To: <awcUm4PvuYb3nGxM@devvm16445.scu0.facebook.com>
On Wed, Nov 25, 2026 at 09:04 AM Stanislav Fomichev <sdf.kernel@gmail.com> wrote:
> On 11/25, Jiayuan Chen wrote:
>> 2. Make these options work. This needs the child set up before the
>> hook, too much for a fix.
>
> What is too much? Moving security_inet_csk_clone to happen at the end of
> tcp_create_openreq_child? Or is it more involved?
Here is what my bot thinks about moving the hook.
That spot fixes the timers only.
The callers set up the rest:
call chain option works after it
----------------------------------------- ----------------------------
subflow_syn_recv_sock()
tcp_v6_syn_recv_sock()
tcp_create_openreq_child()
inet_csk_clone_lock() <- the hook is here today
tcp_init_xmit_timers() SO_KEEPALIVE, TCP_KEEPIDLE
newinet->pinet6 = tcp_inet6_sk(newsk)
memcpy(newnp, np) IPV6_TCLASS
tcp_ca_openreq_child() TCP_CONGESTION
__inet_inherit_port()
inet_ehash_nolisten()
ctx->conn = mptcp_sk_clone_init() SO_SNDBUF, TCP_NOTSENT_LOWAT
There are two callers, v4 and v6. Let's call the hook right before
__inet_inherit_port() in both. Then there is no need for
bpf_sk_clone_setsockopt() and bpf_lsm_clone_sockopt_hooks.
SELinux and Smack shouldn't care. They copy labels from req.
The v4 route lookup in between takes secid from req too.
mptcp sets ctx->conn after inet_ehash_nolisten(). That's too late for
the hook. subflow_write_space() needs a NULL check instead.
bpf CC hits the same NULL and the patch doesn't cover it:
tcp_ca_openreq_child()
tcp_set_ca_state(sk, TCP_CA_Open)
set_state prog: bpf_setsockopt(sk, SOL_SOCKET, SO_SNDBUF)
subflow_write_space(sk)
mptcp_write_space(NULL)
With the move SO_MARK and IP_TOS drop the cached dst of the child.
tcp_init_transfer() looks it up again.
Backports need more. dccp and chtls need their own call.
IPV6=m needs an export.
This replaces patch 1 and goes on top of bpf/master 14f6b10422d6.
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 9a3b05e..759f826 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -1276,8 +1276,6 @@ struct sock *inet_csk_clone_lock(const struct sock *sk,
inet_clone_ulp(req, newsk, priority);
- security_inet_csk_clone(newsk, req);
-
return newsk;
}
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 2fc92a7..d03b50b 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1761,6 +1761,9 @@ struct sock *tcp_v4_syn_recv_sock(const struct sock *sk, struct sk_buff *skb,
goto put_and_exit; /* OOM, release back memory */
#endif
+ /* The child is set up, but is not in bhash and ehash yet. */
+ security_inet_csk_clone(newsk, req);
+
if (__inet_inherit_port(sk, newsk) < 0)
goto put_and_exit;
*own_req = inet_ehash_nolisten(newsk, req_to_sk(req_unhash),
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 5c7ed38..d704d98 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1516,6 +1516,9 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *
goto put_and_exit; /* OOM */
#endif
+ /* The child is set up, but is not in bhash and ehash yet. */
+ security_inet_csk_clone(newsk, req);
+
if (__inet_inherit_port(sk, newsk) < 0)
goto put_and_exit;
*own_req = inet_ehash_nolisten(newsk, req_to_sk(req_unhash),
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 00677fb..a0fd3ce 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -1602,6 +1602,10 @@ static void subflow_write_space(struct sock *ssk)
{
struct sock *sk = mptcp_subflow_ctx(ssk)->conn;
+ /* bpf_setsockopt() on a passive subflow that has no msk yet */
+ if (!sk)
+ return;
+
mptcp_propagate_sndbuf(sk, ssk);
mptcp_write_space(sk);
}
prev parent reply other threads:[~2026-11-28 0:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 7:03 [PATCH bpf v2 1/2] bpf, lsm: fix bpf_setsockopt() on a half set up child in inet_csk_clone Jiayuan Chen
2026-11-25 7:03 ` [PATCH bpf v2 2/2] selftests/bpf: test rejected bpf_setsockopt() in inet_csk_clone hook Jiayuan Chen
2026-11-25 17:04 ` [PATCH bpf v2 1/2] bpf, lsm: fix bpf_setsockopt() on a half set up child in inet_csk_clone Stanislav Fomichev
2026-11-26 12:02 ` Jiayuan Chen
2026-11-28 0:31 ` Alexei Starovoitov [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=DN6F54C8AZSE.3QLYZS0114Q5L@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@kernel.org \
--cc=emil@etsalapatis.com \
--cc=horms@kernel.org \
--cc=ihor.solodrai@linux.dev \
--cc=jiayuan.chen@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=matt@bobrowski.net \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf.kernel@gmail.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=xukuohai@huawei.com \
--cc=yonghong.song@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