]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ovl: port ovl_xattr_set() to cred guard
authorChristian Brauner <brauner@kernel.org>
Mon, 17 Nov 2025 09:34:01 +0000 (10:34 +0100)
committerChristian Brauner <brauner@kernel.org>
Wed, 19 Nov 2025 20:58:24 +0000 (21:58 +0100)
Use the scoped ovl cred guard.

Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-30-b31603935724@kernel.org
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/overlayfs/xattrs.c

index 88055deca9360fd389e8fbc6dd4b3555baed2202..787df86acb266dad3a2d46780de68f3878f35d76 100644 (file)
@@ -41,13 +41,11 @@ static int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char
        struct dentry *upperdentry = ovl_i_dentry_upper(inode);
        struct dentry *realdentry = upperdentry ?: ovl_dentry_lower(dentry);
        struct path realpath;
-       const struct cred *old_cred;
 
        if (!value && !upperdentry) {
                ovl_path_lower(dentry, &realpath);
-               old_cred = ovl_override_creds(dentry->d_sb);
-               err = vfs_getxattr(mnt_idmap(realpath.mnt), realdentry, name, NULL, 0);
-               ovl_revert_creds(old_cred);
+               with_ovl_creds(dentry->d_sb)
+                       err = vfs_getxattr(mnt_idmap(realpath.mnt), realdentry, name, NULL, 0);
                if (err < 0)
                        goto out;
        }
@@ -64,15 +62,14 @@ static int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char
        if (err)
                goto out;
 
-       old_cred = ovl_override_creds(dentry->d_sb);
-       if (value) {
-               err = ovl_do_setxattr(ofs, realdentry, name, value, size,
-                                     flags);
-       } else {
-               WARN_ON(flags != XATTR_REPLACE);
-               err = ovl_do_removexattr(ofs, realdentry, name);
+       with_ovl_creds(dentry->d_sb) {
+               if (value) {
+                       err = ovl_do_setxattr(ofs, realdentry, name, value, size, flags);
+               } else {
+                       WARN_ON(flags != XATTR_REPLACE);
+                       err = ovl_do_removexattr(ofs, realdentry, name);
+               }
        }
-       ovl_revert_creds(old_cred);
        ovl_drop_write(dentry);
 
        /* copy c/mtime */