ovl: port ovl_create_or_link() 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-5-bd1c97a36d7b@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
Christian Brauner 2025-11-17 10:34:42 +01:00
parent 8a227c2766
commit e566bff963
No known key found for this signature in database
GPG Key ID: 91C61BC06578DCA2
1 changed files with 6 additions and 7 deletions

View File

@ -664,10 +664,9 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
struct ovl_cattr *attr, bool origin) struct ovl_cattr *attr, bool origin)
{ {
int err; int err;
const struct cred *new_cred __free(put_cred) = NULL;
struct dentry *parent = dentry->d_parent; struct dentry *parent = dentry->d_parent;
scoped_class(override_creds_ovl, old_cred, dentry->d_sb) { with_ovl_creds(dentry->d_sb) {
/* /*
* When linking a file with copy up origin into a new parent, mark the * When linking a file with copy up origin into a new parent, mark the
* new parent dir "impure". * new parent dir "impure".
@ -695,12 +694,12 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
if (attr->hardlink) if (attr->hardlink)
return ovl_create_handle_whiteouts(dentry, inode, attr); return ovl_create_handle_whiteouts(dentry, inode, attr);
new_cred = ovl_setup_cred_for_create(dentry, inode, attr->mode, old_cred); scoped_class(ovl_override_creator_creds, cred, dentry, inode, attr->mode) {
if (IS_ERR(new_cred)) if (IS_ERR(cred))
return PTR_ERR(new_cred); return PTR_ERR(cred);
return ovl_create_handle_whiteouts(dentry, inode, attr); return ovl_create_handle_whiteouts(dentry, inode, attr);
} }
}
return err; return err;
} }