go to bug id or search bugs for
I'm unable to get PHP 7.3 to run with address sanitizer.
./configure CFLAGS="-fsanitize=address -g" CXXFLAGS="-fsanitize=address -g" LDFLAGS="-fsanitize=address" --enable-debug
leads to a segfault.
This problem does not happen with 7.2.x.
Address Sanitizer has been an extremely helpful tool to identify memory corruption bugs and security issues in PHP, therefore this is concerning, as it might hamper the ability of security researchers to find bugs in PHP.
A stack trace from GDB shows this happens in the function zend_cpu_supports_avx2(). AVX2 support is not available in PHP 7.2, therefore I believe this explains the difference between 7.2 and 7.3.
No segfault with ASAN.
Segfault with ASAN.
Add a Patch
Add a Pull Request
Confirming the segfault. Had to add LIBS="-ldl" to avoid linker errors.
0x555555c21f56 <zend_cpu_supports_sse42+4> callq 0x555555832560 <__cpu_indicator_init>
0x555555c21f5b <zend_cpu_supports_sse42+9> lea 0xb6971e(%rip),%rax
0x555555c21f62 <zend_cpu_supports_sse42+16> lea 0xc(%rax),%rax
0x555555c21f66 <zend_cpu_supports_sse42+20> mov %rax,%rdx
0x555555c21f69 <zend_cpu_supports_sse42+23> shr $0x3,%rdx
0x555555c21f6d <zend_cpu_supports_sse42+27> add $0x7fff8000,%rdx
> 0x555555c21f74 <zend_cpu_supports_sse42+34> movzbl (%rdx),%edx
(gdb) p &__cpu_model
$8 = (<data variable, no debug info> *) 0x55555678b680 <__cpu_model>
(gdb) p/x $rax
$9 = 0x55555678b68c
(gdb) p/x $rdx
$10 = 0xaab2ace96d1
From what I gathered (addr>>3)+0x7fff8000 is the shadow address used by asan, and apparently it is not mapped.
Looks like asan being incompatible with ifunc resolvers is a longstanding problem: https://github.com/google/sanitizers/issues/342
We might be able to work around it with some __attribute__((no_sanitize_address)) attributes.
Automatic comment on behalf of email@example.com
Log: Fixed bug #77447
I tried patching 7.3.1 with that commit and it still crashes for me, so I don't believe this is fixed.
Did you do a full rebuild after applying the change? The header change will not be picked up in an incremental build.
I did, it was a completely fresh build.
Is it possible it's using the headers from the system-wide installed version instead of from the source code?
Could you please provide a stacktrace for the segfault? I'm wondering which codepath is calling cpu_supports() in your case.
Just to check, you are using gcc, and you are compiling with --enable-debug?
The "--enable-debug" was the issue. With it no segfault, without I still get a segfault.
Is this intentional? (I don't think this is good: It will mean people will end up seeing segfaults e.g. if they want to fuzz, where people don't want to enable debugging, because they want max speed.)
No, it's not intentional. I only marked the cpu_supports functions as no_sanitize_address, but with optimization they're probably inlined and the attribute is lost. We'll probably need the attributes also on the ifuncs themselves.
Release builds should be fixed with https://github.com/php/php-src/commit/986b9b5ae3e04e33fda89f102da1bba625aa06ef.
Thanks, with both commits applied no more segfaults!