- proc_lock(p);
- SET(p->p_lflag, P_LTRACED);
- /* Non-attached case, our tracer is our parent. */
- p->p_oppid = p->p_ppid;
- /* Check whether child and parent are allowed to run modified
- * code (they'll have to) */
- struct proc *pproc=proc_find(p->p_oppid);
- proc_unlock(p);
- cs_allow_invalid(p);
- if(pproc) {
+retry_trace_me:;
+ proc_t pproc = proc_parent(p);
+ if (pproc == NULL)
+ return (EINVAL);
+#if CONFIG_MACF
+ /*
+ * NB: Cannot call kauth_authorize_process(..., KAUTH_PROCESS_CANTRACE, ...)
+ * since that assumes the process being checked is the current process
+ * when, in this case, it is the current process's parent.
+ * Most of the other checks in cantrace() don't apply either.
+ */
+ if ((error = mac_proc_check_debug(pproc, p)) == 0) {
+#endif
+ proc_lock(p);
+ /* Make sure the process wasn't re-parented. */
+ if (p->p_ppid != pproc->p_pid) {
+ proc_unlock(p);
+ proc_rele(pproc);
+ goto retry_trace_me;
+ }
+ SET(p->p_lflag, P_LTRACED);
+ /* Non-attached case, our tracer is our parent. */
+ p->p_oppid = p->p_ppid;
+ proc_unlock(p);
+ /* Child and parent will have to be able to run modified code. */
+ cs_allow_invalid(p);