Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp3596864img; Mon, 25 Mar 2019 13:35:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqz8eECFSKXZLSfQQ1LcKahO6YXvqLH+uUWpL9dnKPVaZ7vlt/yugdD7iQ1aLz61boV/u0B1 X-Received: by 2002:a63:4718:: with SMTP id u24mr25566956pga.381.1553546122839; Mon, 25 Mar 2019 13:35:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553546122; cv=none; d=google.com; s=arc-20160816; b=pObVFfGYV351jGPhihaDEtwXaUuKm+hBwljEDi7gj+C0ouE8BKBf1BBh+HIP8dS49U y0wtXXufp0cIStFoecVrDgG+ztkp1ILam0ZLq3JTbw6BM24DWPCIGWywOOtN/xOFcMri KB7kQM4FK1sDTeuGvq8awRyqNEL2N9mEenf/dKJCjEl40Et1HyxsI3B9xAa1yOeAO0L/ jU7jCcxcwJdmUSaDlWysPJpgrBqcY4BbKoUv3CS0SXH5DsZslGFK2sxRTTW8pRPkcgL0 f9NS9w2TZCwhwk2/4bmLpiu3SxnO4OcpGL+78nVXVzCtp1SoLI92gg4CXGGg6TeQbwKR PP6A== 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=epcnJRVRcwZXdSQ+iTPglDNMRevkUZIbnelduCAg4CI=; b=JPJlVJZDGTLrQzi8ZbraCpgKqF0g0sMHko6NDJls7Px82tvYfIHbHtN49QZH6UndRo Zzxtk3NIzMiqjjxkGrWmYPIuMqIUm7l38HGGR7s7rPilT6X7e314GHLR405xbTCOklVV rd08UhX7+4LHHcrlNX/DAGFIutA5bq4w3nSr6bAk8aMqeuGY+ET+S+UyGGjq3jDFdKkb JkebmyOUMeqhVM0LQ40NCZzBxMXz81QUYYsOB+oxI7TEqLE7HfT5F/8zRtgiRrfaWq4q Z4JMGmyDQyLUrwUu9+N9ARbrToqoaP5LhWSWrYeSvA55TZKAnNtn7jZsGaNMxbzilJlK Ac6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=JQcLdfA5; 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 e2si7693687plt.197.2019.03.25.13.35.07; Mon, 25 Mar 2019 13:35:22 -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=JQcLdfA5; 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 S1730236AbfCYUe1 (ORCPT + 99 others); Mon, 25 Mar 2019 16:34:27 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:39922 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729610AbfCYUe1 (ORCPT ); Mon, 25 Mar 2019 16:34:27 -0400 Received: by mail-ot1-f67.google.com with SMTP id f10so9357843otb.6 for ; Mon, 25 Mar 2019 13:34:26 -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=epcnJRVRcwZXdSQ+iTPglDNMRevkUZIbnelduCAg4CI=; b=JQcLdfA5zk+hKV/2XesKq9vYN6WriVOLPAgTeMkFYqiUJakkOKoHWuS0lOfdXl7AUQ neRHS1hJTHTUfpuxDz33edboR36JwF4UYdGQH8TNf3Xswg3ql0XIpc5KbYclXdeI5RhP 5LOchdkEhF2aQDEQoXxHWisRvYlMaL4M826rBCSuXGxtXXE/6xo2SzqFMW+eRaqU0QPt pbXdSkNGtt+JfKkCHhGT15UEJRgZKCt1iHCEhbep3xO1l2KsiXaAdaKcoZAnus23HiCb 14y4FD++oZA2tsyjCWPMhHWLGvNkyRFPX52G1IBVdbda37dAww8Y/cEAWSdPmX6bzz86 U7vw== 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=epcnJRVRcwZXdSQ+iTPglDNMRevkUZIbnelduCAg4CI=; b=E30gNRkLlDBVXqxXN+pWOJFtEAuNIH5U14ta6Fn7C+etl9UPpLAohv3mzOUP4Q7uqT FpepiaDgmKWxl6nju1j8I0V/mDRM2QZ0XJljFnT+2kqfYdbMwaQyhCFBqzW51xdNn0nQ D7+We0nn4x8Qe7IAf6DaJnbjO3cUr8i7y1OQBnRfHFHKNApZzVYF4oO47+ZzEHscunnQ 8YMh/b6nwcJcmEekYeHNwKpT/a8O2OaYrvi5pv4aYffHMUHsBfH9ucIqzrbBef0Zo1ML 99RhW5Dh1QelNHFWW1WScYAkNXC+bSXi/XqygrqUv26/Ukh9TQPbZEbXOgEoSjXuC19q 3PEg== X-Gm-Message-State: APjAAAVkcGWRDJQbW19MLz6ns/OciR9L0ST959bFWDAhus7pifgS68DY +2X0d4ML1rRS/Db2bSfL+iKgZ4TvQ+4nnoRVMO3+YA== X-Received: by 2002:a05:6830:1216:: with SMTP id r22mr20490544otp.198.1553546066315; Mon, 25 Mar 2019 13:34:26 -0700 (PDT) MIME-Version: 1.0 References: <20190325162052.28987-1-christian@brauner.io> <20190325173614.GB25975@google.com> In-Reply-To: From: Jann Horn Date: Mon, 25 Mar 2019 21:34:00 +0100 Message-ID: Subject: Re: [PATCH 0/4] pid: add pidctl() To: Daniel Colascione Cc: Jonathan Kowalski , Joel Fernandes , 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 9:15 PM Daniel Colascione wrote: > On Mon, Mar 25, 2019 at 12:42 PM Jonathan Kowalski wrote: > > On Mon, Mar 25, 2019 at 6:57 PM Daniel Colascione wrote: [...] > > Yes, but everything in /proc is not equivalent to an attribute, or an > > option, and depending on its configuration, you may not want to allow > > processes to even be able to see /proc for any PIDs other than those > > running as their own user (hidepid). This means, even if this new > > system call is added, to respect hidepid, it must, depending on if > > /proc is mounted (and what hidepid is set to, and what gid= is set > > to), return EPERM, because then there is a discrepancy between how the > > two entrypoints to acquire a process handle do access control. > > That's why I proposed that this translation mechanism accept a procfs > root directory --- so you'd specify *which* procfs you want and let > the kernel apply whatever hidepid access restrictions it wants. [...] > > > and 2) it's > > > "fail unsafe": IMHO, most users in practice will skip the line marked > > > "LIVENESS CHECK", and as a result, their code will appear to work but > > > contain subtle race conditions. An explicit interface to translate > > > from a (PIDFD, PROCFS_ROOT) tuple to a /proc/pid directory file > > > descriptor would be both more efficient and fail-safe. > > > > > > [1] as a separate matter, it'd be nice to have a batch version of close(2). > > > > Since /proc is full of gunk, > > People keep saying /proc is bad, but I haven't seen any serious > proposals for a clean replacement. :-) > > > how about adding more to it and making > > the magic symlink of /proc/self/fd for the pidfd to lead to the dirfd > > of the /proc entry of the process it maps to, when one uses > > O_DIRECTORY while opening it? Otherwise, it behaves as it does today. > > It would be equivalent to opening the proc entry with usual access > > restrictions (and hidepid made to work) but without the races, and > > because for processes outside your and children pid ns, it shouldn't > > work anyway, and since they wouldn't have their entry on this procfs > > instance, it would all just fit in nicely? > > Thanks. That'll work. It's a bit magical, but /proc/self/fd is magical > anyway, so that's okay. Please don't do that. /proc/$pid/fd refers to the set of file descriptors the process has open, and semantically doesn't have much to do with the identity of the process. If you want to have a procfs directory entry for getting a pidfd, please add a new entry. (Although I don't see the point in adding a new procfs entry for this when you could instead have an ioctl or syscall operating on the procfs directory fd.)