Commit e6368253 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds

exit_signal: simplify the "we have changed execution domain" logic

exit_notify() checks "tsk->self_exec_id != tsk->parent_exec_id"
to handle the "we have changed execution domain" case.

We can change do_thread() to always set ->exit_signal = SIGCHLD
and remove this check to simplify the code.

We could change setup_new_exec() instead, this looks more logical
because it increments ->self_exec_id. But note that de_thread()
already resets ->exit_signal if it changes the leader, let's keep
both changes close to each other.

Note that we change ->exit_signal lockless, this changes the rules.
Thereafter ->exit_signal is not stable under tasklist but this is
fine, the only possible change is OLDSIG -> SIGCHLD. This can race
with eligible_child() but the race is harmless. We can race with
reparent_leader() which changes our ->exit_signal in parallel, but
it does the same change to SIGCHLD.

The noticeable user-visible change is that the execing task is not
"visible" to do_wait()->eligible_child(__WCLONE) right after exec.
To me this looks more logical, and this is consistent with mt case.
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 5f8aadd8
...@@ -977,6 +977,9 @@ static int de_thread(struct task_struct *tsk) ...@@ -977,6 +977,9 @@ static int de_thread(struct task_struct *tsk)
sig->notify_count = 0; sig->notify_count = 0;
no_thread_group: no_thread_group:
/* we have changed execution domain */
tsk->exit_signal = SIGCHLD;
if (current->mm) if (current->mm)
setmax_mm_hiwater_rss(&sig->maxrss, current->mm); setmax_mm_hiwater_rss(&sig->maxrss, current->mm);
......
...@@ -827,14 +827,9 @@ static void exit_notify(struct task_struct *tsk, int group_dead) ...@@ -827,14 +827,9 @@ static void exit_notify(struct task_struct *tsk, int group_dead)
* If the parent exec id doesn't match the exec id we saved * If the parent exec id doesn't match the exec id we saved
* when we started then we know the parent has changed security * when we started then we know the parent has changed security
* domain. * domain.
*
* If our self_exec id doesn't match our parent_exec_id then
* we have changed execution domain as these two values started
* the same after a fork.
*/ */
if (thread_group_leader(tsk) && tsk->exit_signal != SIGCHLD && if (thread_group_leader(tsk) && tsk->exit_signal != SIGCHLD &&
(tsk->parent_exec_id != tsk->real_parent->self_exec_id || tsk->parent_exec_id != tsk->real_parent->self_exec_id)
tsk->self_exec_id != tsk->parent_exec_id))
tsk->exit_signal = SIGCHLD; tsk->exit_signal = SIGCHLD;
if (unlikely(tsk->ptrace)) { if (unlikely(tsk->ptrace)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment