1 |
commit: a374b1f829a07cce3eb708f078a2a70f9bc4d975 |
2 |
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Oct 28 05:49:33 2021 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Oct 28 05:49:33 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=a374b1f8 |
7 |
|
8 |
libsandbox: fix signal pass through with ptrace main loop |
9 |
|
10 |
When we're notified that the child has received a signal, we need to |
11 |
pass it through since we don't care about signals. We did that, but |
12 |
using PTRACE_CONT which causes the process to just resume, and then |
13 |
we'd call PTRACE_SYSCALL on that resumed state. When the pass thru |
14 |
logic was a signal handler, PTRACE_CONT was correct since it would |
15 |
come in while in the middle of PTRACE_SYSCALL, but after the rewrite |
16 |
of the main loop, it's now the wrong call. Pass the signal back to |
17 |
the existing PTRACE_SYSCALL call so that we stay in the main loop |
18 |
and get notified on the next syscall event. |
19 |
|
20 |
Closes: https://bugs.gentoo.org/820407 |
21 |
Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org> |
22 |
|
23 |
libsandbox/trace.c | 7 +++++-- |
24 |
1 file changed, 5 insertions(+), 2 deletions(-) |
25 |
|
26 |
diff --git a/libsandbox/trace.c b/libsandbox/trace.c |
27 |
index b7e65b4..d53051d 100644 |
28 |
--- a/libsandbox/trace.c |
29 |
+++ b/libsandbox/trace.c |
30 |
@@ -405,13 +405,16 @@ static void trace_loop(void) |
31 |
long ret; |
32 |
int status, sig; |
33 |
const struct syscall_entry *tbl_after_fork; |
34 |
+ void *data; |
35 |
|
36 |
before_exec = true; |
37 |
before_syscall = false; |
38 |
fake_syscall_ret = false; |
39 |
tbl_after_fork = NULL; |
40 |
+ data = NULL; |
41 |
do { |
42 |
- ret = do_ptrace(PTRACE_SYSCALL, NULL, NULL); |
43 |
+ ret = do_ptrace(PTRACE_SYSCALL, NULL, data); |
44 |
+ data = NULL; |
45 |
waitpid(trace_pid, &status, 0); |
46 |
|
47 |
event = (unsigned)status >> 16; |
48 |
@@ -444,7 +447,7 @@ static void trace_loop(void) |
49 |
* and we'll exit then. |
50 |
*/ |
51 |
sb_debug("passing signal through %s (%i)", strsig(sig), sig); |
52 |
- do_ptrace(PTRACE_CONT, NULL, (void *)(uintptr_t)(sig)); |
53 |
+ data = (void *)(uintptr_t)(sig); |
54 |
continue; |
55 |
} |