Thread (15 messages) flat view 15 messages, 4 authors, 2025-02-08

Re: [PATCH v3 2/2] selftests/seccomp: validate uretprobe syscall passes through seccomp

From: Kees Cook <kees@kernel.org>
Date: 2025-02-06 21:18:51
Also in: bpf, linux-trace-kernel, lkml
Subsystem: kernel selftest framework, secure computing, the rest · Maintainers: Shuah Khan, Shuah Khan, Kees Cook, Linus Torvalds

On Sun, Feb 02, 2025 at 01:13:28PM -0800, Eyal Birger wrote:
On Sun, Feb 2, 2025 at 12:51 PM Jiri Olsa [off-list ref] wrote:
quoted
On Sun, Feb 02, 2025 at 08:29:21AM -0800, Eyal Birger wrote:

SNIP
quoted
+TEST_F(URETPROBE, uretprobe_default_block)
+{
+     struct sock_filter filter[] = {
+             BPF_STMT(BPF_LD|BPF_W|BPF_ABS,
+                     offsetof(struct seccomp_data, nr)),
+             BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_exit_group, 1, 0),
+             BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_KILL),
+             BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW),
+     };
+     struct sock_fprog prog = {
+             .len = (unsigned short)ARRAY_SIZE(filter),
+             .filter = filter,
+     };
+
+     ASSERT_EQ(0, run_probed_with_filter(&prog));
+}
+
+TEST_F(URETPROBE, uretprobe_block_uretprobe_syscall)
+{
+     struct sock_filter filter[] = {
+             BPF_STMT(BPF_LD|BPF_W|BPF_ABS,
+                     offsetof(struct seccomp_data, nr)),
+#ifdef __NR_uretprobe
+             BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_uretprobe, 0, 1),
+#endif
does it make sense to run these tests on archs without __NR_uretprobe ?
I considered ifdefing them out, but then thought that given it's not
a lot of code it'd be better for the tests to be compiling and
ready in case support is added on a new platform than to have to
worry about that at that point.
The trouble I had is that on other archs, the tests fail. I've added
this, which retains build coverage, but doesn't trigger failures without
__NR_uretprobe:

diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
index bee4f424c5c3..14ba51b52095 100644
--- a/tools/testing/selftests/seccomp/seccomp_bpf.c
+++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
@@ -4973,6 +4973,10 @@ FIXTURE_SETUP(URETPROBE)
 	ssize_t offset;
 	int type, bit;
 
+#ifndef __NR_uretprobe
+	SKIP(return, "__NR_uretprobe syscall not defined");
+#endif
+
 	if (!variant->attach)
 		return;
 
-- 
Kees Cook
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help