]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
do_sys_truncate(): import pathname only once
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 1 Nov 2025 04:48:31 +0000 (00:48 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Tue, 13 Jan 2026 20:16:44 +0000 (15:16 -0500)
Convert the user_path_at() call inside a retry loop into getname_flags() +
filename_lookup() + putname() and leave only filename_lookup() inside
the loop.

In this case we never pass LOOKUP_EMPTY, so getname_flags() is equivalent
to plain getname().

The things could be further simplified by use of cleanup.h stuff, but
let's not clutter the patch with that.

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

index 6f48fa9c756a3a28d8d994aee915ce304049ae1a..2fea68991d425a40d1f5df4d29a4ce72c16c2c59 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -129,14 +129,16 @@ EXPORT_SYMBOL_GPL(vfs_truncate);
 int do_sys_truncate(const char __user *pathname, loff_t length)
 {
        unsigned int lookup_flags = LOOKUP_FOLLOW;
+       struct filename *name;
        struct path path;
        int error;
 
        if (length < 0) /* sorry, but loff_t says... */
                return -EINVAL;
 
+       name = getname(pathname);
 retry:
-       error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path);
+       error = filename_lookup(AT_FDCWD, name, lookup_flags, &path, NULL);
        if (!error) {
                error = vfs_truncate(&path, length);
                path_put(&path);
@@ -145,6 +147,7 @@ retry:
                lookup_flags |= LOOKUP_REVAL;
                goto retry;
        }
+       putname(name);
        return error;
 }