kernel - Fix race between procfs / proc sysctls and exec, refactor PHOLD/etc
authorMatthew Dillon <dillon@apollo.backplane.com>
Thu, 1 Dec 2011 04:29:15 +0000 (20:29 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Thu, 1 Dec 2011 04:29:15 +0000 (20:29 -0800)
commit82354ad856881fcddea37e6fbb8dae0a683f2ffb
tree5fc5e6c681a69583630bdf884f5d35893683f895
parentb5e19bf65311748dd2ba0922b8778373d2ab4916
kernel - Fix race between procfs / proc sysctls and exec, refactor PHOLD/etc

* During a [v]fork/exec sequence the exec will replace the VM space of the
  target process.  A concurrent 'ps' operation could access the target
  process's vmspace as it was being ripped out, resulting in memory
  corruption.

* The P_INEXEC test in procfs was insufficient, the exec code itself must
  also wait for procfs's PHOLD() on the process to go away before it can
  proceed.  This should properly interlock the entire operation.

* Can occur with procfs or non-procfs ps's (via proc sysctls).

* Possibly related to the seg-fault issue we have where the user stack gets
  corrupted.

* Also revamp PHOLD()/PRELE() and add PSTALL(), changing all manual while()
  loops waiting on p->p_lock to use PSTALL().

  These functions now integrate a wakeup request flag into p->p_lock
  using atomic ops and no longer tsleep() for 1 tick (or hz ticks, or
  whatever).  Wakeups are issued proactively.
sys/kern/kern_exec.c
sys/kern/kern_exit.c
sys/kern/kern_proc.c
sys/sys/proc.h
sys/vfs/procfs/procfs_mem.c