linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] seccomp: passthrough uretprobe systemcall without filtering
@ 2025-01-17  0:55 Eyal Birger
  2025-01-17  1:39 ` Oleg Nesterov
                   ` (2 more replies)
  0 siblings, 3 replies; 35+ messages in thread
From: Eyal Birger @ 2025-01-17  0:55 UTC (permalink / raw)
  To: kees, luto, wad, oleg, mhiramat, andrii, jolsa
  Cc: alexei.starovoitov, olsajiri, cyphar, songliubraving, yhs,
	john.fastabend, peterz, tglx, bp, daniel, ast, andrii.nakryiko,
	rostedt, rafi, shmulik.ladkani, bpf, linux-api,
	linux-trace-kernel, x86, linux-kernel, Eyal Birger, stable

When attaching uretprobes to processes running inside docker, the attached
process is segfaulted when encountering the retprobe.

The reason is that now that uretprobe is a system call the default seccomp
filters in docker block it as they only allow a specific set of known
syscalls. This is true for other userspace applications which use seccomp
to control their syscall surface.

Since uretprobe is a "kernel implementation detail" system call which is
not used by userspace application code directly, it is impractical and
there's very little point in forcing all userspace applications to
explicitly allow it in order to avoid crashing tracked processes.

Pass this systemcall through seccomp without depending on configuration.

Fixes: ff474a78cef5 ("uprobe: Add uretprobe syscall to speed up return probe")
Reported-by: Rafael Buchbinder <rafi@rbk.io>
Link: https://lore.kernel.org/lkml/CAHsH6Gs3Eh8DFU0wq58c_LF8A4_+o6z456J7BidmcVY2AqOnHQ@mail.gmail.com/
Cc: stable@vger.kernel.org
Signed-off-by: Eyal Birger <eyal.birger@gmail.com>
---

The following reproduction script synthetically demonstrates the problem:

cat > /tmp/x.c << EOF

char *syscalls[] = {
	"write",
	"exit_group",
	"fstat",
};

__attribute__((noinline)) int probed(void)
{
	printf("Probed\n");
	return 1;
}

void apply_seccomp_filter(char **syscalls, int num_syscalls)
{
	scmp_filter_ctx ctx;

	ctx = seccomp_init(SCMP_ACT_KILL);
	for (int i = 0; i < num_syscalls; i++) {
		seccomp_rule_add(ctx, SCMP_ACT_ALLOW,
				 seccomp_syscall_resolve_name(syscalls[i]), 0);
	}
	seccomp_load(ctx);
	seccomp_release(ctx);
}

int main(int argc, char *argv[])
{
	int num_syscalls = sizeof(syscalls) / sizeof(syscalls[0]);

	apply_seccomp_filter(syscalls, num_syscalls);

	probed();

	return 0;
}
EOF

cat > /tmp/trace.bt << EOF
uretprobe:/tmp/x:probed
{
    printf("ret=%d\n", retval);
}
EOF

gcc -o /tmp/x /tmp/x.c -lseccomp

/usr/bin/bpftrace /tmp/trace.bt &

sleep 5 # wait for uretprobe attach
/tmp/x

pkill bpftrace

rm /tmp/x /tmp/x.c /tmp/trace.bt
---
 kernel/seccomp.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/seccomp.c b/kernel/seccomp.c
index 385d48293a5f..10a55c9b5c18 100644
--- a/kernel/seccomp.c
+++ b/kernel/seccomp.c
@@ -1359,6 +1359,11 @@ int __secure_computing(const struct seccomp_data *sd)
 	this_syscall = sd ? sd->nr :
 		syscall_get_nr(current, current_pt_regs());
 
+#ifdef CONFIG_X86_64
+	if (unlikely(this_syscall == __NR_uretprobe) && !in_ia32_syscall())
+		return 0;
+#endif
+
 	switch (mode) {
 	case SECCOMP_MODE_STRICT:
 		__secure_computing_strict(this_syscall);  /* may call do_exit */
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2025-01-27 19:43 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-17  0:55 [PATCH] seccomp: passthrough uretprobe systemcall without filtering Eyal Birger
2025-01-17  1:39 ` Oleg Nesterov
2025-01-17  8:02   ` Masami Hiramatsu
2025-01-17 13:36     ` Eyal Birger
2025-01-17 14:09     ` Oleg Nesterov
2025-01-17 17:51       ` Andrii Nakryiko
2025-01-17 19:24         ` Eyal Birger
2025-01-17 19:34           ` Andrii Nakryiko
2025-01-18 15:05         ` Oleg Nesterov
2025-01-17 18:34 ` Dmitry V. Levin
2025-01-17 18:52   ` Eyal Birger
2025-01-18 20:21 ` Kees Cook
2025-01-18 20:31   ` Darrick J. Wong
2025-01-18 20:45   ` Eyal Birger
2025-01-19  2:24     ` Kees Cook
2025-01-19  3:39       ` Eyal Birger
2025-01-19 10:44         ` Jiri Olsa
2025-01-20 21:34         ` Kees Cook
2025-01-27 19:24           ` Eyal Birger
2025-01-27 19:33             ` Kees Cook
2025-01-27 19:39               ` Eyal Birger
2025-01-27 19:43                 ` Kees Cook
2025-01-21 14:38         ` Jiri Olsa
2025-01-21 14:47           ` Eyal Birger
2025-01-21 16:16           ` Steven Rostedt
2025-01-21 16:44             ` Oleg Nesterov
2025-01-21 16:55             ` Jiri Olsa
2025-01-21 22:38               ` Andrii Nakryiko
2025-01-21 22:46                 ` Steven Rostedt
2025-01-21 23:13                   ` Eyal Birger
2025-01-21 23:29                     ` Steven Rostedt
2025-01-19 18:36       ` Andy Lutomirski
2025-01-19 12:40   ` Oleg Nesterov
2025-01-20 21:32     ` Kees Cook
2025-01-21 15:28       ` Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).