freebsd-skq/sys
delphij 8cc8bccf58 Close race conditions between fork() and [sg]etpriority()'s
PRIO_USER case, possibly also other places that deferences
p_ucred.

In the past, we insert a new process into the allproc list right
after PID allocation, and release the allproc_lock sx.  Because
most content in new proc's structure is not yet initialized,
this could lead to undefined result if we do not handle PRS_NEW
with care.

The problem with PRS_NEW state is that it does not provide fine
grained information about how much initialization is done for a
new process.  By defination, after PRIO_USER setpriority(), all
processes that belongs to given user should have their nice value
set to the specified value.  Therefore, if p_{start,end}copy
section was done for a PRS_NEW process, we can not safely ignore
it because p_nice is in this area.  On the other hand, we should
be careful on PRS_NEW processes because we do not allow non-root
users to lower their nice values, and without a successful copy
of the copy section, we can get stale values that is inherted
from the uninitialized area of the process structure.

This commit tries to close the race condition by grabbing proc
mutex *before* we release allproc_lock xlock, and do copy as
well as zero immediately after the allproc_lock xunlock.  This
guarantees that the new process would have its p_copy and p_zero
sections, as well as user credential informaion initialized.  In
getpriority() case, instead of grabbing PROC_LOCK for a PRS_NEW
process, we just skip the process in question, because it does
not affect the final result of the call, as the p_nice value
would be copied from its parent, and we will see it during
allproc traverse.

Other potential solutions are still under evaluation.

Discussed with:	davidxu, jhb, rwatson
PR:		kern/108071
MFC after:	2 weeks
2007-02-26 03:38:09 +00:00
..
amd64 Partial MFp4 of 114977: 2007-02-24 16:49:25 +00:00
arm Define FLASHADDR and LOADERRAMADDR for the Avila, so that we can boot a 2007-02-26 02:04:24 +00:00
boot Fix the cdboot twiddle display. 2007-02-23 21:07:44 +00:00
bsm Merge OpenBSM 1.0 alpha 12 import changes into src/sys/bsm. New events 2006-09-25 12:22:07 +00:00
cam Add an xpt_rescan function and a thread that will field 2007-02-23 05:47:36 +00:00
coda coda_vptofh is never defined nor used. 2007-02-02 15:47:28 +00:00
compat MFp4 (110541): 2007-02-25 12:43:07 +00:00
conf Make IPv6 multicast forwarding dynamically loadable from a GENERIC kernel. 2007-02-24 11:38:47 +00:00
contrib o break newbus api: add a new argument of type driver_filter_t to 2007-02-23 12:19:07 +00:00
crypto Initialize T1 to silent gcc warning. 2006-10-22 02:19:33 +00:00
ddb Use FOREACH_PROC_IN_SYSTEM instead of using its unrolled form. 2007-01-17 15:05:52 +00:00
dev Catch up with bus_setup_intr() modification and garbage collect two 2007-02-25 15:02:03 +00:00
fs Check that the error returned by vfs_getopts() is not ENOENT before assuming 2007-02-21 00:30:09 +00:00
gdb
geom Use tsleep() rather than msleep() with a NULL mtx parameter. 2007-02-23 23:06:10 +00:00
gnu Move vnode-to-file-handle translation from vfs_vptofh to vop_vptofh method. 2007-02-15 22:08:35 +00:00
i4b o break newbus api: add a new argument of type driver_filter_t to 2007-02-24 02:28:07 +00:00
i386 Partial MFp4 of 114977: 2007-02-24 16:49:25 +00:00
ia64 Updated ia64 isa support with the new bus_setup_intr() syntax. 2007-02-24 16:56:22 +00:00
isa o break newbus api: add a new argument of type driver_filter_t to 2007-02-23 12:19:07 +00:00
kern Close race conditions between fork() and [sg]etpriority()'s 2007-02-26 03:38:09 +00:00
libkern Add strstr() function to the libkern. 2006-08-12 15:28:39 +00:00
modules Make IPv6 multicast forwarding dynamically loadable from a GENERIC kernel. 2007-02-24 11:38:47 +00:00
net Move the lock init until after if_alloc in case the allocation fails and we 2007-02-23 19:37:55 +00:00
net80211 clear/reclaim challenge text when switching auth mode and operating as an ap 2007-02-04 05:49:16 +00:00
netatalk Use privilege PRIV_NET_ADDIFADDR rather than suser() to authorize 2007-02-19 22:40:02 +00:00
netatm Sweep kernel replacing suser(9) calls with priv(9) calls, assigning 2006-11-06 13:42:10 +00:00
netgraph o break newbus api: add a new argument of type driver_filter_t to 2007-02-23 12:19:07 +00:00
netinet Unlock a mutex which should be unlocked before returning. 2007-02-25 14:22:03 +00:00
netinet6 Fix tinderbox. ip6_mrouter should be defined in raw_ip6.c as it is 2007-02-24 21:09:35 +00:00
netipsec s,#if INET6,#ifdef INET6, 2006-12-14 17:33:46 +00:00
netipx Further style(9) for ipx_ip. 2007-02-25 00:17:56 +00:00
netkey With exception of the if_name() macro, all definitions in net_osdep.h 2006-08-04 21:27:40 +00:00
netnatm Factor out my copyrights + licenses from Charles D. Cranor and 2007-01-08 22:30:39 +00:00
netncp Sweep kernel replacing suser(9) calls with priv(9) calls, assigning 2006-11-06 13:42:10 +00:00
netsmb Backing out the wrong fix which could possibly trash the memory if devfs 2007-02-09 17:22:10 +00:00
nfs NFSv4 client: 2006-11-28 19:33:28 +00:00
nfs4client Rename some functions and variables from nfs_* to nfs4_* to avoid 2007-01-25 14:33:13 +00:00
nfsclient Backing out an earlier change. It seems harmless for NFS to miss the "force 2007-02-16 03:46:55 +00:00
nfsserver Move vnode-to-file-handle translation from vfs_vptofh to vop_vptofh method. 2007-02-15 22:08:35 +00:00
opencrypto
pc98 Garbage collect a reference to INTR_FAST. 2007-02-25 14:53:55 +00:00
pccard
pci Convert sis(4) to use its own watchdog procedure. 2007-02-24 14:27:36 +00:00
powerpc Catch up with bus_setup_intr() modification and garbage collect a 2007-02-25 15:04:08 +00:00
rpc
security More unnecessary include reduction. 2007-02-23 14:39:04 +00:00
sparc64 Use uma_set_align(). 2007-02-25 10:52:47 +00:00
sun4v o break newbus api: add a new argument of type driver_filter_t to 2007-02-23 12:19:07 +00:00
sys Add a new kernel sleep function pause(9). pause(9) is for places that 2007-02-23 16:22:09 +00:00
tools Cleanup and document the implementation of firmware(9) based on 2007-02-15 17:21:31 +00:00
ufs Account for di_blocks allocations when IN_SPACECOUNTED is set in an 2007-02-23 20:23:35 +00:00
vm Change the way that unmanaged pages are created. Specifically, 2007-02-25 06:14:58 +00:00
Makefile o Add cam to a list of cscope dirs. 2006-11-26 18:27:16 +00:00