Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1 | From 3ed26be2091436296933ed2146f7269c791c7bfe Mon Sep 17 00:00:00 2001 |
| 2 | From: Martin Jansa <martin.jansa@lge.com> |
| 3 | Date: Fri, 1 Jun 2018 08:41:07 +0000 |
| 4 | Subject: [PATCH] Revert "linux-user: fix mmap/munmap/mprotect/mremap/shmat" |
| 5 | |
| 6 | Causes qemu-i386 to hang during gobject-introspection in webkitgtk build |
| 7 | when musl is used on qemux86 - the same issue as |
| 8 | 0010-linux-user-Fix-webkitgtk-hangs-on-32-bit-x86-target.patch |
| 9 | was fixing in 2.11.0 release, but with this patch the fix no longer worked |
| 10 | as discussed here: |
| 11 | http://lists.openembedded.org/pipermail/openembedded-core/2018-May/150302.html |
| 12 | http://lists.openembedded.org/pipermail/openembedded-core/2018-June/151382.html |
| 13 | |
| 14 | This reverts commit ebf9a3630c911d0cfc9c20f7cafe9ba4f88cf583. |
| 15 | |
| 16 | Upstream-Status: Pending |
| 17 | --- |
| 18 | include/exec/cpu-all.h | 6 +----- |
| 19 | include/exec/cpu_ldst.h | 16 +++++++++------- |
| 20 | linux-user/mmap.c | 17 ++++------------- |
| 21 | linux-user/syscall.c | 5 +---- |
| 22 | 4 files changed, 15 insertions(+), 29 deletions(-) |
| 23 | |
| 24 | diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h |
| 25 | index f4fa94e966..0b141683f0 100644 |
| 26 | --- a/include/exec/cpu-all.h |
| 27 | +++ b/include/exec/cpu-all.h |
| 28 | @@ -159,12 +159,8 @@ extern unsigned long guest_base; |
| 29 | extern int have_guest_base; |
| 30 | extern unsigned long reserved_va; |
| 31 | |
| 32 | -#if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS |
| 33 | -#define GUEST_ADDR_MAX (~0ul) |
| 34 | -#else |
| 35 | -#define GUEST_ADDR_MAX (reserved_va ? reserved_va - 1 : \ |
| 36 | +#define GUEST_ADDR_MAX (reserved_va ? reserved_va : \ |
| 37 | (1ul << TARGET_VIRT_ADDR_SPACE_BITS) - 1) |
| 38 | -#endif |
| 39 | #else |
| 40 | |
| 41 | #include "exec/hwaddr.h" |
| 42 | diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h |
| 43 | index 5de8c8a5af..191f2e962a 100644 |
| 44 | --- a/include/exec/cpu_ldst.h |
| 45 | +++ b/include/exec/cpu_ldst.h |
| 46 | @@ -51,13 +51,15 @@ |
| 47 | /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ |
| 48 | #define g2h(x) ((void *)((unsigned long)(target_ulong)(x) + guest_base)) |
| 49 | |
| 50 | -#define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX) |
| 51 | -#define h2g_valid(x) guest_addr_valid((unsigned long)(x) - guest_base) |
| 52 | - |
| 53 | -static inline int guest_range_valid(unsigned long start, unsigned long len) |
| 54 | -{ |
| 55 | - return len - 1 <= GUEST_ADDR_MAX && start <= GUEST_ADDR_MAX - len + 1; |
| 56 | -} |
| 57 | +#if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS |
| 58 | +#define h2g_valid(x) 1 |
| 59 | +#else |
| 60 | +#define h2g_valid(x) ({ \ |
| 61 | + unsigned long __guest = (unsigned long)(x) - guest_base; \ |
| 62 | + (__guest < (1ul << TARGET_VIRT_ADDR_SPACE_BITS)) && \ |
| 63 | + (!reserved_va || (__guest < reserved_va)); \ |
| 64 | +}) |
| 65 | +#endif |
| 66 | |
| 67 | #define h2g_nocheck(x) ({ \ |
| 68 | unsigned long __ret = (unsigned long)(x) - guest_base; \ |
| 69 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c |
| 70 | index 9168a2051c..de85669aab 100644 |
| 71 | --- a/linux-user/mmap.c |
| 72 | +++ b/linux-user/mmap.c |
| 73 | @@ -80,7 +80,7 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot) |
| 74 | return -TARGET_EINVAL; |
| 75 | len = TARGET_PAGE_ALIGN(len); |
| 76 | end = start + len; |
| 77 | - if (!guest_range_valid(start, len)) { |
| 78 | + if (end < start) { |
| 79 | return -TARGET_ENOMEM; |
| 80 | } |
| 81 | prot &= PROT_READ | PROT_WRITE | PROT_EXEC; |
| 82 | @@ -482,8 +482,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, |
| 83 | * It can fail only on 64-bit host with 32-bit target. |
| 84 | * On any other target/host host mmap() handles this error correctly. |
| 85 | */ |
| 86 | - if (!guest_range_valid(start, len)) { |
| 87 | - errno = ENOMEM; |
| 88 | + if ((unsigned long)start + len - 1 > (abi_ulong) -1) { |
| 89 | + errno = EINVAL; |
| 90 | goto fail; |
| 91 | } |
| 92 | |
| 93 | @@ -623,10 +623,8 @@ int target_munmap(abi_ulong start, abi_ulong len) |
| 94 | if (start & ~TARGET_PAGE_MASK) |
| 95 | return -TARGET_EINVAL; |
| 96 | len = TARGET_PAGE_ALIGN(len); |
| 97 | - if (len == 0 || !guest_range_valid(start, len)) { |
| 98 | + if (len == 0) |
| 99 | return -TARGET_EINVAL; |
| 100 | - } |
| 101 | - |
| 102 | mmap_lock(); |
| 103 | end = start + len; |
| 104 | real_start = start & qemu_host_page_mask; |
| 105 | @@ -681,13 +679,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, |
| 106 | int prot; |
| 107 | void *host_addr; |
| 108 | |
| 109 | - if (!guest_range_valid(old_addr, old_size) || |
| 110 | - ((flags & MREMAP_FIXED) && |
| 111 | - !guest_range_valid(new_addr, new_size))) { |
| 112 | - errno = ENOMEM; |
| 113 | - return -1; |
| 114 | - } |
| 115 | - |
| 116 | mmap_lock(); |
| 117 | |
| 118 | if (flags & MREMAP_FIXED) { |
| 119 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c |
| 120 | index 643b8833de..271f215147 100644 |
| 121 | --- a/linux-user/syscall.c |
| 122 | +++ b/linux-user/syscall.c |
| 123 | @@ -4919,9 +4919,6 @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env, |
| 124 | return -TARGET_EINVAL; |
| 125 | } |
| 126 | } |
| 127 | - if (!guest_range_valid(shmaddr, shm_info.shm_segsz)) { |
| 128 | - return -TARGET_EINVAL; |
| 129 | - } |
| 130 | |
| 131 | mmap_lock(); |
| 132 | |
| 133 | @@ -7497,7 +7494,7 @@ static int open_self_maps(void *cpu_env, int fd) |
| 134 | } |
| 135 | if (h2g_valid(min)) { |
| 136 | int flags = page_get_flags(h2g(min)); |
| 137 | - max = h2g_valid(max - 1) ? max : (uintptr_t)g2h(GUEST_ADDR_MAX) + 1; |
| 138 | + max = h2g_valid(max - 1) ? max : (uintptr_t)g2h(GUEST_ADDR_MAX); |
| 139 | if (page_check_range(h2g(min), max - min, flags) == -1) { |
| 140 | continue; |
| 141 | } |