Skip to content

Commit

Permalink
vfio/platform: check the bounds of read/write syscalls
Browse files Browse the repository at this point in the history
commit ce9ff21 upstream.

count and offset are passed from user space and not checked, only
offset is capped to 40 bits, which can be used to read/write out of
bounds of the device.

Fixes: 6e3f264 (“vfio/platform: read and write support for the device fd”)
Cc: stable@vger.kernel.org
Reported-by: Mostafa Saleh <smostafa@google.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Mostafa Saleh <smostafa@google.com>
Tested-by: Mostafa Saleh <smostafa@google.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
awilliam authored and gregkh committed Feb 1, 2025
1 parent 1a1b2b8 commit 6bcb8a5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions drivers/vfio/platform/vfio_platform_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,11 @@ static ssize_t vfio_platform_read_mmio(struct vfio_platform_region *reg,
{
unsigned int done = 0;

if (off >= reg->size)
return -EINVAL;

count = min_t(size_t, count, reg->size - off);

if (!reg->ioaddr) {
reg->ioaddr =
ioremap(reg->addr, reg->size);
Expand Down Expand Up @@ -470,6 +475,11 @@ static ssize_t vfio_platform_write_mmio(struct vfio_platform_region *reg,
{
unsigned int done = 0;

if (off >= reg->size)
return -EINVAL;

count = min_t(size_t, count, reg->size - off);

if (!reg->ioaddr) {
reg->ioaddr =
ioremap(reg->addr, reg->size);
Expand Down

0 comments on commit 6bcb8a5

Please sign in to comment.