vfork: make it killable
authorOleg Nesterov <oleg@redhat.com>
Mon, 5 Mar 2012 22:59:13 +0000 (14:59 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 5 Mar 2012 23:49:42 +0000 (15:49 -0800)
commitd68b46fe16ad59b3a5f51ec73daaa5dc06753798
tree4bae9ddc5f5bed853d1f0936d05c30e4f7ca924d
parentc415c3b47ea2754659d915cca387a20999044163
vfork: make it killable

Make vfork() killable.

Change do_fork(CLONE_VFORK) to do wait_for_completion_killable().  If it
fails we do not return to the user-mode and never touch the memory shared
with our child.

However, in this case we should clear child->vfork_done before return, we
use task_lock() in do_fork()->wait_for_vfork_done() and
complete_vfork_done() to serialize with each other.

Note: now that we use task_lock() we don't really need completion, we
could turn task->vfork_done into "task_struct *wake_up_me" but this needs
some complications.

NOTE: this and the next patches do not affect in-kernel users of
CLONE_VFORK, kernel threads run with all signals ignored including
SIGKILL/SIGSTOP.

However this is obviously the user-visible change.  Not only a fatal
signal can kill the vforking parent, a sub-thread can do execve or
exit_group() and kill the thread sleeping in vfork().

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/sched.h
kernel/fork.c