]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/dev/dtrace/dtrace.c
xnu-1228.7.58.tar.gz
[apple/xnu.git] / bsd / dev / dtrace / dtrace.c
index 9f2be77c494a6360cefa708cdfb580443dc20136..c28ae6f0b7cc32f092e83ef615ae6df2c608890e 100644 (file)
@@ -1003,6 +1003,11 @@ dtrace_priv_proc_destructive(dtrace_state_t *state)
 {
        int action = state->dts_cred.dcr_action;
 
+#if defined(__APPLE__)
+       if (ISSET(current_proc()->p_lflag, P_LNOATTACH))
+               goto bad;
+#endif /* __APPLE__ */
+
        if (((action & DTRACE_CRA_PROC_DESTRUCTIVE_ALLZONE) == 0) &&
            dtrace_priv_proc_common_zone(state) == 0)
                goto bad;
@@ -1026,6 +1031,11 @@ bad:
 static int
 dtrace_priv_proc_control(dtrace_state_t *state)
 {
+#if defined(__APPLE__)
+       if (ISSET(current_proc()->p_lflag, P_LNOATTACH))
+               goto bad;
+#endif /* __APPLE__ */
+
        if (state->dts_cred.dcr_action & DTRACE_CRA_PROC_CONTROL)
                return (1);
 
@@ -1034,6 +1044,9 @@ dtrace_priv_proc_control(dtrace_state_t *state)
            dtrace_priv_proc_common_nocd())
                return (1);
 
+#if defined(__APPLE__)
+bad:
+#endif /* __APPLE__ */
        cpu_core[CPU->cpu_id].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV;
 
        return (0);
@@ -1042,6 +1055,28 @@ dtrace_priv_proc_control(dtrace_state_t *state)
 static int
 dtrace_priv_proc(dtrace_state_t *state)
 {
+#if defined(__APPLE__)
+       if (ISSET(current_proc()->p_lflag, P_LNOATTACH))
+               goto bad;
+#endif /* __APPLE__ */
+
+       if (state->dts_cred.dcr_action & DTRACE_CRA_PROC)
+               return (1);
+
+#if defined(__APPLE__)
+bad:
+#endif /* __APPLE__ */
+       cpu_core[CPU->cpu_id].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV;
+
+       return (0);
+}
+
+#if defined(__APPLE__)
+/* dtrace_priv_proc() omitting the P_LNOATTACH check. For PID and EXECNAME accesses. */
+static int
+dtrace_priv_proc_relaxed(dtrace_state_t *state)
+{
+
        if (state->dts_cred.dcr_action & DTRACE_CRA_PROC)
                return (1);
 
@@ -1049,6 +1084,7 @@ dtrace_priv_proc(dtrace_state_t *state)
 
        return (0);
 }
+#endif /* __APPLE__ */
 
 static int
 dtrace_priv_kernel(dtrace_state_t *state)
@@ -2688,7 +2724,7 @@ dtrace_dif_variable(dtrace_mstate_t *mstate, dtrace_state_t *state, uint64_t v,
 
 #else
        case DIF_VAR_PID:
-               if (!dtrace_priv_proc(state))
+               if (!dtrace_priv_proc_relaxed(state))
                        return (0);
 
                /*
@@ -2717,7 +2753,7 @@ dtrace_dif_variable(dtrace_mstate_t *mstate, dtrace_state_t *state, uint64_t v,
                return ((uint64_t)curthread->t_procp->p_ppid);
 #else
        case DIF_VAR_PPID:
-               if (!dtrace_priv_proc(state))
+               if (!dtrace_priv_proc_relaxed(state))
                        return (0);
 
                /*
@@ -2779,7 +2815,7 @@ dtrace_dif_variable(dtrace_mstate_t *mstate, dtrace_state_t *state, uint64_t v,
                    mstate->dtms_scratch_base + mstate->dtms_scratch_size)
                        return 0;
                        
-               if (!dtrace_priv_proc(state))
+               if (!dtrace_priv_proc_relaxed(state))
                        return (0);
 
                mstate->dtms_scratch_ptr += scratch_size;
@@ -3040,7 +3076,12 @@ dtrace_dif_subr(uint_t subr, uint_t rd, uint64_t *regs,
 
                if (subr == DIF_SUBR_COPYIN) {
                        DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
+#if !defined(__APPLE__)
                        dtrace_copyin(tupregs[0].dttk_value, dest, size);
+#else
+                       if (dtrace_priv_proc(state))
+                               dtrace_copyin(tupregs[0].dttk_value, dest, size);
+#endif /* __APPLE__ */
                        DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
                }
 
@@ -3065,7 +3106,12 @@ dtrace_dif_subr(uint_t subr, uint_t rd, uint64_t *regs,
                }
 
                DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
+#if !defined(__APPLE__)
                dtrace_copyin(tupregs[0].dttk_value, dest, size);
+#else
+               if (dtrace_priv_proc(state))
+                       dtrace_copyin(tupregs[0].dttk_value, dest, size);
+#endif /* __APPLE__ */
                DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
                break;
        }
@@ -3090,7 +3136,12 @@ dtrace_dif_subr(uint_t subr, uint_t rd, uint64_t *regs,
                }
 
                DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
+#if !defined(__APPLE__)
                dtrace_copyinstr(tupregs[0].dttk_value, dest, size);
+#else
+               if (dtrace_priv_proc(state))
+                       dtrace_copyinstr(tupregs[0].dttk_value, dest, size);
+#endif /* __APPLE__ */
                DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
 
                ((char *)dest)[size - 1] = '\0';
@@ -5295,6 +5346,31 @@ __dtrace_probe(dtrace_id_t id, uint64_t arg0, uint64_t arg1,
        now = dtrace_gethrtime(); /* must not precede dtrace_calc_thread_recent_vtime() call! */
 #endif /* __APPLE__ */
 
+#if defined(__APPLE__)
+       /*
+        * A provider may call dtrace_probe_error() in lieu of dtrace_probe() in some circumstances.
+        * See, e.g. fasttrap_isa.c. However the provider has no access to ECB context, so passes
+        * NULL through "arg0" and the probe_id of the ovedrriden probe as arg1. Detect that here
+        * and cons up a viable state (from the probe_id).
+        */
+       if (dtrace_probeid_error == id && NULL == arg0) {
+               dtrace_id_t ftp_id = (dtrace_id_t)arg1;
+               dtrace_probe_t *ftp_probe = dtrace_probes[ftp_id - 1];
+               dtrace_ecb_t *ftp_ecb = ftp_probe->dtpr_ecb;
+
+               if (NULL != ftp_ecb) {
+                       dtrace_state_t *ftp_state = ftp_ecb->dte_state;
+
+                       arg0 = (uint64_t)(uintptr_t)ftp_state;
+                       arg1 = ftp_ecb->dte_epid;
+                       /*
+                        * args[2-4] established by caller.
+                        */
+                       ftp_state->dts_arg_error_illval = -1; /* arg5 */
+               }
+       }
+#endif /* __APPLE__ */
+
        mstate.dtms_probe = probe;
        mstate.dtms_arg[0] = arg0;
        mstate.dtms_arg[1] = arg1;
@@ -5368,16 +5444,6 @@ __dtrace_probe(dtrace_id_t id, uint64_t arg0, uint64_t arg1,
                        }
                }
 
-#if defined(__APPLE__)
-        /*
-         * If the thread on which this probe has fired belongs to a process marked P_LNOATTACH
-         * then this enabling is not permitted to observe it. Move along, nothing to see here.
-         */
-        if (ISSET(current_proc()->p_lflag, P_LNOATTACH)) {
-            continue;
-        }
-#endif /* __APPLE__ */
-
                if (ecb->dte_cond) {
                        /*
                         * If the dte_cond bits indicate that this