[vm] Make sure to use MAP_JIT for callback pages

This is follow up to bd57548 which switched us to use manual copying
for call back pages on Mac OS and iOS. However these newly allocated
pages need to be created with MAP_JIT flag otherwise OS will kill
us with code signing violation if hardened runtime is enabled.

This can only be observed when the binary is signed that's why
we have not seen it on CI.

TEST=manually signed and tested that it no longer crashes.

Fixes https://github.com/dart-lang/sdk/issues/53928

Change-Id: Ic15673d354d4fdf1bb8179066b37c7ae90877982
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333260
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
This commit is contained in:
Vyacheslav Egorov 2023-11-01 22:38:27 +00:00 committed by Commit Queue
parent 66569eb894
commit 6c92ce6049
2 changed files with 13 additions and 3 deletions

View file

@ -97,8 +97,19 @@ VirtualMemory* FfiCallbackMetadata::AllocateTrampolinePage() {
UNREACHABLE();
return nullptr;
#else
#if defined(DART_HOST_OS_MACOS) && !defined(DART_PRECOMPILED_RUNTIME)
// If we are not going to use vm_remap then we need to pass
// is_executable=true so that pages get allocated with MAP_JIT flag if
// necessary. Otherwise OS will kill us with a codesigning violation if
// hardened runtime is enabled.
const bool is_executable = true;
#else
const bool is_executable = false;
#endif
VirtualMemory* new_page = VirtualMemory::AllocateAligned(
MappingSize(), MappingAlignment(), /*is_executable=*/false,
MappingSize(), MappingAlignment(), is_executable,
/*is_compressed=*/false, "FfiCallbackMetadata::TrampolinePage");
if (new_page == nullptr) {
return nullptr;

View file

@ -54,8 +54,7 @@ bool VirtualMemory::DuplicateRX(VirtualMemory* target) {
const intptr_t aligned_size = Utils::RoundUp(size(), PageSize());
ASSERT_LESS_OR_EQUAL(aligned_size, target->size());
#if defined(DART_HOST_OS_MACOS) && \
(defined(DART_PRECOMPILED_RUNTIME) || defined(DART_PRECOMPILER))
#if defined(DART_HOST_OS_MACOS) && defined(DART_PRECOMPILED_RUNTIME)
// Mac is special cased because iOS doesn't allow allocating new executable
// memory, so the default approach would fail. We are allowed to make new
// mappings of existing executable memory using vm_remap though, which is