Skip to content

Commit e3b6872

Browse files
authored
zend call stack adjust case for freebsd to calculate the guard size. (#13586)
it was not wrong but there is a sysctl oid storing the number of guard pages, which is 1 by default but is modifiable at runtime.
1 parent 3d4cb1d commit e3b6872

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Zend/zend_call_stack.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ static bool zend_call_stack_get_freebsd_sysctl(zend_call_stack *stack)
313313
int mib[2] = {CTL_KERN, KERN_USRSTACK};
314314
size_t len = sizeof(stack_base);
315315
struct rlimit rlim;
316+
size_t numguards = 0;
316317

317318
/* This method is relevant only for the main thread */
318319
ZEND_ASSERT(zend_call_stack_is_main_thread());
@@ -329,7 +330,13 @@ static bool zend_call_stack_get_freebsd_sysctl(zend_call_stack *stack)
329330
return false;
330331
}
331332

332-
size_t guard_size = getpagesize();
333+
len = sizeof(numguards);
334+
/* For most of the cases, we do not necessarily need to do so as, by default, it is `1` page, but is user writable */
335+
if (sysctlbyname("security.bsd.stack_guard_page", &numguards, &len, NULL, 0) != 0) {
336+
return false;
337+
}
338+
339+
size_t guard_size = numguards * getpagesize();
333340

334341
stack->base = stack_base;
335342
stack->max_size = rlim.rlim_cur - guard_size;

0 commit comments

Comments
 (0)