From: sashiko-bot@kernel.org
To: "Jiayuan Chen" <jiayuan.chen@linux.dev>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf 1/2] bpf, lsm: fix bpf_setsockopt() on a half set up child in inet_csk_clone
Date: Tue, 24 Nov 2026 06:34:39 +0000 [thread overview]
Message-ID: <sashiko-outbox-230603@kernel.org> (raw)
In-Reply-To: <20261124061544.254586-1-jiayuan.chen@linux.dev>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] bpf: NULL deref in bpf_sk_clone_setsockopt() via MPTCP
subflow_write_space()
- [Medium] bpf: unnecessary rejection of IPV6_AUTOFLOWLABEL in
bpf_sk_clone_setsockopt()
- [Low] bpf: multi-line comment style violation in bpf_lsm.c and
filter.c
--
commit 9470b8f4e13b2c8be2cf5cc10f852d869dbb6f7c
Author: Jiayuan Chen <jiayuan.chen@linux.dev>
bpf, lsm: fix bpf_setsockopt() on a half set up child in inet_csk_clone
This commit introduces a dedicated bpf_setsockopt() helper for the
bpf_lsm_inet_csk_clone hook that rejects socket options unsafe to set on
a partially initialized cloned child socket.
> diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c
> index ae23511fd811b..fa71f52a055c5 100644
> --- a/kernel/bpf/bpf_lsm.c
> +++ b/kernel/bpf/bpf_lsm.c
> @@ -79,6 +79,15 @@ BTF_ID(func, bpf_lsm_inet_conn_established)
> #endif
> BTF_SET_END(bpf_lsm_locked_sockopt_hooks)
>
> +/* List of LSM hooks that trigger on a locked child socket which is not
> + * set up yet, bpf_setsockopt is restricted there.
> + */
[Severity: Low]
This isn't a bug, but BPF multi-line comments place the opening /* on
its own line (here and above bpf_sk_clone_setsockopt() in
net/core/filter.c).
[ ... ]
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 53c042b267ab6..77abc4cb9db51 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -5938,6 +5938,43 @@ const struct bpf_func_proto bpf_sk_setsockopt_proto = {
> .arg5_type = ARG_MEM_SIZE,
> };
>
> +/* security_inet_csk_clone() runs at the end of inet_csk_clone_lock(), the
> + * child is locked but not set up yet: its timers are not initialized, it
> + * holds no reference on icsk_ca_ops and an IPv6 child still points to the
> + * ipv6_pinfo of the listener.
> + */
> +BPF_CALL_5(bpf_sk_clone_setsockopt, struct sock *, sk, int, level,
> + int, optname, char *, optval, int, optlen)
> +{
> + switch (level) {
> + case SOL_SOCKET:
> + if (optname == SO_KEEPALIVE)
> + return -EOPNOTSUPP;
> + break;
> + case SOL_TCP:
> + if (optname == TCP_KEEPIDLE || optname == TCP_CONGESTION)
> + return -EOPNOTSUPP;
> + break;
[Severity: High]
Should bpf_sk_clone_setsockopt() also reject SO_SNDBUF and
TCP_NOTSENT_LOWAT?
When an incoming MPTCP subflow is cloned in inet_csk_clone_lock(),
inet_clone_ulp() -> subflow_ulp_clone() allocates a new
mptcp_subflow_context with new_ctx->conn still NULL while newsk inherits
sk_write_space = subflow_write_space (new_ctx->conn is only populated
later in subflow_syn_recv_sock()). Both SO_SNDBUF in sk_setsockopt()
and TCP_NOTSENT_LOWAT in do_tcp_setsockopt() invoke
sk->sk_write_space(sk):
net/mptcp/subflow.c:subflow_write_space() {
struct sock *sk = mptcp_subflow_ctx(ssk)->conn;
mptcp_propagate_sndbuf(sk, ssk);
mptcp_write_space(sk);
}
Passing sk == NULL into mptcp_write_space() ->
mptcp_stream_memory_free() causes a NULL pointer dereference.
> + case SOL_IPV6:
> + if (optname == IPV6_TCLASS || optname == IPV6_AUTOFLOWLABEL)
> + return -EOPNOTSUPP;
> + break;
[Severity: Medium]
Does IPV6_AUTOFLOWLABEL need to be rejected here?
Since commit 5121516b0c47 ("ipv6: lockless IPV6_AUTOFLOWLABEL
implementation"), do_ipv6_setsockopt() handles IPV6_AUTOFLOWLABEL via
inet6_assign_bit(AUTOFLOWLABEL, sk, valbool) and
inet6_set_bit(AUTOFLOWLABEL_SET, sk), which modify
inet_sk(sk)->inet_flags on the child socket rather than the listener's
ipv6_pinfo.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124061544.254586-1-jiayuan.chen@linux.dev?part=1
prev parent reply other threads:[~2026-11-24 6:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 6:15 [PATCH bpf 1/2] bpf, lsm: fix bpf_setsockopt() on a half set up child in inet_csk_clone Jiayuan Chen
2026-11-24 6:15 ` [PATCH bpf 2/2] selftests/bpf: test rejected bpf_setsockopt() in inet_csk_clone hook Jiayuan Chen
2026-11-24 6:34 ` sashiko-bot [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=sashiko-outbox-230603@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=jiayuan.chen@linux.dev \
--cc=sashiko-reviews@lists.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