aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/fork.c
diff options
context:
space:
mode:
authorJann Horn <jannh@google.com>2018-08-22 01:00:58 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-08-22 13:52:51 -0400
commit06e62a46bbba20aa5286102016a04214bb446141 (patch)
tree614724f8bb48c794cf575e886fc540d0464c9a0f /kernel/fork.c
parent20ab7218d2507b2dbec9c053c2f1b96054e266b6 (diff)
fork: don't copy inconsistent signal handler state to child
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> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/fork.c')
-rw-r--r--kernel/fork.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/kernel/fork.c b/kernel/fork.c
index 8bcef2413f1b..23eb960c701d 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1427,7 +1427,9 @@ static int copy_sighand(unsigned long clone_flags, struct task_struct *tsk)
1427 return -ENOMEM; 1427 return -ENOMEM;
1428 1428
1429 atomic_set(&sig->count, 1); 1429 atomic_set(&sig->count, 1);
1430 spin_lock_irq(&current->sighand->siglock);
1430 memcpy(sig->action, current->sighand->action, sizeof(sig->action)); 1431 memcpy(sig->action, current->sighand->action, sizeof(sig->action));
1432 spin_unlock_irq(&current->sighand->siglock);
1431 return 0; 1433 return 0;
1432} 1434}
1433 1435