public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Andrii Nakryiko <andrii@kernel.org>,
	bpf@vger.kernel.org, ast@kernel.org,  daniel@iogearbox.net,
	martin.lau@kernel.org
Cc: kernel-team@meta.com, Hao Sun <sunhao.th@gmail.com>
Subject: Re: [PATCH bpf-next 3/4] bpf: fix control-flow graph checking in privileged mode
Date: Fri, 10 Nov 2023 00:00:10 +0200	[thread overview]
Message-ID: <9f8030ae333daaf50ae975e192103f236270eb55.camel@gmail.com> (raw)
In-Reply-To: <20231108231152.3583545-4-andrii@kernel.org>

On Wed, 2023-11-08 at 15:11 -0800, Andrii Nakryiko wrote:

Acked-by: Eduard Zingerman <eddyz87@gmail.com>
(given that I understood check in push_insn correctly).

[...]

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index edca7f1ad335..35065cae98b7 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -15433,8 +15433,9 @@ static int check_return_code(struct bpf_verifier_env *env, int regno)

Nitpick: there is a comment right above this enum which has to be
         updated after changes to the enum.

>  enum {
>  	DISCOVERED = 0x10,
>  	EXPLORED = 0x20,
> -	FALLTHROUGH = 1,
> -	BRANCH = 2,
> +	CONDITIONAL = 0x01,
> +	FALLTHROUGH = 0x02,
> +	BRANCH = 0x04,
>  };
>  
>  static void mark_prune_point(struct bpf_verifier_env *env, int idx)
> @@ -15468,16 +15469,15 @@ enum {
>   * w - next instruction
>   * e - edge
>   */
> -static int push_insn(int t, int w, int e, struct bpf_verifier_env *env,
> -		     bool loop_ok)
> +static int push_insn(int t, int w, int e, struct bpf_verifier_env *env)
>  {
>  	int *insn_stack = env->cfg.insn_stack;
>  	int *insn_state = env->cfg.insn_state;
>  
> -	if (e == FALLTHROUGH && insn_state[t] >= (DISCOVERED | FALLTHROUGH))
> +	if ((e & FALLTHROUGH) && insn_state[t] >= (DISCOVERED | FALLTHROUGH))
>  		return DONE_EXPLORING;

This not related to your changes, but '>=' here is so confusing.
The intent is to check:
  ((insn_state[t] & (DISCOVERED | FALLTHROUGH)) == (DISCOVERED | FALLTHROUGH))
i.e. DONE_EXPLORING if fall-through branch of 't' had been explored already,
right?

[...]

  reply	other threads:[~2023-11-09 22:00 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-08 23:11 [PATCH bpf-next 0/4] BPF control flow graph and precision backtrack fixes Andrii Nakryiko
2023-11-08 23:11 ` [PATCH bpf-next 1/4] bpf: handle ldimm64 properly in check_cfg() Andrii Nakryiko
2023-11-09 22:25   ` Eduard Zingerman
2023-11-08 23:11 ` [PATCH bpf-next 2/4] bpf: fix precision backtracking instruction iteration Andrii Nakryiko
2023-11-09 17:20   ` Eduard Zingerman
2023-11-09 23:18     ` Andrii Nakryiko
2023-11-09 23:28       ` Andrii Nakryiko
2023-11-09 23:37         ` Eduard Zingerman
2023-11-08 23:11 ` [PATCH bpf-next 3/4] bpf: fix control-flow graph checking in privileged mode Andrii Nakryiko
2023-11-09 22:00   ` Eduard Zingerman [this message]
2023-11-09 23:25     ` Andrii Nakryiko
2023-11-10  1:26   ` Alexei Starovoitov
2023-11-10  3:41     ` Andrii Nakryiko
2023-11-10  4:08       ` Alexei Starovoitov
2023-11-10  5:31         ` Andrii Nakryiko
2023-11-10  5:33           ` Andrii Nakryiko
2023-11-08 23:11 ` [PATCH bpf-next 4/4] selftests/bpf: add more test cases for check_cfg() Andrii Nakryiko
2023-11-09 22:21   ` Eduard Zingerman

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=9f8030ae333daaf50ae975e192103f236270eb55.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@meta.com \
    --cc=martin.lau@kernel.org \
    --cc=sunhao.th@gmail.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