summaryrefslogtreecommitdiff
path: root/fs/overlayfs
diff options
context:
space:
mode:
authorAmir Goldstein <amir73il@gmail.com>2024-11-14 09:36:35 +0100
committerAmir Goldstein <amir73il@gmail.com>2024-11-14 13:15:46 +0100
commit711747e204ead127235aa41b350e518e92a87fcc (patch)
treece95f3deeb06147510da6a1596bebe5b5a214b14 /fs/overlayfs
parentfc5a1d2287bf23f67da1fc7a178cf26c5e6ba9d0 (diff)
ovl: pass an explicit reference of creators creds to callers
ovl_setup_cred_for_create() decrements one refcount of new creds and ovl_revert_creds() in callers decrements the last refcount. In preparation to revert_creds_light() back to caller creds, pass an explicit reference of the creators creds to the callers and drop the refcount explicitly in the callers after ovl_revert_creds(). Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Diffstat (limited to 'fs/overlayfs')
-rw-r--r--fs/overlayfs/dir.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
index 09db5eb19242..4b0bb7a91d37 100644
--- a/fs/overlayfs/dir.c
+++ b/fs/overlayfs/dir.c
@@ -553,15 +553,17 @@ out_cleanup:
goto out_dput;
}
-static int ovl_setup_cred_for_create(struct dentry *dentry, struct inode *inode,
- umode_t mode, const struct cred *old_cred)
+static const struct cred *ovl_setup_cred_for_create(struct dentry *dentry,
+ struct inode *inode,
+ umode_t mode,
+ const struct cred *old_cred)
{
int err;
struct cred *override_cred;
override_cred = prepare_creds();
if (!override_cred)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
override_cred->fsuid = inode->i_uid;
override_cred->fsgid = inode->i_gid;
@@ -569,19 +571,18 @@ static int ovl_setup_cred_for_create(struct dentry *dentry, struct inode *inode,
old_cred, override_cred);
if (err) {
put_cred(override_cred);
- return err;
+ return ERR_PTR(err);
}
put_cred(override_creds(override_cred));
- put_cred(override_cred);
- return 0;
+ return override_cred;
}
static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
struct ovl_cattr *attr, bool origin)
{
int err;
- const struct cred *old_cred;
+ const struct cred *old_cred, *new_cred = NULL;
struct dentry *parent = dentry->d_parent;
old_cred = ovl_override_creds(dentry->d_sb);
@@ -610,9 +611,13 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
* create a new inode, so just use the ovl mounter's
* fs{u,g}id.
*/
- err = ovl_setup_cred_for_create(dentry, inode, attr->mode, old_cred);
- if (err)
+ new_cred = ovl_setup_cred_for_create(dentry, inode, attr->mode,
+ old_cred);
+ err = PTR_ERR(new_cred);
+ if (IS_ERR(new_cred)) {
+ new_cred = NULL;
goto out_revert_creds;
+ }
}
if (!ovl_dentry_is_whiteout(dentry))
@@ -622,6 +627,7 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
out_revert_creds:
ovl_revert_creds(old_cred);
+ put_cred(new_cred);
return err;
}
@@ -1306,7 +1312,7 @@ out:
static int ovl_create_tmpfile(struct file *file, struct dentry *dentry,
struct inode *inode, umode_t mode)
{
- const struct cred *old_cred;
+ const struct cred *old_cred, *new_cred = NULL;
struct path realparentpath;
struct file *realfile;
struct dentry *newdentry;
@@ -1315,9 +1321,12 @@ static int ovl_create_tmpfile(struct file *file, struct dentry *dentry,
int err;
old_cred = ovl_override_creds(dentry->d_sb);
- err = ovl_setup_cred_for_create(dentry, inode, mode, old_cred);
- if (err)
+ new_cred = ovl_setup_cred_for_create(dentry, inode, mode, old_cred);
+ err = PTR_ERR(new_cred);
+ if (IS_ERR(new_cred)) {
+ new_cred = NULL;
goto out_revert_creds;
+ }
ovl_path_upper(dentry->d_parent, &realparentpath);
realfile = backing_tmpfile_open(&file->f_path, flags, &realparentpath,
@@ -1338,6 +1347,7 @@ static int ovl_create_tmpfile(struct file *file, struct dentry *dentry,
}
out_revert_creds:
ovl_revert_creds(old_cred);
+ put_cred(new_cred);
return err;
}