From nobody Thu Apr 2 06:27:59 2026 Received: from flow-a2-smtp.messagingengine.com (flow-a2-smtp.messagingengine.com [103.168.172.137]) (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 F1098344DA5; Tue, 24 Feb 2026 22:27:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.137 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771972035; cv=none; b=icoxPuurzL1U0HDwrLekVqkzJ2K8xwAppf94DqqajYg4czuXsiYOoEyfJWS4Wp7zh/FGo9BnzdcOTsdvgo3yP/qRw+53PorjP19Yhbpn8cevz56y/rYeeHwkywEs+N+oMnY1HnLi1kFwkN4tCI6scLBTOBGIS7Tzq99WKPQm93A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771972035; c=relaxed/simple; bh=C5XGhxzXvy6Mo0q6KYiYOqWKvpBY4Hkc7vhmgZMdIks=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X7XO3/lmi8v+3meusTGOT/OOx3LWECvrjqc52esRANAHwyqm76ne8SU3F9bUaIE/6H18hbLbOmaxTJuV5fUUjIfnA8l+rZmR/lJ/mXuUd/WQDSL3pQyNMM8I7Mylheso7G1PM8GcOnWOjJHPk4+EDw9FD/BuGq5fhAcfIJfwu30= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ownmail.net; spf=pass smtp.mailfrom=ownmail.net; dkim=pass (2048-bit key) header.d=ownmail.net header.i=@ownmail.net header.b=E4VKyLrB; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ninVMiSe; arc=none smtp.client-ip=103.168.172.137 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ownmail.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ownmail.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ownmail.net header.i=@ownmail.net header.b="E4VKyLrB"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ninVMiSe" Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailflow.phl.internal (Postfix) with ESMTP id 42B0D138052C; Tue, 24 Feb 2026 17:27:13 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Tue, 24 Feb 2026 17:27:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ownmail.net; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:reply-to:subject:subject:to:to; s=fm3; t=1771972033; x=1771979233; bh=2jTTlW9RZgdA98OhmzS3Zb4kiDI7eopW2MuhMcIKiog=; b= E4VKyLrBtcvWb+ODOPq2rc6tFxLCMK8m26Ih5MitN6DWndAAHwui2T9PD+3sjVL/ B3aJXBbn1RxehizMelPZSPiEGWA2FDGSPKfspQ+pQ1/pLQEY2CKcP1IXh8lYDfJP bLpqZ80kotSCmvWb0y8EkAInZrWx8NQ6sIEC6tzNVSvla/GCVbI8MlLH9e0OOFiL OKDTC7MfIQaXpsrvAP2Xbwgt0TtB4PzI+5fjNaOlq8lYKdKw3ZjmxYfCuG+V+QYT 9bbVcddgBaCe280l282lSsl33IPfYKnUdZ7923+CM+hZYKISNy6WIJwr94jXCVmf aQ6vtGsnxRZn9MyQxb86kA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1771972033; x=1771979233; bh=2 jTTlW9RZgdA98OhmzS3Zb4kiDI7eopW2MuhMcIKiog=; b=ninVMiSehwVBOUDCe zLwwgL9e+RdytBF5LKwUjdzgugEI93NT+RPXLtWlc/l1fWltKXxibgCKHsCD2qO9 Ko3/Pj2bzdSXZGgb12i+/D7Pb7ga+5w9U8chL5R9bZ+q9ByRdKCcVpNR7FUYUAEA X7xwowMF7ZiwLXFMfo3m5gZRLpdJHGWuPgm9hQeRtpmvXFnO0PltsfcUoVo4jraq AsLc1SinKbM6hM55DqdvtiWfuBrXB9lsDAPKBMyBrkn+x3MfPr+GRpDO4fkqBDKK io5ROcckvfoQGJjEPPvfcsiyg4WZ9PS8T5qt4TcnG1T6yJZ7ozovR6GHbHEb2jAD X71rA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvgedufeekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhephffvvefufffkofgjfhhrggfgsedtkeertdertddtnecuhfhrohhmpefpvghilheu rhhofihnuceonhgvihhlsgesohifnhhmrghilhdrnhgvtheqnecuggftrfgrthhtvghrnh epveevkeffudeuvefhieeghffgudektdelkeejiedtjedugfeukedvkeffvdefvddunecu vehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrghilhhfrhhomhepnhgvihhlsg esohifnhhmrghilhdrnhgvthdpnhgspghrtghpthhtohepvddvpdhmohguvgepshhmthhp ohhuthdprhgtphhtthhopehvihhrohesiigvnhhivhdrlhhinhhugidrohhrghdruhhkpd hrtghpthhtohepshgvlhhinhhugiesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphht thhopehlihhnuhigqdhunhhiohhnfhhssehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtg hpthhtoheplhhinhhugidqshgvtghurhhithihqdhmohguuhhlvgesvhhgvghrrdhkvghr nhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhnfhhssehvghgvrhdrkhgvrhhnvg hlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhn vghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqfhhsuggvvhgvlhesvhhgvghrrdhkvg hrnhgvlhdrohhrghdprhgtphhtthhopehmihhklhhoshesshiivghrvgguihdrhhhupdhr tghpthhtohepjhgrtghksehsuhhsvgdrtgii X-ME-Proxy: Feedback-ID: i9d664b8f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 24 Feb 2026 17:27:07 -0500 (EST) From: NeilBrown To: Christian Brauner , Alexander Viro , David Howells , Jan Kara , Chuck Lever , Jeff Layton , Miklos Szeredi , Amir Goldstein , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , "Darrick J. Wong" Cc: linux-kernel@vger.kernel.org, netfs@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Subject: [PATCH v3 09/15] ovl: Simplify ovl_lookup_real_one() Date: Wed, 25 Feb 2026 09:16:54 +1100 Message-ID: <20260224222542.3458677-10-neilb@ownmail.net> X-Mailer: git-send-email 2.50.0.107.gf914562f5916.dirty In-Reply-To: <20260224222542.3458677-1-neilb@ownmail.net> References: <20260224222542.3458677-1-neilb@ownmail.net> Reply-To: NeilBrown Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: NeilBrown The primary purpose of this patch is to remove the locking from ovl_lookup_real_one() as part of centralising all locking of directories for name operations. The locking here isn't needed. By performing consistency tests after the lookup we can be sure that the result of the lookup was valid at least for a moment, which is all the original code promised. lookup_noperm_unlocked() is used for the lookup and it will take the lock if needed only where it is needed. Also: - don't take a reference to real->d_parent. The parent is only use for a pointer comparison, and no reference is needed for that. - Several "if" statements have a "goto" followed by "else" - the else isn't needed: the following statement can directly follow the "if" as a new statement - Use a consistent pattern of setting "err" before performing a test and possibly going to "fail". - remove the "out" label (now that we don't need to dput(parent) or unlock) and simply return from fail:. Reviewed-by: Jeff Layton Reviewed-by: Amir Goldstein Signed-off-by: NeilBrown --- fs/overlayfs/export.c | 71 ++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/fs/overlayfs/export.c b/fs/overlayfs/export.c index 83f80fdb1567..896f2e9af2e2 100644 --- a/fs/overlayfs/export.c +++ b/fs/overlayfs/export.c @@ -349,69 +349,64 @@ static struct dentry *ovl_dentry_real_at(struct dentr= y *dentry, int idx) return NULL; } =20 -/* - * Lookup a child overlay dentry to get a connected overlay dentry whose r= eal - * dentry is @real. If @real is on upper layer, we lookup a child overlay - * dentry with the same name as the real dentry. Otherwise, we need to con= sult - * index for lookup. +/** + * ovl_lookup_real_one - Lookup a child overlay dentry to get an overlay = dentry whose real dentry is given + * @connected: parent overlay dentry + * @real: given child real dentry + * @layer: layer in which @real exists + * + * + * Lookup a child overlay dentry in @connected with the same name as the @= real + * dentry. Then check that the parent of the result is the real dentry for + * @connected, and @real is the real dentry for the result. + * + * Returns: + * %-ECHILD if the parent of @real is no longer the real dentry for @con= nected. + * %-ESTALE if @real is not the real dentry of the found dentry. + * Otherwise the found dentry is returned. */ static struct dentry *ovl_lookup_real_one(struct dentry *connected, struct dentry *real, const struct ovl_layer *layer) { - struct inode *dir =3D d_inode(connected); - struct dentry *this, *parent =3D NULL; + struct dentry *this; struct name_snapshot name; int err; =20 /* - * Lookup child overlay dentry by real name. The dir mutex protects us - * from racing with overlay rename. If the overlay dentry that is above - * real has already been moved to a parent that is not under the - * connected overlay dir, we return -ECHILD and restart the lookup of - * connected real path from the top. - */ - inode_lock_nested(dir, I_MUTEX_PARENT); - err =3D -ECHILD; - parent =3D dget_parent(real); - if (ovl_dentry_real_at(connected, layer->idx) !=3D parent) - goto fail; - - /* - * We also need to take a snapshot of real dentry name to protect us + * We need to take a snapshot of real dentry name to protect us * from racing with underlying layer rename. In this case, we don't * care about returning ESTALE, only from dereferencing a free name * pointer because we hold no lock on the real dentry. */ take_dentry_name_snapshot(&name, real); - /* - * No idmap handling here: it's an internal lookup. - */ - this =3D lookup_noperm(&name.name, connected); + this =3D lookup_noperm_unlocked(&name.name, connected); release_dentry_name_snapshot(&name); + + err =3D -ECHILD; + if (ovl_dentry_real_at(connected, layer->idx) !=3D real->d_parent) + goto fail; + err =3D PTR_ERR(this); - if (IS_ERR(this)) { + if (IS_ERR(this)) goto fail; - } else if (!this || !this->d_inode) { - dput(this); - err =3D -ENOENT; + + err =3D -ENOENT; + if (!this || !this->d_inode) goto fail; - } else if (ovl_dentry_real_at(this, layer->idx) !=3D real) { - dput(this); - err =3D -ESTALE; + + err =3D -ESTALE; + if (ovl_dentry_real_at(this, layer->idx) !=3D real) goto fail; - } =20 -out: - dput(parent); - inode_unlock(dir); return this; =20 fail: pr_warn_ratelimited("failed to lookup one by real (%pd2, layer=3D%d, conn= ected=3D%pd2, err=3D%i)\n", real, layer->idx, connected, err); - this =3D ERR_PTR(err); - goto out; + if (!IS_ERR(this)) + dput(this); + return ERR_PTR(err); } =20 static struct dentry *ovl_lookup_real(struct super_block *sb, --=20 2.50.0.107.gf914562f5916.dirty