Skip to content

Commit

Permalink
ovl: do not cleanup unsupported index entries
Browse files Browse the repository at this point in the history
With index=on, ovl_indexdir_cleanup() tries to cleanup invalid index
entries (e.g. bad index name). This behavior could result in cleaning of
entries created by newer kernels and is therefore undesirable.
Instead, abort mount if such entries are encountered. We still cleanup
'stale' entries and 'orphan' entries, both those cases can be a result
of offline changes to lower and upper dirs.

When encoutering an index entry of type directory or whiteout, kernel
was supposed to fallback to read-only mount, but the fill_super()
operation returns EROFS in this case instead of returning success with
read-only mount flag, so mount fails when encoutering directory or
whiteout index entries. Bless this behavior by returning -EINVAL on
directory and whiteout index entries as we do for all unsupported index
entries.

Fixes: 61b6747 ("ovl: do not cleanup directory and whiteout index..")
Cc: <stable@vger.kernel.org> # v4.13
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
  • Loading branch information
Amir Goldstein authored and Miklos Szeredi committed Oct 24, 2017
1 parent 7937a56 commit fa0096e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
7 changes: 3 additions & 4 deletions fs/overlayfs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,13 @@ int ovl_verify_index(struct dentry *index, struct path *lowerstack,
* be treated as stale (i.e. after unlink of the overlay inode).
* We don't know the verification rules for directory and whiteout
* index entries, because they have not been implemented yet, so return
* EROFS if those entries are found to avoid corrupting an index that
* was created by a newer kernel.
* EINVAL if those entries are found to abort the mount to avoid
* corrupting an index that was created by a newer kernel.
*/
err = -EROFS;
err = -EINVAL;
if (d_is_dir(index) || ovl_is_whiteout(index))
goto fail;

err = -EINVAL;
if (index->d_name.len < sizeof(struct ovl_fh)*2)
goto fail;

Expand Down
11 changes: 5 additions & 6 deletions fs/overlayfs/readdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1021,13 +1021,12 @@ int ovl_indexdir_cleanup(struct dentry *dentry, struct vfsmount *mnt,
break;
}
err = ovl_verify_index(index, lowerstack, numlower);
if (err) {
if (err == -EROFS)
break;
/* Cleanup stale and orphan index entries */
if (err && (err == -ESTALE || err == -ENOENT))
err = ovl_cleanup(dir, index);
if (err)
break;
}
if (err)
break;

dput(index);
index = NULL;
}
Expand Down

0 comments on commit fa0096e

Please sign in to comment.