Skip to content

Commit 786534b

Browse files
agruenbaAl Viro
authored andcommitted
tmpfs: listxattr should include POSIX ACL xattrs
When a file on tmpfs has an ACL or a Default ACL, listxattr should include the corresponding xattr name. Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Reviewed-by: James Morris <james.l.morris@oracle.com> Cc: Hugh Dickins <hughd@google.com> Cc: linux-mm@kvack.org Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent aa7c524 commit 786534b

4 files changed

Lines changed: 41 additions & 19 deletions

File tree

‎fs/kernfs/inode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size)
230230
if (!attrs)
231231
return -ENOMEM;
232232

233-
return simple_xattr_list(&attrs->xattrs, buf, size);
233+
return simple_xattr_list(d_inode(dentry), &attrs->xattrs, buf, size);
234234
}
235235

236236
static inline void set_default_inode_attr(struct inode *inode, umode_t mode)

‎fs/xattr.c‎

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -921,38 +921,59 @@ static bool xattr_is_trusted(const char *name)
921921
return !strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN);
922922
}
923923

924+
static int xattr_list_one(char **buffer, ssize_t *remaining_size,
925+
const char *name)
926+
{
927+
size_t len = strlen(name) + 1;
928+
if (*buffer) {
929+
if (*remaining_size < len)
930+
return -ERANGE;
931+
memcpy(*buffer, name, len);
932+
*buffer += len;
933+
}
934+
*remaining_size -= len;
935+
return 0;
936+
}
937+
924938
/*
925939
* xattr LIST operation for in-memory/pseudo filesystems
926940
*/
927-
ssize_t simple_xattr_list(struct simple_xattrs *xattrs, char *buffer,
928-
size_t size)
941+
ssize_t simple_xattr_list(struct inode *inode, struct simple_xattrs *xattrs,
942+
char *buffer, size_t size)
929943
{
930944
bool trusted = capable(CAP_SYS_ADMIN);
931945
struct simple_xattr *xattr;
932-
size_t used = 0;
946+
ssize_t remaining_size = size;
947+
int err;
948+
949+
#ifdef CONFIG_FS_POSIX_ACL
950+
if (inode->i_acl) {
951+
err = xattr_list_one(&buffer, &remaining_size,
952+
XATTR_NAME_POSIX_ACL_ACCESS);
953+
if (err)
954+
return err;
955+
}
956+
if (inode->i_default_acl) {
957+
err = xattr_list_one(&buffer, &remaining_size,
958+
XATTR_NAME_POSIX_ACL_DEFAULT);
959+
if (err)
960+
return err;
961+
}
962+
#endif
933963

934964
spin_lock(&xattrs->lock);
935965
list_for_each_entry(xattr, &xattrs->head, list) {
936-
size_t len;
937-
938966
/* skip "trusted." attributes for unprivileged callers */
939967
if (!trusted && xattr_is_trusted(xattr->name))
940968
continue;
941969

942-
len = strlen(xattr->name) + 1;
943-
used += len;
944-
if (buffer) {
945-
if (size < used) {
946-
used = -ERANGE;
947-
break;
948-
}
949-
memcpy(buffer, xattr->name, len);
950-
buffer += len;
951-
}
970+
err = xattr_list_one(&buffer, &remaining_size, xattr->name);
971+
if (err)
972+
return err;
952973
}
953974
spin_unlock(&xattrs->lock);
954975

955-
return used;
976+
return size - remaining_size;
956977
}
957978

958979
/*

‎include/linux/xattr.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ int simple_xattr_get(struct simple_xattrs *xattrs, const char *name,
104104
void *buffer, size_t size);
105105
int simple_xattr_set(struct simple_xattrs *xattrs, const char *name,
106106
const void *value, size_t size, int flags);
107-
ssize_t simple_xattr_list(struct simple_xattrs *xattrs, char *buffer, size_t size);
107+
ssize_t simple_xattr_list(struct inode *inode, struct simple_xattrs *xattrs, char *buffer,
108+
size_t size);
108109
void simple_xattr_list_add(struct simple_xattrs *xattrs,
109110
struct simple_xattr *new_xattr);
110111

‎mm/shmem.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2606,7 +2606,7 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
26062606
static ssize_t shmem_listxattr(struct dentry *dentry, char *buffer, size_t size)
26072607
{
26082608
struct shmem_inode_info *info = SHMEM_I(d_inode(dentry));
2609-
return simple_xattr_list(&info->xattrs, buffer, size);
2609+
return simple_xattr_list(d_inode(dentry), &info->xattrs, buffer, size);
26102610
}
26112611
#endif /* CONFIG_TMPFS_XATTR */
26122612

0 commit comments

Comments
 (0)