Skip to content

Commit b189152

Browse files
thejhMiklos Szeredi
authored andcommitted
fuse: use unsigned type for getxattr/listxattr size truncation
The existing code uses min_t(ssize_t, outarg.size, XATTR_LIST_MAX) when parsing the FUSE daemon's response to a zero-length getxattr/listxattr request. On 32-bit kernels, where ssize_t and outarg.size are the same size, this is wrong: The min_t() will pass through any size values that are negative when interpreted as signed. fuse_listxattr() will then return this userspace-supplied negative value, which callers will treat as an error value. This kind of bug pattern can lead to fairly bad security bugs because of how error codes are used in the Linux kernel. If a caller were to convert the numeric error into an error pointer, like so: struct foo *func(...) { int len = fuse_getxattr(..., NULL, 0); if (len < 0) return ERR_PTR(len); ... } then it would end up returning this userspace-supplied negative value cast to a pointer - but the caller of this function wouldn't recognize it as an error pointer (IS_ERR_VALUE() only detects values in the narrow range in which legitimate errno values are), and so it would just be treated as a kernel pointer. I think there is at least one theoretical codepath where this could happen, but that path would involve virtio-fs with submounts plus some weird SELinux configuration, so I think it's probably not a concern in practice. Cc: [email protected] # v4.9 Fixes: 63401cc ("fuse: limit xattr returned size") Signed-off-by: Jann Horn <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 8400291 commit b189152

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/fuse/xattr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value,
8181
}
8282
ret = fuse_simple_request(fm, &args);
8383
if (!ret && !size)
84-
ret = min_t(ssize_t, outarg.size, XATTR_SIZE_MAX);
84+
ret = min_t(size_t, outarg.size, XATTR_SIZE_MAX);
8585
if (ret == -ENOSYS) {
8686
fm->fc->no_getxattr = 1;
8787
ret = -EOPNOTSUPP;
@@ -143,7 +143,7 @@ ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size)
143143
}
144144
ret = fuse_simple_request(fm, &args);
145145
if (!ret && !size)
146-
ret = min_t(ssize_t, outarg.size, XATTR_LIST_MAX);
146+
ret = min_t(size_t, outarg.size, XATTR_LIST_MAX);
147147
if (ret > 0 && size)
148148
ret = fuse_verify_xattr_list(list, ret);
149149
if (ret == -ENOSYS) {

0 commit comments

Comments
 (0)