From: Hao Sun <sunhao.th@gmail.com>
To: bpf@vger.kernel.org
Cc: willemb@google.com, ast@kernel.org, andrii@kernel.org,
daniel@iogearbox.net, eddyz87@gmail.com,
linux-kernel@vger.kernel.org, Hao Sun <sunhao.th@gmail.com>
Subject: [PATCH v3 2/2] selftests/bpf: Add tests for alu on PTR_TO_FLOW_KEYS
Date: Fri, 12 Jan 2024 16:20:11 +0100 [thread overview]
Message-ID: <20240112152011.6264-2-sunhao.th@gmail.com> (raw)
In-Reply-To: <20240112152011.6264-1-sunhao.th@gmail.com>
Add two cases for PTR_TO_FLOW_KEYS alu. One for rejecting alu with
variable offset, another for fixed offset.
Signed-off-by: Hao Sun <sunhao.th@gmail.com>
---
.../bpf/progs/verifier_value_illegal_alu.c | 36 +++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c b/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
index 71814a753216..3bcccb4cbc85 100644
--- a/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
+++ b/tools/testing/selftests/bpf/progs/verifier_value_illegal_alu.c
@@ -146,4 +146,40 @@ l0_%=: exit; \
: __clobber_all);
}
+SEC("flow_dissector")
+__description("flow_keys illegal alu op with variable offset")
+__failure __msg("R7 pointer arithmetic on flow_keys prohibited")
+__naked void flow_keys_illegal_variable_offset_alu(void)
+{
+ asm volatile(" \
+ r6 = r1; \
+ r7 = *(u64*)(r6 + %[flow_keys_off]); \
+ r8 = 8; \
+ r8 /= 1; \
+ r8 &= 8; \
+ r7 += r8; \
+ r0 = *(u64*)(r7 + 0); \
+ exit; \
+" :
+ : __imm_const(flow_keys_off, offsetof(struct __sk_buff, flow_keys))
+ : __clobber_all);
+}
+
+SEC("flow_dissector")
+__description("flow_keys valid alu op with fixed offset")
+__success
+__naked void flow_keys_legal_fixed_offset_alu(void)
+{
+ asm volatile(" \
+ r6 = r1; \
+ r7 = *(u64*)(r6 + %[flow_keys_off]); \
+ r8 = 8; \
+ r7 += r8; \
+ r0 = *(u64*)(r7 + 0); \
+ exit; \
+" :
+ : __imm_const(flow_keys_off, offsetof(struct __sk_buff, flow_keys))
+ : __clobber_all);
+}
+
char _license[] SEC("license") = "GPL";
--
2.34.1
next prev parent reply other threads:[~2024-01-12 15:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-12 15:20 [PATCH v3 1/2] bpf: Reject variable offset alu on PTR_TO_FLOW_KEYS Hao Sun
2024-01-12 15:20 ` Hao Sun [this message]
2024-01-12 18:14 ` [PATCH v3 2/2] selftests/bpf: Add tests for " Yonghong Song
2024-01-12 17:56 ` [PATCH v3 1/2] bpf: Reject variable offset " Alexei Starovoitov
2024-01-12 18:02 ` Hao Sun
2024-01-12 18:38 ` Yonghong Song
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=20240112152011.6264-2-sunhao.th@gmail.com \
--to=sunhao.th@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=willemb@google.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 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.