git: kernel - Fix race between procfs / proc sysctls and exec, refactor PHOLD/etc

Matthew Dillon dillon at crater.dragonflybsd.org
Wed Nov 30 20:39:23 PST 2011


commit 82354ad856881fcddea37e6fbb8dae0a683f2ffb
Author: Matthew Dillon <dillon at apollo.backplane.com>
Date:   Wed Nov 30 20:29:15 2011 -0800

    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.

Summary of changes:
 sys/kern/kern_exec.c        |   12 ++++++
 sys/kern/kern_exit.c        |   27 +++++++-----
 sys/kern/kern_proc.c        |   93 ++++++++++++++++++++++++++++++++++++++++---
 sys/sys/proc.h              |    9 +++-
 sys/vfs/procfs/procfs_mem.c |    3 +-
 5 files changed, 124 insertions(+), 20 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/82354ad856881fcddea37e6fbb8dae0a683f2ffb


-- 
DragonFly BSD source repository





More information about the Commits mailing list