提交 6eaf0111 编写于 作者: A Amir Goldstein 提交者: Miklos Szeredi

ovl: fix EIO from lookup of non-indexed upper

Commit fbaf94ee ("ovl: don't set origin on broken lower hardlink")
attempt to avoid the condition of non-indexed upper inode with lower
hardlink as origin. If this condition is found, lookup returns EIO.

The protection of commit mentioned above does not cover the case of lower
that is not a hardlink when it is copied up (with either index=off/on)
and then lower is hardlinked while overlay is offline.

Changes to lower layer while overlayfs is offline should not result in
unexpected behavior, so a permanent EIO error after creating a link in
lower layer should not be considered as correct behavior.

This fix replaces EIO error with success in cases where upper has origin
but no index is found, or index is found that does not match upper
inode. In those cases, lookup will not fail and the returned overlay inode
will be hashed by upper inode instead of by lower origin inode.

Fixes: 359f392c ("ovl: lookup index entry for copy up origin")
Cc: <stable@vger.kernel.org> # v4.13
Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
上级 0ce5cdc9
...@@ -598,18 +598,30 @@ static bool ovl_verify_inode(struct inode *inode, struct dentry *lowerdentry, ...@@ -598,18 +598,30 @@ static bool ovl_verify_inode(struct inode *inode, struct dentry *lowerdentry,
return true; return true;
} }
struct inode *ovl_get_inode(struct dentry *dentry, struct dentry *upperdentry) struct inode *ovl_get_inode(struct dentry *dentry, struct dentry *upperdentry,
struct dentry *index)
{ {
struct dentry *lowerdentry = ovl_dentry_lower(dentry); struct dentry *lowerdentry = ovl_dentry_lower(dentry);
struct inode *realinode = upperdentry ? d_inode(upperdentry) : NULL; struct inode *realinode = upperdentry ? d_inode(upperdentry) : NULL;
struct inode *inode; struct inode *inode;
/* Already indexed or could be indexed on copy up? */
bool indexed = (index || (ovl_indexdir(dentry->d_sb) && !upperdentry));
if (WARN_ON(upperdentry && indexed && !lowerdentry))
return ERR_PTR(-EIO);
if (!realinode) if (!realinode)
realinode = d_inode(lowerdentry); realinode = d_inode(lowerdentry);
if (!S_ISDIR(realinode->i_mode) && /*
(upperdentry || (lowerdentry && ovl_indexdir(dentry->d_sb)))) { * Copy up origin (lower) may exist for non-indexed upper, but we must
struct inode *key = d_inode(lowerdentry ?: upperdentry); * not use lower as hash key in that case.
* Hash inodes that are or could be indexed by origin inode and
* non-indexed upper inodes that could be hard linked by upper inode.
*/
if (!S_ISDIR(realinode->i_mode) && (upperdentry || indexed)) {
struct inode *key = d_inode(indexed ? lowerdentry :
upperdentry);
unsigned int nlink; unsigned int nlink;
inode = iget5_locked(dentry->d_sb, (unsigned long) key, inode = iget5_locked(dentry->d_sb, (unsigned long) key,
......
...@@ -516,18 +516,9 @@ static struct dentry *ovl_lookup_index(struct dentry *dentry, ...@@ -516,18 +516,9 @@ static struct dentry *ovl_lookup_index(struct dentry *dentry,
inode = d_inode(index); inode = d_inode(index);
if (d_is_negative(index)) { if (d_is_negative(index)) {
if (upper && d_inode(origin)->i_nlink > 1) { goto out_dput;
pr_warn_ratelimited("overlayfs: hard link with origin but no index (ino=%lu).\n",
d_inode(origin)->i_ino);
goto fail;
}
dput(index);
index = NULL;
} else if (upper && d_inode(upper) != inode) { } else if (upper && d_inode(upper) != inode) {
pr_warn_ratelimited("overlayfs: wrong index found (index=%pd2, ino=%lu, upper ino=%lu).\n", goto out_dput;
index, inode->i_ino, d_inode(upper)->i_ino);
goto fail;
} else if (ovl_dentry_weird(index) || ovl_is_whiteout(index) || } else if (ovl_dentry_weird(index) || ovl_is_whiteout(index) ||
((inode->i_mode ^ d_inode(origin)->i_mode) & S_IFMT)) { ((inode->i_mode ^ d_inode(origin)->i_mode) & S_IFMT)) {
/* /*
...@@ -547,6 +538,11 @@ static struct dentry *ovl_lookup_index(struct dentry *dentry, ...@@ -547,6 +538,11 @@ static struct dentry *ovl_lookup_index(struct dentry *dentry,
kfree(name.name); kfree(name.name);
return index; return index;
out_dput:
dput(index);
index = NULL;
goto out;
fail: fail:
dput(index); dput(index);
index = ERR_PTR(-EIO); index = ERR_PTR(-EIO);
...@@ -710,7 +706,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, ...@@ -710,7 +706,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
upperdentry = dget(index); upperdentry = dget(index);
if (upperdentry || ctr) { if (upperdentry || ctr) {
inode = ovl_get_inode(dentry, upperdentry); inode = ovl_get_inode(dentry, upperdentry, index);
err = PTR_ERR(inode); err = PTR_ERR(inode);
if (IS_ERR(inode)) if (IS_ERR(inode))
goto out_free_oe; goto out_free_oe;
......
...@@ -286,7 +286,8 @@ int ovl_update_time(struct inode *inode, struct timespec *ts, int flags); ...@@ -286,7 +286,8 @@ int ovl_update_time(struct inode *inode, struct timespec *ts, int flags);
bool ovl_is_private_xattr(const char *name); bool ovl_is_private_xattr(const char *name);
struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev); struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev);
struct inode *ovl_get_inode(struct dentry *dentry, struct dentry *upperdentry); struct inode *ovl_get_inode(struct dentry *dentry, struct dentry *upperdentry,
struct dentry *index);
static inline void ovl_copyattr(struct inode *from, struct inode *to) static inline void ovl_copyattr(struct inode *from, struct inode *to)
{ {
to->i_uid = from->i_uid; to->i_uid = from->i_uid;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册