Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F159321914
D57485.id179322.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D57485.id179322.diff
View Options
diff --git a/tests/sys/kern/ptrace_test.c b/tests/sys/kern/ptrace_test.c
--- a/tests/sys/kern/ptrace_test.c
+++ b/tests/sys/kern/ptrace_test.c
@@ -26,6 +26,8 @@
#include <sys/types.h>
#include <sys/cpuset.h>
#include <sys/elf.h>
+#define _WANT_KERNEL_ERRNO
+#include <sys/errno.h>
#include <sys/event.h>
#include <sys/file.h>
#include <sys/mman.h>
@@ -4472,6 +4474,107 @@
ATF_REQUIRE(ptrace(PT_DETACH, fpid, (caddr_t)1, 0) != -1);
}
+ATF_TC_WITHOUT_HEAD(ptrace__PT_SC_REMOTE_exit);
+ATF_TC_BODY(ptrace__PT_SC_REMOTE_exit, tc)
+{
+ struct ptrace_sc_remote pscr;
+ syscallarg_t args[1];
+ pid_t fpid, wpid;
+ int status;
+
+ ATF_REQUIRE((fpid = fork()) != -1);
+ if (fpid == 0) {
+ trace_me();
+ exit(0);
+ }
+
+ wpid = waitpid(fpid, &status, 0);
+ REQUIRE_EQ(wpid, fpid);
+ ATF_REQUIRE(WIFSTOPPED(status));
+ REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
+
+ args[0] = 42;
+ pscr.pscr_syscall = SYS_exit;
+ pscr.pscr_nargs = 1;
+ pscr.pscr_args = args;
+ ATF_REQUIRE(ptrace(PT_SC_REMOTE, fpid, (caddr_t)&pscr,
+ sizeof(pscr)) != -1);
+
+ wpid = waitpid(fpid, &status, 0);
+ REQUIRE_EQ(wpid, fpid);
+ ATF_REQUIRE(WIFEXITED(status));
+ REQUIRE_EQ(WEXITSTATUS(status), 42);
+}
+
+ATF_TC_WITHOUT_HEAD(ptrace__PT_SC_REMOTE_execve);
+ATF_TC_BODY(ptrace__PT_SC_REMOTE_execve, tc)
+{
+ struct ptrace_sc_remote pscr;
+ syscallarg_t args[3];
+ char *ping_path;
+ char *argv[5];
+ char *envp[1];
+ pid_t fpid, wpid;
+ int status;
+
+ ping_path = __DECONST(char *, "/sbin/ping");
+ argv[0] = ping_path;
+ argv[1] = __DECONST(char *, "-c");
+ argv[2] = __DECONST(char *, "1");
+ argv[3] = __DECONST(char *, "localhost");
+ argv[4] = NULL;
+ envp[0] = NULL;
+
+ ATF_REQUIRE((fpid = fork()) != -1);
+ if (fpid == 0) {
+ trace_me();
+ exit(0);
+ }
+
+ wpid = waitpid(fpid, &status, 0);
+ REQUIRE_EQ(wpid, fpid);
+ ATF_REQUIRE(WIFSTOPPED(status));
+ REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
+
+ args[0] = (syscallarg_t)ping_path;
+ args[1] = (syscallarg_t)argv;
+ args[2] = (syscallarg_t)envp;
+ pscr.pscr_syscall = SYS_execve;
+ pscr.pscr_nargs = 3;
+ pscr.pscr_args = args;
+ ATF_REQUIRE(ptrace(PT_SC_REMOTE, fpid, (caddr_t)&pscr,
+ sizeof(pscr)) != -1);
+ /* EJUSTRETURN here is an implementation detail. */
+ REQUIRE_EQ(pscr.pscr_ret.sr_error, EJUSTRETURN);
+
+ wpid = waitpid(fpid, &status, 0);
+ REQUIRE_EQ(wpid, fpid);
+ ATF_REQUIRE(WIFSTOPPED(status));
+ REQUIRE_EQ(WSTOPSIG(status), SIGSTOP);
+
+ {
+ struct kinfo_proc kp;
+ size_t len;
+ int mib[4];
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PROC;
+ mib[2] = KERN_PROC_PID;
+ mib[3] = fpid;
+ len = sizeof(kp);
+ ATF_REQUIRE(sysctl(mib, nitems(mib), &kp, &len, NULL, 0) == 0);
+ ATF_REQUIRE_STREQ(kp.ki_comm, "ping");
+ }
+
+ /* Let the child (now ping) run to completion. */
+ ATF_REQUIRE(ptrace(PT_DETACH, fpid, (caddr_t)1, 0) != -1);
+
+ wpid = waitpid(fpid, &status, 0);
+ REQUIRE_EQ(wpid, fpid);
+ ATF_REQUIRE(WIFEXITED(status));
+ REQUIRE_EQ(WEXITSTATUS(status), 0);
+}
+
/*
* Ensure that procctl(PROC_REAP_KILL) won't block forever waiting for a target
* process that stopped to report its status to a debugger.
@@ -4712,6 +4815,8 @@
ATF_TP_ADD_TC(tp, ptrace__procdesc_reparent_wait_child);
ATF_TP_ADD_TC(tp, ptrace__PT_SC_REMOTE_getpid);
ATF_TP_ADD_TC(tp, ptrace__PT_SC_REMOTE_syscall_validation);
+ ATF_TP_ADD_TC(tp, ptrace__PT_SC_REMOTE_exit);
+ ATF_TP_ADD_TC(tp, ptrace__PT_SC_REMOTE_execve);
ATF_TP_ADD_TC(tp, ptrace__reap_kill_stopped);
ATF_TP_ADD_TC(tp, ptrace__PT_ATTACH_no_EINTR);
ATF_TP_ADD_TC(tp, ptrace__PT_DETACH_continued);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jun 13, 8:57 PM (15 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33789582
Default Alt Text
D57485.id179322.diff (3 KB)
Attached To
Mode
D57485: tests/ptrace: Validate PT_SC_REMOTE with some tricky syscalls
Attached
Detach File
Event Timeline
Log In to Comment