diff --git a/sandboxed_api/sandbox2/monitor.cc b/sandboxed_api/sandbox2/monitor.cc index 0e44d86..d3e69b6 100644 --- a/sandboxed_api/sandbox2/monitor.cc +++ b/sandboxed_api/sandbox2/monitor.cc @@ -440,7 +440,8 @@ void Monitor::MainLoop(sigset_t* sset) { } else if (WIFSTOPPED(status)) { VLOG(2) << "PID: " << ret << " received signal: " << util::GetSignalName(WSTOPSIG(status)) - << " with event: " << __WPTRACEEVENT(status); + << " with event: " + << util::GetPtraceEventName(__WPTRACEEVENT(status)); StateProcessStopped(ret, status); } else if (WIFCONTINUED(status)) { VLOG(2) << "PID: " << ret << " is being continued"; diff --git a/sandboxed_api/sandbox2/util.cc b/sandboxed_api/sandbox2/util.cc index 4b8c402..8670700 100644 --- a/sandboxed_api/sandbox2/util.cc +++ b/sandboxed_api/sandbox2/util.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -283,6 +284,33 @@ std::string GetRlimitName(int resource) { } } +std::string GetPtraceEventName(int event) { +#if !defined(PTRACE_EVENT_STOP) +#define PTRACE_EVENT_STOP 128 +#endif + + switch (event) { + case PTRACE_EVENT_FORK: + return "PTRACE_EVENT_FORK"; + case PTRACE_EVENT_VFORK: + return "PTRACE_EVENT_VFORK"; + case PTRACE_EVENT_CLONE: + return "PTRACE_EVENT_CLONE"; + case PTRACE_EVENT_EXEC: + return "PTRACE_EVENT_EXEC"; + case PTRACE_EVENT_VFORK_DONE: + return "PTRACE_EVENT_VFORK_DONE"; + case PTRACE_EVENT_EXIT: + return "PTRACE_EVENT_EXIT"; + case PTRACE_EVENT_SECCOMP: + return "PTRACE_EVENT_SECCOMP"; + case PTRACE_EVENT_STOP: + return "PTRACE_EVENT_STOP"; + default: + return absl::StrCat("UNKNOWN: ", event); + } +} + absl::StatusOr ReadCPathFromPid(pid_t pid, uintptr_t ptr) { std::string path(PATH_MAX, '\0'); iovec local_iov[] = {{&path[0], path.size()}}; diff --git a/sandboxed_api/sandbox2/util.h b/sandboxed_api/sandbox2/util.h index 0aaf8f4..95f52cc 100644 --- a/sandboxed_api/sandbox2/util.h +++ b/sandboxed_api/sandbox2/util.h @@ -71,6 +71,9 @@ std::string GetSignalName(int signo); // Returns rlimit resource name std::string GetRlimitName(int resource); +// Returns ptrace event name +std::string GetPtraceEventName(int event); + // Reads a path string (NUL-terminated, shorter than PATH_MAX) from another // process memory absl::StatusOr ReadCPathFromPid(pid_t pid, uintptr_t ptr);