kernel - Fix rare ucred race
* In a threaded program if one thread is modifying the ucred, e.g.
changing the uid or gid or something like that, and another thread
enters a system call at the same time, the second thread can wind
up trying to hold a stale ucred kfree()'d by the first thread.
* Very rare race on top of a ~2-instruction window.
* Fix the problem by obtaining proc->p_spin when updating the per-thread
ucred cache (td->td_ucred) from p->p_ucred, as well as when replacing
p_ucred.
These fixes do NOT impose any critical-path overhead. For the case where
a thread already has the current p_ucred cached on entry to a system call,
absolutely nothing needs to be done.
Reported-by: joris (Joris Giovannangeli)