All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] linux-user: mprotect() should returns 0 when len is 0.
@ 2022-10-06 15:38 Soichiro Isshiki
  2022-10-06 18:13 ` Peter Maydell
  2022-10-07  0:38 ` Richard Henderson
  0 siblings, 2 replies; 6+ messages in thread
From: Soichiro Isshiki @ 2022-10-06 15:38 UTC (permalink / raw)
  To: qemu-devel, qemu-trivial; +Cc: sisshiki1969

From: sisshiki1969 <sisshiki@mac.com>

For now, qemu-x86_64 returns ENOMEM when mprotect() was called with an argument
len is 0 from a guest process.
This behavior is incompatible with the current Linux implementation,
which mprotect() with len = 0 does nothing and returns 0,
although it does not appear to be explicitly described in man.

This is due to the following function which always returns false if len = 0.

```C
static inline bool guest_range_valid_untagged(abi_ulong start, abi_ulong len)
{
    return len - 1 <= GUEST_ADDR_MAX && start <= GUEST_ADDR_MAX - len + 1;
}

```

This patch fix this incompatibility problem.

Signed-off-by: sisshiki1969 <sisshiki@mac.com>
---
 linux-user/mmap.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 28f3bc85ed..1ed79459ea 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -130,12 +130,12 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot)
     }
     len = TARGET_PAGE_ALIGN(len);
     end = start + len;
-    if (!guest_range_valid_untagged(start, len)) {
-        return -TARGET_ENOMEM;
-    }
     if (len == 0) {
         return 0;
     }
+    if (!guest_range_valid_untagged(start, len)) {
+        return -TARGET_ENOMEM;
+    }
 
     mmap_lock();
     host_start = start & qemu_host_page_mask;
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [PATCH] linux-user: mprotect() should returns 0 when len is 0.
@ 2022-10-06 16:43 Soichiro Isshiki
  0 siblings, 0 replies; 6+ messages in thread
From: Soichiro Isshiki @ 2022-10-06 16:43 UTC (permalink / raw)
  Cc: sisshiki1969, Laurent Vivier, open list:All patches CC here

From: sisshiki1969 <sisshiki@mac.com>

Signed-off-by: sisshiki1969 <sisshiki@mac.com>
---
 linux-user/mmap.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index 28f3bc85ed..1ed79459ea 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -130,12 +130,12 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot)
     }
     len = TARGET_PAGE_ALIGN(len);
     end = start + len;
-    if (!guest_range_valid_untagged(start, len)) {
-        return -TARGET_ENOMEM;
-    }
     if (len == 0) {
         return 0;
     }
+    if (!guest_range_valid_untagged(start, len)) {
+        return -TARGET_ENOMEM;
+    }
 
     mmap_lock();
     host_start = start & qemu_host_page_mask;
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-10-07  0:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-06 15:38 [PATCH] linux-user: mprotect() should returns 0 when len is 0 Soichiro Isshiki
2022-10-06 18:13 ` Peter Maydell
2022-10-06 18:31   ` Richard Henderson
2022-10-06 22:28     ` 一色聡一郎
2022-10-07  0:38 ` Richard Henderson
2022-10-06 16:43 Soichiro Isshiki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.