linux/fs/fuse
Jann Horn e24c19c6e3 fuse: use unsigned type for getxattr/listxattr size truncation
commit b18915248a upstream.

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: stable@vger.kernel.org # v4.9
Fixes: 63401ccdb2 ("fuse: limit xattr returned size")
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2024-09-12 11:07:44 +02:00
..
acl.c vfs: add rcu argument to ->get_acl() callback 2021-08-18 22:08:24 +02:00
control.c fuse: Remove the control interface for virtio-fs 2022-08-17 14:24:11 +02:00
cuse.c fuse: fix UAF in rcu pathwalks 2024-09-04 13:23:23 +02:00
dax.c fuse: dax: set fc->dax to NULL in fuse_dax_conn_free() 2023-12-20 15:17:38 +01:00
dev.c fuse: Initialize beyond-EOF page contents before setting uptodate 2024-09-04 13:23:14 +02:00
dir.c fuse: fix root lookup with nonzero generation 2024-04-10 16:18:38 +02:00
file.c fuse: update stats for pages in dropped aux writeback list 2024-09-12 11:07:43 +02:00
fuse_i.h fuse: fix UAF in rcu pathwalks 2024-09-04 13:23:23 +02:00
inode.c fuse: fix UAF in rcu pathwalks 2024-09-04 13:23:23 +02:00
ioctl.c fuse: ioctl: translate ENOSYS in outarg 2023-07-27 08:46:54 +02:00
Kconfig virtiofs: implement dax read/write operations 2020-09-10 11:39:23 +02:00
Makefile fuse: move ioctl to separate source file 2021-04-12 15:04:30 +02:00
readdir.c fuse: nlookup missing decrement in fuse_direntplus_link 2023-09-19 12:23:01 +02:00
virtio_fs.c virtiofs: forbid newlines in tags 2024-09-04 13:23:25 +02:00
xattr.c fuse: use unsigned type for getxattr/listxattr size truncation 2024-09-12 11:07:44 +02:00