Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp261542yba; Sat, 30 Mar 2019 21:49:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqxUTN72+y7LTHe3LH8WJ6YO1TnO204UkAakTAXh2QHWwopRwg1iP+9+L+O4igknXKFdXWIh X-Received: by 2002:aa7:8c84:: with SMTP id p4mr17339360pfd.164.1554007763346; Sat, 30 Mar 2019 21:49:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554007763; cv=none; d=google.com; s=arc-20160816; b=kpVrGiswSo3QrFBb4pZLLSKQnAAR+1D1QQxachqID9KzYLQMQEp0yxk+iEEYHB/IbB svCSnRrFM4zfnso4Y+eRBw/EfX8de0eMqgUsXHuBRl4oD4jBf1xBMF116mRl5TXzCxwa kIqTQwu7DhqAQ37DK2EWOS8HE4W694vyZKcfXnBddvY6vKwUvJcgEqy18CJIrCoxx4PL bJSMTTsDYSyXrP4La54ZPDom3XyeI8S/gUT4kmjUT/RZBIQVp7HWi6Nv2DzOh8TWzaJV n2s0KIBh0moxiyRZM0QW8i2uaZAUNA6upbG9rC57b0H25KMliVIgHCyt+o/pA33mfGFk nxTQ== 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=N10+ICWZPz8HQk9LeagnflXLIl2Hso1t/TO/QeUqXy8=; b=g633OYHMqX7qkMWchSyFLqh3C2C/Q6oHIBrYpQCzho5rMjnePQNLhOSyFl6jv6dtgq j2mpdDCN0qTXGy9XWb22aUbCNlAE21CCMNgRvxsPh/ktN4GZ/DL7e18nDwFdZItuWA6q 3lOHS5R/qXq50MCmPAUy9WDM7s0MMJreyCVPr2IgJZQlw1vlg1g54V9HivCwBFytR077 E5CGxT/2tQX/nu+wdthl0TcsWOx1ZKbkuUrA0gPNDpp8Z++lMB+sxrZGmKpVG8Ma1XEJ DPWaGQKUfzWbKsJ26+/0uktl6k22nvZl7Zf+PuGJnZuQVPKAFjXOV+JOJzK/qVc0+zPU /PLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fYONZllw; 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 d130si5938598pgc.197.2019.03.30.21.48.41; Sat, 30 Mar 2019 21:49:23 -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=fYONZllw; 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 S1726141AbfCaErM (ORCPT + 99 others); Sun, 31 Mar 2019 00:47:12 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:41756 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725878AbfCaErM (ORCPT ); Sun, 31 Mar 2019 00:47:12 -0400 Received: by mail-ot1-f67.google.com with SMTP id 64so5605514otb.8 for ; Sat, 30 Mar 2019 21:47:11 -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=N10+ICWZPz8HQk9LeagnflXLIl2Hso1t/TO/QeUqXy8=; b=fYONZllw1A39Pp24o5a8YvapRNO7aRT4w9HdWafI8jYVhYwoXr77sveyi5eegYnKfp FFVi1imJpqF1Gbu/1/xBbyvQ6vW5adFKcV57jwzhG7SaQ27aXUZFTU+Zf4wZNNq9XMrr FIs536rsAAzqLsABLrOSdy7HPXwESqNO6Qh6SyJ7KxKCZh3aM7rCc/TuVu42zDejsHNK RT52bwlSnE0zy8me/Cyf0LMHZfdK3/nIRjSwmANNEvfFZU6AwReqIJ4jqrxFwSaZ6J+A xZ0CNdnAlrKsq6vlxq4f5759NMxrv5V6YzTgMl7pin4Ovok4TB593kJheZoYvfAaM73M 4iOw== 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=N10+ICWZPz8HQk9LeagnflXLIl2Hso1t/TO/QeUqXy8=; b=m628HBnbbwC/lXXnclXhx7HgqjLl55Iigzaq78dG4fVv9EyNHpUHOVh+m1AdS6fAt6 RjHmxeTTPO1QMmS8n12B2+aYxjgg39Sj9GW+D0huWSSgFYf5drf84TXPTp+I9H/erTiL 1vx1dmOxq/kmQO9kHxF0l4FWyVpQt0S5TIXIifQh0/FnhoA4WUUJtMvpbptzdPyqroxv c0+2L4MCs9VXS87xLvLXCXVUIO5/1OUJro3NoBR9TZMWtKEfLdtpAklqYZvnOjdT57fd AAcXfcY5euu6o5fn2kDGPDj0PHFIpR2NOP+0KGl7IGQTJE9Fz3oPisq68Q2+bWuZdrtr Nu9g== X-Gm-Message-State: APjAAAX883Pkqq06iVtc1z6kk+YX/n1Tupt/9XHK39ued5rrlhCqWBF9 hUIv3I3wHjC5Ob8Csv4ibcaL4aUB0i9YlZMoJLNSgQ== X-Received: by 2002:a9d:694c:: with SMTP id p12mr39641095oto.242.1554007631275; Sat, 30 Mar 2019 21:47:11 -0700 (PDT) MIME-Version: 1.0 References: <20190329155425.26059-1-christian@brauner.io> <20190331010716.GA189578@google.com> <20190331040810.GB189578@google.com> In-Reply-To: <20190331040810.GB189578@google.com> From: Jann Horn Date: Sun, 31 Mar 2019 06:46:44 +0200 Message-ID: Subject: Re: [PATCH v2 0/5] pid: add pidfd_open() To: Joel Fernandes Cc: Linus Torvalds , Daniel Colascione , Christian Brauner , Andrew Lutomirski , David Howells , "Serge E. Hallyn" , Linux API , Linux List Kernel Mailing , Arnd Bergmann , "Eric W. Biederman" , Konstantin Khlebnikov , Kees Cook , Alexey Dobriyan , Thomas Gleixner , Michael Kerrisk-manpages , Jonathan Kowalski , "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 Sun, Mar 31, 2019 at 6:08 AM Joel Fernandes wrote: > On Sun, Mar 31, 2019 at 04:34:57AM +0200, Jann Horn wrote: > > On Sun, Mar 31, 2019 at 3:07 AM Joel Fernandes wrote: > > > As I said I don't really care about "pidfd" solving any racing issues with > > > /proc//* accesses - because I still find it hard to imagine that the pid > > > number can be reused easily from the time you know which to deal with, > > > to the time when you want to read, say, the /proc//status file. > > > > There have been several Android security bugs related to PID reuse. > > Yes PID reuse will be a problem till we have pidfd_clone and > pidfd_send_signal (and any other pidfd related syscalls). I've never denied > PID reuse is *currently* a problem and the set of pidfd syscalls being > proposed are designed to avoid those. So I'm not fully sure what you mean. > Anyway, I would love to see those security bugs you mentioned if you could > point me to them. https://bugs.chromium.org/p/project-zero/issues/detail?id=851 "Android: racy getpidcon usage permits binder service replacement" https://bugs.chromium.org/p/project-zero/issues/detail?id=853 "Android: debuggerd mitigation bypass and infoleak" https://bugs.chromium.org/p/project-zero/issues/detail?id=1404 "Android: Hardware Service Manager Arbitrary Service Replacement due to getpidcon" https://bugs.chromium.org/p/project-zero/issues/detail?id=1406 "Android: Permission bypass in KeyStore service due to getpidcon" https://bugs.chromium.org/p/project-zero/issues/detail?id=1741 "Android: getpidcon() usage in hardware binder servicemanager permits ACL bypass" > > > I am yet > > > to see any real data to show that such overflow happens - you literally need > > > 32k process deaths and forks in such a short time frame > > > > This seems very inaccurate to me. > > > > The time frame in which the PID has to wrap around is not the time > > between process death and use of the PID. It is the time between *the > > creation* of the old process and the use of the PID. Consider the > > following sequence of events: > > > > - process A starts with PID 1000 > > - some time passes in which some process repeatedly forks, with PIDs > > wrapping around to 999 > > - process B starts an attempt to access process A (using PID 1000) > > - process A dies > > - process C spawns with PID 1000 > > - process B accidentally accesses process C > > > > Also, it's probably worth clarifying that here, "processes" means "threads". > > > > If there are a lot of active processes, that reduces the number of > > times you have to clone() to get the PID to wrap around. > > Ok, that's fair and I take your point. But I wonder what access you're > talking about, is it killing the process? If yes, pidfd_clone + > pidfd_send_signal will solve that in the race free way without relying on the > PID number. Sure, given a pidfd_clone() syscall, as long as the parent of the process is giving you a pidfd for it and you don't have to deal with grandchildren created by fork() calls outside your control, that works. > Is it accessing /proc//? then see below. > > > and on 64-bit, that > > > number is really high > > > > Which number is really high on 64-bit? Checking on a walleye phone, > > pid_max is still only 32768: > > > > walleye:/ # cat /proc/sys/kernel/pid_max > > 32768 > > walleye:/ # > > Ok. I was talking about the theoretical limit of pid_max on a 64-bit > platform. But since we are talking about NOT relying on the PID number in the > first place, we can move on from this point. (pid_t is a signed 32-bit value, that's UAPI.) > > > that its not even an issue. And if this is really an > > > issue, then you can just open a handle to /proc/ at process creation > > > time and keep it around. If the is reused, you can still use openat(2) > > > on that handle without any races. > > > > But not if you want to implement something like killall in a > > race-free way, for example. > > I am not at all talking about killing processes in your last quote of my > email above, I'm talking about access to /proc// files. > > As I said, at the time of process creation, you can obtain an fd by opening > /proc// and keep it open. Then you can do an openat(2) on that fd > without worrying at reuse, no? And then access all the files that way. Yeah, if you're the parent of a process with a termination signal, that works. > As for killall in Android. I don't think that "killing processes by name" is > relied on for the runtime operation of Android. That would be a very bad > idea. Low memory killer does not kill processes by name. It kills processes > by the PID number using kill(2) which we'd like to replace with > pidfd_send_signal. Yeah, I somehow lost context when replying to your mail here; sorry about that. I didn't mean to imply that this is a usecase on Android.