kernel - Fix rare allproc scan vs p_ucred race
authorMatthew Dillon <dillon@apollo.backplane.com>
Wed, 27 Sep 2017 04:31:04 +0000 (21:31 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Wed, 27 Sep 2017 04:34:52 +0000 (21:34 -0700)
commit6cbfbdb972fd2d15f247741880322725f3ce638a
treec5639f81bfbbf7df96ef4bb074c01a3f640f37fc
parent7adf09fa6578cf272287f7aa5ee8f3dec69027d2
kernel - Fix rare allproc scan vs p_ucred race

* This race can occur because p->p_ucred can change out from under
  an allproc scan when the allproc scan is filtering based on
  credentials.

* Access p->p_ucred via the per-process spinlock (p->p_spin).  Also
  maintain a  cache of the last ucred during the loop in order to
  avoid having to spin-lock every process.

* Add missing spinlock around p->p_ucred = NULL in exit1().  This
  is also only applicable to races against allproc scans since
  p_token is held during exit1().

Reported-by: mjg_
sys/kern/kern_exit.c
sys/kern/kern_proc.c
sys/sys/proc.h