summaryrefslogtreecommitdiff
path: root/fs/xattr.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2024-09-26 17:53:13 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2024-11-06 12:59:39 -0500
commit60ad149cf395ff0a502976963d9a89c2f5dfe424 (patch)
tree7486d6d58b4dd16c691af10f57a9e6edb2c37394 /fs/xattr.c
parent0158005aaa3c946ecac9d251c34708a40a85cbe1 (diff)
downloadlwn-60ad149cf395ff0a502976963d9a89c2f5dfe424.tar.gz
lwn-60ad149cf395ff0a502976963d9a89c2f5dfe424.zip
new helpers: file_listxattr(), filename_listxattr()
switch path_listxattr() and flistxattr(2) to those Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/xattr.c')
-rw-r--r--fs/xattr.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/fs/xattr.c b/fs/xattr.c
index d55f3d1e7589..988ea737ae7e 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -888,24 +888,43 @@ listxattr(struct dentry *d, char __user *list, size_t size)
return error;
}
-static ssize_t path_listxattr(const char __user *pathname, char __user *list,
- size_t size, unsigned int lookup_flags)
+static
+ssize_t file_listxattr(struct file *f, char __user *list, size_t size)
+{
+ audit_file(f);
+ 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,
+ char __user *list, size_t size)
{
struct path path;
ssize_t error;
retry:
- error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path);
+ error = filename_lookup(dfd, filename, lookup_flags, &path, NULL);
if (error)
- return error;
+ goto out;
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;
}
+static ssize_t path_listxattr(const char __user *pathname, char __user *list,
+ size_t size, unsigned int lookup_flags)
+{
+ return filename_listxattr(AT_FDCWD, getname(pathname), lookup_flags,
+ list, size);
+}
+
SYSCALL_DEFINE3(listxattr, const char __user *, pathname, char __user *, list,
size_t, size)
{
@@ -924,8 +943,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
if (fd_empty(f))
return -EBADF;
- audit_file(fd_file(f));
- return listxattr(fd_file(f)->f_path.dentry, list, size);
+ return file_listxattr(fd_file(f), list, size);
}
/*