Skip to content

Commit

Permalink
linux-user: Unset MAP_FIXED_NOREPLACE for host
Browse files Browse the repository at this point in the history
Passing MAP_FIXED_NOREPLACE to host will fail for reserved_va because
the address space is reserved with mmap.  Replace it with MAP_FIXED
in that case.

Signed-off-by: Akihiko Odaki <[email protected]>
Message-Id: <[email protected]>
[rth: Expand inline commentary.]
Reviewed-by: Richard Henderson <[email protected]>
Signed-off-by: Richard Henderson <[email protected]>
  • Loading branch information
akihikodaki authored and rth7680 committed Aug 6, 2023
1 parent 4333f09 commit c3dd50d
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions linux-user/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,26 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
goto fail;
}

/* Validate that the chosen range is empty. */
if ((flags & MAP_FIXED_NOREPLACE)
&& !page_check_range_empty(start, last)) {
errno = EEXIST;
goto fail;
if (flags & MAP_FIXED_NOREPLACE) {
/* Validate that the chosen range is empty. */
if (!page_check_range_empty(start, last)) {
errno = EEXIST;
goto fail;
}

/*
* With reserved_va, the entire address space is mmaped in the
* host to ensure it isn't accidentally used for something else.
* We have just checked that the guest address is not mapped
* within the guest, but need to replace the host reservation.
*
* Without reserved_va, despite the guest address check above,
* keep MAP_FIXED_NOREPLACE so that the guest does not overwrite
* any host address mappings.
*/
if (reserved_va) {
flags = (flags & ~MAP_FIXED_NOREPLACE) | MAP_FIXED;
}
}

/*
Expand Down

0 comments on commit c3dd50d

Please sign in to comment.