Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp659641yba; Wed, 15 May 2019 07:50:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqzNByq3y3w1W54rwB9XQ1cVjYU5yTAO71/FtOCWQqMMLitR2H2ypKj+ve0MTHKIx8COwt0M X-Received: by 2002:aa7:8b12:: with SMTP id f18mr47250241pfd.178.1557931857933; Wed, 15 May 2019 07:50:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557931857; cv=none; d=google.com; s=arc-20160816; b=GgjyRN8L1VgREHeFYqhUz6WUYh3FsHrm0gt4IqWKoQGTIbBLeDMUnNnsoxW7s9Lqrk IJiO7vM36ZMVL61p+uW4QGNLpHSKduUsR7ZyFxuDyCroQuJTYYorWyETaV8QWpoIo/to Mf39HANuSD8YA3/MZ99FHE49T19Vj21VV2ftiYXieJkEV+Fi8DqBXSpZYKK8nR+sZ3fr HM+UtLzW8SP9SfSVa/I16YxioWRybtdEUiy/+rJPeuROrbLNnRvx3gulj3qddyI8h8Dc zPP3Fea/VbBnGL9LyBEy2rDRFaeOmpq8fJytmtmzuumRroERPJbeHXOJkSp8lumZ3/iK IAPA== 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=oKULkZSRwqaiQxP7TL4UYPkN+uTDZlr88Vcbz3QuA1I=; b=0HT2jWnQZw33KazdHd65m0sQhC3zw4lnWFj6aqdYHgVKRAUR+d3RQVgVkhpB5vH59d ZK0QGmpvfpA038rLSy+Jf7mLx2Yer1fEnHFzSRGugokTtZOpzhI7Wy6SmkQKrNx1FVkN /JQNp8Lmx8j7EUqvjdONUhIinzEcKLH2IRpl9ytDan+tGskLoH0zMZv5cOQtYpVQYLKa FHhYum2rIHwD4xOXCTLhDL7g5Qp51XLIIm9f/pKxzbKhZ3Zj+JiDl+zCOri3iiue9MtK SussL0YNp5aIk+vNfGGIRurSDn7AvGXZj0QT/PYHY59+yTVNJOmJYNPBTmoaEJoVNN7c ilvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brauner.io header.s=google header.b=gbthNhor; 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 s21si1999263pgk.139.2019.05.15.07.50.42; Wed, 15 May 2019 07:50:57 -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=gbthNhor; 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 S1727991AbfEOOtd (ORCPT + 99 others); Wed, 15 May 2019 10:49:33 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:35735 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727472AbfEOOtc (ORCPT ); Wed, 15 May 2019 10:49:32 -0400 Received: by mail-ed1-f68.google.com with SMTP id p26so243580edr.2 for ; Wed, 15 May 2019 07:49:31 -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=oKULkZSRwqaiQxP7TL4UYPkN+uTDZlr88Vcbz3QuA1I=; b=gbthNhordMIYVnTy317gMGg6f/dfC5iQgBxjq6Pg3jScMLdLI0Vq4OcwB79UHvgEgC U1AgURPKc8JVgJXOo0PlK1NBODmUH4LG0c3iQOkHAxHOhxIV3lZFFgtryVL471yH2yaW C3klxUr1MKghIvHXbdcitmAziIPiCtbEw5zo2mlbo+BrqzIdRMNr8g8Hd8yvC+RFkoND 3U7iWRnczi1gGSuo/hShIfYUEndn7uxrlNKw8BfZPzT5nVaY90n0JScdqCfYtxsar1cX tdmjNXgvyrjanexmF/91CzUGx8XsXtV3i+hqAVIqFgPvc7YR3o00EzVeVZB9N4qN/XJl yDqg== 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=oKULkZSRwqaiQxP7TL4UYPkN+uTDZlr88Vcbz3QuA1I=; b=S7L+atl7VfW+5CJYQxbfOa5PfCoHzPOkJ3fDPojZr041sSISYDilUz1WCqaxo3EmGj e4PjseFhE2+V/rerxgisLvlV4wfSoQKJNVn6WnUef6ELPEptu06Nr8VmpktuarV4fSIw 5pe9JkmSH+km533uQi66vddN2w7h3QTFUDt/XzXZkH8vXUKoyQcwfaFC2i4nJRB6JeOE HTLCUlN48Qt1bPQW1U3ZwQwHqmbLslYigw7wr4fY6E15lQs+sVnauXSYwqBaqBj13jym 7dPqyQShUD/MnP5SKTndd2rhgAa1j9kEzyy/2YnYSwuXzYjv0KrFZTRDB2/BivvffVJS v45Q== X-Gm-Message-State: APjAAAUS+e+DLChUv7Ciux6879HS39JgIhXLmShy1JAkaDgoMgP4Z/q5 xfTT5gkc2ZoJgE27il8rWXJdvA== X-Received: by 2002:a50:8eb6:: with SMTP id w51mr43141017edw.34.1557931770356; Wed, 15 May 2019 07:49:30 -0700 (PDT) Received: from brauner.io ([178.19.218.101]) by smtp.gmail.com with ESMTPSA id a32sm873557ede.76.2019.05.15.07.49.29 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 15 May 2019 07:49:29 -0700 (PDT) Date: Wed, 15 May 2019 16:49:28 +0200 From: Christian Brauner To: Oleg Nesterov Cc: jannh@google.com, viro@zeniv.linux.org.uk, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, arnd@arndb.de, dhowells@redhat.com, akpm@linux-foundation.org, cyphar@cyphar.com, ebiederm@xmission.com, elena.reshetova@intel.com, keescook@chromium.org, luto@amacapital.net, luto@kernel.org, tglx@linutronix.de, 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@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH 1/2] pid: add pidfd_open() Message-ID: <20190515144927.f2yxyi6w6lhn3xx7@brauner.io> References: <20190515100400.3450-1-christian@brauner.io> <20190515143857.GB18892@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190515143857.GB18892@redhat.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 15, 2019 at 04:38:58PM +0200, Oleg Nesterov wrote: > On 05/15, Christian Brauner wrote: > > > > +SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags) > > +{ > > + int fd, ret; > > + struct pid *p; > > + struct task_struct *tsk; > > + > > + if (flags) > > + return -EINVAL; > > + > > + if (pid <= 0) > > + return -EINVAL; > > + > > + p = find_get_pid(pid); > > + if (!p) > > + return -ESRCH; > > + > > + rcu_read_lock(); > > + tsk = pid_task(p, PIDTYPE_PID); > > You do not need find_get_pid() before rcu_lock and put_pid() at the end. > You can just do find_vpid() under rcu_read_lock(). Will do. > > > + if (!tsk) > > + ret = -ESRCH; > > + else if (unlikely(!thread_group_leader(tsk))) > > + ret = -EINVAL; > > it seems that you can do a single check > > tsk = pid_task(p, PIDTYPE_TGID); > if (!tsk) > ret = -ESRCH; > > this even looks more correct if we race with exec changing the leader. The logic here being that you can only reach the thread_group leader from struct pid if PIDTYPE_PID == PIDTYPE_TGID for this struct pid? Thanks, Oleg. Christian