From 5372a1d0c0a71d1c51e3107547c3a605175b60cd Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Thu, 18 Aug 2022 19:37:37 +0100 Subject: [PATCH 1/2] GH-9370: Fix opcache jit protection bits. Allow mprotect to occur, pthread_jit_write_np are just to allow mprotect flags to be used. --- ext/opcache/jit/zend_jit.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/ext/opcache/jit/zend_jit.c b/ext/opcache/jit/zend_jit.c index ac4fba9877a8..8bf7c6937778 100644 --- a/ext/opcache/jit/zend_jit.c +++ b/ext/opcache/jit/zend_jit.c @@ -4611,7 +4611,6 @@ ZEND_EXT_API void zend_jit_unprotect(void) #ifdef HAVE_PTHREAD_JIT_WRITE_PROTECT_NP if (zend_write_protect) { pthread_jit_write_protect_np(0); - return; } #endif opts |= PROT_EXEC; @@ -4645,7 +4644,6 @@ ZEND_EXT_API void zend_jit_protect(void) #ifdef HAVE_PTHREAD_JIT_WRITE_PROTECT_NP if (zend_write_protect) { pthread_jit_write_protect_np(1); - return; } #endif if (mprotect(dasm_buf, dasm_size, PROT_READ | PROT_EXEC) != 0) { From 8fd9cdfd2909e86269e907578b1d72df9d533c84 Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Mon, 22 Aug 2022 09:25:28 +0100 Subject: [PATCH 2/2] changes from review --- ext/opcache/shared_alloc_mmap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ext/opcache/shared_alloc_mmap.c b/ext/opcache/shared_alloc_mmap.c index add07cd1694b..8a9921532d32 100644 --- a/ext/opcache/shared_alloc_mmap.c +++ b/ext/opcache/shared_alloc_mmap.c @@ -166,6 +166,9 @@ static int create_segments(size_t requested_size, zend_shared_segment ***shared_ #ifdef PROT_MAX flags |= PROT_MAX(PROT_READ | PROT_WRITE | PROT_EXEC); #endif +#ifdef MAP_JIT + flags |= MAP_JIT; +#endif #if (defined(__linux__) || defined(__FreeBSD__)) && (defined(__x86_64__) || defined (__aarch64__)) void *hint = find_prefered_mmap_base(requested_size); if (hint != MAP_FAILED) {