From: Jiayuan Chen <mrpre@163.com>
To: bpf@vger.kernel.org, ast@kernel.org
Cc: daniel@iogearbox.net, john.fastabend@gmail.com,
andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com,
song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org,
sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org,
mykolal@fb.com, shuah@kernel.org, Jiayuan Chen <mrpre@163.com>
Subject: [PATCH bpf-next v1 2/2] bpf/selftest: add selftest for may_goto
Date: Wed, 12 Feb 2025 21:52:51 +0800 [thread overview]
Message-ID: <20250212135251.85487-3-mrpre@163.com> (raw)
In-Reply-To: <20250212135251.85487-1-mrpre@163.com>
Add test case to ensure normal operation when may_goto exists and the
stack size has already reached 512.
./test_progs -t verifier_stack_ptr
...
verifier_stack_ptr/PTR_TO_STACK max stack size > 512:OK
verifier_stack_ptr/PTR_TO_STACK max stack size 512 with may_goto:OK
...
Signed-off-by: Jiayuan Chen <mrpre@163.com>
---
.../selftests/bpf/progs/verifier_stack_ptr.c | 33 +++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/verifier_stack_ptr.c b/tools/testing/selftests/bpf/progs/verifier_stack_ptr.c
index 417c61cd4b19..b2e84714e1bc 100644
--- a/tools/testing/selftests/bpf/progs/verifier_stack_ptr.c
+++ b/tools/testing/selftests/bpf/progs/verifier_stack_ptr.c
@@ -481,4 +481,37 @@ l1_%=: r0 = 42; \
: __clobber_all);
}
+SEC("socket")
+__description("PTR_TO_STACK max stack size > 512")
+__failure __msg("invalid write to stack R1 off=-520 size=8")
+__naked void stack_check_size_gt_512(void)
+{
+ asm volatile (
+ "r1 = r10;"
+ "r1 += -520;"
+ "r0 = 42;"
+ "*(u64*)(r1 + 0) = r0;"
+ "exit;"
+ ::: __clobber_all);
+}
+
+#ifdef __BPF_FEATURE_MAY_GOTO
+SEC("socket")
+__description("PTR_TO_STACK max stack size 512 with may_goto")
+__success
+__retval(42)
+__naked void stack_check_size_512_with_may_goto(void)
+{
+ asm volatile (
+ "r1 = r10;"
+ "r1 += -512;"
+ "r0 = 42;"
+ "*(u32*)(r1 + 0) = r0;"
+ "may_goto end;"
+ "r2 = 100;"
+"end: exit;"
+ ::: __clobber_all);
+}
+#endif
+
char _license[] SEC("license") = "GPL";
--
2.47.1
prev parent reply other threads:[~2025-02-12 13:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-12 13:52 [PATCH bpf-next v1 0/2] bpf: Fix array bounds error with may_goto and add selftest Jiayuan Chen
2025-02-12 13:52 ` [PATCH bpf-next v1 1/2] bpf: Fix array bounds error with may_goto Jiayuan Chen
2025-02-12 15:52 ` Alexei Starovoitov
2025-02-12 13:52 ` Jiayuan Chen [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=20250212135251.85487-3-mrpre@163.com \
--to=mrpre@163.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=mykolal@fb.com \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--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 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.