svn commit: r338511 - head/lib/libvmmapi
John Baldwin
jhb at FreeBSD.org
Thu Sep 6 20:29:41 UTC 2018
Author: jhb
Date: Thu Sep 6 20:29:40 2018
New Revision: 338511
URL: https://svnweb.freebsd.org/changeset/base/338511
Log:
bhyve: Use MAP_GUARD when mapping guest memory ranges.
Instead of relying on PROT_NONE mappings with MAP_ANON, use MAP_GUARD
to reserve address space around guest memory ranges including the
guard ranges of address space around mappings.
Submitted by: Shawn Webb
Reviewed by: araujo
Approved by: re (rgrimes)
MFC after: 1 month
Sponsored by: HardendBSD and G2, Inc
Differential Revision: https://reviews.freebsd.org/D16822
Modified:
head/lib/libvmmapi/vmmapi.c
Modified: head/lib/libvmmapi/vmmapi.c
==============================================================================
--- head/lib/libvmmapi/vmmapi.c Thu Sep 6 20:02:19 2018 (r338510)
+++ head/lib/libvmmapi/vmmapi.c Thu Sep 6 20:29:40 2018 (r338511)
@@ -362,7 +362,7 @@ vm_setup_memory(struct vmctx *ctx, size_t memsize, enu
size_t objsize, len;
vm_paddr_t gpa;
char *baseaddr, *ptr;
- int error, flags;
+ int error;
assert(vms == VM_MMAP_ALL);
@@ -389,8 +389,7 @@ vm_setup_memory(struct vmctx *ctx, size_t memsize, enu
* and the adjoining guard regions.
*/
len = VM_MMAP_GUARD_SIZE + objsize + VM_MMAP_GUARD_SIZE;
- flags = MAP_PRIVATE | MAP_ANON | MAP_NOCORE | MAP_ALIGNED_SUPER;
- ptr = mmap(NULL, len, PROT_NONE, flags, -1, 0);
+ ptr = mmap(NULL, len, PROT_NONE, MAP_GUARD | MAP_ALIGNED_SUPER, -1, 0);
if (ptr == MAP_FAILED)
return (-1);
@@ -492,8 +491,8 @@ vm_create_devmem(struct vmctx *ctx, int segid, const c
* adjoining guard regions.
*/
len2 = VM_MMAP_GUARD_SIZE + len + VM_MMAP_GUARD_SIZE;
- flags = MAP_PRIVATE | MAP_ANON | MAP_NOCORE | MAP_ALIGNED_SUPER;
- base = mmap(NULL, len2, PROT_NONE, flags, -1, 0);
+ base = mmap(NULL, len2, PROT_NONE, MAP_GUARD | MAP_ALIGNED_SUPER, -1,
+ 0);
if (base == MAP_FAILED)
goto done;
More information about the svn-src-all
mailing list