Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp650192yba; Wed, 15 May 2019 07:40:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqy/BvC9Sz2hevuqyD1246xKnVsx10S9Yow2uKsK/CZl0WwKg3gIsyKGd2LK/iyQ/FVIfk/K X-Received: by 2002:a63:5608:: with SMTP id k8mr45106346pgb.393.1557931250161; Wed, 15 May 2019 07:40:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557931250; cv=none; d=google.com; s=arc-20160816; b=JBhyK+TMoLtW28jbEzVBvyjaQfkdgLjxp2XMiTTY/8dyyAMyOj5pcW/8bA6IAE2Tab UlOdbczErKHw1A5+mYhCx+k9Oi7TwgCgDh7Kmy4Q2EZVpFz79MzB6CQ550MsYmo9cnHW FVQv35m9oiLp8mDkcVbWQlD4oIB1PI1uvPTTZ47agNuCqJKod+/eGh9/WQFR1ikHJQYO Tzm395TLKUgLYg8kWiHTfwIosowQP2RAj2kWoIMMUhXTyS/rcmCwR5OzReKQJ+SVsrsN vaPI4ixTuwdpo19wcU04K8pehz2D9Z4SGzmsFas+6RDIv4+sJj/quhmpJvIFQS/xCV5D 5t4g== 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; bh=q/vRzGQE+4HtjOUgEPo3Wk2qY9XFe1QCz7/kP31V+Jw=; b=hRx1zXUrq0VzSHexkY9ThcbHvEwY99yZ1y7El7hU3BxvQwNwIe2ZElMkB7MbFMbcYl 87xsRP7ZcIxVM0rVe6ErIeW2BzkQpq29Egtbllgn38aAXXBGaCl6ZP6R6S9/i5ql38e0 XWzHKqpT5EUoxZmUjQ73AEDMjPBXVWMXhQH/8Q4TfOJWIBWXMZSRxqcB6MLIuQOssdih Ktb7OvScaIqiw6j4RYXg0AoEn41Mr8trG0JXDKtP92M9B6a+QIv6zHmFQ2E9TpkmVBGM 4R8IZ1IfjKZJcscW1cGKejGuFlHqSjpyrBw3qF8TOP7e0qrFKTQFQ+jhRk9trtdYc5h8 +r0w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a71si1957277pge.211.2019.05.15.07.40.35; Wed, 15 May 2019 07:40:50 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728093AbfEOOj2 (ORCPT + 99 others); Wed, 15 May 2019 10:39:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57012 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726452AbfEOOj1 (ORCPT ); Wed, 15 May 2019 10:39:27 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0BF1451471; Wed, 15 May 2019 14:39:11 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.159]) by smtp.corp.redhat.com (Postfix) with SMTP id 7F2A15D706; Wed, 15 May 2019 14:39:01 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Wed, 15 May 2019 16:39:08 +0200 (CEST) Date: Wed, 15 May 2019 16:38:58 +0200 From: Oleg Nesterov To: Christian Brauner 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: <20190515143857.GB18892@redhat.com> References: <20190515100400.3450-1-christian@brauner.io> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190515100400.3450-1-christian@brauner.io> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 15 May 2019 14:39:26 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(). > + 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. Oleg.