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

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
14271427 return -ENOMEM;
14281428
14291429 atomic_set(&sig->count, 1);
1430+ spin_lock_irq(&current->sighand->siglock);
14301431 memcpy(sig->action, current->sighand->action, sizeof(sig->action));
1432+ spin_unlock_irq(&current->sighand->siglock);
14311433 return 0;
14321434 }
14331435

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