From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751711AbdFFTOx (ORCPT ); Tue, 6 Jun 2017 15:14:53 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:51881 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751977AbdFFTOr (ORCPT ); Tue, 6 Jun 2017 15:14:47 -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:27 -0500 Message-Id: <20170606190338.28347-15-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=1dIJuZ-0006wd-LF;;;mid=<20170606190338.28347-15-ebiederm@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=97.121.81.159;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX197X+3DIH2jdd16Gwcwu51HdMEGfOACfA8= 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 * 0.0 TVD_RCVD_IP Message was received from an IP address * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_02 5+ unique symbols in subject * 0.0 T_TooManySym_03 6+ unique symbols in subject * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa07 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: *;linux-kernel@vger.kernel.org X-Spam-Relay-Country: X-Spam-Timing: total 5546 ms - load_scoreonly_sql: 0.07 (0.0%), signal_user_changed: 2.6 (0.0%), b_tie_ro: 1.74 (0.0%), parse: 1.27 (0.0%), extract_message_metadata: 17 (0.3%), get_uri_detail_list: 1.95 (0.0%), tests_pri_-1000: 7 (0.1%), tests_pri_-950: 1.20 (0.0%), tests_pri_-900: 1.04 (0.0%), tests_pri_-400: 19 (0.3%), check_bayes: 18 (0.3%), b_tokenize: 7 (0.1%), b_tok_get_all: 5 (0.1%), b_comp_prob: 1.75 (0.0%), b_tok_touch_all: 2.4 (0.0%), b_finish: 0.59 (0.0%), tests_pri_0: 263 (4.7%), check_dkim_signature: 0.52 (0.0%), check_dkim_adsp: 86 (1.5%), tests_pri_500: 5230 (94.3%), poll_dns_idle: 5223 (94.2%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 15/26] wait: Don't delay !ptrace_reparented leaders 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 ptracing waitpid(pid) has two possible meanings. - Wait for the task with tid == pid to exit - Wait for the thread group with tgid == pid to exit Linux resolves this ambiguity by prefering the thread group interpretation if it is possible. As the exit of a thread group containing a task is the superset of the exit of a task. Delaying reaping of thread group leaders for ptraced children is how the code implements this resolution. For ptraced tasks that are not also children this ambiguity does not exit. The only possible valid meaning of waitpid(pid) is to wait for the task with tid == pid to exit. As such there is no need to delay reaping ptraced tasks when the tasks are not also children of the tracer. Change this carefully as the real parent does need to delay reaping of these tasks. Signed-off-by: "Eric W. Biederman" --- kernel/exit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index dbf3fce00a1f..85b34eff8807 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -1144,7 +1144,8 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p) /* If parent wants a zombie, don't release it now */ state = EXIT_ZOMBIE; - if (do_notify_parent(p, p->exit_signal)) + if (thread_group_empty(p) && + do_notify_parent(p, p->exit_signal)) state = EXIT_DEAD; p->exit_state = state; write_unlock_irq(&tasklist_lock); @@ -1366,8 +1367,7 @@ static int wait_consider_task(struct wait_opts *wo, int ptrace, * ptracer detaches. */ if ((exit_state == EXIT_ZOMBIE) && ptrace && - (!thread_group_leader(p) || - (ptrace_reparented(p) && thread_group_empty(p)))) + (!thread_group_leader(p) || ptrace_reparented(p))) return wait_task_zombie(wo, p); if (unlikely(exit_state == EXIT_TRACE)) { -- 2.10.1