All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Amery Hung" <ameryhung@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 11/15] bpf: tcp: Support selected sock_ops callbacks as struct_ops
Date: Tue, 23 Jun 2026 23:22:49 +0000	[thread overview]
Message-ID: <20260623232250.6F1551F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260623175006.3136053-12-ameryhung@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] bpf_tcp_ops allows sleepable BPF programs which will trigger kernel panics when executed within the RCU read-side critical sections of the dispatcher macros.
- [Low] Multi-line comments in BPF subsystem files must have the opening `/*` on its own line.
--

commit c794084a252357df7f0bbf934f1e1707d2dd52fd
Author: Martin KaFai Lau <martin.lau@kernel.org>
Subject: bpf: tcp: Add bpf_tcp_ops and support attaching to cgroups

This commit adds a TCP-specific struct_ops type, bpf_tcp_ops, and supports
attaching it to cgroups. It wires up several existing sock_ops callbacks to
allow each callback to have its own function signature.

Link: https://drive.google.com/file/d/1wjKZth6T0llLJ_ONPAL_6Q_jbxbAjByp/view?usp=sharing

> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index 6d376ea4d1c0..2102f9f2afd6 100644
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h
[ ... ]
> @@ -2953,12 +2953,120 @@ static inline void tcp_clear_sock_ops_cb_flags(struct sock *sk)
>  
>  #endif
>  
> +#if defined(CONFIG_BPF_JIT) && defined(CONFIG_CGROUP_BPF)
> +
> +struct bpf_tcp_ops {
> +	/* Should return the initial SYN (active open) or SYN-ACK (passive open)
> +	 * retransmission timeout. Return the timeout in jiffies, or <= 0 for
> +	 * the kernel default.
> +	 *
> +	 * @req: request_sock on the passive (synack) path; NULL otherwise.
> +	 */

[Severity: Low]
This isn't a bug, but could these multi-line comments be updated to place the
opening /* on its own line?

[ ... ]
> diff --git a/net/ipv4/bpf_tcp_ops.c b/net/ipv4/bpf_tcp_ops.c
> new file mode 100644
> index 000000000000..cf53c95a0dbc
> --- /dev/null
> +++ b/net/ipv4/bpf_tcp_ops.c
[ ... ]
> +BPF_CALL_0(bpf_tcp_ops_get_retval)
> +{
> +	struct bpf_tramp_run_ctx *ctx =
> +		container_of(current->bpf_ctx, struct bpf_tramp_run_ctx, run_ctx);
> +
> +	/* bpf_get_retval() is only exposed to timeout_init/rwnd_init, which
> +	 * always run via bpf_tcp_ops_call_int(). Its run_ctx carries the int
> +	 * return value chained across the bpf_tcp_ops attached to the cgroup
> +	 * and is this program's saved_run_ctx.
> +	 */

[Severity: Low]
This isn't a bug, but would it be better to adjust this multi-line comment so
that the opening /* rests on its own line?

[ ... ]
> +static struct bpf_struct_ops bpf_tcp_ops = {
> +	.verifier_ops = &bpf_tcp_ops_verifier,
> +	.init_member = bpf_tcp_ops_init_member,
> +	.init = bpf_tcp_ops_init,
> +	.validate = bpf_tcp_ops_validate,
> +	.name = "bpf_tcp_ops",
> +	.cgroup_atype = CGROUP_TCP_SOCK_OPS,
> +	.cfi_stubs = &__bpf_tcp_ops,
> +	.owner = THIS_MODULE,
> +};

[Severity: High]
Is it possible for sleepable BPF programs to be loaded for this struct_ops
type?

Without a .check_member callback to explicitly reject them, the verifier
might allow sleepable programs to attach.

If a sleepable program is attached, could it trigger a scheduling while
atomic kernel panic?

Looking at include/net/tcp.h, the callbacks are invoked inside an RCU
read-side critical section:

bpf_tcp_ops_call()
    rcu_read_lock_dont_migrate();
    bpf_cgroup_struct_ops_foreach(...) {
        if (tcp_ops->op)
            tcp_ops->op(...);
    }
    rcu_read_unlock_migrate();

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260623175006.3136053-1-ameryhung@gmail.com?part=11

  reply	other threads:[~2026-06-23 23:22 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-23 17:49 [PATCH bpf-next v2 00/15] bpf: A common way to attach struct_ops to a cgroup Amery Hung
2026-06-23 17:49 ` [PATCH bpf-next v2 01/15] bpf: Remove __rcu tagging in st_link->map Amery Hung
2026-06-23 17:49 ` [PATCH bpf-next v2 02/15] bpf: Make struct_ops tasks_rcu grace period optional Amery Hung
2026-06-23 17:49 ` [PATCH bpf-next v2 03/15] bpf: Add bpf_struct_ops accessor helpers Amery Hung
2026-06-23 21:40   ` sashiko-bot
2026-06-23 17:49 ` [PATCH bpf-next v2 04/15] bpf: Remove unnecessary prog_list_prog() check Amery Hung
2026-06-23 17:49 ` [PATCH bpf-next v2 05/15] bpf: Replace prog_list_prog() check with direct pl->prog and pl->link check Amery Hung
2026-06-23 17:49 ` [PATCH bpf-next v2 06/15] bpf: Add prog_list_init_item(), prog_list_replace_item(), and prog_list_id() Amery Hung
2026-06-23 17:49 ` [PATCH bpf-next v2 07/15] bpf: Move LSM trampoline unlink into bpf_cgroup_link_auto_detach() Amery Hung
2026-06-23 17:49 ` [PATCH bpf-next v2 08/15] bpf: Add a few bpf_cgroup_array_* helper functions Amery Hung
2026-06-23 22:25   ` sashiko-bot
2026-06-23 17:49 ` [PATCH bpf-next v2 09/15] bpf: Add infrastructure to support attaching struct_ops to cgroups Amery Hung
2026-06-23 22:53   ` sashiko-bot
2026-06-23 17:49 ` [PATCH bpf-next v2 10/15] bpf: Allow all struct_ops to use bpf_dynptr_from_skb() Amery Hung
2026-06-23 17:49 ` [PATCH bpf-next v2 11/15] bpf: tcp: Support selected sock_ops callbacks as struct_ops Amery Hung
2026-06-23 23:22   ` sashiko-bot [this message]
2026-06-23 17:50 ` [PATCH bpf-next v2 12/15] bpf: tcp: Support parse/len/write header option hooks in bpf_tcp_ops Amery Hung
2026-06-23 23:40   ` sashiko-bot
2026-06-23 17:50 ` [PATCH bpf-next v2 13/15] libbpf: Support attaching struct_ops to a cgroup Amery Hung
2026-06-23 23:53   ` sashiko-bot
2026-06-23 17:50 ` [PATCH bpf-next v2 14/15] selftests/bpf: Test " Amery Hung
2026-06-24  0:03   ` sashiko-bot
2026-06-23 17:50 ` [PATCH bpf-next v2 15/15] selftests/bpf: Add test for bpf_tcp_ops header option hooks Amery Hung
2026-06-24  0:14   ` sashiko-bot
     [not found] ` <0e6fb8d7eca4b5494e08a2230056e333bdd814d97c16784b3e1f7687b3640990@mail.kernel.org>
2026-06-23 21:11   ` [PATCH bpf-next v2 00/15] bpf: A common way to attach struct_ops to a cgroup Amery Hung

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=20260623232250.6F1551F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ameryhung@gmail.com \
    --cc=bpf@vger.kernel.org \
    --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 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.