Index: sys/kern/kern_thread.c =================================================================== --- sys/kern/kern_thread.c +++ sys/kern/kern_thread.c @@ -936,6 +936,14 @@ } /* + * Catch-all for other return codes for the case where + * the process is in a suspending state, but we were + * required to not suspend right now. + */ + if (return_instead) + return (ERESTART); + + /* * If the process is waiting for us to exit, * this thread should just suicide. * Assumes that P_SINGLE_EXIT implies P_STOPPED_SINGLE. Index: sys/kern/sys_process.c =================================================================== --- sys/kern/sys_process.c +++ sys/kern/sys_process.c @@ -744,12 +744,23 @@ */ switch (req) { case PT_TRACE_ME: - /* Always legal. */ + /* + * Always legal, when there is a parent process which + * could trace us. Otherwise, reject. + */ + if ((p->p_flag & P_TRACED) != 0) { + error = EBUSY; + goto fail; + } + if (p->p_pptr == initproc) { + error = EPERM; + goto fail; + } break; case PT_ATTACH: /* Self */ - if (p->p_pid == td->td_proc->p_pid) { + if (p == td->td_proc) { error = EINVAL; goto fail; }