]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
filename_...xattr(): don't consume filename reference
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 6 Dec 2025 19:33:29 +0000 (14:33 -0500)
committerAl Viro <viro@zeniv.linux.org.uk>
Fri, 16 Jan 2026 17:52:03 +0000 (12:52 -0500)
Callers switched to CLASS(filename_maybe_null) (in fs/xattr.c)
and CLASS(filename_complete_delayed) (in io_uring/xattr.c).

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/xattr.c
io_uring/xattr.c

index 32d445fb60aaf2aaf4b16b62934dc99bad378067..3e49e612e1badc0b3a7c5ab1bf92e0559625bc00 100644 (file)
@@ -649,7 +649,6 @@ int file_setxattr(struct file *f, struct kernel_xattr_ctx *ctx)
        return error;
 }
 
-/* unconditionally consumes filename */
 int filename_setxattr(int dfd, struct filename *filename,
                      unsigned int lookup_flags, struct kernel_xattr_ctx *ctx)
 {
@@ -659,7 +658,7 @@ int filename_setxattr(int dfd, struct filename *filename,
 retry:
        error = filename_lookup(dfd, filename, lookup_flags, &path, NULL);
        if (error)
-               goto out;
+               return error;
        error = mnt_want_write(path.mnt);
        if (!error) {
                error = do_setxattr(mnt_idmap(path.mnt), path.dentry, ctx);
@@ -670,9 +669,6 @@ retry:
                lookup_flags |= LOOKUP_REVAL;
                goto retry;
        }
-
-out:
-       putname(filename);
        return error;
 }
 
@@ -688,7 +684,6 @@ static int path_setxattrat(int dfd, const char __user *pathname,
                .kname  = &kname,
                .flags  = flags,
        };
-       struct filename *filename;
        unsigned int lookup_flags = 0;
        int error;
 
@@ -702,7 +697,7 @@ static int path_setxattrat(int dfd, const char __user *pathname,
        if (error)
                return error;
 
-       filename = getname_maybe_null(pathname, at_flags);
+       CLASS(filename_maybe_null, filename)(pathname, at_flags);
        if (!filename && dfd >= 0) {
                CLASS(fd, f)(dfd);
                if (fd_empty(f))
@@ -804,7 +799,6 @@ ssize_t file_getxattr(struct file *f, struct kernel_xattr_ctx *ctx)
        return do_getxattr(file_mnt_idmap(f), f->f_path.dentry, ctx);
 }
 
-/* unconditionally consumes filename */
 ssize_t filename_getxattr(int dfd, struct filename *filename,
                          unsigned int lookup_flags, struct kernel_xattr_ctx *ctx)
 {
@@ -813,15 +807,13 @@ ssize_t filename_getxattr(int dfd, struct filename *filename,
 retry:
        error = filename_lookup(dfd, filename, lookup_flags, &path, NULL);
        if (error)
-               goto out;
+               return error;
        error = do_getxattr(mnt_idmap(path.mnt), path.dentry, ctx);
        path_put(&path);
        if (retry_estale(error, lookup_flags)) {
                lookup_flags |= LOOKUP_REVAL;
                goto retry;
        }
-out:
-       putname(filename);
        return error;
 }
 
@@ -836,7 +828,6 @@ static ssize_t path_getxattrat(int dfd, const char __user *pathname,
                .kname    = &kname,
                .flags    = 0,
        };
-       struct filename *filename;
        ssize_t error;
 
        if ((at_flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) != 0)
@@ -846,7 +837,7 @@ static ssize_t path_getxattrat(int dfd, const char __user *pathname,
        if (error)
                return error;
 
-       filename = getname_maybe_null(pathname, at_flags);
+       CLASS(filename_maybe_null, filename)(pathname, at_flags);
        if (!filename && dfd >= 0) {
                CLASS(fd, f)(dfd);
                if (fd_empty(f))
@@ -943,7 +934,6 @@ ssize_t file_listxattr(struct file *f, char __user *list, size_t size)
        return listxattr(f->f_path.dentry, list, size);
 }
 
-/* unconditionally consumes filename */
 static
 ssize_t filename_listxattr(int dfd, struct filename *filename,
                           unsigned int lookup_flags,
@@ -954,15 +944,13 @@ ssize_t filename_listxattr(int dfd, struct filename *filename,
 retry:
        error = filename_lookup(dfd, filename, lookup_flags, &path, NULL);
        if (error)
-               goto out;
+               return error;
        error = listxattr(path.dentry, list, size);
        path_put(&path);
        if (retry_estale(error, lookup_flags)) {
                lookup_flags |= LOOKUP_REVAL;
                goto retry;
        }
-out:
-       putname(filename);
        return error;
 }
 
@@ -970,13 +958,12 @@ static ssize_t path_listxattrat(int dfd, const char __user *pathname,
                                unsigned int at_flags, char __user *list,
                                size_t size)
 {
-       struct filename *filename;
        int lookup_flags;
 
        if ((at_flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) != 0)
                return -EINVAL;
 
-       filename = getname_maybe_null(pathname, at_flags);
+       CLASS(filename_maybe_null, filename)(pathname, at_flags);
        if (!filename) {
                CLASS(fd, f)(dfd);
                if (fd_empty(f))
@@ -1036,7 +1023,6 @@ static int file_removexattr(struct file *f, struct xattr_name *kname)
        return error;
 }
 
-/* unconditionally consumes filename */
 static int filename_removexattr(int dfd, struct filename *filename,
                                unsigned int lookup_flags, struct xattr_name *kname)
 {
@@ -1046,7 +1032,7 @@ static int filename_removexattr(int dfd, struct filename *filename,
 retry:
        error = filename_lookup(dfd, filename, lookup_flags, &path, NULL);
        if (error)
-               goto out;
+               return error;
        error = mnt_want_write(path.mnt);
        if (!error) {
                error = removexattr(mnt_idmap(path.mnt), path.dentry, kname->name);
@@ -1057,8 +1043,6 @@ retry:
                lookup_flags |= LOOKUP_REVAL;
                goto retry;
        }
-out:
-       putname(filename);
        return error;
 }
 
@@ -1066,7 +1050,6 @@ static int path_removexattrat(int dfd, const char __user *pathname,
                              unsigned int at_flags, const char __user *name)
 {
        struct xattr_name kname;
-       struct filename *filename;
        unsigned int lookup_flags;
        int error;
 
@@ -1077,7 +1060,7 @@ static int path_removexattrat(int dfd, const char __user *pathname,
        if (error)
                return error;
 
-       filename = getname_maybe_null(pathname, at_flags);
+       CLASS(filename_maybe_null, filename)(pathname, at_flags);
        if (!filename) {
                CLASS(fd, f)(dfd);
                if (fd_empty(f))
index 0fb4e5303500b62c41d7457b015b7626431abac8..ba2b98cf13f9eb995365825cb73e04aaef6d451d 100644 (file)
@@ -109,12 +109,12 @@ int io_fgetxattr(struct io_kiocb *req, unsigned int issue_flags)
 int io_getxattr(struct io_kiocb *req, unsigned int issue_flags)
 {
        struct io_xattr *ix = io_kiocb_to_cmd(req, struct io_xattr);
+       CLASS(filename_complete_delayed, name)(&ix->filename);
        int ret;
 
        WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
 
-       ret = filename_getxattr(AT_FDCWD, complete_getname(&ix->filename),
-                               LOOKUP_FOLLOW, &ix->ctx);
+       ret = filename_getxattr(AT_FDCWD, name, LOOKUP_FOLLOW, &ix->ctx);
        io_xattr_finish(req, ret);
        return IOU_COMPLETE;
 }
@@ -186,12 +186,12 @@ int io_fsetxattr(struct io_kiocb *req, unsigned int issue_flags)
 int io_setxattr(struct io_kiocb *req, unsigned int issue_flags)
 {
        struct io_xattr *ix = io_kiocb_to_cmd(req, struct io_xattr);
+       CLASS(filename_complete_delayed, name)(&ix->filename);
        int ret;
 
        WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK);
 
-       ret = filename_setxattr(AT_FDCWD, complete_getname(&ix->filename),
-                               LOOKUP_FOLLOW, &ix->ctx);
+       ret = filename_setxattr(AT_FDCWD, name, LOOKUP_FOLLOW, &ix->ctx);
        io_xattr_finish(req, ret);
        return IOU_COMPLETE;
 }