1 |
commit: d8b9a41d76de38cab079951cd494cdb491b55126 |
2 |
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Oct 31 23:50:01 2021 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Oct 31 23:50:01 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=d8b9a41d |
7 |
|
8 |
libsandbox: do not use ptrace if it returns ENOSYS |
9 |
|
10 |
QEMU's linux-user does not implement ptrace for any architecture, and |
11 |
any attempt to call it fails with ENOSYS. Detect that scenario. |
12 |
|
13 |
Closes: https://bugs.gentoo.org/648516 |
14 |
Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org> |
15 |
|
16 |
libsandbox/trace.c | 10 ++++++++-- |
17 |
1 file changed, 8 insertions(+), 2 deletions(-) |
18 |
|
19 |
diff --git a/libsandbox/trace.c b/libsandbox/trace.c |
20 |
index 4e01f6e..4ae58aa 100644 |
21 |
--- a/libsandbox/trace.c |
22 |
+++ b/libsandbox/trace.c |
23 |
@@ -584,8 +584,14 @@ static char *flatten_args(char *const argv[]) |
24 |
|
25 |
bool trace_possible(const char *filename, char *const argv[], const void *data) |
26 |
{ |
27 |
- if (_trace_possible(data)) |
28 |
- return true; |
29 |
+ if (_trace_possible(data)) { |
30 |
+ /* If we're in an environment like QEMU where ptrace doesn't work, then |
31 |
+ * don't try to use it. If ptrace does work, this should fail with ESRCH. |
32 |
+ */ |
33 |
+ errno = 0; |
34 |
+ ptrace(PTRACE_CONT, 0, NULL, NULL); |
35 |
+ return errno == ENOSYS ? false : true; |
36 |
+ } |
37 |
|
38 |
char *args = flatten_args(argv); |
39 |
sb_eqawarn("Unable to trace static ELF: %s: %s\n", filename, args); |