aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2009-04-01 09:19:23 -0400
committerMike Frysinger <vapier@gentoo.org>2009-04-05 03:54:02 -0400
commit3cb4b1d9dff9d301025d5eaaef546dd22a9c17a0 (patch)
treed527b24b487fb5d65f213ca9a0e423def0631674 /libsandbox
parentlibsandbox: tweak /proc/.../cmdline check for hardened (diff)
downloadsandbox-3cb4b1d9dff9d301025d5eaaef546dd22a9c17a0.tar.gz
sandbox-3cb4b1d9dff9d301025d5eaaef546dd22a9c17a0.tar.bz2
sandbox-3cb4b1d9dff9d301025d5eaaef546dd22a9c17a0.zip
libsandbox: fix slightly broken logic with ptrace() return
The code attempted to account for the PEEK requests returning -1 in the normal case via errno, but the logic was incorrect. This ended up flagging some successful ptrace() calls when the data returned was -1. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'libsandbox')
-rw-r--r--libsandbox/trace.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/libsandbox/trace.c b/libsandbox/trace.c
index fc58ab1..7df9570 100644
--- a/libsandbox/trace.c
+++ b/libsandbox/trace.c
@@ -30,15 +30,19 @@ static volatile bool child_stopped;
static long _do_ptrace(enum __ptrace_request request, const char *srequest, void *addr, void *data)
{
long ret;
- errno = 0;
try_again:
+ errno = 0;
ret = ptrace(request, trace_pid, addr, data);
- if (ret == -1 || (request == PTRACE_PEEKUSER && errno)) {
+ if (ret == -1) {
/* Child hasn't gotten to the next marker yet */
if (errno == ESRCH) {
sched_yield();
goto try_again;
- }
+ } else if (!errno)
+ if (request == PTRACE_PEEKDATA ||
+ request == PTRACE_PEEKTEXT ||
+ request == PTRACE_PEEKUSER)
+ return ret;
SB_EERROR("ISE:_do_ptrace ", "ptrace(%s, ..., %p, %p): %s\n",
srequest, addr, data, strerror(errno));
@@ -374,6 +378,9 @@ void trace_main(const char *filename, char *const argv[])
sa.sa_sigaction = trace_child_signal;
sigaction(SIGCHLD, &sa, &old_sa);
+ if (is_env_on(ENV_SANDBOX_DEBUG))
+ SB_EINFO("trace_main", " tracing: %s\n", filename);
+
trace_pid = fork();
if (trace_pid == -1) {
SB_EERROR("ISE:trace_main ", "vfork() failed: %s\n",