summaryrefslogtreecommitdiff
path: root/linux-user/mmap.c
diff options
context:
space:
mode:
authorMaximilian Riemensberger <riemensberger@cadami.net>2018-01-07 01:01:44 +0000
committerLaurent Vivier <laurent@vivier.eu>2018-01-23 14:20:52 +0100
commit95e6d4305affbbf5258c6a533be9bfd24599da90 (patch)
tree69f43fca0ef20746517d23ae334ee9ac948d64a2 /linux-user/mmap.c
parent10fa993aae539fa8d0da1da17169e05f1dfb4f95 (diff)
downloadqemu-95e6d4305affbbf5258c6a533be9bfd24599da90.tar.gz
linux-user/mmap.c: Avoid choosing NULL as start address
mmap() is required by the linux kernel ABI and POSIX to return a non-NULL address when the implementation chooses a start address for the mapping. The current implementation of mmap_find_vma_reserved() can return NULL as start address of a mapping which leads to subsequent crashes inside the guests glibc, e.g. output of qemu-arm-static --strace executing a test binary stx_test: 1879 mmap2(NULL,8388608,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS|0x20000,-1,0) = 0x00000000 1879 write(2,0xf6fd39d0,79) stx_test: allocatestack.c:514: allocate_stack: Assertion `mem != NULL' failed. This patch fixes mmap_find_vma_reserved() by skipping NULL as start address while searching for a suitable mapping start address. CC: Riku Voipio <riku.voipio@iki.fi> CC: Laurent Vivier <laurent@vivier.eu> CC: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Maximilian Riemensberger <riemensberger@cadami.net> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <1515286904-86418-1-git-send-email-riemensberger@cadami.net> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Diffstat (limited to 'linux-user/mmap.c')
-rw-r--r--linux-user/mmap.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 4888f53139..0fbfd6dff2 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -234,7 +234,7 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong start, abi_ulong size)
if (prot) {
end_addr = addr;
}
- if (addr + size == end_addr) {
+ if (addr && addr + size == end_addr) {
break;
}
addr -= qemu_host_page_size;