BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
	daniel@iogearbox.net,  martin.lau@linux.dev, kernel-team@fb.com,
	yhs@fb.com
Subject: Re: [PATCH bpf-next v2 1/4] bpf: verify scalar ids mapping in regsafe() using check_ids()
Date: Thu, 01 Jun 2023 02:42:10 +0300	[thread overview]
Message-ID: <12d9acab03e76491a34318dc2973b60f10712239.camel@gmail.com> (raw)
In-Reply-To: <CAEf4Bza+60Wjbk=Hww1joxoykx+HeyP_Nv5igP7V0RZi=-3OVg@mail.gmail.com>

On Wed, 2023-05-31 at 15:54 -0700, Andrii Nakryiko wrote:
> [...] 
>
> well, what can I say... force all imprecise logic isn't that
> straightforward either, but so far it still holds. And the big idea
> here is similar: whatever happens between two checkpoints doesn't
> matter if its effect is not visible at the end of the checkpoint.
> 
> So I guess the intent of my proposal is correct: every time we mark r6
> as precise, we should mark r7 as well in each state in which they are
> still linked. Which necessitates to do this on each walk up the state
> chain.
> 
> At least let's give it a try and see how it holds up against existing
> tests and whatever test you can come up with?..
 
I'll try this thing, thanks a lot for all the input!
Hopefully will get back tomorrow.

> [...]
> 
> BTW, I did contemplate extending jmp_history to contain extra flags
> about "interesting" instructions, though. Specifically, last
> unsupported case for precision backtracking is when register other
> than r10 is used for stack access (which can happen when one passes a
> pointer to a SCALAR to parent function's stack), for which having a
> bit next to such instruction saying "this is really a stack access"
> would help cover the last class of unsupported situations.

Yes, it would have required some kind of redesign for this case as
well. My expectation is that only a few registers get range on each
find_equal_scalars() call, so storing big masks for all frame levels
is very sub-optimal.

> But this is a pretty significant complication. And to make it really
> practical, we'd need to think very hard on how to implement
> jmp_history more efficiently, without constant reallocations. I have a
> hunch that jmp_history should be one large resizable array that all
> states share and just point into different parts of it. When state is
> pushed to the stack, we just remember at which index it starts. When a
> state is finalized, its jump history segment shouldn't be needed by
> that state and can be reused by its siblings and parent states.
> Ultimately, we only have a linear chain of actively worked-on states
> which do use jmp_history, and all others either don't need it
> *anymore* (verified states) or don't need it *yet* (enqueued states).
>
> This would allow us to even have an exact "log of execution" with
> insn_idx and associated extra information, but it will be code path
> dependent, unlike bpf_insn_aux. And the best property is that it will
> never grow beyond 1 million instructions deep (absolute worst case).

I'm not sure I understand why is it bounded.
Conditionals and loops potentially give big number of possible
execution paths over a small number of instructions.
So, keeping per-path / per-instruction still is going to blow up in
terms of memory use. To keep it bounded (?) something smart needs to
know which visited states could never be visited again.

> We might not even need backtracking in its current form if we just
> proactively maintain involved registers information (something that we
> currently derive during instruction interpretation in backtrack_insn).

Well, precision marks still have to be propagated backwards, so some
form of "backward movement" within a state will have to happen anyway.
Like, we have a combination of forward and backward analyses in any case.
Sounds a bit like you want to converge the design to some kind of a
classical data flow analysis, but have states instead of basic blocks.

> So at some point I'd like to get to thinking and implementing this,
> but it isn't the most pressing need right now, of course.
> [...]

  reply	other threads:[~2023-05-31 23:42 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-30 17:27 [PATCH bpf-next v2 0/4] verify scalar ids mapping in regsafe() Eduard Zingerman
2023-05-30 17:27 ` [PATCH bpf-next v2 1/4] bpf: verify scalar ids mapping in regsafe() using check_ids() Eduard Zingerman
2023-05-30 21:37   ` Andrii Nakryiko
2023-05-30 23:02     ` Eduard Zingerman
2023-06-01  2:05       ` Alexei Starovoitov
2023-06-01 16:57         ` Eduard Zingerman
2023-06-01 17:13           ` Alexei Starovoitov
2023-06-01 18:52             ` Eduard Zingerman
2023-06-02 18:50               ` Andrii Nakryiko
2023-06-02 19:13                 ` Eduard Zingerman
2023-06-02 19:27                   ` Alexei Starovoitov
2023-06-02 19:37                     ` Eduard Zingerman
2023-06-02 19:43                       ` Alexei Starovoitov
2023-06-02 19:51                         ` Eduard Zingerman
2023-06-02 20:03                           ` Alexei Starovoitov
2023-06-02 20:22                             ` Eduard Zingerman
2023-06-02 20:17                   ` Andrii Nakryiko
2023-06-02 21:13                     ` Eduard Zingerman
2023-06-02 22:07                       ` Andrii Nakryiko
2023-06-02 23:20                         ` Eduard Zingerman
2023-06-05 20:43                           ` Eduard Zingerman
     [not found]     ` <f2abf39bcd4de841a89bb248de9e242a880aaa93.camel@gmail.com>
2023-05-31 18:29       ` Andrii Nakryiko
2023-05-31 19:30         ` Eduard Zingerman
2023-05-31 20:12           ` Andrii Nakryiko
2023-05-31 20:31             ` Eduard Zingerman
2023-05-31 21:14               ` Andrii Nakryiko
2023-05-31 22:15                 ` Eduard Zingerman
2023-05-31 22:54                   ` Andrii Nakryiko
2023-05-31 23:42                     ` Eduard Zingerman [this message]
2023-06-01  0:23                       ` Andrii Nakryiko
2023-05-30 17:27 ` [PATCH bpf-next v2 2/4] selftests/bpf: verify that check_ids() is used for scalars in regsafe() Eduard Zingerman
2023-05-30 17:27 ` [PATCH bpf-next v2 3/4] bpf: filter out scalar ids not used for range transfer " Eduard Zingerman
2023-05-30 17:27 ` [PATCH bpf-next v2 4/4] selftests/bpf: check env->that range_transfer_ids has effect 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=12d9acab03e76491a34318dc2973b60f10712239.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=martin.lau@linux.dev \
    --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