Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5162508imu; Tue, 8 Jan 2019 12:40:16 -0800 (PST) X-Google-Smtp-Source: ALg8bN56WIdOkY/ON0Hgzvi+FbR9xR+DEpJQfywxPTE566fBQ5a/gICNQI2yPhP7q5LSxhcuhSCp X-Received: by 2002:a63:d50f:: with SMTP id c15mr2845287pgg.287.1546980016074; Tue, 08 Jan 2019 12:40:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546980016; cv=none; d=google.com; s=arc-20160816; b=jZQT+zlkyFtCXuOAy2YP13qxuut8rP9K3Bb9G8hEJ3JNvj+VKtciR+WhkVUOclxsVI LcFJKnvhxV2wNoPhYrQs1XHPcOmN/6iOlf6fMWPkX5sXeySOj/MAYk48PeP40QXDzV1V cfSG20r7x7rmzFXBLROmc9J5QW9gabB41PoIf6qixaq+G6XVez0PgqJBUo/uJpk4H3cZ uTmeugKh0bc8XcdjOpkxIFGqhXNyGSy4fIwOq97ct70zNAhI3kIj626yW0FBKYmmqCed 16TEu6aAwahDo4jHZUbMYz/qHFN//5BtaIjjN64hiVSGknToStvEDwhRHPW1o/vsfmjA Glew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=HAiNRxjnamjJs7foBFRydsfbmARLDQ7hr/Drh+QCbSE=; b=II43m/avyZoLK/E4bXF14MG7dbXpn9AAwoLFB6qXVh52EIln9FgPEzF+bCJJKQzsEC /VlM+O2TOUiOPaqyqidPv9S52ZLQ2hEiCNAkl6iBRnciqPVUP3jk0MQAJyhMxZiS1kee KF5lSJB7ngJrgWttaHvpAdTi4cI53+f2Ygy/K+1ASSRqsUkIDEmfl/KUVtwwIaiaXvpN sxKHOTQr9XJlWaTr2/gqylvUYuFk9Buk0AouUBGvPVYu7m/hiwT4X+U++jYS2QvaDslu OAp7LVx1D4Y/kTZIEWb+h4DWRizagTHKs2M66kiqjFA9hixEkZh5AbCdij/1ZGcYI3fC /L5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mdKw8BcY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n15si63802560pgk.27.2019.01.08.12.39.42; Tue, 08 Jan 2019 12:40:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mdKw8BcY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729156AbfAHUgQ (ORCPT + 99 others); Tue, 8 Jan 2019 15:36:16 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:42737 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728313AbfAHUgQ (ORCPT ); Tue, 8 Jan 2019 15:36:16 -0500 Received: by mail-pl1-f196.google.com with SMTP id y1so2429312plp.9 for ; Tue, 08 Jan 2019 12:36:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=HAiNRxjnamjJs7foBFRydsfbmARLDQ7hr/Drh+QCbSE=; b=mdKw8BcY9LnhFjtdwY8huJ6ltRHDFB/UWcjqrz/TDSihtSk7IgEuX7qyRFOnpw8mkj MA9FuyZV8ZBcbl5mtqxHdqzB23ehuMMga/JdfwTz/jwTWrgvwR9I2swP6pIh1qQfJyTX gxS0/qiSOF9VnweaBW3xXzO5kxml+9Gn7EgrKaoxhQrNdcVhXL60nBtMfmBGi9BgW/L8 n87mSwGL4Fdh2JnOf32V4sGrp8qhlAKXBkDsaoYJmFxmgqQC2qoIhZBDTZAhIHCKQd/h Z+zJBdDAF+Nf0LtfQMNYgu/ER3bbWVqpfAfI0EMiWaO6epxf1xJnLZRAyvFa2/QUmDzf 3IhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=HAiNRxjnamjJs7foBFRydsfbmARLDQ7hr/Drh+QCbSE=; b=Ias2hQgqArq2L9TJE91bnJMj6B5NIducYhH1WLsZbf7SD0CRFqPbYVi+j8TH+Fsn8i JzzdB28LcJLbzmXWhIKQsunJ4NdEm/A5JjksIb2WCdWSJmt9wyAW2AwYvKsvgQT4T9VO KhFyAAciHWoXI1e6IPBWufRstrkxfEMJglCzTlS8BS0Fx2tzfFptimvA9fnC25vVBJCj LNLNkS4pLC/qU6yOgSb1pVj7/nhxkegn94qANLElCvWKg7Zqpy8xUtXrwmQwUrqfvyHb dN+PaR2XObHlpLQkbbghJ2CkCo/vwbvnZY7AfvL/8Mdg7kpjBAsmurZHq6d0dX1VIQJS xrTg== X-Gm-Message-State: AJcUukc384iYTVmYDadtDPEqimPeti58+HEINCTdcPmkIyu5SGO2Rg3W uRTEKULz+23e9a59OzCBTUE= X-Received: by 2002:a17:902:6848:: with SMTP id f8mr3147703pln.300.1546979774989; Tue, 08 Jan 2019 12:36:14 -0800 (PST) Received: from gmail.com ([2620:0:1008:fd00:78b4:3a07:980a:287b]) by smtp.gmail.com with ESMTPSA id h134sm140961811pfe.27.2019.01.08.12.36.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Jan 2019 12:36:14 -0800 (PST) Date: Tue, 8 Jan 2019 12:36:13 -0800 From: Andrei Vagin To: Oleg Nesterov Cc: Andrew Morton , linux-kernel@vger.kernel.org, "Eric W. Biederman" Subject: Re: [PATCH] kernel: release ptraced tasks before zap_pid_ns_processes Message-ID: <20190108203612.GA19454@gmail.com> References: <20190102205939.26231-1-avagin@gmail.com> <20190108165043.GA10240@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline In-Reply-To: <20190108165043.GA10240@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 08, 2019 at 05:50:43PM +0100, Oleg Nesterov wrote: > Sorry for delay, vacation, > > On 01/02, Andrei Vagin wrote: > > > > zap_pid_ns_processes() can stuck on waiting tasks from the dead list. In > > this case, we will have one unkillable process with one or more dead > > children. > > Thanks! > > > --- a/kernel/exit.c > > +++ b/kernel/exit.c > > @@ -664,9 +664,6 @@ static void forget_original_parent(struct task_struct *father, > > { > > struct task_struct *p, *t, *reaper; > > > > - if (unlikely(!list_empty(&father->ptraced))) > > - exit_ptrace(father, dead); > > - > > /* Can drop and reacquire tasklist_lock */ > > reaper = find_child_reaper(father); > > if (list_empty(&father->children)) > > @@ -705,8 +702,18 @@ static void exit_notify(struct task_struct *tsk, int group_dead) > > LIST_HEAD(dead); > > > > write_lock_irq(&tasklist_lock); > > - forget_original_parent(tsk, &dead); > > + if (unlikely(!list_empty(&tsk->ptraced))) > > + exit_ptrace(tsk, &dead); > > + write_unlock_irq(&tasklist_lock); > > + > > + /* Ptraced tasks have to be released before zap_pid_ns_processes(). */ > > + list_for_each_entry_safe(p, n, &dead, ptrace_entry) { > > + list_del_init(&p->ptrace_entry); > > + release_task(p); > > + } > > > > + write_lock_irq(&tasklist_lock); > > + forget_original_parent(tsk, &dead); > > if (group_dead) > > kill_orphaned_pgrp(tsk->group_leader, NULL); > > How about a different fix below? It avoids additional write_lock/unlock(tasklist), > and another list_for_each_entry_safe(dead) loop is called only if it is actually > needed. > > Or I missed something? No, you don't. The patch looks really nice. Thanks! BTW: We probably need to add the "Fixes:" tag, but I am not sure to which commit, it looks like the issue is here for years. Acked-by: Andrei Vagin > > Oleg. > > > --- x/kernel/exit.c > +++ x/kernel/exit.c > @@ -558,12 +558,14 @@ static struct task_struct *find_alive_th > return NULL; > } > > -static struct task_struct *find_child_reaper(struct task_struct *father) > +static struct task_struct *find_child_reaper(struct task_struct *father, > + struct list_head *dead) > __releases(&tasklist_lock) > __acquires(&tasklist_lock) > { > struct pid_namespace *pid_ns = task_active_pid_ns(father); > struct task_struct *reaper = pid_ns->child_reaper; > + struct task_struct *p, *n; > > if (likely(reaper != father)) > return reaper; > @@ -579,6 +581,11 @@ static struct task_struct *find_child_re > panic("Attempted to kill init! exitcode=0x%08x\n", > father->signal->group_exit_code ?: father->exit_code); > } > + > + list_for_each_entry_safe(p, n, &dead, ptrace_entry) { > + list_del_init(&p->ptrace_entry); > + release_task(p); > + } > zap_pid_ns_processes(pid_ns); > write_lock_irq(&tasklist_lock); > > @@ -668,7 +675,7 @@ static void forget_original_parent(struc > exit_ptrace(father, dead); > > /* Can drop and reacquire tasklist_lock */ > - reaper = find_child_reaper(father); > + reaper = find_child_reaper(father, dead); > if (list_empty(&father->children)) > return; > >