Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp667523yba; Thu, 16 May 2019 07:09:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqylsc4PLnGVjHyWkgBeDuTO6X4lrOImpIpw/aR0JnYmAIvBuOMARkznjXW8rQV8tHcJT0wo X-Received: by 2002:a17:902:9693:: with SMTP id n19mr50161341plp.92.1558015759484; Thu, 16 May 2019 07:09:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558015759; cv=none; d=google.com; s=arc-20160816; b=u2tL4eEmBkDmJlDdnHXky9lOiwM1HLsp9stshxkH73rSNeGUgJMLupK8eHjYSEiePq 5jFkBaNyBQr7SgdkgaoDBxUvvmfk8Rjz2zcXrO97sPtMf3ZfuvGdr2kFk3xAGfV2k/BG RWh/Fcp9r3nmt7qYDgQDkBTPIXSn2I+oP7Q2zF8QeBLMBNrq0UjNP0hgQ3ZkSYZuU7Tx +vozwXI663E4A3T7KQAyRS8+K+e/2jK6lJcXFjvD8TpcYB8kf3JEqeSH5KY2yw0NjmA0 EbQHjB2Yxg0Y6jhedHZxbJiliS8UsYNysNlBNWJ7Igwwx1Ujs1HsS0Ge4kgXg+LXB193 BFGA== 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=bYyJnADr9ubhW5oaXdh9WlhTHjyzAGu0DQI2eQ+pHaE=; b=qndztwAOnCSZlpg5ViCLu1VC+MB7okuA5DWwmntedXl8ayEdQ4DyJDQHkICkHaEhzD jZrXarrlnkJud7dILlfYhwbZ5hXs6M9HRKTPPCFOCnUHTQt/GI+NI2RF8mw4dkJ454dY 0iUf2OhVxZyPqgsHceq/iFAGrdhIPCIwfEiecjg9eNY6xzHa4rSDASEehasGqFtcQDLR Z6TrB6b+w4FUKMBv9ZAzgZUXen4/KIVle5uFKgNlPNof5DBgQKAAogeoKtk4ob3uW53t v13s5cTpqT/PVqmv2JTUUGvpHmCjhsWmlqQOdnzkXadsm825GF/dgZ3pYZHNFrPFll+C 80eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brauner.io header.s=google header.b=MhjOHc+1; 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 b2si4823576pls.279.2019.05.16.07.08.39; Thu, 16 May 2019 07:09:19 -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=MhjOHc+1; 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 S1727697AbfEPOFO (ORCPT + 99 others); Thu, 16 May 2019 10:05:14 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:40998 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727651AbfEPOFN (ORCPT ); Thu, 16 May 2019 10:05:13 -0400 Received: by mail-ed1-f65.google.com with SMTP id m4so5436770edd.8 for ; Thu, 16 May 2019 07:05:11 -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=bYyJnADr9ubhW5oaXdh9WlhTHjyzAGu0DQI2eQ+pHaE=; b=MhjOHc+12NO1kjqTg26hcfpFarWJK6UO4uKen3mnBZiVvgNz65ljzXS/ZRyK+jjEzc /JF15wWLnH7LRgIqtY0MD+nIanFGFyFhIksGgTJWi2bGoTMD18BMjjca67gxxRvxi8+0 yQTTRxRIh7g2VDxBQ0zKZz1vXg1chuW2SN2qbepgb4FeuGMxhGooqxVI7+7FHAOj9N1M FHodeukkhZGpge8teMzG2zc9TJCjzMji+6KCaGF81DZdV6StlcqORhINQ4uQjbmc8vco TjK91z8PkXrFbRk1vdkCD5WKK6krFwmTdVA0wTPdFmhQ9BFoHPYiofHEVgNBJZi0CYJz Lvrg== 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=bYyJnADr9ubhW5oaXdh9WlhTHjyzAGu0DQI2eQ+pHaE=; b=PfD0/MvC0xitazkL56yZmFt41Ok5LlmEDqeBpCWTUC5yBmIBgMI4Ok5EwF+LJx5ENj eEEImsp2FV/4XIcabdTR3NiWxWyh1pifjUwTn/Sj5+fxDmOcCNa+CFd1rKFPvVotOWWL +QFx4GKwZ73fYFh+h9F6aCM13k+GdK+/GN0NX0bw2m/t1W3NQuVlmetZ0GQpd1F50f5K 0fcdWUuwzU5HVDw9JfsEaf4Je/U4lpMYIiHqeOQbfHG37eaHnp7PLeyxfY9rZqYkV39d s/quipI7PULclaqkfLLkj2FrkRHzd79oWIavuVBIZoQPF9RAmza1wFgn81UANB6C61oz sWfA== X-Gm-Message-State: APjAAAV6MnuIfywdRWv8g3t/KYr9th1cysT5hW/FtSOcdpWnAe8VPdJb HF0VR61vbDpAAXccbWVZ/mRvNA== X-Received: by 2002:a17:906:65d2:: with SMTP id z18mr20105763ejn.68.1558015510995; Thu, 16 May 2019 07:05:10 -0700 (PDT) Received: from brauner.io ([193.96.224.243]) by smtp.gmail.com with ESMTPSA id b53sm1120044edd.89.2019.05.16.07.05.09 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 16 May 2019 07:05:10 -0700 (PDT) Date: Thu, 16 May 2019 16:05:08 +0200 From: Christian Brauner To: Jann Horn Cc: Daniel Colascione , Oleg Nesterov , Al Viro , Linus Torvalds , linux-kernel , Arnd Bergmann , David Howells , Andrew Morton , Aleksa Sarai , "Eric W. Biederman" , Elena Reshetova , Kees Cook , Andy Lutomirski , Andy Lutomirski , Thomas Gleixner , linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390 , linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org, Linux API , linux-arch , "open list:KERNEL SELFTEST FRAMEWORK" Subject: Re: [PATCH 1/2] pid: add pidfd_open() Message-ID: <20190516140507.75crjbaulasw6mj6@brauner.io> References: <20190515100400.3450-1-christian@brauner.io> <20190516130813.i66ujfzftbgpqhnh@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 Thu, May 16, 2019 at 04:03:27PM +0200, Jann Horn wrote: > On Thu, May 16, 2019 at 3:08 PM Christian Brauner wrote: > > On Wed, May 15, 2019 at 10:45:06AM -0700, Daniel Colascione wrote: > > > On Wed, May 15, 2019 at 3:04 AM Christian Brauner wrote: > > > > > > > > This adds the pidfd_open() syscall. It allows a caller to retrieve pollable > > > > pidfds for a process which did not get created via CLONE_PIDFD, i.e. for a > > > > process that is created via traditional fork()/clone() calls that is only > > > > referenced by a PID: > [...] > > > > +/** > > > > + * pidfd_open() - Open new pid file descriptor. > > > > + * > > > > + * @pid: pid for which to retrieve a pidfd > > > > + * @flags: flags to pass > > > > + * > > > > + * This creates a new pid file descriptor with the O_CLOEXEC flag set for > > > > + * the process identified by @pid. Currently, the process identified by > > > > + * @pid must be a thread-group leader. This restriction currently exists > > > > + * for all aspects of pidfds including pidfd creation (CLONE_PIDFD cannot > > > > + * be used with CLONE_THREAD) and pidfd polling (only supports thread group > > > > + * leaders). > > > > + * > > > > + * Return: On success, a cloexec pidfd is returned. > > > > + * On error, a negative errno number will be returned. > > > > + */ > > > > +SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags) > > > > +{ > [...] > > > > + if (pid <= 0) > > > > + return -EINVAL; > > > > > > WDYT of defining pid == 0 to mean "open myself"? > > > > I'm torn. It be a nice shortcut of course but pid being 0 is usually an > > indicator for child processes. So unless the getpid() before > > pidfd_open() is an issue I'd say let's leave it as is. If you really > > want the shortcut might -1 be better? > > Joining the bikeshed painting club: Please don't allow either 0 or -1 > as shortcut for "self". James Forshaw found an Android security bug a > while back (https://bugs.chromium.org/p/project-zero/issues/detail?id=727) > that passed a PID to getpidcon(), except that the PID was 0 > (placeholder for oneway binder transactions), and then the service > thought it was talking to itself. You could pick some other number and > provide a #define for that, but I think pidfd_open(getpid(), ...) > makes more sense. Yes, I agree. I left it as is for v1, i.e. no shortcut; getpid() should do. Christian