Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 May 2019 22:31:47 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r347409 - in stable/11/sys/amd64: include vmm
Message-ID:  <201905092231.x49MVlQp012302@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Thu May  9 22:31:47 2019
New Revision: 347409
URL: https://svnweb.freebsd.org/changeset/base/347409

Log:
  MFC 333639:
  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.

Modified:
  stable/11/sys/amd64/include/vmm.h
  stable/11/sys/amd64/vmm/vmm.c
  stable/11/sys/amd64/vmm/vmm_dev.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/amd64/include/vmm.h
==============================================================================
--- stable/11/sys/amd64/include/vmm.h	Thu May  9 22:25:12 2019	(r347408)
+++ stable/11/sys/amd64/include/vmm.h	Thu May  9 22:31:47 2019	(r347409)
@@ -201,6 +201,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: stable/11/sys/amd64/vmm/vmm.c
==============================================================================
--- stable/11/sys/amd64/vmm/vmm.c	Thu May  9 22:25:12 2019	(r347408)
+++ stable/11/sys/amd64/vmm/vmm.c	Thu May  9 22:31:47 2019	(r347409)
@@ -773,8 +773,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;
@@ -883,7 +883,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: stable/11/sys/amd64/vmm/vmm_dev.c
==============================================================================
--- stable/11/sys/amd64/vmm/vmm_dev.c	Thu May  9 22:25:12 2019	(r347408)
+++ stable/11/sys/amd64/vmm/vmm_dev.c	Thu May  9 22:31:47 2019	(r347409)
@@ -171,7 +171,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;
 
@@ -187,6 +187,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;
@@ -202,7 +203,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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201905092231.x49MVlQp012302>