Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp692298yba; Wed, 15 May 2019 08:20:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqz4vkbCQmvb+E2kPt3Z+Xv4H3Hc6XyfjpllPr8LspbAdXD7wqKAT7otJT28tDPjbLLgW5/I X-Received: by 2002:a63:5c5f:: with SMTP id n31mr45142380pgm.325.1557933649764; Wed, 15 May 2019 08:20:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557933649; cv=none; d=google.com; s=arc-20160816; b=MvygtHQ6ViRX2Syz5pJCPrPsSlALmARupzZ96XZJBhuqfdJddUlZUQXEw3nusCo0tP T9Eky7/eYA4ODW6zVgbt+QANxlphJbdqUNa64jeDfWsSMhekNP1QJpdxgql4AQO91h+5 yMd/be6quKefJ0yH2HZEI9F8dNZihr1q2xqP59YtS4khSLYJpNrzrDRZJTh/fXn5R0YN OLenD0FT5H05G8sFBgofcU2/1VH1F9BX/uD3M82W44XnjXezjRdXsn2Unc3uu0ofN/1e a5LzRU4ZIDCpLDxAJtscasLy+NGPanZIu4NKweK2zOgwyRhvp2BKVoiytkarJIjmdebl j5nA== 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=/nsDv4vXDDtdxCgezB7uE4EXdGuGYw+kRkNGrGlUjVE=; b=S6/1/Cq5lqqrdmOnmedFrsAKMVF75StW8QVVr86UGFc9DlewOpKd7jJEkHJhsYy20L gI/Gwu4mc9k/9sTYfL0r5VyKM2osDZc/ALaK39364GukZSvM5GsIUKkP2Y4o9FrC/aKc 0EKy86uqO/55fzvRfgvedymLSFusfToJ0NKfxykg5OyfCdDx4CjmDhYCvTwuWElnh3Rk wKj8n+WlRnP6dPP7aBj72N6mEJS1LTMXlTxf/8S0C6bmeNiVJufO4op5l+YckhJ3Xl2N DErusFoJdWf4fALOZ6r+uieDTmmLcnrqezil3DO+PGEONXm5ANqQLc60bf/xMYlJLqn7 VYpA== 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 w16si2002813pgk.290.2019.05.15.08.20.34; Wed, 15 May 2019 08:20:49 -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 S1728130AbfEOPTX (ORCPT + 99 others); Wed, 15 May 2019 11:19:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26961 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726581AbfEOPTW (ORCPT ); Wed, 15 May 2019 11:19:22 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1942D301A3E1; Wed, 15 May 2019 15:19:22 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.159]) by smtp.corp.redhat.com (Postfix) with SMTP id AC9925D9C0; Wed, 15 May 2019 15:19:16 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Wed, 15 May 2019 17:19:19 +0200 (CEST) Date: Wed, 15 May 2019 17:19:13 +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: <20190515151912.GE18892@redhat.com> References: <20190515100400.3450-1-christian@brauner.io> <20190515143857.GB18892@redhat.com> <20190515144927.f2yxyi6w6lhn3xx7@brauner.io> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190515144927.f2yxyi6w6lhn3xx7@brauner.io> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 15 May 2019 15:19:22 +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: > > On Wed, May 15, 2019 at 04:38:58PM +0200, Oleg Nesterov wrote: > > > > 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? Not exactly... it is not that PIDTYPE_PID == PIDTYPE_TGID for this pid, struct pid has no "type" or something like this. The logic is that pid->tasks[PIDTYPE_XXX] is the list of task which use this pid as "XXX" type. For example, clone(CLONE_THREAD) creates a pid which has a single non- empty list, pid->tasks[PIDTYPE_PID]. This pid can't be used as TGID or SID. So if pid_task(PIDTYPE_TGID) returns non-NULL we know that this pid was used for a group-leader, see copy_process() which does if (thread_group_leader(p)) attach_pid(p, PIDTYPE_TGID); If we race with exec which changes the leader pid_task(TGID) can return the old leader. We do not care, but this means that we should not check thread_group_leader(). Oleg.