diff options
author | Jann Horn <jannh@google.com> | 2018-07-04 11:25:45 +0200 |
---|---|---|
committer | Michal Hocko <mhocko@suse.com> | 2018-07-04 11:25:45 +0200 |
commit | 9c7891e9d968955e667f5ec4c2f20625289eb330 (patch) | |
tree | 4dbfc022fde7cdbe1f4a8c99a8cc94282768559c | |
parent | fc36def997cfd6cbff3eda4f82853a5c311c5466 (diff) | |
download | mm-akpm/fork.tar.gz |
fork: don't copy inconsistent signal handler state to childakpm/fork
Before this change, if a multithreaded process forks while one of its
threads is changing a signal handler using sigaction(), the memcpy() in
copy_sighand() can race with the struct assignment in do_sigaction(). It
isn't clear whether this can cause corruption of the userspace signal
handler pointer, but it definitely can cause inconsistency between
different fields of struct sigaction.
Take the appropriate spinlock to avoid this.
I have tested that this patch prevents inconsistency between sa_sigaction
and sa_flags, which is possible before this patch.
Link: http://lkml.kernel.org/r/20180702145108.73189-1-jannh@google.com
Signed-off-by: Jann Horn <jannh@google.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
-rw-r--r-- | kernel/fork.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/kernel/fork.c b/kernel/fork.c index 9440d61b925ca..4c86e8daae536 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1394,7 +1394,9 @@ static int copy_sighand(unsigned long clone_flags, struct task_struct *tsk) return -ENOMEM; atomic_set(&sig->count, 1); + spin_lock_irq(¤t->sighand->siglock); memcpy(sig->action, current->sighand->action, sizeof(sig->action)); + spin_unlock_irq(¤t->sighand->siglock); return 0; } |