git: 844942888f7d - main - tests: Add a simple regression test for ptrace(PT_SC_REMOTE)
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 26 May 2023 20:06:53 UTC
The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=844942888f7d87885c79d87d808311086c664417 commit 844942888f7d87885c79d87d808311086c664417 Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2023-05-26 19:13:20 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2023-05-26 19:38:08 +0000 tests: Add a simple regression test for ptrace(PT_SC_REMOTE) MFC after: 1 week --- tests/sys/kern/ptrace_test.c | 55 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/tests/sys/kern/ptrace_test.c b/tests/sys/kern/ptrace_test.c index 9cee07639f0c..49670fbf102e 100644 --- a/tests/sys/kern/ptrace_test.c +++ b/tests/sys/kern/ptrace_test.c @@ -4318,9 +4318,61 @@ ATF_TC_BODY(ptrace__procdesc_reparent_wait_child, tc) REQUIRE_EQ(close(pd), 0); } -ATF_TP_ADD_TCS(tp) +/* + * Try using PT_SC_REMOTE to get the PID of a traced child process. + */ +ATF_TC_WITHOUT_HEAD(ptrace__PT_SC_REMOTE_getpid); +ATF_TC_BODY(ptrace__PT_SC_REMOTE_getpid, tc) { + struct ptrace_sc_remote pscr; + pid_t fpid, wpid; + int status; + + ATF_REQUIRE((fpid = fork()) != -1); + if (fpid == 0) { + trace_me(); + exit(0); + } + + attach_child(fpid); + + pscr.pscr_syscall = SYS_getpid; + pscr.pscr_nargs = 0; + pscr.pscr_args = NULL; + ATF_REQUIRE(ptrace(PT_SC_REMOTE, fpid, (caddr_t)&pscr, sizeof(pscr)) != + -1); + ATF_REQUIRE_MSG(pscr.pscr_ret.sr_error == 0, + "remote getpid failed with error %d", pscr.pscr_ret.sr_error); + ATF_REQUIRE_MSG(pscr.pscr_ret.sr_retval[0] == fpid, + "unexpected return value %lu instead of %d", + pscr.pscr_ret.sr_retval[0], fpid); + + wpid = waitpid(fpid, &status, 0); + REQUIRE_EQ(wpid, fpid); + ATF_REQUIRE(WIFSTOPPED(status)); + REQUIRE_EQ(WSTOPSIG(status), SIGSTOP); + pscr.pscr_syscall = SYS_getppid; + pscr.pscr_nargs = 0; + pscr.pscr_args = NULL; + ATF_REQUIRE(ptrace(PT_SC_REMOTE, fpid, (caddr_t)&pscr, sizeof(pscr)) != + -1); + ATF_REQUIRE_MSG(pscr.pscr_ret.sr_error == 0, + "remote getppid failed with error %d", pscr.pscr_ret.sr_error); + ATF_REQUIRE_MSG(pscr.pscr_ret.sr_retval[0] == getpid(), + "unexpected return value %lu instead of %d", + pscr.pscr_ret.sr_retval[0], fpid); + + wpid = waitpid(fpid, &status, 0); + REQUIRE_EQ(wpid, fpid); + ATF_REQUIRE(WIFSTOPPED(status)); + REQUIRE_EQ(WSTOPSIG(status), SIGSTOP); + + ATF_REQUIRE(ptrace(PT_DETACH, fpid, (caddr_t)1, 0) != -1); +} + +ATF_TP_ADD_TCS(tp) +{ ATF_TP_ADD_TC(tp, ptrace__parent_wait_after_trace_me); ATF_TP_ADD_TC(tp, ptrace__parent_wait_after_attach); ATF_TP_ADD_TC(tp, ptrace__parent_sees_exit_after_child_debugger); @@ -4384,6 +4436,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, ptrace__proc_reparent); ATF_TP_ADD_TC(tp, ptrace__procdesc_wait_child); ATF_TP_ADD_TC(tp, ptrace__procdesc_reparent_wait_child); + ATF_TP_ADD_TC(tp, ptrace__PT_SC_REMOTE_getpid); return (atf_no_error()); }