|
@@ -80,8 +80,9 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
|
|
|
return -EINVAL;
|
|
|
len = TARGET_PAGE_ALIGN(len);
|
|
|
end = start + len;
|
|
|
- if (end < start)
|
|
|
- return -EINVAL;
|
|
|
+ if (!guest_range_valid(start, len)) {
|
|
|
+ return -ENOMEM;
|
|
|
+ }
|
|
|
prot &= PROT_READ | PROT_WRITE | PROT_EXEC;
|
|
|
if (len == 0)
|
|
|
return 0;
|
|
@@ -481,8 +482,8 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
|
|
|
* It can fail only on 64-bit host with 32-bit target.
|
|
|
* On any other target/host host mmap() handles this error correctly.
|
|
|
*/
|
|
|
- if ((unsigned long)start + len - 1 > (abi_ulong) -1) {
|
|
|
- errno = EINVAL;
|
|
|
+ if (!guest_range_valid(start, len)) {
|
|
|
+ errno = ENOMEM;
|
|
|
goto fail;
|
|
|
}
|
|
|
|
|
@@ -622,8 +623,10 @@ int target_munmap(abi_ulong start, abi_ulong len)
|
|
|
if (start & ~TARGET_PAGE_MASK)
|
|
|
return -EINVAL;
|
|
|
len = TARGET_PAGE_ALIGN(len);
|
|
|
- if (len == 0)
|
|
|
+ if (len == 0 || !guest_range_valid(start, len)) {
|
|
|
return -EINVAL;
|
|
|
+ }
|
|
|
+
|
|
|
mmap_lock();
|
|
|
end = start + len;
|
|
|
real_start = start & qemu_host_page_mask;
|
|
@@ -678,6 +681,13 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
|
|
|
int prot;
|
|
|
void *host_addr;
|
|
|
|
|
|
+ if (!guest_range_valid(old_addr, old_size) ||
|
|
|
+ ((flags & MREMAP_FIXED) &&
|
|
|
+ !guest_range_valid(new_addr, new_size))) {
|
|
|
+ errno = ENOMEM;
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
mmap_lock();
|
|
|
|
|
|
if (flags & MREMAP_FIXED) {
|