[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] linux-user: mprotect() should returns 0 when len is 0.
From: |
Soichiro Isshiki |
Subject: |
[PATCH] linux-user: mprotect() should returns 0 when len is 0. |
Date: |
Fri, 7 Oct 2022 00:38:43 +0900 |
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
- [PATCH] linux-user: mprotect() should returns 0 when len is 0.,
Soichiro Isshiki <=