do_sys_truncate(): import pathname only once

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>
This commit is contained in:
Al Viro
2025-11-01 00:48:31 -04:00
parent 85a4fe3c99
commit cf6b819c22

View File

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