From 6fb8b9d721d0e0e001780cc0d1f11842aedcff83 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Mon, 18 Mar 2024 17:18:33 +0100 Subject: [PATCH] Fix possible segfault with 0x0 shared opcache base Moving the minimum base of the shared opcache memory to the second huge page to avoid a possible 0x0 base, which may cause all sorts of segfaults. This is not a problem on most systems which have a mmap_min_addr which is non-zero, but e.g. WSL1 doesn't have a minimum mapping address. --- ext/opcache/shared_alloc_mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/opcache/shared_alloc_mmap.c b/ext/opcache/shared_alloc_mmap.c index 6f01f1d631b..1840b214705 100644 --- a/ext/opcache/shared_alloc_mmap.c +++ b/ext/opcache/shared_alloc_mmap.c @@ -49,7 +49,7 @@ static void *find_prefered_mmap_base(size_t requested_size) { size_t huge_page_size = 2 * 1024 * 1024; - uintptr_t last_free_addr = 0; + uintptr_t last_free_addr = huge_page_size; uintptr_t last_candidate = (uintptr_t)MAP_FAILED; uintptr_t start, end, text_start = 0; #if defined(__linux__)