From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from flow-a1-smtp.messagingengine.com (flow-a1-smtp.messagingengine.com [103.168.172.136]) (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 D02B62BD5B4; Mon, 23 Feb 2026 01:14:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.136 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771809244; cv=none; b=XePCkAYBvnGdczqd0kprGTft2d96PETxF7l+yfEqhgkvUnLHXIGbTI9sLAXGn/EC9SFurZ5y90N9zBlKVTXWwEiC0Davvali7GP/4ZBxWf/ZhEI9iX4yjH9NKtoctI68RiS/kMd1o4zfnTCEg9UhZVwq0ENbeguyzKeXm1NRwfo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771809244; c=relaxed/simple; bh=jlJ9DWdOy/WeR7QWrpmvr1QyEtCF9bsrk1spWZE7J5Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OQhKcFl2gqECMTSNTbQEARRIFymKvQnuGZ0ST4qRjhpu7gQ9oO4GNU3qp6335WTOfLuzLbYZpEqPnDBmp4Ef7irnLNg44n7GCWuDFfhFOjFvwK97YQ56pJXqeD3GVDakCD4ijw2FiJte0wlDLSXJFG7qRYPeSpDVG2226z9AHbM= 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=ip3ChFt0; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=fEi5FjX6; arc=none smtp.client-ip=103.168.172.136 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="ip3ChFt0"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fEi5FjX6" Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailflow.phl.internal (Postfix) with ESMTP id 4A9F613807AC; Sun, 22 Feb 2026 20:14:02 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Sun, 22 Feb 2026 20:14:02 -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=1771809242; x=1771816442; bh=Vj23dTx8hYfvjWUpL8KmWQGYvEI277aBCAy+9LFoa/c=; b= ip3ChFt0GNXjluOzCSkY5OL1ja+hX8MEjp9VIZC5tzMGcRIhBMEaW0PeI+IoP846 5yh5xxUS5476SxpJYUxikpBzYb5CzkrGpoO9vkrxsB4ym6G9mNLjPjeaxSshPWew OuasBeZqbQ4rJwHSS2viUPCSMz2hYeN9WRCQcymPKI+h7HiVoh2blLGKEzirvfgI 6pvkWCaoqpxR/4DE11hr8D6VZLq+1+sXtoE3kTDYh0/1WSh3VHaOAXgV4WORmchw lHGaui5S9oRhElf7u21v+hNCi3WFNTqibStsdwSUKi0sEzCfL5z35cjaWPGcJ40W 9svj7Ai70aZqQgHjbh5M4Q== 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=1771809242; x=1771816442; bh=V j23dTx8hYfvjWUpL8KmWQGYvEI277aBCAy+9LFoa/c=; b=fEi5FjX6HJJiCeFco BGUOk15IAFcgniie6btSm4SCL2KgYllsAMlvxcOFOFK+yUEXhnFjFzcSnFnLmwwz tSIgI3v8+K1n7QLrmgxyvg+Bd51F2315thr1CRuEcCsZV70yTmLK9ccPIiK9qbzC xIWQ155ID3uXxrlMpdl+OIjDM/dk+LFGx572EDmHVeCW2nmY0VCKeOs9Ds6KbmRP Ky8eUYmGH0BzmC6ZFIXnhBIBKsrE/x6l9gSTGYlgIwuMJimCUEH7f3McJaLWnrEz rWt7RBfzj1cdVpR/k7QYBiqKYhRxpD7pe/GzRdlqdcPn25Lhs29SpKcIQA4WnVb/ K2hJg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvfeehkeegucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhephffvvefufffkofgjfhhrggfgsedtkeertdertddtnecuhfhrohhmpefpvghilheu rhhofihnuceonhgvihhlsgesohifnhhmrghilhdrnhgvtheqnecuggftrfgrthhtvghrnh epveevkeffudeuvefhieeghffgudektdelkeejiedtjedugfeukedvkeffvdefvddunecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepnhgvihhlsg 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; Sun, 22 Feb 2026 20:13:55 -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 v2 10/15] cachefiles: change cachefiles_bury_object to use start_renaming_dentry() Date: Mon, 23 Feb 2026 12:06:25 +1100 Message-ID: <20260223011210.3853517-11-neilb@ownmail.net> X-Mailer: git-send-email 2.50.0.107.gf914562f5916.dirty In-Reply-To: <20260223011210.3853517-1-neilb@ownmail.net> References: <20260223011210.3853517-1-neilb@ownmail.net> Reply-To: NeilBrown Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: NeilBrown Rather then using lock_rename() and lookup_one() etc we can use the new start_renaming_dentry(). This is part of centralising dir locking and lookup so that locking rules can be changed. Some error check are removed as not necessary. Checks for rep being a non-dir or IS_DEADDIR and the check that ->graveyard is still a directory only provide slightly more informative errors and have been dropped. Reviewed-by: Jeff Layton Signed-off-by: NeilBrown --- fs/cachefiles/namei.c | 76 ++++++++----------------------------------- 1 file changed, 14 insertions(+), 62 deletions(-) diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c index e5ec90dccc27..3af42ec78411 100644 --- a/fs/cachefiles/namei.c +++ b/fs/cachefiles/namei.c @@ -270,7 +270,8 @@ int cachefiles_bury_object(struct cachefiles_cache *cache, struct dentry *rep, enum fscache_why_object_killed why) { - struct dentry *grave, *trap; + struct dentry *grave; + struct renamedata rd = {}; struct path path, path_to_graveyard; char nbuffer[8 + 8 + 1]; int ret; @@ -302,77 +303,36 @@ int cachefiles_bury_object(struct cachefiles_cache *cache, (uint32_t) ktime_get_real_seconds(), (uint32_t) atomic_inc_return(&cache->gravecounter)); - /* do the multiway lock magic */ - trap = lock_rename(cache->graveyard, dir); - if (IS_ERR(trap)) - return PTR_ERR(trap); - - /* do some checks before getting the grave dentry */ - if (rep->d_parent != dir || IS_DEADDIR(d_inode(rep))) { - /* the entry was probably culled when we dropped the parent dir - * lock */ - unlock_rename(cache->graveyard, dir); - _leave(" = 0 [culled?]"); - return 0; - } - - if (!d_can_lookup(cache->graveyard)) { - unlock_rename(cache->graveyard, dir); - cachefiles_io_error(cache, "Graveyard no longer a directory"); - return -EIO; - } - - if (trap == rep) { - unlock_rename(cache->graveyard, dir); - cachefiles_io_error(cache, "May not make directory loop"); + rd.mnt_idmap = &nop_mnt_idmap; + rd.old_parent = dir; + rd.new_parent = cache->graveyard; + rd.flags = 0; + ret = start_renaming_dentry(&rd, 0, rep, &QSTR(nbuffer)); + if (ret) { + cachefiles_io_error(cache, "Cannot lock/lookup in graveyard"); return -EIO; } if (d_mountpoint(rep)) { - unlock_rename(cache->graveyard, dir); + end_renaming(&rd); cachefiles_io_error(cache, "Mountpoint in cache"); return -EIO; } - grave = lookup_one(&nop_mnt_idmap, &QSTR(nbuffer), cache->graveyard); - if (IS_ERR(grave)) { - unlock_rename(cache->graveyard, dir); - trace_cachefiles_vfs_error(object, d_inode(cache->graveyard), - PTR_ERR(grave), - cachefiles_trace_lookup_error); - - if (PTR_ERR(grave) == -ENOMEM) { - _leave(" = -ENOMEM"); - return -ENOMEM; - } - - cachefiles_io_error(cache, "Lookup error %ld", PTR_ERR(grave)); - return -EIO; - } - + grave = rd.new_dentry; if (d_is_positive(grave)) { - unlock_rename(cache->graveyard, dir); - dput(grave); + end_renaming(&rd); grave = NULL; cond_resched(); goto try_again; } if (d_mountpoint(grave)) { - unlock_rename(cache->graveyard, dir); - dput(grave); + end_renaming(&rd); cachefiles_io_error(cache, "Mountpoint in graveyard"); return -EIO; } - /* target should not be an ancestor of source */ - if (trap == grave) { - unlock_rename(cache->graveyard, dir); - dput(grave); - cachefiles_io_error(cache, "May not make directory loop"); - return -EIO; - } - /* attempt the rename */ path.mnt = cache->mnt; path.dentry = dir; @@ -382,13 +342,6 @@ int cachefiles_bury_object(struct cachefiles_cache *cache, if (ret < 0) { cachefiles_io_error(cache, "Rename security error %d", ret); } else { - struct renamedata rd = { - .mnt_idmap = &nop_mnt_idmap, - .old_parent = dir, - .old_dentry = rep, - .new_parent = cache->graveyard, - .new_dentry = grave, - }; trace_cachefiles_rename(object, d_inode(rep)->i_ino, why); ret = cachefiles_inject_read_error(); if (ret == 0) @@ -402,8 +355,7 @@ int cachefiles_bury_object(struct cachefiles_cache *cache, } __cachefiles_unmark_inode_in_use(object, d_inode(rep)); - unlock_rename(cache->graveyard, dir); - dput(grave); + end_renaming(&rd); _leave(" = 0"); return 0; } -- 2.50.0.107.gf914562f5916.dirty