Skip to contentSkip to conversation

vhost_vdpa: Fix potential underflow in vhost_vdpa_mmap()

PATCH Applied Dan Carpenter 2 participants 2 messages Jun 10, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost_vdpa: Fix potential underflow in vhost_vdpa_mmap()

The "vma->vm_pgoff" variable is an unsigned long so if it's larger than INT_MAX then "index" can be negative leading to an underflow. Fix this by changing the type of "index" to "unsigned long".

Fixes ddd89d0a059d ("vhost_vdpa: support doorbell mapping via mmap")
---
 drivers/vhost/vdpa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vhost/vdpa.c +1 -1
index 7580e34f76c10..a54b60d6623f0 100644
@@ -818,7 +818,7 @@ static int vhost_vdpa_mmap(struct file *file, struct vm_area_struct *vma)
 	struct vdpa_device *vdpa = v->vdpa;
 	const struct vdpa_config_ops *ops = vdpa->config;
 	struct vdpa_notification_area notify;
-	int index = vma->vm_pgoff;
+	unsigned long index = vma->vm_pgoff;
 
 	if (vma->vm_end - vma->vm_start != PAGE_SIZE)
 		return -EINVAL;
Signature · 1 line
2.26.2
maintainer Applied
#1 lore raw
Quoted 6 lines · Dan Carpenter

The "vma->vm_pgoff" variable is an unsigned long so if it's larger than INT_MAX then "index" can be negative leading to an underflow. Fix this by changing the type of "index" to "unsigned long".

Fixes ddd89d0a059d ("vhost_vdpa: support doorbell mapping via mmap")

Applied, thanks!

Quoted 19 lines
---
 drivers/vhost/vdpa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vhost/vdpa.c +1 -1
index 7580e34f76c10..a54b60d6623f0 100644
@@ -818,7 +818,7 @@ static int vhost_vdpa_mmap(struct file *file, struct vm_area_struct *vma)
 	struct vdpa_device *vdpa = v->vdpa;
 	const struct vdpa_config_ops *ops = vdpa->config;
 	struct vdpa_notification_area notify;
-	int index = vma->vm_pgoff;
+	unsigned long index = vma->vm_pgoff;
 
 	if (vma->vm_end - vma->vm_start != PAGE_SIZE)
 		return -EINVAL;
Signature · 1 line
2.26.2