From: Youlin Li <liulin063@gmail.com>
To: daniel@iogearbox.net, haoluo@google.com
Cc: ast@kernel.org, john.fastabend@gmail.com, andrii@kernel.org,
martin.lau@linux.dev, song@kernel.org, yhs@fb.com,
kpsingh@kernel.org, sdf@google.com, jolsa@kernel.org,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
Youlin Li <liulin063@gmail.com>
Subject: [PATCH 2/2] bpf, selftests: Add verifier test case for ALU64
Date: Wed, 10 Aug 2022 18:09:19 +0800 [thread overview]
Message-ID: <20220810100919.26447-1-liulin063@gmail.com> (raw)
In-Reply-To: <9f954e67-67fc-e3b9-d810-22bfea95d2aa@iogearbox.net>
Add a test case to ensure that 32-bit bounds can be learned from 64-bit
bounds when performing 64-bit ALU operations.
Make use of dead code elimination, so that we can see the verifier
bailing out on unmodified kernels.
Before:
./test_verifier 165
#165/p 32-bit bounds update in ALU64 FAIL
Failed to load prog 'Permission denied'!
R2 !read_ok
verification time 49 usec
stack depth 0
processed 8 insns (limit 1000000) max_states_per_insn 0 total_states
0 peak_states 0 mark_read 0
Summary: 0 PASSED, 1 SKIPPED, 1 FAILED
After:
./test_verifier 165
#165/p 32-bit bounds update in ALU64 OK
Summary: 1 PASSED, 1 SKIPPED, 0 FAILED
Signed-off-by: Youlin Li <liulin063@gmail.com>
---
tools/testing/selftests/bpf/verifier/bounds.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/tools/testing/selftests/bpf/verifier/bounds.c b/tools/testing/selftests/bpf/verifier/bounds.c
index 33125d5f6772..b9aee2f2c66e 100644
--- a/tools/testing/selftests/bpf/verifier/bounds.c
+++ b/tools/testing/selftests/bpf/verifier/bounds.c
@@ -753,3 +753,20 @@
.result_unpriv = REJECT,
.result = ACCEPT,
},
+{
+ "32-bit bounds update in ALU64",
+ .insns = {
+ BPF_MOV64_IMM(BPF_REG_0, 0),
+ BPF_MOV64_IMM(BPF_REG_1, 0),
+ BPF_ALU64_IMM(BPF_NEG, BPF_REG_1, 0),
+ BPF_ALU64_IMM(BPF_NEG, BPF_REG_1, 0),
+ BPF_ALU64_IMM(BPF_ARSH, BPF_REG_1, 63),
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 2),
+ BPF_JMP32_IMM(BPF_JGE, BPF_REG_1, 1, 1),
+ BPF_MOV64_REG(BPF_REG_0, BPF_REG_2),
+ BPF_JMP32_IMM(BPF_JLE, BPF_REG_1, 2, 1),
+ BPF_MOV64_REG(BPF_REG_0, BPF_REG_2),
+ BPF_EXIT_INSN()
+ },
+ .result = ACCEPT,
+},
--
2.25.1
prev parent reply other threads:[~2022-08-10 10:09 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-29 3:30 [PATCH bpf] bpf: Do more tight ALU bounds tracking Kuee K1r0a
2022-07-29 3:51 ` Hao Luo
2022-07-29 4:43 ` Youlin Li
2022-07-29 17:11 ` Hao Luo
2022-07-29 22:42 ` Youlin Li
2022-07-29 22:48 ` Hao Luo
2022-08-08 13:25 ` Daniel Borkmann
[not found] ` <CANdZH3U7axKg6zDY+iswF2d1fBYY1Xo2jeVsbgMYMoJfd1AYJg@mail.gmail.com>
2022-08-08 15:14 ` Fwd: " Kuee k1r0a
2022-08-08 15:42 ` Daniel Borkmann
2022-08-10 10:08 ` [PATCH 1/2] bpf: Fix 32bit bounds update in ALU64 Youlin Li
2022-08-17 20:31 ` Daniel Borkmann
2022-08-27 13:57 ` [PATCH bpf v2 1/2] bpf: Do more tight ALU bounds tracking Youlin Li
2022-08-30 0:19 ` Hao Luo
2022-08-10 10:09 ` Youlin Li [this message]
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=20220810100919.26447-1-liulin063@gmail.com \
--to=liulin063@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=sdf@google.com \
--cc=song@kernel.org \
--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