Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9923989ybi; Wed, 24 Jul 2019 12:24:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqyzhvJYK6K5pYIhvF8bKCcucPBWAsEWifCZbEldIcOn2bUUADuhypWowuTEXt/pIL0RHhrN X-Received: by 2002:a17:90a:2768:: with SMTP id o95mr88828611pje.37.1563996276331; Wed, 24 Jul 2019 12:24:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563996276; cv=none; d=google.com; s=arc-20160816; b=L2wboGhoae236eCjDpbWgD/nHOF3VDDc92EhwvkXBaNvk/MFEI6dFAlIZve3I2B1bK DRJ6otqRtNZV9+v+t548HUsiplwkQNlIvJRt736nHVxCz7G8yFfcTCVNm6WVxnPu9Kbk OPAOimAKcyMXFwOQO+wuPZ4O+3C1yFhaz4oWurky2UybuTP6ENMeAdlvB6a24gNTevRc tVfvkwnEoPssF9eQCLExaeMg8ZEjX38Z05gSyQX1ji+7mbX2jxU1iYm1rhPibdm2kODS I0xXXpny6EstIkKMlmA4PQjlqiJL2riVMnr+inIxpn+2iQHV0GjtB0xsqNfo0jRtNI3K a21w== 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=qBB4NIUezJfffKo6WArQqxSmCR6R1iK7nA9Imt65nrA=; b=k7K3a8F5HC7LBFdjJGsNj6I0OSSjmFZlGar2jQWjYk7d4pIUa+cT3X/UM0z0u+0FJ1 Ez7Ts5mn4z9tEIaOa+6iLp6E6Uc1CBBKwF9JIT9RnT9x8V4X5mwT1WpNd2K1kTin1zfX 2RLjCGNxr4mzranUrXFvRc8eN8OvjQvZa0j6rD3N3yNrGWmgLKpxSVK7q8ts4Xhb7gmK UEPrmK8O3i612tJyaTQKFw0209jjwzcV2BWB0XcAYLgvohMlxDcfPn7+GcaD8frd05Gw w3vitHlT8mIqv3X7QGElJI3hgra9PRmMNYjNPmYVCPKueYRbzLIVqE75dckybCy4dGT9 ugSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=lWNkNy2H; 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 d37si13342074pla.288.2019.07.24.12.24.21; Wed, 24 Jul 2019 12:24:36 -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=lWNkNy2H; 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 S1728116AbfGXSOy (ORCPT + 99 others); Wed, 24 Jul 2019 14:14:54 -0400 Received: from mail-ot1-f65.google.com ([209.85.210.65]:42678 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728011AbfGXSOx (ORCPT ); Wed, 24 Jul 2019 14:14:53 -0400 Received: by mail-ot1-f65.google.com with SMTP id l15so48821400otn.9 for ; Wed, 24 Jul 2019 11:14:52 -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=qBB4NIUezJfffKo6WArQqxSmCR6R1iK7nA9Imt65nrA=; b=lWNkNy2HocdqrSPSjM86VbsoPLqsarjkWdpIa+rbyfMi2VVwhNVXgnmJbHOpO1W7FT LQMzXGrgksgL9tGb50G9TiUwzlVWVbhzfAN6YgzYvj9m0yrQTGiGJQ6UBv0FRFiUeI0Y 0Pu6bKOZZAfkCCJlOZkDOX7Sot7v/XhX7gKi7M6McIRW/+SPegOlDe8lp/F2tcsjSooD yoc081wlkW7WCUVG3wHzzrnhXOxIHoMB4QEeSlGWs5yVG93jDJsFjxlbNrryYK6ptn6i 6hV19p7RkJbrSN7B0r9AaIRRx/7XrpljhjtHs8tAhBqO1U4zdzM1POwxhMmkzWwsle0x TalA== 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=qBB4NIUezJfffKo6WArQqxSmCR6R1iK7nA9Imt65nrA=; b=iVidYSagnqQN2NH5D17296fN3lg+ML+yJVvW2HrKlh/L24d6utGsp57JRjHyip58nX fpoYI7lAMal91A51RRIBIqornmuRY6hX6Q5w4CYttUT3F+4vxqOWeh/xL2g2HL0LNWiA Jy28CEqXd87Kozrb9OV27TAg2o1K9p+YlU2FLUhQTNiJADQ79pTiCc9GW1gjFfkYVc2y P4tCnEpDenK2T7clFj8ulqGi6aoGsLbEe0K8MYCZ1jagkIoFJdiWPw5ICLicE5M4KWGC KwwqA5VPt5qKnoAM4Ag8kEQKgrZjPW2rhQZEUxuR4usJHQJpwzV+LupP+Y709aLHDh/v BpRg== X-Gm-Message-State: APjAAAXrZcfWSbeAWLhhaRUtkTPgujhiv/8awBM1+uvgRaZHPNfGnvku PbFjHekioR0u9GdqEw/6qq9J3DABR6VTlno0z6TtEw== X-Received: by 2002:a05:6830:15cd:: with SMTP id j13mr44476599otr.110.1563992092278; Wed, 24 Jul 2019 11:14:52 -0700 (PDT) MIME-Version: 1.0 References: <20190724144651.28272-1-christian@brauner.io> <20190724144651.28272-5-christian@brauner.io> In-Reply-To: <20190724144651.28272-5-christian@brauner.io> From: Jann Horn Date: Wed, 24 Jul 2019 20:14:26 +0200 Message-ID: Subject: Re: [PATCH 4/5] pidfd: add CLONE_WAIT_PID To: Christian Brauner Cc: kernel list , Oleg Nesterov , Arnd Bergmann , "Eric W. Biederman" , Kees Cook , "Joel Fernandes (Google)" , Thomas Gleixner , Tejun Heo , David Howells , Andy Lutomirski , Andrew Morton , Aleksa Sarai , Linus Torvalds , Al Viro , kernel-team , Ingo Molnar , Peter Zijlstra , Linux API 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 Wed, Jul 24, 2019 at 4:48 PM Christian Brauner wrote: > If CLONE_WAIT_PID is set the newly created process will not be > considered by process wait requests that wait generically on children > such as: > > syscall(__NR_wait4, -1, wstatus, options, rusage) > syscall(__NR_waitpid, -1, wstatus, options) > syscall(__NR_waitid, P_ALL, -1, siginfo, options, rusage) > syscall(__NR_waitid, P_PGID, -1, siginfo, options, rusage) > syscall(__NR_waitpid, -pid, wstatus, options) > syscall(__NR_wait4, -pid, wstatus, options, rusage) > > A process created with CLONE_WAIT_PID can only be waited upon with a > focussed wait call. This ensures that processes can be reaped even if > all file descriptors referring to it are closed. [...] > diff --git a/kernel/fork.c b/kernel/fork.c > index baaff6570517..a067f3876e2e 100644 > --- a/kernel/fork.c > +++ b/kernel/fork.c > @@ -1910,6 +1910,8 @@ static __latent_entropy struct task_struct *copy_process( > delayacct_tsk_init(p); /* Must remain after dup_task_struct() */ > p->flags &= ~(PF_SUPERPRIV | PF_WQ_WORKER | PF_IDLE); > p->flags |= PF_FORKNOEXEC; > + if (clone_flags & CLONE_WAIT_PID) > + p->flags |= PF_WAIT_PID; > INIT_LIST_HEAD(&p->children); > INIT_LIST_HEAD(&p->sibling); > rcu_copy_process(p); This means that if a process with PF_WAIT_PID forks, the child inherits the flag, right? That seems unintended? You might have to add something like "if (clone_flags & CLONE_THREAD == 0) p->flags &= ~PF_WAIT_PID;" before this. (I think threads do have to inherit the flag so that the case where a non-leader thread of the child goes through execve and steals the leader's identity is handled properly.) Or you could cram it somewhere into signal_struct instead of on the task - that might be a more logical place for it?