mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 03:01:39 -04:00
exec: do not abuse ->cred_guard_mutex in threadgroup_lock()
threadgroup_lock() takes signal->cred_guard_mutex to ensure that thread_group_leader() is stable. This doesn't look nice, the scope of this lock in do_execve() is huge. And as Dave pointed out this can lead to deadlock, we have the following dependencies: do_execve: cred_guard_mutex -> i_mutex cgroup_mount: i_mutex -> cgroup_mutex attach_task_by_pid: cgroup_mutex -> cred_guard_mutex Change de_thread() to take threadgroup_change_begin() around the switch-the-leader code and change threadgroup_lock() to avoid ->cred_guard_mutex. Note that de_thread() can't sleep with ->group_rwsem held, this can obviously deadlock with the exiting leader if the writer is active, so it does threadgroup_change_end() before schedule(). Reported-by: Dave Jones <[email protected]> Acked-by: Tejun Heo <[email protected]> Acked-by: Li Zefan <[email protected]> Signed-off-by: Oleg Nesterov <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
12eaaf309a
commit
e56fb28740
2 changed files with 7 additions and 14 deletions
|
|
@ -898,11 +898,13 @@ static int de_thread(struct task_struct *tsk)
|
|||
|
||||
sig->notify_count = -1; /* for exit_notify() */
|
||||
for (;;) {
|
||||
threadgroup_change_begin(tsk);
|
||||
write_lock_irq(&tasklist_lock);
|
||||
if (likely(leader->exit_state))
|
||||
break;
|
||||
__set_current_state(TASK_KILLABLE);
|
||||
write_unlock_irq(&tasklist_lock);
|
||||
threadgroup_change_end(tsk);
|
||||
schedule();
|
||||
if (unlikely(__fatal_signal_pending(tsk)))
|
||||
goto killed;
|
||||
|
|
@ -960,6 +962,7 @@ static int de_thread(struct task_struct *tsk)
|
|||
if (unlikely(leader->ptrace))
|
||||
__wake_up_parent(leader, leader->parent);
|
||||
write_unlock_irq(&tasklist_lock);
|
||||
threadgroup_change_end(tsk);
|
||||
|
||||
release_task(leader);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue