From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: Stanislav Fomichev <sdf.kernel@gmail.com>
Cc: bpf@vger.kernel.org, kpsingh@kernel.org, matt@bobrowski.net,
Alexei Starovoitov <ast@kernel.org>,
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: Thu, 26 Nov 2026 20:02:54 +0800 [thread overview]
Message-ID: <eb8abbc0-3028-4bd6-9010-0a855305e294@linux.dev> (raw)
In-Reply-To: <awcUm4PvuYb3nGxM@devvm16445.scu0.facebook.com>
On 11/26/26 1:04 AM, Stanislav Fomichev wrote:
> On 11/25, Jiayuan Chen wrote:
>> security_inet_csk_clone() is called at the end of inet_csk_clone_lock().
>> The child is locked, which is why the hook is in
>> bpf_lsm_locked_sockopt_hooks, but it is not set up yet:
>> icsk->icsk_ca_ops and the ipv6_pinfo still point to the ones of the
>> listener, and the timers are not initialized.
>>
>> So bpf_setsockopt() from a lsm_cgroup prog is wrong there for:
>>
>> - TCP_CONGESTION: puts icsk->icsk_ca_ops, which the child holds no
>> reference on.
>> - IPV6_TCLASS: writes to the ipv6_pinfo of the listener.
>> - SO_KEEPALIVE, TCP_KEEPIDLE: arm the keepalive timer before
>> tcp_init_xmit_timers() sets it up.
>>
>> Options considered:
>> 1. Remove the hook from bpf_lsm_locked_sockopt_hooks, as commit
>> 5416c9aea832 ("bpf: Fix the kernel crash caused by bpf_setsockopt().")
>> did for socket_sock_rcv_skb. Not done, setting options like
>> SO_PRIORITY on the child is what the hook is used for and it works.
>
> [..]
>
>> 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?
It is more involved. The end of tcp_create_openreq_child() only fixes
the timers. icsk_ca_ops is set by tcp_ca_openreq_child() and pinet6 is
switched in tcp_v6_syn_recv_sock(), both after
tcp_create_openreq_child() returns. For MPTCP, subflow->conn is set
even later, in subflow_syn_recv_sock().
next prev parent reply other threads:[~2026-11-26 12:03 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 [this message]
2026-11-28 0:31 ` Alexei Starovoitov
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=eb8abbc0-3028-4bd6-9010-0a855305e294@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@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=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 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.