Skip to content

Commit 60ad149

Browse files
author
Al Viro
committed
new helpers: file_listxattr(), filename_listxattr()
switch path_listxattr() and flistxattr(2) to those Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 0158005 commit 60ad149

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

fs/xattr.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -888,24 +888,43 @@ listxattr(struct dentry *d, char __user *list, size_t size)
888888
return error;
889889
}
890890

891-
static ssize_t path_listxattr(const char __user *pathname, char __user *list,
892-
size_t size, unsigned int lookup_flags)
891+
static
892+
ssize_t file_listxattr(struct file *f, char __user *list, size_t size)
893+
{
894+
audit_file(f);
895+
return listxattr(f->f_path.dentry, list, size);
896+
}
897+
898+
/* unconditionally consumes filename */
899+
static
900+
ssize_t filename_listxattr(int dfd, struct filename *filename,
901+
unsigned int lookup_flags,
902+
char __user *list, size_t size)
893903
{
894904
struct path path;
895905
ssize_t error;
896906
retry:
897-
error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path);
907+
error = filename_lookup(dfd, filename, lookup_flags, &path, NULL);
898908
if (error)
899-
return error;
909+
goto out;
900910
error = listxattr(path.dentry, list, size);
901911
path_put(&path);
902912
if (retry_estale(error, lookup_flags)) {
903913
lookup_flags |= LOOKUP_REVAL;
904914
goto retry;
905915
}
916+
out:
917+
putname(filename);
906918
return error;
907919
}
908920

921+
static ssize_t path_listxattr(const char __user *pathname, char __user *list,
922+
size_t size, unsigned int lookup_flags)
923+
{
924+
return filename_listxattr(AT_FDCWD, getname(pathname), lookup_flags,
925+
list, size);
926+
}
927+
909928
SYSCALL_DEFINE3(listxattr, const char __user *, pathname, char __user *, list,
910929
size_t, size)
911930
{
@@ -924,8 +943,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
924943

925944
if (fd_empty(f))
926945
return -EBADF;
927-
audit_file(fd_file(f));
928-
return listxattr(fd_file(f)->f_path.dentry, list, size);
946+
return file_listxattr(fd_file(f), list, size);
929947
}
930948

931949
/*

0 commit comments

Comments
 (0)