From 3ff9dc9cc1f69605f9e9e3c028d81957c37349a3 Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Mon, 11 Feb 2019 18:04:29 -0800 Subject: gvisor: check that ptrace properly handles int3 PiperOrigin-RevId: 233516412 Change-Id: I7a0f1443de7eeebb5d8ad59e4759ca2e036a3c4d --- test/syscalls/linux/ptrace.cc | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test/syscalls') 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; -- cgit v1.2.3