From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751959AbdFFTOm (ORCPT ); Tue, 6 Jun 2017 15:14:42 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:50509 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751471AbdFFTOh (ORCPT ); Tue, 6 Jun 2017 15:14:37 -0400 From: "Eric W. Biederman" To: linux-kernel@vger.kernel.org Cc: linux-api@vger.kernel.org, Linus Torvalds , Oleg Nesterov , Ingo Molnar , Thomas Gleixner , Kees Cook , Roland McGrath , Al Viro , David Howells , "Michael Kerrisk (man-pages)" , "Eric W. Biederman" Date: Tue, 6 Jun 2017 14:03:28 -0500 Message-Id: <20170606190338.28347-16-ebiederm@xmission.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170606190338.28347-1-ebiederm@xmission.com> References: <877f0pym71.fsf@xmission.com> <20170606190338.28347-1-ebiederm@xmission.com> X-XM-SPF: eid=1dIJuh-0006wd-IK;;;mid=<20170606190338.28347-16-ebiederm@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=97.121.81.159;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+c+4YHkfvLhHOmw5GoeGjDKqPTdcQ9qWM= X-SA-Exim-Connect-IP: 97.121.81.159 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.7 XMSubLong Long Subject * 0.0 TVD_RCVD_IP Message was received from an IP address * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa02 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject * 0.1 XMSolicitRefs_0 Weightloss drug X-Spam-DCC: XMission; sa02 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;linux-kernel@vger.kernel.org X-Spam-Relay-Country: X-Spam-Timing: total 5564 ms - load_scoreonly_sql: 0.08 (0.0%), signal_user_changed: 3.1 (0.1%), b_tie_ro: 2.0 (0.0%), parse: 1.37 (0.0%), extract_message_metadata: 31 (0.6%), get_uri_detail_list: 3.3 (0.1%), tests_pri_-1000: 13 (0.2%), tests_pri_-950: 2.6 (0.0%), tests_pri_-900: 2.1 (0.0%), tests_pri_-400: 31 (0.6%), check_bayes: 28 (0.5%), b_tokenize: 12 (0.2%), b_tok_get_all: 7 (0.1%), b_comp_prob: 3.8 (0.1%), b_tok_touch_all: 2.8 (0.0%), b_finish: 0.85 (0.0%), tests_pri_0: 456 (8.2%), check_dkim_signature: 0.99 (0.0%), check_dkim_adsp: 5.0 (0.1%), tests_pri_500: 5018 (90.2%), poll_dns_idle: 5008 (90.0%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 16/26] exit: Fix reporting a ptraced !reparented leader has exited X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a task exits and uses do_notify_parent to send tsk->exit_signal or SIGCHLD this has one of two possible meanings. - The ptraced task has exited - The thread group has exited Linux resolves this ambiguity by preferring the thread group exit interpretation if it is possible. As the exit of a thread group containing a task is a superset of the exit of a task. The code attempts to implement this in it's selection of signal before calling do_notify_parent for a ptraced task. Unfortunately it fails to properly handle the case when the thread_group is still running (but it's leader has exited). Fix this for a ptraced child leader by skipping the notification instead of changing the exit signal. If we skip sending the signal in exit_noitfy, when the last of the other threads are reaped release_task will send the signal for us. Signed-off-by: "Eric W. Biederman" --- kernel/exit.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index 85b34eff8807..72591eb5e361 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -639,7 +639,7 @@ static void forget_original_parent(struct task_struct *father, */ static void exit_notify(struct task_struct *tsk, int group_dead) { - bool autoreap; + bool autoreap = true; struct task_struct *p, *n; LIST_HEAD(dead); @@ -649,17 +649,12 @@ static void exit_notify(struct task_struct *tsk, int group_dead) if (group_dead) kill_orphaned_pgrp(tsk->group_leader, NULL); - if (unlikely(tsk->ptrace)) { - int sig = thread_group_leader(tsk) && - thread_group_empty(tsk) && - !ptrace_reparented(tsk) ? - tsk->exit_signal : SIGCHLD; - autoreap = do_notify_parent(tsk, sig); - } else if (thread_group_leader(tsk)) { + if (thread_group_leader(tsk) && !ptrace_reparented(tsk)) { autoreap = thread_group_empty(tsk) && do_notify_parent(tsk, tsk->exit_signal); - } else { - autoreap = true; + } + else if (unlikely(tsk->ptrace)) { + autoreap = do_notify_parent(tsk, SIGCHLD); } tsk->exit_state = autoreap ? EXIT_DEAD : EXIT_ZOMBIE; -- 2.10.1