Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3875661ybi; Fri, 19 Jul 2019 10:33:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYITxgt9Dzrz4B4mbdn09oUIEAlzu6hDucJf5ugCE3oiWSwCgOr76yIBBZ8JXsBh4k5I4j X-Received: by 2002:a65:514c:: with SMTP id g12mr55499819pgq.76.1563557609075; Fri, 19 Jul 2019 10:33:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563557609; cv=none; d=google.com; s=arc-20160816; b=AXaReJj6jV2Wfgd7L4chpwk0rys+gkS/AcYRxZYcknd2RDaI9owEs6nLrmq2ovzs+u UBWl4e/4QoxEg1zQaPv75NxCaDGf2JZzVU+rTzWpstgzLNKK3lC2ET6nK1d+wj9tBoDa nLPTdRlB/SHlnfmebeMu7rB6kIbY7JGX7YjoYJxb1C6VWEx9JNCBSWhsSasYBV4Bgv1Q 3w4zuMVdQQ4mfr07GdeAB2KXgzqXfGc6J7TPg07cBcsLRwqMsZUAv9eiz7rBi50CWAUk kn4GFQX27jLaazVDHD0sRc8UbSW3npYjapWP+FczyirfEt0nbZLvXwRs5RNJNFL5bz45 17tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=MD20IfExCxC1GSVGQW60wKgomTGICWCjQ6hD4XxAnGw=; b=ZyHhJiVA5sS2OcR3T7EwiIYaZp77ouaT2Fxnt+EWoVJXylc+haoKNqrGF8xTG+VT4T VbT2ZKsanpOvakZeFg+4SEWnM5GIDVM3mGfmapjCzAqVBzpsXlnHlMxQvvtks3BniFsf tbWXoM+mvXsvP39Vtlpa46HXOgXASKB09ED7ouOUpttep/bw93dtuahY5fbZNBZAqvIE BXXVSvdEKhuVT+7cSVMVyc4GTO3LzchiJM9EE7k166bTIZaECpJ1bt7HDYVleJzMPToU Gy1h8mVQ6z3gY1jA7zFIPolsNxSZvhG8sulUw3cqhqhQyiWevQ21AuV6Sm1q6mZKJu0q /TxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kpemiLVu; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m39si1557085plg.155.2019.07.19.10.33.13; Fri, 19 Jul 2019 10:33:29 -0700 (PDT) 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=@google.com header.s=20161025 header.b=kpemiLVu; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728584AbfGSQve (ORCPT + 99 others); Fri, 19 Jul 2019 12:51:34 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:44109 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728148AbfGSQvd (ORCPT ); Fri, 19 Jul 2019 12:51:33 -0400 Received: by mail-qk1-f196.google.com with SMTP id d79so23679596qke.11 for ; Fri, 19 Jul 2019 09:51:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MD20IfExCxC1GSVGQW60wKgomTGICWCjQ6hD4XxAnGw=; b=kpemiLVuSTkgT1yRxRYlnKwPO1WAGRaWdvcqlRA3oLQwivdx6ZKdJ7WbUnqL/ge+RK vWKFZXCa7xA0NhQqNQmi1YLnL8o8BU/PtEAbdIA2WDCLJrxWy/h+Qbru5yd2c/AqKMnW K17Nh83xnyZ0IEHjtPwvOY8Gcp7TapRJCrQuqGwxZkdu7/CckPAfel11whgQ+G0WHYto 1XcWWVF6KPmQxdIkDVeFJkQqSkoIb6/0vuF3cX9ImdLB4v7gkjhzYrPZ6ihwA+/mM3/1 x2d2cT/J9Vrv08GmCH564foY6M3QTyHmB1BkmMRljqh5qvs8ZcLBk/wfBeCQogizVvGw Tbrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MD20IfExCxC1GSVGQW60wKgomTGICWCjQ6hD4XxAnGw=; b=dLcA7HWZo70GG7a0zNfVYRUgN37yA3ji/lwgz+UR+UX9l+88et1qjb9EBsqpESBxfw G1faTIM6RofXqPfljJzjzAzAVXgqjyTc0A2AQz0MxEpYyBj3m+cJdKS4HcGcBRGovldV fn2CIXtaQmO+0VyZXDK2eJgKc8kKQG5T5toaygH2qNWBXpDptIxNKKIDHUcdVFPN6XUg mKGntVM0Wzd+Ff653tC/wtg4fKjKLcDOSSFJvMblcfhufcHGXZKovZsy5GCrFfMf7SNB BuY9gKumbrdUnzSaS2Wru2uQH7/qf0SA/9W5Rb1TqN432zrquWh9IPOzSql0TW0jhg6u b0RA== X-Gm-Message-State: APjAAAVtNSgzLRDn1YiWWl6KK57sAemwzvrIyBqPZxl/Ky2ciHc2dDPa O8/LEqmbLAM5SreRrTAZt8ViwVK+PgSxSx2ngiCvoQ== X-Received: by 2002:a37:4714:: with SMTP id u20mr35695754qka.162.1563555092394; Fri, 19 Jul 2019 09:51:32 -0700 (PDT) MIME-Version: 1.0 References: <20190717172100.261204-1-joel@joelfernandes.org> <20190719161404.GA24170@redhat.com> <20190719162726.u5fi5k3tqove6hgn@brauner.io> In-Reply-To: <20190719162726.u5fi5k3tqove6hgn@brauner.io> From: Joel Fernandes Date: Fri, 19 Jul 2019 12:51:20 -0400 Message-ID: Subject: Re: [PATCH RFC v1] pidfd: fix a race in setting exit_state for pidfd polling To: Christian Brauner Cc: Oleg Nesterov , "Joel Fernandes (Google)" , LKML , Suren Baghdasaryan , "Cc: Android Kernel" , Andrea Arcangeli , Andrew Morton , "Eric W. Biederman" , Tejun Heo Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 19, 2019 at 12:27 PM Christian Brauner wrote: > > On Fri, Jul 19, 2019 at 06:14:05PM +0200, Oleg Nesterov wrote: > > it seems that I missed something else... > > > > On 07/17, Joel Fernandes (Google) wrote: > > > > > > @@ -1156,10 +1157,11 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p) > > > ptrace_unlink(p); > > > > > > /* If parent wants a zombie, don't release it now */ > > > - state = EXIT_ZOMBIE; > > > + p->exit_state = EXIT_ZOMBIE; > > > if (do_notify_parent(p, p->exit_signal)) > > > - state = EXIT_DEAD; > > > - p->exit_state = state; > > > + p->exit_state = EXIT_DEAD; > > > + > > > + state = p->exit_state; > > > write_unlock_irq(&tasklist_lock); > > > > why do you think we also need to change wait_task_zombie() ? > > > > pidfd_poll() only needs the exit_state != 0 check, we know that it > > is not zero at this point. Why do we need to change exit_state before > > do_notify_parent() ? > > Oh, because of?: > > /* > * Move the task's state to DEAD/TRACE, only one thread can do this. > */ > state = (ptrace_reparented(p) && thread_group_leader(p)) ? > EXIT_TRACE : EXIT_DEAD; > if (cmpxchg(&p->exit_state, EXIT_ZOMBIE, state) != EXIT_ZOMBIE) > return 0; > > So exit_state will definitely be set in this scenario. Good point. > Agreed. Christian, do you mind dropping this hunk from the patch or do you want me to resend the patch with the hunk dropped?