Skip to contentSkip to conversation

xen/gntdev: avoid out of bounds access in case of partial gntdev_mmap()

PATCH Applied Juergen Gross 2 participants 5 messages Oct 25, 2017 – Oct 26, 2017

Subsystems (2)
lore
Share & tools
lore

Juergen Gross

author maintainer
#0 lore raw

PATCH 1/1 xen/gntdev: avoid out of bounds access in case of partial gntdev_mmap()

In case gntdev_mmap() succeeds only partially in mapping grant pages it will leave some vital information uninitialized needed later for cleanup. This will lead to an out of bounds array access when unmapping the already mapped pages.

So just initialize the data needed for unmapping the pages a little bit earlier.

---
 drivers/xen/gntdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/xen/gntdev.c +1 -1
index 82360594fa8e..57efbd3b053b 100644
@@ -1024,6 +1024,7 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma)
 	mutex_unlock(&priv->lock);
 
 	if (use_ptemod) {
+		map->pages_vm_start = vma->vm_start;
 		err = apply_to_page_range(vma->vm_mm, vma->vm_start,
 					  vma->vm_end - vma->vm_start,
 					  find_grant_ptes, map);
@@ -1061,7 +1062,6 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma)
 					    set_grant_ptes_as_special, NULL);
 		}
 #endif
-		map->pages_vm_start = vma->vm_start;
 	}
 
 	return 0;
Signature · 1 line
2.12.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Juergen Gross

In case gntdev_mmap() succeeds only partially in mapping grant pages it will leave some vital information uninitialized needed later for cleanup. This will lead to an out of bounds array access when unmapping the already mapped pages.

So just initialize the data needed for unmapping the pages a little bit earlier.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v1 1/1
#2 lore raw
In reply to Juergen Gross
Quoted 11 lines · Juergen Gross

In case gntdev_mmap() succeeds only partially in mapping grant pages it will leave some vital information uninitialized needed later for cleanup. This will lead to an out of bounds array access when unmapping the already mapped pages.

So just initialize the data needed for unmapping the pages a little bit earlier.

#3 lore raw
Quoted 6 lines · Boris Ostrovsky
Quoted 5 lines · Juergen Gross

In case gntdev_mmap() succeeds only partially in mapping grant pages it will leave some vital information uninitialized needed later for cleanup. This will lead to an out of bounds array access when unmapping the already mapped pages.

Quoted 8 lines
Quoted 6 lines

So just initialize the data needed for unmapping the pages a little bit earlier.

Applied to for-linus-4.14c.

-boris

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw
In reply to Boris Ostrovsky
Quoted 6 lines · Boris Ostrovsky
Quoted 5 lines · Juergen Gross

In case gntdev_mmap() succeeds only partially in mapping grant pages it will leave some vital information uninitialized needed later for cleanup. This will lead to an out of bounds array access when unmapping the already mapped pages.

Quoted 8 lines
Quoted 6 lines

So just initialize the data needed for unmapping the pages a little bit earlier.

Applied to for-linus-4.14c.

-boris