Skip to content

Commit 27c1936

Browse files
Miklos Szeredigregkh
authored andcommitted
ovl: allow upperdir inside lowerdir
commit 708fa01 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 71d5845 commit 27c1936

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
@@ -1759,7 +1759,8 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,
17591759
* - upper/work dir of any overlayfs instance
17601760
*/
17611761
static int ovl_check_layer(struct super_block *sb, struct ovl_fs *ofs,
1762-
struct dentry *dentry, const char *name)
1762+
struct dentry *dentry, const char *name,
1763+
bool is_lower)
17631764
{
17641765
struct dentry *next = dentry, *parent;
17651766
int err = 0;
@@ -1771,7 +1772,7 @@ static int ovl_check_layer(struct super_block *sb, struct ovl_fs *ofs,
17711772

17721773
/* Walk back ancestors to root (inclusive) looking for traps */
17731774
while (!err && parent != next) {
1774-
if (ovl_lookup_trap_inode(sb, parent)) {
1775+
if (is_lower && ovl_lookup_trap_inode(sb, parent)) {
17751776
err = -ELOOP;
17761777
pr_err("overlapping %s path\n", name);
17771778
} else if (ovl_is_inuse(parent)) {
@@ -1797,7 +1798,7 @@ static int ovl_check_overlapping_layers(struct super_block *sb,
17971798

17981799
if (ovl_upper_mnt(ofs)) {
17991800
err = ovl_check_layer(sb, ofs, ovl_upper_mnt(ofs)->mnt_root,
1800-
"upperdir");
1801+
"upperdir", false);
18011802
if (err)
18021803
return err;
18031804

@@ -1808,15 +1809,16 @@ static int ovl_check_overlapping_layers(struct super_block *sb,
18081809
* workbasedir. In that case, we already have their traps in
18091810
* inode cache and we will catch that case on lookup.
18101811
*/
1811-
err = ovl_check_layer(sb, ofs, ofs->workbasedir, "workdir");
1812+
err = ovl_check_layer(sb, ofs, ofs->workbasedir, "workdir",
1813+
false);
18121814
if (err)
18131815
return err;
18141816
}
18151817

18161818
for (i = 1; i < ofs->numlayer; i++) {
18171819
err = ovl_check_layer(sb, ofs,
18181820
ofs->layers[i].mnt->mnt_root,
1819-
"lowerdir");
1821+
"lowerdir", true);
18201822
if (err)
18211823
return err;
18221824
}

0 commit comments

Comments
 (0)