From: Eduard Zingerman <eddyz87@gmail.com>
To: bpf@vger.kernel.org, ast@kernel.org
Cc: andrii@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev,
kernel-team@fb.com, yonghong.song@linux.dev, memxor@gmail.com,
awerner32@gmail.com, john.fastabend@gmail.com,
Eduard Zingerman <eddyz87@gmail.com>
Subject: [PATCH bpf-next 0/5] exact states comparison for iterator convergence checks
Date: Sat, 21 Oct 2023 03:59:34 +0300 [thread overview]
Message-ID: <20231021005939.1041-1-eddyz87@gmail.com> (raw)
Iterator convergence logic in is_state_visited() uses state_equals()
for states with branches counter > 0 to check if iterator based loop
converges. This is not fully correct because state_equals() relies on
presence of read and precision marks on registers. These marks are not
guaranteed to be finalized while state has branches.
Commit message for patch #1 describes a program that exhibits such
behavior.
This patch-set aims to fix iterator convergence logic by adding notion
of exact states comparison. Exact comparison does not rely on presence
of read or precision marks and thus is more strict.
As explained in commit message for patch #1 exact comparisons require
addition of speculative register bounds widening. The end result for
BPF verifier users could be summarized as follows:
(!) After this update verifier would reject programs that conjure an
imprecise value on first loop iteration and use it as precise on
a second (for iterator based loops).
I urge people to at least skim over the commit message for patch #1.
Patches are organized as follows:
- patch #1: introduces exact mode for states comparison and adds
widening heuristic;
- patch #2: adds test-cases that demonstrate why the series is
necessary;
- patch #3: extends patch #1 with a notion of state loop entries,
these entries have to be tracked to correctly identify that
different verifier states belong to the same states loop;
- patch #4: adds a test-case that demonstrates a program
which requires loop entry tracking for correct verification;
- patch #5: just adds a few debug prints.
The following actions are planned as a followup for this patch-set:
- implementation has to be adapted for callbacks handling logic as a
part of a fix for [1];
- it is necessary to explore ways to improve widening heuristic to
handle iters_task_vma test w/o need to insert barrier_var() calls;
- explored states eviction logic on cache miss has to be extended
to either:
- allow eviction of checkpoint states -or-
- be sped up in case if there are many active checkpoints associated
with the same instruction.
The patch-set is a followup for mailing list discussion [1].
[1] https://lore.kernel.org/bpf/97a90da09404c65c8e810cf83c94ac703705dc0e.camel@gmail.com/
Eduard Zingerman (5):
bpf: exact states comparison for iterator convergence checks
selftests/bpf: tests with delayed read/precision makrs in loop body
bpf: correct loop detection for iterators convergence
selftests/bpf: test if state loops are detected in a tricky case
bpf: print full verifier states on infinite loop detection
include/linux/bpf_verifier.h | 16 +
kernel/bpf/verifier.c | 440 ++++++++++++-
tools/testing/selftests/bpf/progs/iters.c | 620 ++++++++++++++++++
.../selftests/bpf/progs/iters_task_vma.c | 1 +
4 files changed, 1043 insertions(+), 34 deletions(-)
--
2.42.0
next reply other threads:[~2023-10-21 1:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-21 0:59 Eduard Zingerman [this message]
2023-10-21 0:59 ` [PATCH bpf-next 1/5] bpf: exact states comparison for iterator convergence checks Eduard Zingerman
2023-10-21 21:41 ` Alexei Starovoitov
2023-10-21 0:59 ` [PATCH bpf-next 2/5] selftests/bpf: tests with delayed read/precision makrs in loop body Eduard Zingerman
2023-10-21 7:18 ` kernel test robot
2023-10-21 0:59 ` [PATCH bpf-next 3/5] bpf: correct loop detection for iterators convergence Eduard Zingerman
2023-10-21 0:59 ` [PATCH bpf-next 4/5] selftests/bpf: test if state loops are detected in a tricky case Eduard Zingerman
2023-10-21 7:30 ` kernel test robot
2023-10-21 0:59 ` [PATCH bpf-next 5/5] bpf: print full verifier states on infinite loop detection 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=20231021005939.1041-1-eddyz87@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=awerner32@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=kernel-team@fb.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=yonghong.song@linux.dev \
/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