BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Hao Sun <sunhao.th@gmail.com>,
	Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Andrei Matei <andreimatei1@gmail.com>,
	bpf@vger.kernel.org, ast@kernel.org,
	 kernel-team@dataexmachina.dev
Subject: Re: [PATCH bpf] bpf: fix tracking of stack size for var-off access
Date: Wed, 22 Nov 2023 14:46:09 +0200	[thread overview]
Message-ID: <dc1a84bde2c62445b2bd05ea99dfc716d4724f6c.camel@gmail.com> (raw)
In-Reply-To: <CACkBjsbWdOVMs7vRXvxi0MCoOAh+skYWFN1douBjkRzeTX=wvg@mail.gmail.com>

On Tue, 2023-11-21 at 18:16 +0100, Hao Sun wrote:
[...]
> Yet, the sample direct read would be rejected:
> 
> func#0 @0
> 0: R1=ctx() R10=fp0
> 0: (bf) r6 = r10                      ; R6_w=fp0 R10=fp0
> 1: (61) r7 = *(u32 *)(r6 -200)
> invalid read from stack R6 off=-200 size=4
> 
> Eduard, you added support for reading uninit slots, should we also add something
> like the following:
> 
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 8c2d31aa3d31..aa861d2da240 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -6446,7 +6446,7 @@ static int check_stack_slot_within_bounds(int off,
>  {
>         int min_valid_off;
> 
> -       if (t == BPF_WRITE)
> +       if (t == BPF_WRITE || env->allow_uninit_stack)
>                 min_valid_off = -MAX_BPF_STACK;
>         else
>                 min_valid_off = -state->allocated_stack;

I agree with your logic and this change seems reasonable.
Sorry for delayed response.

  parent reply	other threads:[~2023-11-22 12:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-13 23:50 [PATCH bpf] bpf: fix tracking of stack size for var-off access Andrei Matei
2023-11-21  0:46 ` Andrii Nakryiko
2023-11-21 17:16   ` Hao Sun
2023-11-21 20:29     ` Andrei Matei
2023-11-21 21:55       ` Andrii Nakryiko
2023-11-22 12:38         ` Eduard Zingerman
2023-11-22 12:46     ` Eduard Zingerman [this message]
2023-11-21 20:34   ` Andrei Matei

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=dc1a84bde2c62445b2bd05ea99dfc716d4724f6c.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andreimatei1@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=kernel-team@dataexmachina.dev \
    --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