Unverified Commit 8d7fc461 authored by Christian Brauner's avatar Christian Brauner
Browse files

ovl: port ovl_create_tmpfile() to new ovl_override_creator_creds cleanup guard

This clearly indicates the double-credential override and makes the code
a lot easier to grasp with one glance.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-prepare-v2-2-bd1c97a36d7b@kernel.org


Reviewed-by: default avatarAmir Goldstein <amir73il@gmail.com>
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent f37b3347
Loading
Loading
Loading
Loading
+26 −26
Original line number Diff line number Diff line
@@ -1381,7 +1381,6 @@ static int ovl_rename(struct mnt_idmap *idmap, struct inode *olddir,
static int ovl_create_tmpfile(struct file *file, struct dentry *dentry,
			      struct inode *inode, umode_t mode)
{
	const struct cred *new_cred __free(put_cred) = NULL;
	struct path realparentpath;
	struct file *realfile;
	struct ovl_file *of;
@@ -1390,10 +1389,10 @@ static int ovl_create_tmpfile(struct file *file, struct dentry *dentry,
	int flags = file->f_flags | OVL_OPEN_FLAGS;
	int err;

	scoped_class(override_creds_ovl, old_cred, dentry->d_sb) {
		new_cred = ovl_setup_cred_for_create(dentry, inode, mode, old_cred);
		if (IS_ERR(new_cred))
			return PTR_ERR(new_cred);
	with_ovl_creds(dentry->d_sb) {
		scoped_class(ovl_override_creator_creds, cred, dentry, inode, mode) {
			if (IS_ERR(cred))
				return PTR_ERR(cred);

			ovl_path_upper(dentry->d_parent, &realparentpath);
			realfile = backing_tmpfile_open(&file->f_path, flags, &realparentpath,
@@ -1419,6 +1418,7 @@ static int ovl_create_tmpfile(struct file *file, struct dentry *dentry,
				ovl_file_free(of);
			}
		}
	}
	return err;
}