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.
Unified · Split
| @@ -1427,7 +1427,9 @@ static int copy_sighand(unsigned long clone_flags, struct task_struct *tsk) · 1426 unmodified lines | ||
| 1427 | 1427 | return -ENOMEM; |
| 1428 | 1428 | |
| 1429 | 1429 | atomic_set(&sig->count, 1); |
| 1430 | + spin_lock_irq(¤t->sighand->siglock); | |
| 1430 | 1431 | memcpy(sig->action, current->sighand->action, sizeof(sig->action)); |
| 1432 | + spin_unlock_irq(¤t->sighand->siglock); | |
| 1431 | 1433 | return 0; |
| 1432 | 1434 | } |
| 1433 | 1435 | |