Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp2601997rdg; Mon, 14 Aug 2023 07:42:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQXBy8yk1QOpchODVQj9FeD8pQlZpd9brK4b1Al0jZt+hREy1YGaW3ZfRYh7c6YxDX8JQl X-Received: by 2002:a05:6a20:1609:b0:133:5da8:2fa7 with SMTP id l9-20020a056a20160900b001335da82fa7mr17350968pzj.25.1692024147876; Mon, 14 Aug 2023 07:42:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692024147; cv=none; d=google.com; s=arc-20160816; b=u9plw7ISFg40k97cbrWXiyi0yKU1R0YK67QS30me8gpPu6N0xEl1dVeYxGvT8IJLB4 PzkpbiUr9pEtQuwV1JtWI/1sd98RJFbJ4Ayb0sWizOcisEx9UZrPYmW04jPo0EmCA2ft x1FFQXClY26KqgvswJ6j1abuxo9yvnKNPs8Tju3Tx0EJ7t0tdV6XTM2CFWlrZE0V/8R2 5ePPCOCe2AXlCUksilxEstkRmUF7rpUZlatSusV6yTBloRV/iP04TY4hrQn0gMJCZo2J u2JebLXYOIKlEYx6ibpLQlhyBJ8sxVHTdDjEoQ73IFV6TueGucKZ3bJ/szseIlg2QIKM 7c6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=lrFQ1Piu7kOD9w6iKIQkZ8h3C5VVMWcr3aHpTSKZPi0=; fh=2c1GEbuodncZ0FCUChb1MOY/sQHxloSKrdAIJSCULec=; b=KN9/s13LOSblrFx6dVM24JZM2m8gm+EyI0Q3KtMat2zK0xg9lp5k6Y5+aSOBpGd1+e p2PDh9TmP6FE4xtyLWIqbVFwAQMuVKwioObtAKyiVRnpfk4iWMZ8u9z7LJSWz1sTnDGU JnqRJDOw5vSZigGCC7St51pf5+RuAaOp4jm2H2Ftu2t6GKKASBOUmCGfJoeLiHV+8MO+ h+mbuA4DvMz15oDJF6jsR+Vwfqr/Dapx1cfWE6PWBfYlYcZsK5CurL6/fdt2SKYzTiYE wj+vagrSugwciEzukoUwTm1+xMX3cKdkav+h6sFzF6pUEWVpEj6l02OoZyBN3SiB58OM 2ggw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TyxHk3EP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t20-20020a656094000000b0056382a0bc99si8401288pgu.580.2023.08.14.07.42.15; Mon, 14 Aug 2023 07:42:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TyxHk3EP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230138AbjHNNXT (ORCPT + 99 others); Mon, 14 Aug 2023 09:23:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230163AbjHNNWu (ORCPT ); Mon, 14 Aug 2023 09:22:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3B93F5 for ; Mon, 14 Aug 2023 06:21:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692019300; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=lrFQ1Piu7kOD9w6iKIQkZ8h3C5VVMWcr3aHpTSKZPi0=; b=TyxHk3EPLYb2xGFWR5URHCq7r3t6bPq+RlOJJqWOpWTbwpvTdam68y2lWZ9u+RJJut71Kn y4loUZ6E+UA4eEpB83bhh3iCa43SejhXi+cZcVnh3Tu5/seVzf2gWX46U2GSy2lcNfBSB5 hfzbEE27w1lsHRLHEhFU1JMCfC3KaeU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-107-PXYjbQvYPpCo2pWxCD1h_A-1; Mon, 14 Aug 2023 09:21:35 -0400 X-MC-Unique: PXYjbQvYPpCo2pWxCD1h_A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 214F285CBEB; Mon, 14 Aug 2023 13:21:25 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.225.27]) by smtp.corp.redhat.com (Postfix) with SMTP id 53E9F2166B25; Mon, 14 Aug 2023 13:21:22 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Mon, 14 Aug 2023 15:20:42 +0200 (CEST) Date: Mon, 14 Aug 2023 15:20:39 +0200 From: Oleg Nesterov To: David Rheinsberg Cc: Christian Brauner , linux-kernel@vger.kernel.org, Jan Kara , Kees Cook , Alexander Mikhalitsyn , Luca Boccassi Subject: Re: [PATCH] pid: allow pidfds for reaped tasks Message-ID: <20230814132039.GA17738@redhat.com> References: <20230807085203.819772-1-david@readahead.eu> <20230807-porzellan-rehkitz-9fde1b94dd6b@brauner> <20230811112911.GA22566@redhat.com> <20230811-perplex-installieren-899f5925534d@brauner> <20230811115710.GA21779@redhat.com> <6feef7e0-ea72-412d-837e-34b6fdd3b869@app.fastmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6feef7e0-ea72-412d-837e-34b6fdd3b869@app.fastmail.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/14, David Rheinsberg wrote: > > Hi Oleg, > > On Fri, Aug 11, 2023, at 1:57 PM, Oleg Nesterov wrote: > >> What code do we need to allow userspace to open a pidfd to a leader pid > >> even if it has already been exited and reaped (without also accidently > >> allowing to open non-lead pid pidfds)? > > > > I'll try to think more, but can you also explain why do we need this? > > > > See my another email. Can't we simply shift the pid_has_task(PIDTYPE_TGID) > > check from pidfd_prepare() to pidfd_create() ? (and then we can kill > > pidfd_prepare and rename __pidfd_prepare to pidfd_prepare). > > Yes, the easiest solution would be to use `__pidfd_prepare()` and ensure > that the caller only ever calls this on tg-leaders. This would work just > fine, imo. And this was my initial approach. Great, > I think Christian preferred an explicit assertion that ensures we do not > accidentally hand out pidfds for non-tg-leaders. The question is thus whether > there is an easy way to assert this even for reaped tasks? > Or whether there is a simple way to flag a pid that was used as tg-leader? I do not see how can we check if a detached pid was a leader pid, and I don't think it makes sense to add a new member into struct pid... > Or, ultimately, whether this has limited use and we should just use > `__pidfd_prepare()`? Well, if you confirm that sk->sk_peer_pid and scm->pid are always initialized with task_tgid(current), I'd certainly prefer this approach unless Christian objects. Oleg.