From: NeilBrown Date: Tue, 24 Feb 2026 22:16:58 +0000 (+1100) Subject: ovl: use is_subdir() for testing if one thing is a subdir of another X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=56c8fd738ed86667daa13c8a28fd1074f8a22cb7;p=thirdparty%2Fkernel%2Flinux.git ovl: use is_subdir() for testing if one thing is a subdir of another Rather than using lock_rename(), use the more obvious is_subdir() for ensuring that neither upper nor workdir contain the other. Also be explicit in the comment that the two directories cannot be the same. As this is a point-it-time sanity check and does not provide any on-going guarantees, the removal of locking does not introduce any interesting races. Reviewed-by: Amir Goldstein Reviewed-by: Jeff Layton Signed-off-by: NeilBrown Link: https://patch.msgid.link/20260224222542.3458677-14-neilb@ownmail.net Signed-off-by: Christian Brauner --- diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 109643930b9fc..58adefb1c5b8a 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -451,18 +451,13 @@ static int ovl_lower_dir(const char *name, const struct path *path, return 0; } -/* Workdir should not be subdir of upperdir and vice versa */ +/* + * Workdir should not be subdir of upperdir and vice versa, and + * they should not be the same. + */ static bool ovl_workdir_ok(struct dentry *workdir, struct dentry *upperdir) { - bool ok = false; - - if (workdir != upperdir) { - struct dentry *trap = lock_rename(workdir, upperdir); - if (!IS_ERR(trap)) - unlock_rename(workdir, upperdir); - ok = (trap == NULL); - } - return ok; + return !is_subdir(workdir, upperdir) && !is_subdir(upperdir, workdir); } static int ovl_setup_trap(struct super_block *sb, struct dentry *dir,