History

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.

Jann Horn committed 8 years ago

Commit 06e62a41 parent 20ab7211 file · +2 −0Browse files

Showing the changes to kernel (1 of 1 file). Show all

Unified · Split

kernel/fork.c+2−0
@@ -1427,7 +1427,9 @@ static int copy_sighand(unsigned long clone_flags, struct task_struct *tsk) · 1426 unmodified lines
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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t