Hi,
After updating to MacOS 11.2 I noticed that attempting to call mprotect to remove write access on pages that were mapped using PROT_EXEC results in a permission denied error on Apple Silicon. In prior versions of Big Sur, I did not receive this behavior.
Is this a new restriction added in the 11.2 update, and if so, what would be the correct way to implement write protecting a previously RWX page?
A small test program demonstrating what I am trying is shown below:
This program outputs the below text when ran:
After updating to MacOS 11.2 I noticed that attempting to call mprotect to remove write access on pages that were mapped using PROT_EXEC results in a permission denied error on Apple Silicon. In prior versions of Big Sur, I did not receive this behavior.
Is this a new restriction added in the 11.2 update, and if so, what would be the correct way to implement write protecting a previously RWX page?
A small test program demonstrating what I am trying is shown below:
Code Block #include <stdio.h> #include <sys/mman.h> int main(int argc, const char * argv[]) { int size = 4096; int map_flags = MAP_ANON | MAP_PRIVATE | MAP_JIT; void* mem = mmap(nullptr, size, PROT_READ | PROT_WRITE | PROT_EXEC, map_flags, -1, 0); if (mem == MAP_FAILED||mem==nullptr) printf("Failed to allocate executable memory"); if (mprotect(mem, size, PROT_READ | PROT_EXEC) != 0) printf("WriteProtectMemory failed!\nmprotect: %s\n", strerror(errno)); return 0; }
This program outputs the below text when ran:
Code Block WriteProtectMemory failed! mprotect: Permission denied