blob: 0f7d2ce04c22948f0e63a7fa3fd776d8656eb3a5 [file] [log] [blame]
Andrew Geisslerd1e89492021-02-12 15:35:20 -06001If mremap() is called without the MREMAP_MAYMOVE flag with a start address
2just before the end of memory (reserved_va) where new_size would exceed
3GUEST_ADD_MAX, the assert(end - 1 <= GUEST_ADDR_MAX) in page_set_flags()
4would trigger.
5
6Add an extra guard to the guest_range_valid() checks to prevent this and
7avoid asserting binaries when reserved_va is set.
8
9This meant a test case now gives the same behaviour regardless of whether
10reserved_va is set or not.
11
12Upstream-Status: Pending
13Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org
14
15Index: qemu-5.2.0/linux-user/mmap.c
16===================================================================
17--- qemu-5.2.0.orig/linux-user/mmap.c
18+++ qemu-5.2.0/linux-user/mmap.c
19@@ -727,7 +727,9 @@ abi_long target_mremap(abi_ulong old_add
20
21 if (!guest_range_valid(old_addr, old_size) ||
22 ((flags & MREMAP_FIXED) &&
23- !guest_range_valid(new_addr, new_size))) {
24+ !guest_range_valid(new_addr, new_size)) ||
25+ ((flags & MREMAP_MAYMOVE) == 0 &&
26+ !guest_range_valid(old_addr, new_size))) {
27 errno = ENOMEM;
28 return -1;
29 }