Skip to content

Commit 6bcb8a5

Browse files
Alex Williamsongregkh
authored andcommitted
vfio/platform: check the bounds of read/write syscalls
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>
1 parent 1a1b2b8 commit 6bcb8a5

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

drivers/vfio/platform/vfio_platform_common.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,11 @@ static ssize_t vfio_platform_read_mmio(struct vfio_platform_region *reg,
391391
{
392392
unsigned int done = 0;
393393

394+
if (off >= reg->size)
395+
return -EINVAL;
396+
397+
count = min_t(size_t, count, reg->size - off);
398+
394399
if (!reg->ioaddr) {
395400
reg->ioaddr =
396401
ioremap(reg->addr, reg->size);
@@ -470,6 +475,11 @@ static ssize_t vfio_platform_write_mmio(struct vfio_platform_region *reg,
470475
{
471476
unsigned int done = 0;
472477

478+
if (off >= reg->size)
479+
return -EINVAL;
480+
481+
count = min_t(size_t, count, reg->size - off);
482+
473483
if (!reg->ioaddr) {
474484
reg->ioaddr =
475485
ioremap(reg->addr, reg->size);

0 commit comments

Comments
 (0)