From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: bpf@vger.kernel.org
Cc: kkd@meta.com, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>, Tao Lyu <tao.lyu@epfl.ch>,
Mathias Payer <mathias.payer@nebelwelt.net>,
Meng Xu <meng.xu.cs@uwaterloo.ca>,
Sanidhya Kashyap <sanidhya.kashyap@epfl.ch>,
kernel-team@fb.com
Subject: [PATCH bpf v4 4/5] selftests/bpf: Add test for reading from STACK_INVALID slots
Date: Tue, 3 Dec 2024 20:47:56 -0800 [thread overview]
Message-ID: <20241204044757.1483141-5-memxor@gmail.com> (raw)
In-Reply-To: <20241204044757.1483141-1-memxor@gmail.com>
Ensure that when CAP_PERFMON is dropped, and the verifier sees
allow_ptr_leaks as false, we are not permitted to read from a
STACK_INVALID slot. Without the fix, the test will report unexpected
success in loading.
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
---
.../selftests/bpf/progs/verifier_spill_fill.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/tools/testing/selftests/bpf/progs/verifier_spill_fill.c b/tools/testing/selftests/bpf/progs/verifier_spill_fill.c
index 671d9f415dbf..bab6d789ba00 100644
--- a/tools/testing/selftests/bpf/progs/verifier_spill_fill.c
+++ b/tools/testing/selftests/bpf/progs/verifier_spill_fill.c
@@ -1244,4 +1244,22 @@ __naked void old_stack_misc_vs_cur_ctx_ptr(void)
: __clobber_all);
}
+SEC("socket")
+__description("stack_noperfmon: reject read of invalid slots")
+__success
+__caps_unpriv(CAP_BPF)
+__failure_unpriv __msg_unpriv("invalid read from stack off -8+1 size 8")
+__naked void stack_noperfmon_reject_invalid_read(void)
+{
+ asm volatile (" \
+ r2 = 1; \
+ r6 = r10; \
+ r6 += -8; \
+ *(u8 *)(r6 + 0) = r2; \
+ r2 = *(u64 *)(r6 + 0); \
+ r0 = 0; \
+ exit; \
+" ::: __clobber_all);
+}
+
char _license[] SEC("license") = "GPL";
--
2.43.5
next prev parent reply other threads:[~2024-12-04 4:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-04 4:47 [PATCH bpf v4 0/5] Fixes for stack with allow_ptr_leaks Kumar Kartikeya Dwivedi
2024-12-04 4:47 ` [PATCH bpf v4 1/5] bpf: Don't mark STACK_INVALID as STACK_MISC in mark_stack_slot_misc Kumar Kartikeya Dwivedi
2024-12-04 4:47 ` [PATCH bpf v4 2/5] bpf: Fix narrow scalar spill onto 64-bit spilled scalar slots Kumar Kartikeya Dwivedi
2024-12-04 4:47 ` [PATCH bpf v4 3/5] selftests/bpf: Introduce __caps_unpriv annotation for tests Kumar Kartikeya Dwivedi
2024-12-04 4:47 ` Kumar Kartikeya Dwivedi [this message]
2024-12-04 4:47 ` [PATCH bpf v4 5/5] selftests/bpf: Add test for narrow spill into 64-bit spilled scalar Kumar Kartikeya Dwivedi
2024-12-04 17:30 ` [PATCH bpf v4 0/5] Fixes for stack with allow_ptr_leaks 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=20241204044757.1483141-5-memxor@gmail.com \
--to=memxor@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=kernel-team@fb.com \
--cc=kkd@meta.com \
--cc=martin.lau@kernel.org \
--cc=mathias.payer@nebelwelt.net \
--cc=meng.xu.cs@uwaterloo.ca \
--cc=sanidhya.kashyap@epfl.ch \
--cc=tao.lyu@epfl.ch \
/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