summaryrefslogtreecommitdiffhomepage
path: root/test/syscalls/linux
diff options
context:
space:
mode:
authorAndrei Vagin <avagin@google.com>2019-02-11 18:04:29 -0800
committerShentubot <shentubot@google.com>2019-02-11 18:05:34 -0800
commit3ff9dc9cc1f69605f9e9e3c028d81957c37349a3 (patch)
treeca6d658f7a38fa5564af39113eb115c020a686f0 /test/syscalls/linux
parentecce96bab56de3aedd7d5cf47a6981f0f56acba1 (diff)
gvisor: check that ptrace properly handles int3
PiperOrigin-RevId: 233516412 Change-Id: I7a0f1443de7eeebb5d8ad59e4759ca2e036a3c4d
Diffstat (limited to 'test/syscalls/linux')
-rw-r--r--test/syscalls/linux/ptrace.cc38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/syscalls/linux/ptrace.cc b/test/syscalls/linux/ptrace.cc
index f063cc92b..6f1701aef 100644
--- a/test/syscalls/linux/ptrace.cc
+++ b/test/syscalls/linux/ptrace.cc
@@ -809,6 +809,44 @@ TEST(PtraceTest,
// These tests requires knowledge of architecture-specific syscall convention.
#ifdef __x86_64__
+TEST(PtraceTest, Int3) {
+ switch (GvisorPlatform()) {
+ case Platform::kKVM:
+ // TODO: int3 isn't handled properly.
+ return;
+ default:
+ break;
+ }
+ pid_t const child_pid = fork();
+ if (child_pid == 0) {
+ // In child process.
+
+ // Enable tracing.
+ TEST_PCHECK(ptrace(PTRACE_TRACEME, 0, 0, 0) == 0);
+
+ // Interrupt 3 - trap to debugger
+ asm("int3");
+
+ _exit(56);
+ }
+ // In parent process.
+ ASSERT_THAT(child_pid, SyscallSucceeds());
+
+ int status;
+ ASSERT_THAT(waitpid(child_pid, &status, 0),
+ SyscallSucceedsWithValue(child_pid));
+ EXPECT_TRUE(WIFSTOPPED(status) && WSTOPSIG(status) == SIGTRAP)
+ << " status " << status;
+
+ ASSERT_THAT(ptrace(PTRACE_CONT, child_pid, 0, 0), SyscallSucceeds());
+
+ // The child should validate the injected return value and then exit normally.
+ ASSERT_THAT(waitpid(child_pid, &status, 0),
+ SyscallSucceedsWithValue(child_pid));
+ EXPECT_TRUE(WIFEXITED(status) && WEXITSTATUS(status) == 56)
+ << " status " << status;
+}
+
TEST(PtraceTest, Sysemu_PokeUser) {
constexpr int kSysemuHelperFirstExitCode = 126;
constexpr uint64_t kSysemuInjectedExitGroupReturn = 42;