From 32a008dee7e436829fc7b03f20840ff71422d990 Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Fri, 21 Feb 2020 00:56:38 -0800 Subject: [PATCH] fixup! [LibOS] return error on munmap()/mprotect() for outside of user address --- LibOS/shim/src/sys/shim_mmap.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/LibOS/shim/src/sys/shim_mmap.c b/LibOS/shim/src/sys/shim_mmap.c index 6ac5f3bc..5c095886 100644 --- a/LibOS/shim/src/sys/shim_mmap.c +++ b/LibOS/shim/src/sys/shim_mmap.c @@ -161,8 +161,12 @@ int shim_do_mprotect(void* addr, size_t length, int prot) { if (!IS_ALLOC_ALIGNED(length)) length = ALLOC_ALIGN_UP(length); - if (!completely_within_user_address(addr, length)) - return -ENOMEM; + if (!completely_within_user_address(addr, length)) { + /* Pal may load the executable outside of user address. Allow rtld to mprotect it */ + if (!(PAL_CB(executable_range.start) <= addr && + addr + length <= PAL_CB(executable_range.end))) + return -ENOMEM; + } if (bkeep_mprotect(addr, length, prot, 0) < 0) return -EPERM; @@ -187,12 +191,8 @@ int shim_do_munmap(void* addr, size_t length) { if (!IS_ALLOC_ALIGNED(length)) length = ALLOC_ALIGN_UP(length); - if (!completely_within_user_address(addr, length)) { - /* Pal loads the executable outside of user address. Allow rtld to mprotect it */ - if (!(PAL_CB(executable_range.start) <= addr && - addr + length <= PAL_CB(executable_range.end))) - return -EINVAL; - } + if (!completely_within_user_address(addr, length)) + return -EINVAL; struct shim_vma_val vma;