Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp3720883img; Mon, 25 Mar 2019 16:44:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqziAhpg6xs081bdFvwvIQrsjzg3Rd119ZK/B03ux2FU5wp6yJz5xqT9VfIyd3rAnnVdeKyw X-Received: by 2002:a62:b608:: with SMTP id j8mr27518819pff.183.1553557485151; Mon, 25 Mar 2019 16:44:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553557485; cv=none; d=google.com; s=arc-20160816; b=R+4mzurjIULgH15JoV+QtU6bRVCi/sli/veqF1yCEYlagPUrfLsapSfjX1cbmLAwDZ ByRh8lLg8dJ6JTGZ1mth3K6FsS1ekezTZ/8FMuIul6PRmLDF3UwypBdd+i4xk1P4atIW F7EdRNncV3X9GCYXkx0ZJPtnXfMv4dDDJ+1nMDduIOFtCm0wGkbVU7KEgPb/LD8yTZci tHLBVGw0KxzRO2NQ2BGQLxRaxAJg3tjfa4nmiKwyBhRtRbXyzUH2SP/HaNnO0Eh7P8KM +gZ9lDsRy1eNLSSnIjGLx0FMBa/+HbFG6tfi2aISvCDa3+KCbZ1TF/J8PFpK+NgRlAWp DElw== 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=OxM8WM56bdIxohxJESFvPRW7wrHVtEd54KEmTwxxrOs=; b=xll7MegOByELgGql+WEQhfc4n/FAg1SOfltBEIoAjpDhZpIIXS4aaFCKx4MSYL0OFR AKH5Q8/l9NezIdSYBzJAlSS1C5aQnKVNz52xVUNmytfEh5sNVFjxbUTnUVzoRtgAXbCN E9OTUWJOsuc5E4BcGJ6Pkdf6RmaDtPzQ/Qu8vv69Sv0eR/fEDCsigrKJAhX/sOmAYR56 gLZpKN3FIJ0k/sljZtZf/Rk2S+5dGAYkyNNsxRCsZB6SuJiVjNWIbBCU/wXptbDffAwL +NUkWXpaAVAflSKzjPSXkGufmFE5G0HLU/1hbc0beXLOaw7Q/P+JVRN5vAOx02IAufb2 dPFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Ep/KL1+d"; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m8si10108776pgp.68.2019.03.25.16.44.29; Mon, 25 Mar 2019 16:44:45 -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=@kernel.org header.s=default header.b="Ep/KL1+d"; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730513AbfCYXma (ORCPT + 99 others); Mon, 25 Mar 2019 19:42:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:50232 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726553AbfCYXm2 (ORCPT ); Mon, 25 Mar 2019 19:42:28 -0400 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3D3AE20854 for ; Mon, 25 Mar 2019 23:42:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553557347; bh=9HKKstgDeo0vs0rQiPhWD1UARtFAZEryCAqL281TzC8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Ep/KL1+deZDNfjqGXtXYY2NdhRdebRBYCVkEuBUYdm/oXouy1NtxYOcVOzWAQt4dt zCssZYorC9vIBLmbaA4sjJHg3cA3l3jDlLpzPNPfBQCKQIbAFXZb1KvlvSPJ5ayGnl iqDJ+CmHgaz9JQmvjSoazOPgJWtxNJDMqP6yQUMk= Received: by mail-wm1-f47.google.com with SMTP id y197so10956617wmd.0 for ; Mon, 25 Mar 2019 16:42:27 -0700 (PDT) X-Gm-Message-State: APjAAAUX3ML+Xz/Bp9aMDNTsLwn0kRlj3FP50IAwCYl7uSx8dXE4XRxi gZtsh0fufFiM5eyRpFcnFf2xgWfgVr8JFiYSduCZpw== X-Received: by 2002:a7b:c257:: with SMTP id b23mr12729658wmj.83.1553557345804; Mon, 25 Mar 2019 16:42:25 -0700 (PDT) MIME-Version: 1.0 References: <20190319231020.tdcttojlbmx57gke@brauner.io> <20190320015249.GC129907@google.com> <20190320035953.mnhax3vd47ya4zzm@brauner.io> <4A06C5BB-9171-4E70-BE31-9574B4083A9F@joelfernandes.org> <20190320182649.spryp5uaeiaxijum@brauner.io> <20190320185156.7bq775vvtsxqlzfn@brauner.io> <20190320191412.5ykyast3rgotz3nu@brauner.io> In-Reply-To: From: Andy Lutomirski Date: Mon, 25 Mar 2019 16:42:14 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: pidfd design To: Daniel Colascione Cc: Jann Horn , Andy Lutomirski , Christian Brauner , Joel Fernandes , Suren Baghdasaryan , Steven Rostedt , Sultan Alsawaf , Tim Murray , Michal Hocko , Greg Kroah-Hartman , =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , Todd Kjos , Martijn Coenen , Ingo Molnar , Peter Zijlstra , LKML , "open list:ANDROID DRIVERS" , kernel-team , Oleg Nesterov , "Serge E. Hallyn" , Kees Cook , Jonathan Kowalski , 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 Mon, Mar 25, 2019 at 1:23 PM Daniel Colascione wrote: > > On Mon, Mar 25, 2019 at 1:14 PM Jann Horn wrote: > > > > On Mon, Mar 25, 2019 at 8:44 PM Andy Lutomirski wrote: > > One ioctl on procfs roots to translate pidfds into that procfs, > > subject to both the normal lookup permission checks and only working > > if the pidfd has a translation into the procfs: > > > > int proc_root_fd = open("/proc", O_RDONLY); > > int proc_dir_fd = ioctl(proc_root_fd, PROC_PIDFD_TO_PROCFSFD, pidfd); > > > > And one ioctl on procfs directories to translate from PGIDs and PIDs to pidfds: > > > > int proc_pgid_fd = open("/proc/self", O_RDONLY); > > int self_pg_pidfd = ioctl(proc_pgid_fd, PROC_PROCFSFD_TO_PIDFD, 0); > > int proc_pid_fd = open("/proc/thread-self", O_RDONLY); > > int self_p_pidfd = ioctl(proc_pid_fd, PROC_PROCFSFD_TO_PIDFD, 0); > > This sounds okay to me. Or we could make it so that a procfs directory fd also works as a pidfd, but that seems more likely to be problematic than just allowing two-way translation like this > > > > And then, as you proposed, the new sys_clone() can just return a > > pidfd, and you can convert it into a procfs fd yourself if you want. > > I think that's the consensus we reached on the other thread. The > O_DIRECTORY open on /proc/self/fd/mypidfd seems like it'd work well > enough. I must have missed this particular email. IMO, if /proc/self/fd/mypidfd allows O_DIRECTORY open to work, then it really ought to do function just like /proc/self/fd/mypidfd/. and /proc/self/fd/mypidfd/status should work. And these latter two options seem nutty. Also, this O_DIRECTORY thing is missing the entire point of the ioctl interface -- it doesn't require procfs access. --Andy