Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F168559281
D20361.id60485.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D20361.id60485.diff
View Options
Index: head/sys/kern/sys_procdesc.c
===================================================================
--- head/sys/kern/sys_procdesc.c
+++ head/sys/kern/sys_procdesc.c
@@ -416,7 +416,13 @@
* terminate with prejudice.
*/
p->p_sigparent = SIGCHLD;
- proc_reparent(p, p->p_reaper, true);
+ if ((p->p_flag & P_TRACED) == 0) {
+ proc_reparent(p, p->p_reaper, true);
+ } else {
+ clear_orphan(p);
+ p->p_oppid = p->p_reaper->p_pid;
+ proc_add_orphan(p, p->p_reaper);
+ }
if ((pd->pd_flags & PDF_DAEMON) == 0)
kern_psignal(p, SIGKILL);
PROC_UNLOCK(p);
Index: head/tests/sys/kern/ptrace_test.c
===================================================================
--- head/tests/sys/kern/ptrace_test.c
+++ head/tests/sys/kern/ptrace_test.c
@@ -32,6 +32,7 @@
#include <sys/file.h>
#include <sys/time.h>
#include <sys/procctl.h>
+#include <sys/procdesc.h>
#include <sys/ptrace.h>
#include <sys/queue.h>
#include <sys/runq.h>
@@ -4075,6 +4076,60 @@
ATF_REQUIRE(errno == ECHILD);
}
+/*
+ * Verify that when the process is traced that it isn't reparent
+ * to the init process when we close all process descriptors.
+ */
+ATF_TC(ptrace__proc_reparent);
+ATF_TC_HEAD(ptrace__proc_reparent, tc)
+{
+
+ atf_tc_set_md_var(tc, "timeout", "2");
+}
+ATF_TC_BODY(ptrace__proc_reparent, tc)
+{
+ pid_t traced, debuger, wpid;
+ int pd, status;
+
+ traced = pdfork(&pd, 0);
+ ATF_REQUIRE(traced >= 0);
+ if (traced == 0) {
+ raise(SIGSTOP);
+ exit(0);
+ }
+ ATF_REQUIRE(pd >= 0);
+
+ debuger = fork();
+ ATF_REQUIRE(debuger >= 0);
+ if (debuger == 0) {
+ /* The traced process is reparented to debuger. */
+ ATF_REQUIRE(ptrace(PT_ATTACH, traced, 0, 0) == 0);
+ wpid = waitpid(traced, &status, 0);
+ ATF_REQUIRE(wpid == traced);
+ ATF_REQUIRE(WIFSTOPPED(status));
+ ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
+ ATF_REQUIRE(close(pd) == 0);
+ ATF_REQUIRE(ptrace(PT_DETACH, traced, (caddr_t)1, 0) == 0);
+
+ /* We closed pd so we should not have any child. */
+ wpid = wait(&status);
+ ATF_REQUIRE(wpid == -1);
+ ATF_REQUIRE(errno == ECHILD);
+
+ exit(0);
+ }
+
+ ATF_REQUIRE(close(pd) == 0);
+ wpid = waitpid(debuger, &status, 0);
+ ATF_REQUIRE(wpid == debuger);
+ ATF_REQUIRE(WEXITSTATUS(status) == 0);
+
+ /* Check if we still have any child. */
+ wpid = wait(&status);
+ ATF_REQUIRE(wpid == -1);
+ ATF_REQUIRE(errno == ECHILD);
+}
+
ATF_TP_ADD_TCS(tp)
{
@@ -4137,6 +4192,7 @@
#endif
ATF_TP_ADD_TC(tp, ptrace__PT_LWPINFO_stale_siginfo);
ATF_TP_ADD_TC(tp, ptrace__syscall_args);
+ ATF_TP_ADD_TC(tp, ptrace__proc_reparent);
return (atf_no_error());
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Aug 30, 12:49 AM (30 m, 13 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
37552881
Default Alt Text
D20361.id60485.diff (2 KB)
Attached To
Mode
D20361: procdesc: fix reparenting when the debugger is attached
Attached
Detach File
Event Timeline
Log In to Comment