[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 8/9] bsd-user/mmap.c: Implement MAP_EXCL, required by jema
From: |
Richard Henderson |
Subject: |
Re: [PATCH v2 8/9] bsd-user/mmap.c: Implement MAP_EXCL, required by jemalloc in head |
Date: |
Thu, 23 Sep 2021 10:52:50 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 |
On 9/21/21 9:56 PM, Warner Losh wrote:
+ /* Reject the mapping if any page within the range is mapped */
+ if (flags & MAP_EXCL) {
+ for (addr = start; addr < end; addr++) {
+ if (page_get_flags(addr) != 0)
+ goto fail;
+ }
+ }
How about
if ((flags & MAP_EXCL) &&
page_check_range(start, len, 0) < 0) {
goto fail;
}
Hmm. This (and your page_get_flags check) could assert due to out-of-range guest address.
You're currently attempting that,
/*
* Test if requested memory area fits target address space
* It can fail only on 64-bit host with 32-bit target.
* On any other target/host host mmap() handles this error correctly.
*/
#if TARGET_ABI_BITS == 32 && HOST_LONG_BITS == 64
if ((unsigned long)start + len - 1 > (abi_ulong) -1) {
errno = EINVAL;
goto fail;
}
#endif
but the test isn't correct. Note that reserved_va may be applied to 64-bit guests, and
certainly may be smaller than (abi_ulong)-1.
You want guest_range_valid_untagged here.
r~
- Re: [PATCH v2 2/9] bsd-user/mmap.c: check pread's return value to fix warnings with _FORTIFY_SOURCE, (continued)
- [PATCH v2 4/9] bsd-user/mmap.c: mmap return ENOMEM on overflow, Warner Losh, 2021/09/22
- [PATCH v2 6/9] bsd-user/mmap.c: line wrap change, Warner Losh, 2021/09/22
- [PATCH v2 8/9] bsd-user/mmap.c: Implement MAP_EXCL, required by jemalloc in head, Warner Losh, 2021/09/22
- Re: [PATCH v2 8/9] bsd-user/mmap.c: Implement MAP_EXCL, required by jemalloc in head,
Richard Henderson <=
- [PATCH v2 5/9] bsd-user/mmap.c: mmap prefer MAP_ANON for BSD, Warner Losh, 2021/09/22
- [PATCH v2 7/9] bsd-user/mmap.c: Don't mmap fd == -1 independently from MAP_ANON flag, Warner Losh, 2021/09/22
[PATCH v2 9/9] bsd-user/mmap.c: assert that target_mprotect cannot fail, Warner Losh, 2021/09/22