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
This commit is contained in:
parent
7c5ccd2dce
commit
147d12a7d3
@ -212,6 +212,7 @@ int vm_mmap_getnext(struct vm *vm, vm_paddr_t *gpa, int *segid,
|
|||||||
vm_ooffset_t *segoff, size_t *len, int *prot, int *flags);
|
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,
|
int vm_get_memseg(struct vm *vm, int ident, size_t *len, bool *sysmem,
|
||||||
struct vm_object **objptr);
|
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,
|
void *vm_gpa_hold(struct vm *, int vcpuid, vm_paddr_t gpa, size_t len,
|
||||||
int prot, void **cookie);
|
int prot, void **cookie);
|
||||||
void vm_gpa_release(void *cookie);
|
void vm_gpa_release(void *cookie);
|
||||||
|
@ -821,8 +821,8 @@ sysmem_mapping(struct vm *vm, struct mem_map *mm)
|
|||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static vm_paddr_t
|
vm_paddr_t
|
||||||
sysmem_maxaddr(struct vm *vm)
|
vmm_sysmem_maxaddr(struct vm *vm)
|
||||||
{
|
{
|
||||||
struct mem_map *mm;
|
struct mem_map *mm;
|
||||||
vm_paddr_t maxaddr;
|
vm_paddr_t maxaddr;
|
||||||
@ -931,7 +931,7 @@ vm_assign_pptdev(struct vm *vm, int bus, int slot, int func)
|
|||||||
if (ppt_assigned_devices(vm) == 0) {
|
if (ppt_assigned_devices(vm) == 0) {
|
||||||
KASSERT(vm->iommu == NULL,
|
KASSERT(vm->iommu == NULL,
|
||||||
("vm_assign_pptdev: iommu must be NULL"));
|
("vm_assign_pptdev: iommu must be NULL"));
|
||||||
maxaddr = sysmem_maxaddr(vm);
|
maxaddr = vmm_sysmem_maxaddr(vm);
|
||||||
vm->iommu = iommu_create_domain(maxaddr);
|
vm->iommu = iommu_create_domain(maxaddr);
|
||||||
if (vm->iommu == NULL)
|
if (vm->iommu == NULL)
|
||||||
return (ENXIO);
|
return (ENXIO);
|
||||||
|
@ -173,7 +173,7 @@ static int
|
|||||||
vmmdev_rw(struct cdev *cdev, struct uio *uio, int flags)
|
vmmdev_rw(struct cdev *cdev, struct uio *uio, int flags)
|
||||||
{
|
{
|
||||||
int error, off, c, prot;
|
int error, off, c, prot;
|
||||||
vm_paddr_t gpa;
|
vm_paddr_t gpa, maxaddr;
|
||||||
void *hpa, *cookie;
|
void *hpa, *cookie;
|
||||||
struct vmmdev_softc *sc;
|
struct vmmdev_softc *sc;
|
||||||
|
|
||||||
@ -189,6 +189,7 @@ vmmdev_rw(struct cdev *cdev, struct uio *uio, int flags)
|
|||||||
return (error);
|
return (error);
|
||||||
|
|
||||||
prot = (uio->uio_rw == UIO_WRITE ? VM_PROT_WRITE : VM_PROT_READ);
|
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) {
|
while (uio->uio_resid > 0 && error == 0) {
|
||||||
gpa = uio->uio_offset;
|
gpa = uio->uio_offset;
|
||||||
off = gpa & PAGE_MASK;
|
off = gpa & PAGE_MASK;
|
||||||
@ -204,7 +205,7 @@ vmmdev_rw(struct cdev *cdev, struct uio *uio, int flags)
|
|||||||
*/
|
*/
|
||||||
hpa = vm_gpa_hold(sc->vm, VM_MAXCPU - 1, gpa, c, prot, &cookie);
|
hpa = vm_gpa_hold(sc->vm, VM_MAXCPU - 1, gpa, c, prot, &cookie);
|
||||||
if (hpa == NULL) {
|
if (hpa == NULL) {
|
||||||
if (uio->uio_rw == UIO_READ)
|
if (uio->uio_rw == UIO_READ && gpa < maxaddr)
|
||||||
error = uiomove(__DECONST(void *, zero_region),
|
error = uiomove(__DECONST(void *, zero_region),
|
||||||
c, uio);
|
c, uio);
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user