Skip to content

Commit

Permalink
ovl: compare inodes
Browse files Browse the repository at this point in the history
When checking for consistency in directory operations (unlink, rename,
etc.) match inodes not dentries.

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  • Loading branch information
Miklos Szeredi committed Jul 4, 2017
1 parent 25b7713 commit 9020df3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions fs/overlayfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,11 @@ static int ovl_link(struct dentry *old, struct inode *newdir,
return err;
}

static bool ovl_matches_upper(struct dentry *dentry, struct dentry *upper)
{
return d_inode(ovl_dentry_upper(dentry)) == d_inode(upper);
}

static int ovl_remove_and_whiteout(struct dentry *dentry, bool is_dir)
{
struct dentry *workdir = ovl_workdir(dentry);
Expand Down Expand Up @@ -646,7 +651,7 @@ static int ovl_remove_and_whiteout(struct dentry *dentry, bool is_dir)
err = -ESTALE;
if ((opaquedir && upper != opaquedir) ||
(!opaquedir && ovl_dentry_upper(dentry) &&
upper != ovl_dentry_upper(dentry))) {
!ovl_matches_upper(dentry, upper))) {
goto out_dput_upper;
}

Expand Down Expand Up @@ -707,7 +712,7 @@ static int ovl_remove_upper(struct dentry *dentry, bool is_dir)

err = -ESTALE;
if ((opaquedir && upper != opaquedir) ||
(!opaquedir && upper != ovl_dentry_upper(dentry)))
(!opaquedir && !ovl_matches_upper(dentry, upper)))
goto out_dput_upper;

if (is_dir)
Expand Down Expand Up @@ -985,7 +990,7 @@ static int ovl_rename(struct inode *olddir, struct dentry *old,
goto out_unlock;

err = -ESTALE;
if (olddentry != ovl_dentry_upper(old))
if (!ovl_matches_upper(old, olddentry))
goto out_dput_old;

newdentry = lookup_one_len(new->d_name.name, new_upperdir,
Expand All @@ -1003,7 +1008,7 @@ static int ovl_rename(struct inode *olddir, struct dentry *old,
if (newdentry != opaquedir)
goto out_dput;
} else {
if (newdentry != ovl_dentry_upper(new))
if (!ovl_matches_upper(new, newdentry))
goto out_dput;
}
} else {
Expand Down

0 comments on commit 9020df3

Please sign in to comment.