commit: a374b1f829a07cce3eb708f078a2a70f9bc4d975 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> AuthorDate: Thu Oct 28 05:49:33 2021 +0000 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> CommitDate: Thu Oct 28 05:49:33 2021 +0000 URL: https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=a374b1f8
libsandbox: fix signal pass through with ptrace main loop When we're notified that the child has received a signal, we need to pass it through since we don't care about signals. We did that, but using PTRACE_CONT which causes the process to just resume, and then we'd call PTRACE_SYSCALL on that resumed state. When the pass thru logic was a signal handler, PTRACE_CONT was correct since it would come in while in the middle of PTRACE_SYSCALL, but after the rewrite of the main loop, it's now the wrong call. Pass the signal back to the existing PTRACE_SYSCALL call so that we stay in the main loop and get notified on the next syscall event. Closes: https://bugs.gentoo.org/820407 Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org> libsandbox/trace.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libsandbox/trace.c b/libsandbox/trace.c index b7e65b4..d53051d 100644 --- a/libsandbox/trace.c +++ b/libsandbox/trace.c @@ -405,13 +405,16 @@ static void trace_loop(void) long ret; int status, sig; const struct syscall_entry *tbl_after_fork; + void *data; before_exec = true; before_syscall = false; fake_syscall_ret = false; tbl_after_fork = NULL; + data = NULL; do { - ret = do_ptrace(PTRACE_SYSCALL, NULL, NULL); + ret = do_ptrace(PTRACE_SYSCALL, NULL, data); + data = NULL; waitpid(trace_pid, &status, 0); event = (unsigned)status >> 16; @@ -444,7 +447,7 @@ static void trace_loop(void) * and we'll exit then. */ sb_debug("passing signal through %s (%i)", strsig(sig), sig); - do_ptrace(PTRACE_CONT, NULL, (void *)(uintptr_t)(sig)); + data = (void *)(uintptr_t)(sig); continue; }
