Commit e85f82ff authored by Miklos Szeredi's avatar Miklos Szeredi

ovl: copy-up: don't unlock between lookup and link

Nothing prevents mischief on upper layer while we are busy copying up the
data.

Move the lookup right before the looked up dentry is actually used.
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
Fixes: 01ad3eb8 ("ovl: concurrent copy up of regular files")
Cc: <stable@vger.kernel.org> # v4.11
parent c0bc126f
...@@ -330,15 +330,9 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir, ...@@ -330,15 +330,9 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir,
.link = link .link = link
}; };
upper = lookup_one_len(dentry->d_name.name, upperdir,
dentry->d_name.len);
err = PTR_ERR(upper);
if (IS_ERR(upper))
goto out;
err = security_inode_copy_up(dentry, &new_creds); err = security_inode_copy_up(dentry, &new_creds);
if (err < 0) if (err < 0)
goto out1; goto out;
if (new_creds) if (new_creds)
old_creds = override_creds(new_creds); old_creds = override_creds(new_creds);
...@@ -362,7 +356,7 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir, ...@@ -362,7 +356,7 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir,
} }
if (err) if (err)
goto out2; goto out;
if (S_ISREG(stat->mode)) { if (S_ISREG(stat->mode)) {
struct path upperpath; struct path upperpath;
...@@ -403,6 +397,14 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir, ...@@ -403,6 +397,14 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir,
if (err) if (err)
goto out_cleanup; goto out_cleanup;
upper = lookup_one_len(dentry->d_name.name, upperdir,
dentry->d_name.len);
if (IS_ERR(upper)) {
err = PTR_ERR(upper);
upper = NULL;
goto out_cleanup;
}
if (tmpfile) if (tmpfile)
err = ovl_do_link(temp, udir, upper, true); err = ovl_do_link(temp, udir, upper, true);
else else
...@@ -416,17 +418,15 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir, ...@@ -416,17 +418,15 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir,
/* Restore timestamps on parent (best effort) */ /* Restore timestamps on parent (best effort) */
ovl_set_timestamps(upperdir, pstat); ovl_set_timestamps(upperdir, pstat);
out2: out:
dput(temp); dput(temp);
out1:
dput(upper); dput(upper);
out:
return err; return err;
out_cleanup: out_cleanup:
if (!tmpfile) if (!tmpfile)
ovl_cleanup(wdir, temp); ovl_cleanup(wdir, temp);
goto out2; goto out;
} }
/* /*
......
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