Skip to content

Commit c981c32

Browse files
awilliamgregkh
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: [email protected] Reported-by: Mostafa Saleh <[email protected]> Reviewed-by: Eric Auger <[email protected]> Reviewed-by: Mostafa Saleh <[email protected]> Tested-by: Mostafa Saleh <[email protected]> Signed-off-by: Alex Williamson <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7d6405c commit c981c32

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drivers/vfio/platform/vfio_platform_common.c

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

391+
if (off >= reg->size)
392+
return -EINVAL;
393+
394+
count = min_t(size_t, count, reg->size - off);
395+
391396
if (!reg->ioaddr) {
392397
reg->ioaddr =
393398
ioremap(reg->addr, reg->size);
@@ -467,6 +472,11 @@ static ssize_t vfio_platform_write_mmio(struct vfio_platform_region *reg,
467472
{
468473
unsigned int done = 0;
469474

475+
if (off >= reg->size)
476+
return -EINVAL;
477+
478+
count = min_t(size_t, count, reg->size - off);
479+
470480
if (!reg->ioaddr) {
471481
reg->ioaddr =
472482
ioremap(reg->addr, reg->size);

0 commit comments

Comments
 (0)