Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp3739750img; Mon, 25 Mar 2019 17:13:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqyp7CCY9237G7T7PvI69x33muYHdx9ylvDKiubtXDVWCBYJ/PlxbEInae3Fbvdq2WvuXGzR X-Received: by 2002:a17:902:2c83:: with SMTP id n3mr28902765plb.281.1553559238190; Mon, 25 Mar 2019 17:13:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553559238; cv=none; d=google.com; s=arc-20160816; b=slaAmgz2wvE2FGRi7FbTZz4iXoWPFCizk8HFTcWBkY30VQF0vGOwdbBoA1YOu/mUk1 yhIFzrkzLYoPwiH7o8IROzZfeO+jiOsJh1KKLv/sWAdO9fsoM5fBMuU3ApSU/LP5fopL 5XNHgAhpt4MA59H1zmNTZRipzRhas583JVflAz2KJ4nfNyNn7ITXR8otjrqj4G1h50M5 HfO5L+iCLsie3VcWQRfq9WQ0hO/lSVv9RxW4AzuSZ7S3HN2oF5dgFit+CT5QBHqqcnSs kRrVXvEbWInGspfPxWnIw3KYG//UjQk7IzkFmsKlE0LOW5tZx+SxeJsyZHV2IHsptE9M gBgA== 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=EUv+xdNYdc786qvzqesqD1NyIqXBHKDwzmd4iq/Z2dA=; b=UR2T4ZuTtRDyl1BiWuPeX+YuGUqEKsci5TZ1uvyRo21Qf2sMdYmp5RIV0bzFuWscaE FwSqUScjskAjyxSUUGh+FuvqzWHKhR+5qCUwhpqXfuBSVx/Cp56P4CJ0RGJY+GLO1rNz cvDn43XJYXWKVmihFSPXqtTrmPdccr48J81CQ+WEEGwihaZOOBW1zJ/AwlbQPMDUXg3s mlvEg4wy3B/pXKKuaJqn4/pbk1SgOcTLg3cGDu+UD9rIHV8AKQtTGp1gyu9kbnDhFWjd OIuyD+E9kC7xWd/di48VpJHSIKmQmMcQhdX3AfZbke1irUMVdPva9R+GOoA9ssvtkkXD iNlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brauner.io header.s=google header.b="RpHO7y/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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p10si14859573plk.413.2019.03.25.17.13.42; Mon, 25 Mar 2019 17:13:58 -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=@brauner.io header.s=google header.b="RpHO7y/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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730273AbfCZAMh (ORCPT + 99 others); Mon, 25 Mar 2019 20:12:37 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:33245 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726553AbfCZAMg (ORCPT ); Mon, 25 Mar 2019 20:12:36 -0400 Received: by mail-ed1-f65.google.com with SMTP id q3so9210969edg.0 for ; Mon, 25 Mar 2019 17:12:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brauner.io; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=EUv+xdNYdc786qvzqesqD1NyIqXBHKDwzmd4iq/Z2dA=; b=RpHO7y/DbBoeKKb1sWkAm1Zq34D0HBEHkTMQ8gOeNS0ZEBU2/QEf9LXSMXrummEzRr 6y8eupxHC1MqO9lZX3vIllY2PeQ7UrzaqaS7ytDCbD9ufN+L+dKJrEwKLyEPClmKQXEg p4V3lhH+WvyA+4avMEmIqwCMC/4qEslcDxg138c/HmEATWnOKcHZQMiPlZAuFbzn8K/j C3x6oQAVabgxT/BsGVSJqghe2BD2X/r4n+slDrhbSLiJ4ti4DmlDduifM3GxwRC0N7QN Fb8bL+1KJFIsU4T628j33bt2Nf3NrOXR85W+5ZcS3B7qWTa/JhrtHDlI/zTrDwjh7vgt JTAw== 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=EUv+xdNYdc786qvzqesqD1NyIqXBHKDwzmd4iq/Z2dA=; b=tCnSh4z7GhBgoEjHpnnO7X+6/Wluwz6kih3iljsUkLSPsxyXvS6eeTc3dBQhPETOxO 0Fb7GOcTu47TxX8GHQNGpdB+nBIy8u6KOQAOUj6NKq4Li3W90Uqpe+OhyCyTtP+/P33P 0/XsR2Q9z9e2n8NVLoMYoUOqYMcTAwfOTUYnoLlegaJMBDYYQgwD93e5CSDymhYhgE/b 0YMGmbESGCxI8b/5Xlo647Ca/6FNWgdtQRs2ka5da7vM3j5pAcF8Y+yTLI0wUPVi9hiz B5xbmaUj8dhFacg/SrVttlDo1OMJ7R2/yHozLb3EHVE91KfZIryvWsFKGkKeP/T2enoY LAuw== X-Gm-Message-State: APjAAAVmXppdO0xmQfK0HEFkQWAL/3rEMNrxmgcur39/t2T42kMvuaQB O48l/Ay8LHoUg5d2sGdJ1MsOvA== X-Received: by 2002:a50:91d3:: with SMTP id h19mr18484493eda.218.1553559154256; Mon, 25 Mar 2019 17:12:34 -0700 (PDT) Received: from brauner.io ([2a02:8109:b6bf:d24a:b136:35b0:7c8c:280a]) by smtp.gmail.com with ESMTPSA id z17sm5767689edi.67.2019.03.25.17.12.32 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 25 Mar 2019 17:12:33 -0700 (PDT) Date: Tue, 26 Mar 2019 01:12:32 +0100 From: Christian Brauner To: Andy Lutomirski Cc: Daniel Colascione , Jann Horn , Joel Fernandes , Suren Baghdasaryan , Steven Rostedt , Sultan Alsawaf , Tim Murray , Michal Hocko , Greg Kroah-Hartman , Arve =?utf-8?B?SGrDuG5uZXbDpWc=?= , 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 Subject: Re: pidfd design Message-ID: <20190326001231.3tnhhlvzg26mof33@brauner.io> References: <20190320185156.7bq775vvtsxqlzfn@brauner.io> <20190320191412.5ykyast3rgotz3nu@brauner.io> <20190325234547.wo6lyimrp52qie5p@brauner.io> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 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 05:00:17PM -0700, Andy Lutomirski wrote: > On Mon, Mar 25, 2019 at 4:45 PM Christian Brauner wrote: > > > > On Mon, Mar 25, 2019 at 04:42:14PM -0700, Andy Lutomirski wrote: > > > 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. > > > > The other option was to encode the pid in the callers pid namespace into > > the pidfd's fdinfo so that you can parse it out and open /proc/. > > You'd just need an event on the pidfd to tell you when the process has > > died. Jonathan and I just discussed this. > > From an application developer's POV, the ioctl interface sounds much, > much nicer. Some people are strongly against ioctl()s some don't. I'm not against them so both options are fine with me if people can agree. Christian