BPF List
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	John Fastabend <john.fastabend@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
	Kui-Feng Lee <kuifeng@fb.com>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH 1/2] bpf: Invoke __bpf_prog_exit_sleepable_recur() on recursion in kern_sys_bpf().
Date: Fri, 1 Sep 2023 16:02:00 +0200	[thread overview]
Message-ID: <ZPHu2OeYCckX8gKJ@krava> (raw)
In-Reply-To: <20230830080405.251926-2-bigeasy@linutronix.de>

On Wed, Aug 30, 2023 at 10:04:04AM +0200, Sebastian Andrzej Siewior wrote:
> If __bpf_prog_enter_sleepable_recur() detects recursion then it returns
> 0 without undoing rcu_read_lock_trace(), migrate_disable() or
> decrementing the recursion counter. This is fine in the JIT case because
> the JIT code will jump in the 0 case to the end and invoke the matching
> exit trampoline (__bpf_prog_exit_sleepable_recur()).
> 
> This is not the case in kern_sys_bpf() which returns directly to the
> caller with an error code.
> 
> Add __bpf_prog_exit_sleepable_recur() as clean up in the recursion case.
> 
> Fixes: b1d18a7574d0d ("bpf: Extend sys_bpf commands for bpf_syscall programs.")
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Acked-by: Jiri Olsa <jolsa@kernel.org>

jirka

> ---
>  kernel/bpf/syscall.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index a2aef900519c2..c925c270ed8b4 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -5307,6 +5307,7 @@ int kern_sys_bpf(int cmd, union bpf_attr *attr, unsigned int size)
>  		run_ctx.saved_run_ctx = NULL;
>  		if (!__bpf_prog_enter_sleepable_recur(prog, &run_ctx)) {
>  			/* recursion detected */
> +			__bpf_prog_exit_sleepable_recur(prog, 0, &run_ctx);
>  			bpf_prog_put(prog);
>  			return -EBUSY;
>  		}
> -- 
> 2.40.1
> 

  reply	other threads:[~2023-09-01 14:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-30  8:04 [PATCH 0/2] bpf: Recursion detection related fixes Sebastian Andrzej Siewior
2023-08-30  8:04 ` [PATCH 1/2] bpf: Invoke __bpf_prog_exit_sleepable_recur() on recursion in kern_sys_bpf() Sebastian Andrzej Siewior
2023-09-01 14:02   ` Jiri Olsa [this message]
2023-08-30  8:04 ` [PATCH 2/2] bpf: Assign bpf_tramp_run_ctx::saved_run_ctx before recursion check Sebastian Andrzej Siewior
2023-09-01 14:13   ` Jiri Olsa
2023-09-01 14:19     ` Sebastian Andrzej Siewior
2023-09-06  8:52       ` Daniel Borkmann
2023-09-07 10:12         ` Sebastian Andrzej Siewior
2023-09-06  9:00 ` [PATCH 0/2] bpf: Recursion detection related fixes patchwork-bot+netdevbpf

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=ZPHu2OeYCckX8gKJ@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bigeasy@linutronix.de \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=kpsingh@kernel.org \
    --cc=kuifeng@fb.com \
    --cc=martin.lau@linux.dev \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=yhs@fb.com \
    /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