[php-src] PR #11073: Increase zend.reserved_stack_size minimum value in ASAN/MSAN builds
| From: | arnaud-lb | Date: | Fri, 14 Apr 2023 10:55:48 +0000 |
| Subject: | [php-src] PR #11073: Increase zend.reserved_stack_size minimum value in ASAN/MSAN builds | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-22318@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/11073
Author: arnaud-lb
zend.reserved_stack_size is the size of the stack space that is reserved for native
code called by the VM. This reserved space is similar to the shadow space described in https://pangin.pro/posts/stack-overflow-handling.
The minimum and default value of zend.reserved_stack_size is ZEND_ALLOCA_MAX_SIZE +
some empirically chosen value. If this is too low, the program may crash as if no [stack
limit](https://github.com/php/php-src/pull/9104) was in place.
ASAN/MSAN builds use considerably more stack space due to instrumentation, so this default value is
too low in these builds. https://clang.llvm.org/docs/AddressSanitizer.html#limitations
mentions an increase of up to 3x, but the stack usage of individual functions can increase much more
than that. For example, here is a stack trace annotated with stack usage of each function as
reported by -fstack-usage:
```
non-asan asan
total 5176 52912
zend_mm_small_size_to_bin 40 88
zend_mm_alloc_heap 96 424
_zend_mm_alloc 64 120
zend_mm_realloc_heap 192 1224
_erealloc 96 184
_safe_erealloc 64 152
zend_stack_push 48 296
enter_nesting 48 152
lex_scan 1056 30424
zendlex 80 152
zendparse 2448 17688
zend_compile 224 280
compile_file 304 184
compile_filename 144 216
zend_include_or_eval 176 408
ZEND_INCLUDE_OR_EVAL_SPEC_CONST_HANDLER 96 920
execute_ex <-- stack limit check is made here
```
In this PR I increase the minimum and default value of zend.reserved_stack_size by 10x
in ASAN/MSAN builds.