Commit 0e082555 authored by Amir Goldstein's avatar Amir Goldstein Committed by Miklos Szeredi

ovl: check for bad and whiteout index on lookup

Index should always be of the same file type as origin, except for
the case of a whiteout index.  A whiteout index should only exist
if all lower aliases have been unlinked, which means that finding
a lower origin on lookup whose index is a whiteout should be treated
as a lookup error.
Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
parent 61b67471
...@@ -513,6 +513,7 @@ static struct dentry *ovl_lookup_index(struct dentry *dentry, ...@@ -513,6 +513,7 @@ static struct dentry *ovl_lookup_index(struct dentry *dentry,
goto out; goto out;
} }
inode = d_inode(index);
if (d_is_negative(index)) { if (d_is_negative(index)) {
if (upper && d_inode(origin)->i_nlink > 1) { if (upper && d_inode(origin)->i_nlink > 1) {
pr_warn_ratelimited("overlayfs: hard link with origin but no index (ino=%lu).\n", pr_warn_ratelimited("overlayfs: hard link with origin but no index (ino=%lu).\n",
...@@ -522,11 +523,22 @@ static struct dentry *ovl_lookup_index(struct dentry *dentry, ...@@ -522,11 +523,22 @@ static struct dentry *ovl_lookup_index(struct dentry *dentry,
dput(index); dput(index);
index = NULL; index = NULL;
} else if (upper && d_inode(index) != d_inode(upper)) { } else if (upper && d_inode(upper) != inode) {
inode = d_inode(index); pr_warn_ratelimited("overlayfs: wrong index found (index=%pd2, ino=%lu, upper ino=%lu).\n",
pr_warn_ratelimited("overlayfs: wrong index found (index ino: %lu, upper ino: %lu).\n", index, inode->i_ino, d_inode(upper)->i_ino);
d_inode(index)->i_ino, goto fail;
d_inode(upper)->i_ino); } else if (ovl_dentry_weird(index) || ovl_is_whiteout(index) ||
((inode->i_mode ^ d_inode(origin)->i_mode) & S_IFMT)) {
/*
* Index should always be of the same file type as origin
* except for the case of a whiteout index. A whiteout
* index should only exist if all lower aliases have been
* unlinked, which means that finding a lower origin on lookup
* whose index is a whiteout should be treated as an error.
*/
pr_warn_ratelimited("overlayfs: bad index found (index=%pd2, ftype=%x, origin ftype=%x).\n",
index, d_inode(index)->i_mode & S_IFMT,
d_inode(origin)->i_mode & S_IFMT);
goto fail; goto fail;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment