Skip to content

Commit 56c8fd7

Browse files
neilbrownbrauner
authored andcommitted
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 <amir73il@gmail.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: NeilBrown <neil@brown.name> Link: https://patch.msgid.link/20260224222542.3458677-14-neilb@ownmail.net Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 8348278 commit 56c8fd7

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

fs/overlayfs/super.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -451,18 +451,13 @@ static int ovl_lower_dir(const char *name, const struct path *path,
451451
return 0;
452452
}
453453

454-
/* Workdir should not be subdir of upperdir and vice versa */
454+
/*
455+
* Workdir should not be subdir of upperdir and vice versa, and
456+
* they should not be the same.
457+
*/
455458
static bool ovl_workdir_ok(struct dentry *workdir, struct dentry *upperdir)
456459
{
457-
bool ok = false;
458-
459-
if (workdir != upperdir) {
460-
struct dentry *trap = lock_rename(workdir, upperdir);
461-
if (!IS_ERR(trap))
462-
unlock_rename(workdir, upperdir);
463-
ok = (trap == NULL);
464-
}
465-
return ok;
460+
return !is_subdir(workdir, upperdir) && !is_subdir(upperdir, workdir);
466461
}
467462

468463
static int ovl_setup_trap(struct super_block *sb, struct dentry *dir,

0 commit comments

Comments
 (0)