Patchwork [7/7] linux-user: Do not ignore mmap failure from host

login
register
mail settings
Submitter riku.voipio@linaro.org
Date July 10, 2013, 10:20 a.m.
Message ID <8384274eda1d7cb01f326143fa6118562c1eb5be.1373051589.git.riku.voipio@linaro.org>
Download mbox | patch
Permalink /patch/258007/
State New
Headers show

Comments

riku.voipio@linaro.org - July 10, 2013, 10:20 a.m.
From: Jürg Billeter <j@bitron.ch>

File mapping may fail with EACCES.

Signed-off-by: Jürg Billeter <j@bitron.ch>
Message-id: 1372498892-23676-1-git-send-email-j@bitron.ch
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
---
 linux-user/mmap.c | 4 ++++
 1 file changed, 4 insertions(+)

Patch

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index b412e3f..de22197 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -483,6 +483,10 @@  abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
         if (!(flags & MAP_ANONYMOUS)) {
             p = mmap(g2h(start), len, prot,
                      flags | MAP_FIXED, fd, host_offset);
+            if (p == MAP_FAILED) {
+                munmap(g2h(start), host_len);
+                goto fail;
+            }
             host_start += offset - host_offset;
         }
         start = h2g(host_start);