Skip to content

Commit

Permalink
fuse: listxattr: verify xattr list
Browse files Browse the repository at this point in the history
Make sure userspace filesystem is returning a well formed list of xattr
names (zero or more nonzero length, null terminated strings).

[Michael Theall: only verify in the nonzero size case]

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Cc: <stable@vger.kernel.org>
  • Loading branch information
Miklos Szeredi committed Oct 1, 2016
1 parent 08895a8 commit cb3ae6d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions fs/fuse/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,23 @@ static ssize_t fuse_getxattr(struct dentry *entry, struct inode *inode,
return ret;
}

static int fuse_verify_xattr_list(char *list, size_t size)
{
size_t origsize = size;

while (size) {
size_t thislen = strnlen(list, size);

if (!thislen || thislen == size)
return -EIO;

size -= thislen + 1;
list += thislen + 1;
}

return origsize;
}

static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size)
{
struct inode *inode = d_inode(entry);
Expand Down Expand Up @@ -1836,6 +1853,8 @@ static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size)
ret = fuse_simple_request(fc, &args);
if (!ret && !size)
ret = outarg.size;
if (ret > 0 && size)
ret = fuse_verify_xattr_list(list, ret);
if (ret == -ENOSYS) {
fc->no_listxattr = 1;
ret = -EOPNOTSUPP;
Expand Down

0 comments on commit cb3ae6d

Please sign in to comment.