Fix a race between file operations and rfork(RFCFDG) by parking

all other threads at user boundary, the race can crash kernel
under stress testing.

Reviewed by: jhb
MFC after: 3 days
This commit is contained in:
David Xu 2006-03-15 23:24:14 +00:00
parent 83a244dbe0
commit 795a11d049
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=156759

View File

@ -220,6 +220,16 @@ fork1(td, flags, pages, procp)
* certain parts of a process from itself.
*/
if ((flags & RFPROC) == 0) {
if ((p1->p_flag & P_HADTHREADS) &&
(flags & (RFCFDG | RFFDG))) {
PROC_LOCK(p1);
if (thread_single(SINGLE_BOUNDARY)) {
PROC_UNLOCK(p1);
return (ERESTART);
}
PROC_UNLOCK(p1);
}
vm_forkproc(td, NULL, NULL, flags);
/*
@ -237,6 +247,13 @@ fork1(td, flags, pages, procp)
*/
if (flags & RFFDG)
fdunshare(p1, td);
if ((p1->p_flag & P_HADTHREADS) &&
(flags & (RFCFDG | RFFDG))) {
PROC_LOCK(p1);
thread_single_end();
PROC_UNLOCK(p1);
}
*procp = NULL;
return (0);
}