Skip to contentSkip to conversation

vfio/fsl-mc: prevent underflow in vfio_fsl_mc_mmap()

PATCH Applied Dan Carpenter 3 participants 3 messages Oct 23, 2020 – Nov 3, 2020

Subsystems (4)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 vfio/fsl-mc: prevent underflow in vfio_fsl_mc_mmap()

My static analsysis tool complains that the "index" can be negative. There are some checks in do_mmap() which try to prevent underflows but I don't know if they are sufficient for this situation. Either way, making "index" unsigned is harmless so let's do it just to be safe.

Fixes 67247289688d ("vfio/fsl-mc: Allow userspace to MMAP fsl-mc device MMIO regions")
---
 drivers/vfio/fsl-mc/vfio_fsl_mc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/fsl-mc/vfio_fsl_mc.c +1 -1
index 21f22e3da11f..f27e25112c40 100644
@@ -472,7 +472,7 @@ static int vfio_fsl_mc_mmap(void *device_data, struct vm_area_struct *vma)
 {
 	struct vfio_fsl_mc_device *vdev = device_data;
 	struct fsl_mc_device *mc_dev = vdev->mc_dev;
-	int index;
+	unsigned int index;
 
 	index = vma->vm_pgoff >> (VFIO_FSL_MC_OFFSET_SHIFT - PAGE_SHIFT);
 
Signature · 1 line
2.28.0
#1 lore raw

Hi Diana, same for this one. Thanks,

Alex

Quoted 24 lines · On Fri, 23 Oct 2020 14:29:47 +0300 Dan Carpenter <[email protected]>…

My static analsysis tool complains that the "index" can be negative. There are some checks in do_mmap() which try to prevent underflows but I don't know if they are sufficient for this situation. Either way, making "index" unsigned is harmless so let's do it just to be safe.

Fixes 67247289688d ("vfio/fsl-mc: Allow userspace to MMAP fsl-mc device MMIO regions")
---
 drivers/vfio/fsl-mc/vfio_fsl_mc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/fsl-mc/vfio_fsl_mc.c +1 -1
index 21f22e3da11f..f27e25112c40 100644
@@ -472,7 +472,7 @@ static int vfio_fsl_mc_mmap(void *device_data, struct vm_area_struct *vma)
 {
 	struct vfio_fsl_mc_device *vdev = device_data;
 	struct fsl_mc_device *mc_dev = vdev->mc_dev;
-	int index;
+	unsigned int index;
 
 	index = vma->vm_pgoff >> (VFIO_FSL_MC_OFFSET_SHIFT - PAGE_SHIFT);
 
Acked-by on v1 2/2
#2 lore raw
In reply to Dan Carpenter
Quoted 25 lines · Dan Carpenter

My static analsysis tool complains that the "index" can be negative. There are some checks in do_mmap() which try to prevent underflows but I don't know if they are sufficient for this situation. Either way, making "index" unsigned is harmless so let's do it just to be safe.

Fixes 67247289688d ("vfio/fsl-mc: Allow userspace to MMAP fsl-mc device MMIO regions")
---
  drivers/vfio/fsl-mc/vfio_fsl_mc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/fsl-mc/vfio_fsl_mc.c +1 -1
index 21f22e3da11f..f27e25112c40 100644
@@ -472,7 +472,7 @@ static int vfio_fsl_mc_mmap(void *device_data, struct vm_area_struct *vma)
  {
  	struct vfio_fsl_mc_device *vdev = device_data;
  	struct fsl_mc_device *mc_dev = vdev->mc_dev;
-	int index;
+	unsigned int index;
 
  	index = vma->vm_pgoff >> (VFIO_FSL_MC_OFFSET_SHIFT - PAGE_SHIFT);