Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp3659992img; Mon, 25 Mar 2019 15:08:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqzaCa8OSb2Y6YA6aiCBg+rfub3darDU2EH28NElZc/cb1+EPMvNHM/omkkTvqBRdu+TKWj+ X-Received: by 2002:a17:902:9341:: with SMTP id g1mr27797746plp.80.1553551698640; Mon, 25 Mar 2019 15:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553551698; cv=none; d=google.com; s=arc-20160816; b=DJlrtjOLxgG9Y1auqEqz1ORkilqib0lZVF3LSQVUTdS76f7tomFvFv6TZgSIZC8zku AIFol2tE/Er1GcEp+PzlV1rgPFRMOBKzVSznSS6qwt90GTzARIsCsVAHjp4LDy/nSvGk RkxeoYyZQBpt4wYla+z6xqfho0o3X/RQ+h27qZCCWd2KQwJR9vBEvr5V4/UnVsy0th3T FbHgzbphb73GUa867RgnDL2RspLnPGTvhuhOGMfFSd0rqxvJ+6JPhRIFmxw8o9wajsLa qzVRYADkQ3kdAva6zez/ove53Qajv9vgNXf9uYw3FTnutpWQXWtLTgAush4109LV8MT4 ZWCQ== 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=l8Kt5g0xQuiHEvUzy0l6vIAHbYuidiEQQbmDh4SgmAc=; b=USPXYCYEB0HrYHY1L0G9fc013J2oPKhAlojH9OovxUUZ7oNrE6CswqGyLWyD8CeDhh O5Vrmg/ZqMq1sFBgJCr9nUrZq070rEUXs49Idmyx83oCw9FQ++tv3P4Ju7tWhDRoOa85 GTEfeHm6YUcIYlCRXmQkZAFQI5NAojgje5DwexojoXR/xQmGT4FlI0dMl4rfvS+ORKsi hzOAmsKmONhiwrNJ+W7AGaAnWdGrmjLsr/yjb3Z+4DUocYMTPqTMldj0EJCFWakzE7Uw UTGmIvqeiSkOxiFSIPoKMS7MZRV4z1vaUK8rX9R7gRKSzjv7r6iUbu6XcYF4DvhnBH16 f/DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=wM+w9Sr1; 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 t22si15103197plo.79.2019.03.25.15.08.03; Mon, 25 Mar 2019 15:08:18 -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=wM+w9Sr1; 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 S1730012AbfCYWH2 (ORCPT + 99 others); Mon, 25 Mar 2019 18:07:28 -0400 Received: from mail-vs1-f66.google.com ([209.85.217.66]:34085 "EHLO mail-vs1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729297AbfCYWH1 (ORCPT ); Mon, 25 Mar 2019 18:07:27 -0400 Received: by mail-vs1-f66.google.com with SMTP id t78so6438841vsc.1 for ; Mon, 25 Mar 2019 15:07:27 -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=l8Kt5g0xQuiHEvUzy0l6vIAHbYuidiEQQbmDh4SgmAc=; b=wM+w9Sr1hH5S87yVczvVzzf9epUmzqXRJdZBqFythZ1CaODErF06WAAurwOKteG1pP ClsO5Uk81HU8o36HvGTOOtxnzKCyMYzA4Y+HPnsOKcBRF1DNQKcpCJYGwoSbXejpc3k7 ovqG8HVPypDUOstY74F61CBU7ArPp7Z8dAa8XP7WRJSIslL6Su5zrfmsrT/daATfqyDs tdK2eFmtdt5TwDmzrUylAgOmtKYTh2yCARS/APht1QDsdCb1ZWSV9y2e8oME8mhH1mfQ LoZfEjgxeWLCmauCaFRavyRH/Ie74QNv+QpVUCDEuErABRNUveWUM9AQyZsGgGIPXGTc GfBQ== 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=l8Kt5g0xQuiHEvUzy0l6vIAHbYuidiEQQbmDh4SgmAc=; b=k9Mb6nz9aj2XotCdI3gQVN9t94zfB+29tkaOtWoZjBT+pNwicbpZYUhKrG4FSAhU5p cyqGH46YuKVAjZPOJSNv6ezdldQl+vcnPFyqqIsTb/vFjKx0P0/MhhCeP27VIbJUycmr dKbbN9/eK1HiaunpRsE4L33GwxoAY7+NhchioLiRhvbtFMQvBB76wr2Y7y+21m+hqoFA uHYoBbk37KZ69rP4VlfRVQI3E+JGXeafMrNaBOCX4TJenkvNZF4LwF0umm+4eYtplxrl G4I7gcPTZhHx0pcrpSwfe/yPWmE0ZHBIjfB/CWAT0ch7VKFf9lmKxKu5lDTalwDFbk5b sIzg== X-Gm-Message-State: APjAAAUsZ+tKA3zqN7NPybk66JlTloIO7spsqkBgvRJlw1jjs83FKGmT a6KhXv9uQdIC3CvTv9lhebKpRCZfgIfVwnwYkWKo8A== X-Received: by 2002:a05:6102:18d:: with SMTP id r13mr257253vsq.171.1553551646548; Mon, 25 Mar 2019 15:07:26 -0700 (PDT) MIME-Version: 1.0 References: <20190325162052.28987-1-christian@brauner.io> <20190325173614.GB25975@google.com> <20190325201544.7o2kwuie3infcblp@brauner.io> <20190325211132.GA6494@google.com> <20190325214338.GA16969@google.com> In-Reply-To: From: Daniel Colascione Date: Mon, 25 Mar 2019 15:07:14 -0700 Message-ID: Subject: Re: [PATCH 0/4] pid: add pidctl() To: Jonathan Kowalski Cc: Joel Fernandes , Jann Horn , Christian Brauner , Konstantin Khlebnikov , Andy Lutomirski , David Howells , "Serge E. Hallyn" , "Eric W. Biederman" , Linux API , linux-kernel , Arnd Bergmann , Kees Cook , Alexey Dobriyan , Thomas Gleixner , Michael Kerrisk-manpages , "Dmitry V. Levin" , Andrew Morton , Oleg Nesterov , Nagarathnam Muthusamy , Aleksa Sarai , Al Viro 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 Mon, Mar 25, 2019 at 2:55 PM Jonathan Kowalski wrote: > > On Mon, Mar 25, 2019 at 9:43 PM Joel Fernandes wrote: > > > > On Mon, Mar 25, 2019 at 10:19:26PM +0100, Jann Horn wrote: > > > On Mon, Mar 25, 2019 at 10:11 PM Joel Fernandes wrote: > > > > > > But often you don't just want to wait for a single thing to happen; > > > you want to wait for many things at once, and react as soon as any one > > > of them happens. This is why the kernel has epoll and all the other > > > "wait for event on FD" APIs. If waiting for a process isn't possible > > > with fd-based APIs like epoll, users of this API have to spin up > > > useless helper threads. > > > > This is true. I almost forgot about the polling requirement, sorry. So then a > > new syscall it is.. About what to wait for, that can be a separate parameter > > to pidfd_wait then. > > > > This introduces a time window where the process changes state between > "get pidfd" and "setup waitfd", it would be simpler if the pidfd > itself supported .poll and on termination the exit status was made > readable from the file descriptor. I don't see a race here. Process state moves in one direction, so there's no race. If you want the poll to end when a process exits and the process exits before you poll, the poll should finish immediately. If the process exits before you even create the polling FD, whatever creates the polling FD can fail with ESRCH, which is what usually happens when you try to do anything with a process that's gone. Either way, whatever's trying to set up the poll knows the state of the process and there's no possibility of a missed wakeup. > Further, in the clone4 patchset, there was a mechanism to autoreap > such a process so that it does not interfere with waiting a process > does normally. How do you intend to handle this case if anyone except > the parent is wanting to *wait* on the process (a second process, > without reaping, so as to not disrupt any waiting in the parent), and > for things like libraries that finally can manage their own set of > process when pidfd_clone is added, by excluding this process from the > process's normal wait handling logic. I think that discussion is best had around pidfd_clone. pidfd waiting functionality shouldn't affect wait* in any way nor affect a zombie transition or reaping. > Moreover, should anyone except the parent process be allowed to open a > readable pidfd (or waitfd), without additional capabilities? That's a separate discussion. See https://lore.kernel.org/lkml/CAKOZueussVwABQaC+O9fW+MZayccvttKQZfWg0hh-cZ+1ykXig@mail.gmail.com/, where we talked about permissions extensively. Anyone can hammer on /proc today or hammer on kill(pid, 0) to learn about a process exiting, so anyone should be able to wait for a process to die --- it just automates what anyone can do manually. What's left is the question of who should be able to learn a process's exit code. As I mentioned in the linked email, process exit codes are public on FreeBSD, and the simplest option is to make them public in Linux too.