diff options
author | 2021-10-31 19:50:01 -0400 | |
---|---|---|
committer | 2021-10-31 19:50:01 -0400 | |
commit | d8b9a41d76de38cab079951cd494cdb491b55126 (patch) | |
tree | ddcbeb804527cec98f8b542a3a80d9d1b697c1e3 | |
parent | libsandbox: drop args to trace_main (diff) | |
download | sandbox-d8b9a41d76de38cab079951cd494cdb491b55126.tar.gz sandbox-d8b9a41d76de38cab079951cd494cdb491b55126.tar.bz2 sandbox-d8b9a41d76de38cab079951cd494cdb491b55126.zip |
libsandbox: do not use ptrace if it returns ENOSYS
QEMU's linux-user does not implement ptrace for any architecture, and
any attempt to call it fails with ENOSYS. Detect that scenario.
Closes: https://bugs.gentoo.org/648516
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r-- | libsandbox/trace.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/libsandbox/trace.c b/libsandbox/trace.c index 4e01f6e..4ae58aa 100644 --- a/libsandbox/trace.c +++ b/libsandbox/trace.c @@ -584,8 +584,14 @@ static char *flatten_args(char *const argv[]) bool trace_possible(const char *filename, char *const argv[], const void *data) { - if (_trace_possible(data)) - return true; + if (_trace_possible(data)) { + /* If we're in an environment like QEMU where ptrace doesn't work, then + * don't try to use it. If ptrace does work, this should fail with ESRCH. + */ + errno = 0; + ptrace(PTRACE_CONT, 0, NULL, NULL); + return errno == ENOSYS ? false : true; + } char *args = flatten_args(argv); sb_eqawarn("Unable to trace static ELF: %s: %s\n", filename, args); |