]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
vfs: stop using user_path_at_empty in do_readlinkat
authorMateusz Guzik <mjguzik@gmail.com>
Tue, 4 Jun 2024 15:52:55 +0000 (17:52 +0200)
committerChristian Brauner <brauner@kernel.org>
Wed, 5 Jun 2024 15:03:56 +0000 (17:03 +0200)
It is the only consumer and it saddles getname_flags with an argument set
to NULL by everyone else.

Instead the routine can do the empty check on its own.

Then user_path_at_empty can get retired and getname_flags can lose the
argument.

Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
Link: https://lore.kernel.org/r/20240604155257.109500-2-mjguzik@gmail.com
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/stat.c

index 70bd3e888cfa301be28acf5f6fa5a5b655549d2a..7f786154450033e598b400e4fc8d84e0c9a4606d 100644 (file)
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -488,34 +488,39 @@ static int do_readlinkat(int dfd, const char __user *pathname,
                         char __user *buf, int bufsiz)
 {
        struct path path;
+       struct filename *name;
        int error;
-       int empty = 0;
        unsigned int lookup_flags = LOOKUP_EMPTY;
 
        if (bufsiz <= 0)
                return -EINVAL;
 
 retry:
-       error = user_path_at_empty(dfd, pathname, lookup_flags, &path, &empty);
-       if (!error) {
-               struct inode *inode = d_backing_inode(path.dentry);
+       name = getname_flags(pathname, lookup_flags, NULL);
+       error = filename_lookup(dfd, name, lookup_flags, &path, NULL);
+       if (unlikely(error)) {
+               putname(name);
+               return error;
+       }
 
-               error = empty ? -ENOENT : -EINVAL;
-               /*
-                * AFS mountpoints allow readlink(2) but are not symlinks
-                */
-               if (d_is_symlink(path.dentry) || inode->i_op->readlink) {
-                       error = security_inode_readlink(path.dentry);
-                       if (!error) {
-                               touch_atime(&path);
-                               error = vfs_readlink(path.dentry, buf, bufsiz);
-                       }
-               }
-               path_put(&path);
-               if (retry_estale(error, lookup_flags)) {
-                       lookup_flags |= LOOKUP_REVAL;
-                       goto retry;
+       /*
+        * AFS mountpoints allow readlink(2) but are not symlinks
+        */
+       if (d_is_symlink(path.dentry) ||
+           d_backing_inode(path.dentry)->i_op->readlink) {
+               error = security_inode_readlink(path.dentry);
+               if (!error) {
+                       touch_atime(&path);
+                       error = vfs_readlink(path.dentry, buf, bufsiz);
                }
+       } else {
+               error = (name->name[0] == '\0') ? -ENOENT : -EINVAL;
+       }
+       path_put(&path);
+       putname(name);
+       if (retry_estale(error, lookup_flags)) {
+               lookup_flags |= LOOKUP_REVAL;
+               goto retry;
        }
        return error;
 }