svn commit: r333639 - in head/sys/amd64: include vmm

Antoine Brodin antoine at FreeBSD.org
Tue May 15 17:21:00 UTC 2018


Author: antoine
Date: Tue May 15 17:20:58 2018
New Revision: 333639
URL: https://svnweb.freebsd.org/changeset/base/333639

Log:
  vmmdev: return EFAULT when trying to read beyond VM system memory max address
  
  Currently, when using dd(1) to take a VM memory image, the capture never ends,
  reading zeroes when it's beyond VM system memory max address.
  Return EFAULT when trying to read beyond VM system memory max address.
  
  Reviewed by:	imp, grehan, anish
  Approved by:	grehan
  Differential Revision:	https://reviews.freebsd.org/D15156

Modified:
  head/sys/amd64/include/vmm.h
  head/sys/amd64/vmm/vmm.c
  head/sys/amd64/vmm/vmm_dev.c

Modified: head/sys/amd64/include/vmm.h
==============================================================================
--- head/sys/amd64/include/vmm.h	Tue May 15 16:56:30 2018	(r333638)
+++ head/sys/amd64/include/vmm.h	Tue May 15 17:20:58 2018	(r333639)
@@ -212,6 +212,7 @@ int vm_mmap_getnext(struct vm *vm, vm_paddr_t *gpa, in
     vm_ooffset_t *segoff, size_t *len, int *prot, int *flags);
 int vm_get_memseg(struct vm *vm, int ident, size_t *len, bool *sysmem,
     struct vm_object **objptr);
+vm_paddr_t vmm_sysmem_maxaddr(struct vm *vm);
 void *vm_gpa_hold(struct vm *, int vcpuid, vm_paddr_t gpa, size_t len,
     int prot, void **cookie);
 void vm_gpa_release(void *cookie);

Modified: head/sys/amd64/vmm/vmm.c
==============================================================================
--- head/sys/amd64/vmm/vmm.c	Tue May 15 16:56:30 2018	(r333638)
+++ head/sys/amd64/vmm/vmm.c	Tue May 15 17:20:58 2018	(r333639)
@@ -821,8 +821,8 @@ sysmem_mapping(struct vm *vm, struct mem_map *mm)
 		return (false);
 }
 
-static vm_paddr_t
-sysmem_maxaddr(struct vm *vm)
+vm_paddr_t
+vmm_sysmem_maxaddr(struct vm *vm)
 {
 	struct mem_map *mm;
 	vm_paddr_t maxaddr;
@@ -931,7 +931,7 @@ vm_assign_pptdev(struct vm *vm, int bus, int slot, int
 	if (ppt_assigned_devices(vm) == 0) {
 		KASSERT(vm->iommu == NULL,
 		    ("vm_assign_pptdev: iommu must be NULL"));
-		maxaddr = sysmem_maxaddr(vm);
+		maxaddr = vmm_sysmem_maxaddr(vm);
 		vm->iommu = iommu_create_domain(maxaddr);
 		if (vm->iommu == NULL)
 			return (ENXIO);

Modified: head/sys/amd64/vmm/vmm_dev.c
==============================================================================
--- head/sys/amd64/vmm/vmm_dev.c	Tue May 15 16:56:30 2018	(r333638)
+++ head/sys/amd64/vmm/vmm_dev.c	Tue May 15 17:20:58 2018	(r333639)
@@ -173,7 +173,7 @@ static int
 vmmdev_rw(struct cdev *cdev, struct uio *uio, int flags)
 {
 	int error, off, c, prot;
-	vm_paddr_t gpa;
+	vm_paddr_t gpa, maxaddr;
 	void *hpa, *cookie;
 	struct vmmdev_softc *sc;
 
@@ -189,6 +189,7 @@ vmmdev_rw(struct cdev *cdev, struct uio *uio, int flag
 		return (error);
 
 	prot = (uio->uio_rw == UIO_WRITE ? VM_PROT_WRITE : VM_PROT_READ);
+	maxaddr = vmm_sysmem_maxaddr(sc->vm);
 	while (uio->uio_resid > 0 && error == 0) {
 		gpa = uio->uio_offset;
 		off = gpa & PAGE_MASK;
@@ -204,7 +205,7 @@ vmmdev_rw(struct cdev *cdev, struct uio *uio, int flag
 		 */
 		hpa = vm_gpa_hold(sc->vm, VM_MAXCPU - 1, gpa, c, prot, &cookie);
 		if (hpa == NULL) {
-			if (uio->uio_rw == UIO_READ)
+			if (uio->uio_rw == UIO_READ && gpa < maxaddr)
 				error = uiomove(__DECONST(void *, zero_region),
 				    c, uio);
 			else


More information about the svn-src-all mailing list