Skip to content

Fix SELinux mprotect execheap error due to mem adjacent to heap #12942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion ext/opcache/shared_alloc_mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ static void *find_prefered_mmap_base(size_t requested_size)
}

while (fgets(buffer, MAXPATHLEN, f) && sscanf(buffer, "%lx-%lx", &start, &end) == 2) {
/* Don't place the segment directly before or after the heap segment. Due to an selinux bug,
* a segment directly preceding or following the heap is interpreted as heap memory, which
* will result in an execheap violation for the JIT.
* See https://bugzilla.kernel.org/show_bug.cgi?id=218258. */
bool heap_segment = strstr(buffer, "[heap]") != NULL;
if (heap_segment) {
uintptr_t start_base = start & ~(huge_page_size - 1);
if (last_free_addr + requested_size >= start_base) {
last_free_addr = ZEND_MM_ALIGNED_SIZE_EX(end + huge_page_size, huge_page_size);
continue;
}
}
if ((uintptr_t)execute_ex >= start) {
/* the current segment lays before PHP .text segment or PHP .text segment itself */
if (last_free_addr + requested_size <= start) {
Expand Down Expand Up @@ -90,7 +102,9 @@ static void *find_prefered_mmap_base(size_t requested_size)
}
}
last_free_addr = ZEND_MM_ALIGNED_SIZE_EX(end, huge_page_size);

if (heap_segment) {
last_free_addr += huge_page_size;
}
}
fclose(f);
#elif defined(__FreeBSD__)
Expand Down