Avoid dereferencing curthread->td_proc->p_cred in DTrace probe context.
authormarkj <markj@FreeBSD.org>
Sun, 2 Aug 2015 00:11:56 +0000 (00:11 +0000)
committermarkj <markj@FreeBSD.org>
Sun, 2 Aug 2015 00:11:56 +0000 (00:11 +0000)
commit6f6b650c527203f4b216ec945b2d7ea7ea345231
treee68a50d2770d510d86188da1c7ed0cbc9985f4bf
parent01f99f4430fdfd5701198107d96895e40dfee9db
Avoid dereferencing curthread->td_proc->p_cred in DTrace probe context.

When a process is exiting, there is a narrow window where p_cred may be
NULL while its threads are still executing. Specifically, the last thread
to exit a process sets the process state to PRS_ZOMBIE with the proc
spinlock held and then calls thread_exit(). thread_exit() drops the spin
lock, permitting the process to be reaped and thus causing its cred struct
to be released. However, the exiting thread may still cause DTrace probes
to fire by calling sched_throw(), resulting in a double fault if such a
probe enabling attempts to access the GID or UID DIF variables.

The thread's cred reference is not susceptible to this race since it is not
released until after the thread has exited.

MFC after: 1 week
sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c