From: John Fastabend <john.fastabend@gmail.com>
To: Andrii Nakryiko <andrii@kernel.org>,
bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
martin.lau@kernel.org
Cc: andrii@kernel.org, kernel-team@meta.com
Subject: RE: [PATCH bpf-next 4/5] bpf: disambiguate SCALAR register state output in verifier logs
Date: Wed, 11 Oct 2023 22:33:40 -0700 [thread overview]
Message-ID: <65278534a3cb0_4a01020845@john.notmuch> (raw)
In-Reply-To: <20231011223728.3188086-5-andrii@kernel.org>
Andrii Nakryiko wrote:
> Currently the way that verifier prints SCALAR_VALUE register state (and
> PTR_TO_PACKET, which can have var_off and ranges info as well) is very
> ambiguous.
>
> In the name of brevity we are trying to eliminate "unnecessary" output
> of umin/umax, smin/smax, u32_min/u32_max, and s32_min/s32_max values, if
> possible. Current rules are that if any of those have their default
> value (which for mins is the minimal value of its respective types: 0,
> S32_MIN, or S64_MIN, while for maxs it's U32_MAX, S32_MAX, S64_MAX, or
> U64_MAX) *OR* if there is another min/max value that as matching value.
> E.g., if smin=100 and umin=100, we'll emit only umin=10, omitting smin
> altogether. This approach has a few problems, being both ambiguous and
> sort-of incorrect in some cases.
>
> Ambiguity is due to missing value could be either default value or value
> of umin/umax or smin/smax. This is especially confusing when we mix
> signed and unsigned ranges. Quite often, umin=0 and smin=0, and so we'll
> have only `umin=0` leaving anyone reading verifier log to guess whether
> smin is actually 0 or it's actually -9223372036854775808 (S64_MIN). And
> often times it's important to know, especially when debugging tricky
> issues.
+1
>
> "Sort-of incorrectness" comes from mixing negative and positive values.
> E.g., if umin is some large positive number, it can be equal to smin
> which is, interpreted as signed value, is actually some negative value.
> Currently, that smin will be omitted and only umin will be emitted with
> a large positive value, giving an impression that smin is also positive.
>
> Anyway, ambiguity is the biggest issue making it impossible to have an
> exact understanding of register state, preventing any sort of automated
> testing of verifier state based on verifier log. This patch is
> attempting to rectify the situation by removing ambiguity, while
> minimizing the verboseness of register state output.
>
> The rules are straightforward:
> - if some of the values are missing, then it definitely has a default
> value. I.e., `umin=0` means that umin is zero, but smin is actually
> S64_MIN;
> - all the various boundaries that happen to have the same value are
> emitted in one equality separated sequence. E.g., if umin and smin are
> both 100, we'll emit `smin=umin=100`, making this explicit;
> - we do not mix negative and positive values together, and even if
> they happen to have the same bit-level value, they will be emitted
> separately with proper sign. I.e., if both umax and smax happen to be
> 0xffffffffffffffff, we'll emit them both separately as
> `smax=-1,umax=18446744073709551615`;
> - in the name of a bit more uniformity and consistency,
> {u32,s32}_{min,max} are renamed to {s,u}{min,max}32, which seems to
> improve readability.
agree.
>
> The above means that in case of all 4 ranges being, say, [50, 100] range,
> we'd previously see hugely ambiguous:
>
> R1=scalar(umin=50,umax=100)
>
> Now, we'll be more explicit:
>
> R1=scalar(smin=umin=smin32=umin32=50,smax=umax=smax32=umax32=100)
>
> This is slightly more verbose, but distinct from the case when we don't
> know anything about signed boundaries and 32-bit boundaries, which under
> new rules will match the old case:
>
> R1=scalar(umin=50,umax=100)
Did you consider perhaps just always printing the entire set? Its overly
verbose I guess but I find it easier to track state across multiple
steps this way.
Otherwise patch LGTM.
next prev parent reply other threads:[~2023-10-12 5:33 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-11 22:37 [PATCH bpf-next 0/5] BPF verifier log improvements Andrii Nakryiko
2023-10-11 22:37 ` [PATCH bpf-next 1/5] selftests/bpf: improve percpu_alloc test robustness Andrii Nakryiko
2023-10-12 6:04 ` Yafang Shao
2023-10-12 16:37 ` Andrii Nakryiko
2023-10-11 22:37 ` [PATCH bpf-next 2/5] selftests/bpf: improve missed_kprobe_recursion " Andrii Nakryiko
2023-10-12 13:22 ` Jiri Olsa
2023-10-11 22:37 ` [PATCH bpf-next 3/5] selftests/bpf: make align selftests more robust Andrii Nakryiko
2023-10-11 22:37 ` [PATCH bpf-next 4/5] bpf: disambiguate SCALAR register state output in verifier logs Andrii Nakryiko
2023-10-12 5:33 ` John Fastabend [this message]
2023-10-12 16:22 ` Andrii Nakryiko
2023-10-12 16:59 ` John Fastabend
2023-10-12 17:45 ` Andrii Nakryiko
2023-10-11 22:37 ` [PATCH bpf-next 5/5] bpf: ensure proper register state printing for cond jumps Andrii Nakryiko
2023-10-12 5:40 ` [PATCH bpf-next 0/5] BPF verifier log improvements John Fastabend
2023-10-12 15:00 ` Eduard Zingerman
2023-10-16 12:00 ` patchwork-bot+netdevbpf
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=65278534a3cb0_4a01020845@john.notmuch \
--to=john.fastabend@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.