Skip to content

Commit 708fa01

Browse files
author
Miklos Szeredi
committed
ovl: allow upperdir inside lowerdir
Commit 146d62e ("ovl: detect overlapping layers") made sure we don't have overlapping layers, but it also broke the arguably valid use case of mount -olowerdir=/,upperdir=/subdir,.. where upperdir overlaps lowerdir on the same filesystem. This has been causing regressions. Revert the check, but only for the specific case where upperdir and/or workdir are subdirectories of lowerdir. Any other overlap (e.g. lowerdir is subdirectory of upperdir, etc) case is crazy, so leave the check in place for those. Overlaps are detected at lookup time too, so reverting the mount time check should be safe. Fixes: 146d62e ("ovl: detect overlapping layers") Cc: <stable@vger.kernel.org> # v5.2 Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 321b46b commit 708fa01

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎fs/overlayfs/super.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,8 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,
18541854
* - upper/work dir of any overlayfs instance
18551855
*/
18561856
static int ovl_check_layer(struct super_block *sb, struct ovl_fs *ofs,
1857-
struct dentry *dentry, const char *name)
1857+
struct dentry *dentry, const char *name,
1858+
bool is_lower)
18581859
{
18591860
struct dentry *next = dentry, *parent;
18601861
int err = 0;
@@ -1866,7 +1867,7 @@ static int ovl_check_layer(struct super_block *sb, struct ovl_fs *ofs,
18661867

18671868
/* Walk back ancestors to root (inclusive) looking for traps */
18681869
while (!err && parent != next) {
1869-
if (ovl_lookup_trap_inode(sb, parent)) {
1870+
if (is_lower && ovl_lookup_trap_inode(sb, parent)) {
18701871
err = -ELOOP;
18711872
pr_err("overlapping %s path\n", name);
18721873
} else if (ovl_is_inuse(parent)) {
@@ -1892,7 +1893,7 @@ static int ovl_check_overlapping_layers(struct super_block *sb,
18921893

18931894
if (ovl_upper_mnt(ofs)) {
18941895
err = ovl_check_layer(sb, ofs, ovl_upper_mnt(ofs)->mnt_root,
1895-
"upperdir");
1896+
"upperdir", false);
18961897
if (err)
18971898
return err;
18981899

@@ -1903,15 +1904,16 @@ static int ovl_check_overlapping_layers(struct super_block *sb,
19031904
* workbasedir. In that case, we already have their traps in
19041905
* inode cache and we will catch that case on lookup.
19051906
*/
1906-
err = ovl_check_layer(sb, ofs, ofs->workbasedir, "workdir");
1907+
err = ovl_check_layer(sb, ofs, ofs->workbasedir, "workdir",
1908+
false);
19071909
if (err)
19081910
return err;
19091911
}
19101912

19111913
for (i = 1; i < ofs->numlayer; i++) {
19121914
err = ovl_check_layer(sb, ofs,
19131915
ofs->layers[i].mnt->mnt_root,
1914-
"lowerdir");
1916+
"lowerdir", true);
19151917
if (err)
19161918
return err;
19171919
}

0 commit comments

Comments
 (0)