BPF List
 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
Subject: Re: [PATCH bpf-next 04/10] bpf: enforce exact retval range on subprog/callback exit
Date: Wed, 22 Nov 2023 17:13:05 +0200	[thread overview]
Message-ID: <a6edebc8d7063836c7d031d86a3c43f2dd0f49bd.camel@gmail.com> (raw)
In-Reply-To: <20231122011656.1105943-5-andrii@kernel.org>

On Tue, 2023-11-21 at 17:16 -0800, Andrii Nakryiko wrote:
> Instead of relying on potentially imprecise tnum representation of
> expected return value range for callbacks and subprogs, validate that
> both tnum and umin/umax range satisfy exact expected range of return
> values.
> 
> E.g., if callback would need to return [0, 2] range, tnum can't
> represent this precisely and instead will allow [0, 3] range. By
> additionally checking umin/umax range, we can make sure that
> subprog/callback indeed returns only valid [0, 2] range.
> 
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
> ---

Acked-by: Eduard Zingerman <eddyz87@gmail.com>
(but please see a question below)

[...]

> @@ -9464,6 +9477,16 @@ static bool in_rbtree_lock_required_cb(struct bpf_verifier_env *env)
>  	return is_rbtree_lock_required_kfunc(kfunc_btf_id);
>  }
>  
> +static bool retval_range_within(struct bpf_retval_range range, const struct bpf_reg_state *reg)
> +{
> +	struct tnum trange = retval_range_as_tnum(range);
> +
> +	if (!tnum_in(trange, reg->var_off))
> +		return false;

Q: When is it necessary to do this check?
   I tried commenting it and test_{verifier,progs} still pass.
   Are there situations when umin/umax change is not sufficient?

> +
> +	return range.minval <= reg->umin_value && reg->umax_value <= range.maxval;
> +}
> +

[...]



  reply	other threads:[~2023-11-22 15:13 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-22  1:16 [PATCH bpf-next 00/10] BPF verifier retval logic fixes Andrii Nakryiko
2023-11-22  1:16 ` [PATCH bpf-next 01/10] bpf: rearrange bpf_func_state fields to save a bit of memory Andrii Nakryiko
2023-11-22 15:12   ` Eduard Zingerman
2023-11-22  1:16 ` [PATCH bpf-next 02/10] bpf: provide correct register name for exception callback retval check Andrii Nakryiko
2023-11-22 15:12   ` Eduard Zingerman
2023-11-23  1:44   ` Alexei Starovoitov
2023-11-24  3:39     ` Andrii Nakryiko
2023-11-22  1:16 ` [PATCH bpf-next 03/10] bpf: enforce precision of R0 on callback return Andrii Nakryiko
2023-11-22 15:12   ` Eduard Zingerman
2023-11-22  1:16 ` [PATCH bpf-next 04/10] bpf: enforce exact retval range on subprog/callback exit Andrii Nakryiko
2023-11-22 15:13   ` Eduard Zingerman [this message]
2023-11-22 17:45     ` Andrii Nakryiko
2023-11-27 10:55       ` Shung-Hsi Yu
2023-11-27 18:19         ` Andrii Nakryiko
2023-11-22  1:16 ` [PATCH bpf-next 05/10] selftests/bpf: add selftest validating callback result is enforced Andrii Nakryiko
2023-11-22 15:13   ` Eduard Zingerman
2023-11-22 17:46     ` Andrii Nakryiko
2023-11-22  1:16 ` [PATCH bpf-next 06/10] bpf: enforce precise retval range on program exit Andrii Nakryiko
2023-11-22 15:13   ` Eduard Zingerman
2023-11-22  1:16 ` [PATCH bpf-next 07/10] bpf: unify async callback and program retval checks Andrii Nakryiko
2023-11-22 15:13   ` Eduard Zingerman
2023-11-22  1:16 ` [PATCH bpf-next 08/10] bpf: enforce precision of R0 on program/async callback return Andrii Nakryiko
2023-11-22 15:13   ` Eduard Zingerman
2023-11-22  1:16 ` [PATCH bpf-next 09/10] selftests/bpf: validate async callback return value check correctness Andrii Nakryiko
2023-11-22 15:13   ` Eduard Zingerman
2023-11-22  1:16 ` [PATCH bpf-next 10/10] selftests/bpf: adjust global_func15 test to validate prog exit precision Andrii Nakryiko
2023-11-22 15:13   ` 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=a6edebc8d7063836c7d031d86a3c43f2dd0f49bd.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 \
    /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