From: Christoph M. Becker Date: Tue, 21 May 2019 12:34:55 +0000 (+0200) Subject: Merge branch 'PHP-7.4' X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=68e6c1542e402af133b81518e354b261a5ef6d15;p=php Merge branch 'PHP-7.4' * PHP-7.4: Fix ASLR related invalid opline handler issues --- 68e6c1542e402af133b81518e354b261a5ef6d15 diff --cc ext/opcache/shared_alloc_win32.c index 76533cc4f4,2755f39486..c92eb4bab8 --- a/ext/opcache/shared_alloc_win32.c +++ b/ext/opcache/shared_alloc_win32.c @@@ -181,12 -199,17 +199,17 @@@ static int zend_shared_alloc_reattach(s return ALLOC_FALLBACK; } #endif - err = ERROR_INVALID_ADDRESS; - zend_win_error_message(ACCEL_LOG_FATAL, "Base address marks unusable memory region. Please setup opcache.file_cache and opcache.file_cache_fallback directives for more convenient Opcache usage", err); + if (execute_ex_moved) { + err = ERROR_INVALID_ADDRESS; + zend_win_error_message(ACCEL_LOG_FATAL, "Opcode handlers are unusable due to ASLR. Please setup opcache.file_cache and opcache.file_cache_fallback directives for more convenient Opcache usage", err); + } else { + err = ERROR_INVALID_ADDRESS; + zend_win_error_message(ACCEL_LOG_FATAL, "Base address marks unusable memory region. Please setup opcache.file_cache and opcache.file_cache_fallback directives for more convenient Opcache usage", err); + } return ALLOC_FAILURE; - } + } - mapping_base = MapViewOfFileEx(memfile, FILE_MAP_ALL_ACCESS, 0, 0, 0, wanted_mapping_base); + mapping_base = MapViewOfFileEx(memfile, FILE_MAP_ALL_ACCESS|FILE_MAP_EXECUTE, 0, 0, 0, wanted_mapping_base); if (mapping_base == NULL) { err = GetLastError(); @@@ -323,17 -337,9 +346,18 @@@ static int create_segments(size_t reque *error_in = "MapViewOfFile"; return ALLOC_FAILURE; } else { - char *mmap_base_file = get_mmap_base_file(); + char *mmap_base_file; + void *execute_ex_base = (void *)execute_ex; - FILE *fp = fopen(mmap_base_file, "w"); + FILE *fp; + DWORD old; + + if (!VirtualProtect(mapping_base, requested_size, PAGE_READWRITE, &old)) { + err = GetLastError(); + zend_win_error_message(ACCEL_LOG_FATAL, "VirtualProtect() failed", err); + return ALLOC_FAILURE; + } + mmap_base_file = get_mmap_base_file(); + fp = fopen(mmap_base_file, "w"); if (!fp) { err = GetLastError(); zend_shared_alloc_unlock_win32();