Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp3200522rdb; Tue, 6 Feb 2024 09:55:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGSz2nJz+suffk+9p9O5rBWhIX59iq2y1Iul3g4eZKS6UXcaltOMmmP11GbDT1okY9QEdIs X-Received: by 2002:a05:622a:18c:b0:42a:9a69:b40a with SMTP id s12-20020a05622a018c00b0042a9a69b40amr3534064qtw.30.1707242134502; Tue, 06 Feb 2024 09:55:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707242134; cv=pass; d=google.com; s=arc-20160816; b=fYTuFs8CyC5XS4mR8BBOx0DNkNf/VOSaXDM+VnB6tkeIb31nyv9/KpVwiGn6U26Py5 XNwN0uphflfdz79sa+diW8VfC+oJECBSLgxjk/XqU6upFaQ9k2SVyBt7bnCLOGU8os7K Z9vOhwy9ixI7m8oC52U0SGeZW+2XPO52j50QujBUYLYMQDiHq1BlEcM4xZfVmckXlgVs hQBz37UxMb8NXTJSzI2hO1G07vIuUU6jFNqiDaSYXLEkZFrdvLo+YP8yZ5nq8OdDy2Pr MLZpoUvkvmNExLSxyRSPOK0Lk6a78bGy52ceq9KtiJRknRdEPXU4kWhaHUoaQ5VbPd49 turg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:feedback-id:dkim-signature:dkim-signature; bh=e1EAQQRKi125NncAMIEO4HlMNemKHBTjJx/Rtk6PoO4=; fh=oD4hcI38ShI3k2/XxPk4AtXFzrfDkwq+ND1bx66LxoQ=; b=MYngGmbITPT+SkbRv3g5nWqguHXiqU+I0OEMz5EHtYtvMvfcDiy23EgGTGdoaPJhXS DSeuN2a5qUkM1JEL1cJZd4Kw/BH2N7ROdoknZcNXX8V/gDkpCixDXJWgPa3o8U/lXU2V WHStTs5crQKQzHxT+ojqAy39jfvqQwnkGaHMF5u1tFZJSJszQoYJkgfC3imTcFgamzai A9xqzu0Qu0gfEcABukjEuSbPwywYFIC0um+4KtZvI4CfQ0q1jl7iZ2uSfKaNohYY7/5S ZwAl0/fNyxIUw7dCLkgnm6e4WTBrXSKJXwNTtMp83uXvXZUsysjlSsiTmSoKuNayn49k KpqQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tycho.pizza header.s=fm2 header.b=U6dbarqv; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=F2G1epIv; arc=pass (i=1 spf=pass spfdomain=tycho.pizza dkim=pass dkdomain=tycho.pizza dkim=pass dkdomain=messagingengine.com); spf=pass (google.com: domain of linux-kernel+bounces-55426-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55426-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUry6h7dxAtefCEuQ8F7UYTANWMqUiayLW64GJcmdgeZLbdLwCtZ70oDvD4enrkDmo0uoKvzqt/sxcNHljATJ9Col+alejTga2iO60waA== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id z2-20020ac87f82000000b0042aa70b5cb1si2950849qtj.47.2024.02.06.09.55.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 09:55:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55426-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@tycho.pizza header.s=fm2 header.b=U6dbarqv; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=F2G1epIv; arc=pass (i=1 spf=pass spfdomain=tycho.pizza dkim=pass dkdomain=tycho.pizza dkim=pass dkdomain=messagingengine.com); spf=pass (google.com: domain of linux-kernel+bounces-55426-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55426-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id AEB131C2419B for ; Tue, 6 Feb 2024 17:55:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 20610DDD9; Tue, 6 Feb 2024 17:55:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tycho.pizza header.i=@tycho.pizza header.b="U6dbarqv"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="F2G1epIv" Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB42EDDCF; Tue, 6 Feb 2024 17:55:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.111.4.29 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707242125; cv=none; b=bzc5aw2Tzgym6Gp0edb+XRqyZyeZmD+j2vmna6yp0Ts30OtFW6CBPFuTrA28HMCc3Q8lzGn8zMm7Fq441XhOjWILSlaXstwbCR6ktVJc9fCcs91L7XBZNKgvAx1HX0GzKQyY2rLpRiqDHDbYBbdezGdkoePLuN64xv99a1uDNg8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707242125; c=relaxed/simple; bh=vYpVklxsp9a2xUIs/wY88jNQ5mHAiOcEwhPYeMKMGD0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=m7qcUVLK/UoJPAwKZfuI1kVeEKnhYlL8IGPR3O+v68kwE48fxEr6d0zz3TMKiLYbEdkEgMwxyH2MdGjut26+TNFMrVtrodZkqh1uIGZJGnuGBj4mkdG8vxXynl6Osf+Tni+L8gSW4ta8nlAJAluOXXrYQyQVnDFuwV+AmzA7fDg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tycho.pizza; spf=pass smtp.mailfrom=tycho.pizza; dkim=pass (2048-bit key) header.d=tycho.pizza header.i=@tycho.pizza header.b=U6dbarqv; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=F2G1epIv; arc=none smtp.client-ip=66.111.4.29 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tycho.pizza Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tycho.pizza Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id A40535C005A; Tue, 6 Feb 2024 12:55:21 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 06 Feb 2024 12:55:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho.pizza; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1707242121; x=1707328521; bh=e1EAQQRKi1 25NncAMIEO4HlMNemKHBTjJx/Rtk6PoO4=; b=U6dbarqvMSQGmpM+Cx9ag8ZNYl ycUk8RFTbSkcSc/ntfTCf0w+WHOkyrESISZKn3yS7vQeXQutAu6yyMSHDml7muY0 WAGCveIzfhH0umAK+oyDLb7DJB3fK2wCOUvF6HarlTnFzS3VCgn43+uweGP7tCuG nNc4cYLCORWfU1+p4xu3JO6yeS8Kdu0y7IAgRuS/IMuBbkIk6laDN+dSeJdkViTK HgBV+LzhOg7x5cPvf0aXirO3/o2tVrWyt5iJxSLxvYEjv9bA4cBG/HJKTRIijAxa RVRLcRf84VYl+CYBzXCHaMNJeFCZ5araxjOam1H2zbsKBZQPPvfxwzFhPCdg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1707242121; x=1707328521; bh=e1EAQQRKi125NncAMIEO4HlMNemK HBTjJx/Rtk6PoO4=; b=F2G1epIvD5u5UEZ6DwZO86jU3+FmrXMNGT0gbVEZug4Q oRN27UoCf4CZuY7HrdfsBGi+QgeyiJHeRrLgj402LTx6+HHx1/aHpoQdG69P+uql bxBtmtviTONfV/NLwtJot/5KMQcJHQ7EiGxLBnvWFhVpEBvvk/VINqzZr3skWlr8 xQ3qRPOoaP9OsTf6djYbHT+mTfsbRCCVurWgclb1S5WGrdC4fYHnvm/UD1/jp+jO JussFIFuAJU9sY7VjExslHqvkpg3viQ4OePSimGU4G8b5Bubx5gN1zDbW6+bMHRj W9XiYA2rNsKNd0u4VQGnVpTrj+Op2QPOaDiPp3PauQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrtddtgdejjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefvhigthhho ucetnhguvghrshgvnhcuoehthigthhhosehthigthhhordhpihiiiigrqeenucggtffrrg htthgvrhhnpeeutedttefgjeefffehffffkeejueevieefudelgeejuddtfeffteeklefh leelteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hthigthhhosehthigthhhordhpihiiiigr X-ME-Proxy: Feedback-ID: i21f147d5:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 6 Feb 2024 12:55:20 -0500 (EST) Date: Tue, 6 Feb 2024 10:55:19 -0700 From: Tycho Andersen To: Oleg Nesterov Cc: Christian Brauner , "Eric W . Biederman" , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Tycho Andersen Subject: Re: [PATCH] pidfd: getfd should always report ESRCH if a task is exiting Message-ID: References: <20240206164308.62620-1-tycho@tycho.pizza> <20240206173722.GA3593@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240206173722.GA3593@redhat.com> On Tue, Feb 06, 2024 at 06:37:22PM +0100, Oleg Nesterov wrote: > > --- a/kernel/pid.c > > +++ b/kernel/pid.c > > @@ -688,7 +688,7 @@ static int pidfd_getfd(struct pid *pid, int fd) > > int ret; > > > > task = get_pid_task(pid, PIDTYPE_PID); > > - if (!task) > > + if (!task || task->flags & PF_EXITING) > > return -ESRCH; > > This looks racy. Suppose that pidfd_getfd() races with the exiting task. > > It is possible that this task sets PF_EXITING and does exit_files() > after the "task->flags & PF_EXITING" check above and before pidfd_getfd() > does __pidfd_fget(), in this case pidfd_getfd() still returns the same > EBADF we want to avoid. > > Perhaps we can change pidfd_getfd() to do > > if (IS_ERR(file)) > return (task->flags & PF_EXITING) ? -ESRCH : PTR_ERR(file); > > instead? > > This needs a comment to explain the PF_EXITING check. And perhaps another > comment to explain that we can't miss PF_EXITING if the target task has > already passed exit_files, both exit_files() and fget_task() take the same > task_lock(task). > > What do you think? Yes, you're absolutely right. Let me resend. Tycho