|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-11-24 06:32 UTC] wattwood at tcstire dot com
Description:
------------
PHP will randomly crash on zend_hash_find after zend_set_compiled_filename. This is on Ubuntu 14.04.1 LTS.
The file is always the same for the crash. As you can see, this happens before any PHP code is executed. It's not always on zend_hash_find. At times, it's on zend_stack_push as well. Again, before any code executes.
Here is the backtrace:
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00007f7b1dcd4291 in zend_hash_find (ht=ht@entry=0x7f7b1e48ab50 <compiler_globals+272>, arKey=arKey@entry=0x7f7b23fc4388 "/var/lib/jenkins/workspace/TireCore/app/webroot/index.php",
nKeyLength=nKeyLength@entry=58, pData=pData@entry=0x7fffbede6c70) at /build/buildd/php5-5.5.9+dfsg/Zend/zend_hash.c:924
924 p = ht->arBuckets[nIndex];
#0 0x00007f7b1dcd4291 in zend_hash_find (ht=ht@entry=0x7f7b1e48ab50 <compiler_globals+272>,
arKey=arKey@entry=0x7f7b23fc4388 "/var/lib/jenkins/workspace/TireCore/app/webroot/index.php", nKeyLength=nKeyLength@entry=58, pData=pData@entry=0x7fffbede6c70)
at /build/buildd/php5-5.5.9+dfsg/Zend/zend_hash.c:924
#1 0x00007f7b1dca2a3c in zend_set_compiled_filename (new_compiled_filename=0x7f7b23fc4388 "/var/lib/jenkins/workspace/TireCore/app/webroot/index.php")
at /build/buildd/php5-5.5.9+dfsg/Zend/zend_compile.c:254
#2 0x00007f7b1dc900ba in open_file_for_scanning (file_handle=file_handle@entry=0x7fffbede70a0) at Zend/zend_language_scanner.l:537
#3 0x00007f7b1dc902d3 in compile_file (file_handle=file_handle@entry=0x7fffbede70a0, type=2) at Zend/zend_language_scanner.l:574
#4 0x00007f7b1dcb5afa in dtrace_compile_file (file_handle=0x7fffbede70a0, type=<optimized out>) at /build/buildd/php5-5.5.9+dfsg/Zend/zend_dtrace.c:40
#5 0x00007f7b1db3ecb4 in phar_compile_file (file_handle=<optimized out>, type=<optimized out>) at /build/buildd/php5-5.5.9+dfsg/ext/phar/phar.c:3383
#6 0x00007f7b1dcc757f in zend_execute_scripts (type=type@entry=2, retval=retval@entry=0x0, file_count=file_count@entry=1) at /build/buildd/php5-5.5.9+dfsg/Zend/zend.c:1308
#7 0x00007f7b1dd774fd in php_handler (r=<optimized out>) at /build/buildd/php5-5.5.9+dfsg/sapi/apache2handler/sapi_apache2.c:669
#8 0x00007f7b22463680 in ap_run_handler (r=0x7f7b2230f3a8) at config.c:169
#9 0x00007f7b22463bc9 in ap_invoke_handler (r=r@entry=0x7f7b2230f3a8) at config.c:439
#10 0x00007f7b22478c2c in ap_internal_redirect (new_uri=<optimized out>, r=<optimized out>) at http_request.c:644
#11 0x00007f7b1ba4ccfc in handler_redirect (r=0x7f7b222fe0a0) at mod_rewrite.c:5063
#12 0x00007f7b22463680 in ap_run_handler (r=0x7f7b222fe0a0) at config.c:169
#13 0x00007f7b22463bc9 in ap_invoke_handler (r=r@entry=0x7f7b222fe0a0) at config.c:439
#14 0x00007f7b2247916a in ap_process_async_request (r=r@entry=0x7f7b222fe0a0) at http_request.c:317
#15 0x00007f7b22479444 in ap_process_request (r=r@entry=0x7f7b222fe0a0) at http_request.c:363
#16 0x00007f7b22475f02 in ap_process_http_sync_connection (c=0x7f7b2231b290) at http_core.c:190
#17 ap_process_http_connection (c=0x7f7b2231b290) at http_core.c:231
#18 0x00007f7b2246ccc0 in ap_run_process_connection (c=0x7f7b2231b290) at connection.c:41
#19 0x00007f7b2246d0a8 in ap_process_connection (c=c@entry=0x7f7b2231b290, csd=<optimized out>) at connection.c:202
#20 0x00007f7b1e697767 in child_main (child_num_arg=child_num_arg@entry=0) at prefork.c:704
#21 0x00007f7b1e6979a6 in make_child (s=0x7f7b223cade0, slot=0) at prefork.c:800
#22 0x00007f7b1e69860e in perform_idle_server_maintenance (p=<optimized out>) at prefork.c:902
#23 prefork_run (_pconf=<optimized out>, plog=<optimized out>, s=<optimized out>) at prefork.c:1090
#24 0x00007f7b2244a69e in ap_run_mpm (pconf=0x7f7b22400028, plog=0x7f7b223ce028, s=0x7f7b223cade0) at mpm_common.c:96
#25 0x00007f7b22443e36 in main (argc=3, argv=0x7fffbede7848) at main.c:777
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00007f7b1dcc497d in zend_stack_push (stack=stack@entry=0x7f7b1e48aca0 <compiler_globals+608>, element=element@entry=0x7f7b1e48ac78 <compiler_globals+568>, size=size@entry=40)
at /build/buildd/php5-5.5.9+dfsg/Zend/zend_stack.c:42
42 stack->elements[stack->top] = (void *) emalloc(size);
#0 0x00007f7b1dcc497d in zend_stack_push (stack=stack@entry=0x7f7b1e48aca0 <compiler_globals+608>, element=element@entry=0x7f7b1e48ac78 <compiler_globals+568>, size=size@entry=40)
at /build/buildd/php5-5.5.9+dfsg/Zend/zend_stack.c:42
#1 0x00007f7b1dc9031e in compile_file (file_handle=file_handle@entry=0x7fffbede70a0, type=2) at Zend/zend_language_scanner.l:586
#2 0x00007f7b1dcb5afa in dtrace_compile_file (file_handle=0x7fffbede70a0, type=<optimized out>) at /build/buildd/php5-5.5.9+dfsg/Zend/zend_dtrace.c:40
#3 0x00007f7b1db3ecb4 in phar_compile_file (file_handle=<optimized out>, type=<optimized out>) at /build/buildd/php5-5.5.9+dfsg/ext/phar/phar.c:3383
#4 0x00007f7b1dcc757f in zend_execute_scripts (type=type@entry=2, retval=retval@entry=0x0, file_count=file_count@entry=1) at /build/buildd/php5-5.5.9+dfsg/Zend/zend.c:1308
#5 0x00007f7b1dd774fd in php_handler (r=<optimized out>) at /build/buildd/php5-5.5.9+dfsg/sapi/apache2handler/sapi_apache2.c:669
#6 0x00007f7b22463680 in ap_run_handler (r=0x7f7b223053a8) at config.c:169
#7 0x00007f7b22463bc9 in ap_invoke_handler (r=r@entry=0x7f7b223053a8) at config.c:439
#8 0x00007f7b22478c2c in ap_internal_redirect (new_uri=<optimized out>, r=<optimized out>) at http_request.c:644
#9 0x00007f7b1ba4ccfc in handler_redirect (r=0x7f7b223010a0) at mod_rewrite.c:5063
#10 0x00007f7b22463680 in ap_run_handler (r=0x7f7b223010a0) at config.c:169
#11 0x00007f7b22463bc9 in ap_invoke_handler (r=r@entry=0x7f7b223010a0) at config.c:439
#12 0x00007f7b2247916a in ap_process_async_request (r=r@entry=0x7f7b223010a0) at http_request.c:317
#13 0x00007f7b22479444 in ap_process_request (r=r@entry=0x7f7b223010a0) at http_request.c:363
#14 0x00007f7b22475f02 in ap_process_http_sync_connection (c=0x7f7b2231b290) at http_core.c:190
#15 ap_process_http_connection (c=0x7f7b2231b290) at http_core.c:231
#16 0x00007f7b2246ccc0 in ap_run_process_connection (c=0x7f7b2231b290) at connection.c:41
#17 0x00007f7b2246d0a8 in ap_process_connection (c=c@entry=0x7f7b2231b290, csd=<optimized out>) at connection.c:202
#18 0x00007f7b1e697767 in child_main (child_num_arg=child_num_arg@entry=10) at prefork.c:704
#19 0x00007f7b1e6979a6 in make_child (s=0x7f7b223cade0, slot=10) at prefork.c:800
#20 0x00007f7b1e69860e in perform_idle_server_maintenance (p=<optimized out>) at prefork.c:902
#21 prefork_run (_pconf=<optimized out>, plog=<optimized out>, s=<optimized out>) at prefork.c:1090
#22 0x00007f7b2244a69e in ap_run_mpm (pconf=0x7f7b22400028, plog=0x7f7b223ce028, s=0x7f7b223cade0) at mpm_common.c:96
#23 0x00007f7b22443e36 in main (argc=3, argv=0x7fffbede7848) at main.c:777
Test script:
---------------
Unavailable as no code executes prior to the crash.
Patchessapi-logic-cleanup (last revision 2015-03-24 23:44 UTC by gmoniker at gmail dot com)sapi_apache2.gmoniker.patch (last revision 2015-03-18 15:25 UTC by php at bof dot de) Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 01:00:02 2025 UTC |
Happy to find this bug.... Ran into the same problems when trying to upgrade from an older openSUSE system with Apache 2.2, to a current one with Apache 2.4. PHP in both cases, is a self-built 5.6.6 (also tested with 5.6.7RC1 and an older 5.6.4) build. As soon as I tried this in production, I got, on a box with about 2000 req/min, 2-3 coredumps per minute. Trials with opcache disabled, pointed to exactly the kind of backtraces reported here. Trials with opcache enabled (normal production) almost always resulted in backtraces like this: #0 0x00007fc2c1c0a347 in i_create_execute_data_from_op_array ( nested=<optimized out>, op_array=<optimized out>) at /usr/src/phb/build/release-5.6.7-Og/php-src/Zend/zend_execute.c:1676 1676 EX(prev_execute_data) = EG(current_execute_data); (gdb) bt #0 0x00007fc2c1c0a347 in i_create_execute_data_from_op_array ( nested=<optimized out>, op_array=<optimized out>) at /usr/src/phb/build/release-5.6.7-Og/php-src/Zend/zend_execute.c:1676 #1 zend_execute (op_array=0x7fc2c06c10f8) at /usr/src/phb/build/release-5.6.7-Og/php-src/Zend/zend_vm_execute.h:388 #2 0x00007fc2c1b78bf3 in zend_execute_scripts (type=type@entry=2, retval=retval@entry=0x0, file_count=file_count@entry=1) at /usr/src/phb/build/release-5.6.7-Og/php-src/Zend/zend.c:1341 #3 0x00007fc2c1c0d672 in php_handler (r=<optimized out>) at /usr/src/phb/build/release-5.6.7-Og/php-src/sapi/apache2handler/sapi_apache2.c:669 ..... I can fully reproduce the issue now on my development system, using the echo/netcat double request from the last comment against a trivial (only one echo) test script. The following patch, against the 5.6.7RC1 sources, fixes the coredump, and results in both pipelined test script calls returning the expected result. I have not yet tested whether the patch has negative consequences, though. Here it is: diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c index 088ff77..0f80aee 100644 --- a/sapi/apache2handler/sapi_apache2.c +++ b/sapi/apache2handler/sapi_apache2.c @@ -549,7 +549,7 @@ static int php_handler(request_rec *r) /* apply_config() needs r in some cases, so allocate server_context early */ ctx = SG(server_context); - if (ctx == NULL || (ctx && ctx->request_processed && !strcmp(r->protocol, "INCLUDED"))) { + if (1 || ctx == NULL || (ctx && ctx->request_processed && !strcmp(r->protocol, "INCLUDED"))) { normal: ctx = SG(server_context) = apr_pcalloc(r->pool, sizeof(*ctx)); /* register a cleanup so we clear out the SG(server_context)Just ran a single step session (xdebug + opcache disabled), first breakpoint in apache SAPI php_handler line 669 (call to zend_execute_scripts, triggering on the second pipelined request), then second breakpoint in compile_file() like 584 where the call zend_stack_push(&CG(context_stack), (void *) &CG(context), sizeof(CG(context))); bombed. Stepping into zend_stack_push I find: (gdb) step zend_stack_push (stack=stack@entry=0x7fbd1b595478 <compiler_globals+696>, element=element@entry=0x7fbd1b595450 <compiler_globals+656>, size=size@entry=40) at /usr/src/phb/build/release-5.6.7-Og/php-src/Zend/zend_stack.c:34 34 { (gdb) step 35 if (stack->top >= stack->max) { /* we need to allocate more memory */ (gdb) print *stack $1 = {top = 0, max = 64, elements = 0x0} So the code thinks it does not need to allocate - and then bombs on the following assignment to stack->elements[stack->top]. Looks like CG(context_stack).max is not properly reset somehow after the previous request...It seems to me that it will be hard to revalidate this handler if it is changed extensively. Just did some testing with a one line adjustment to the code of "sapi/apache2handler/sapi_apache2.c". Towards the end of php_handler(request_rec *r) I included the line: apr_pool_cleanup_run(r->pool, (void *)&SG(server_context), php_server_context_cleanup); So it becomes: if (!parent_req) { php_apache_request_dtor(r TSRMLS_CC); ctx->request_processed = 1; bucket = apr_bucket_eos_create(r->connection->bucket_alloc); APR_BRIGADE_INSERT_TAIL(brigade, bucket); rv = ap_pass_brigade(r->output_filters, brigade); if (rv != APR_SUCCESS || r->connection->aborted) { zend_first_try { php_handle_aborted_connection(); } zend_end_try(); } apr_brigade_cleanup(brigade); apr_pool_cleanup_run(r->pool, (void *)&SG(server_context), php_server_context_cleanup); } else { ctx->r = parent_req; } It seems to me this solves the missing automatic request pool destruction after a request in Apache 2.4 leading the php_handler routine to consider independent follow-on requests a subrequest of the first request when they are not. The request pool can continue on, but without the php_struct in it. I am afraid the Apache 2.4 handling of these pipelines can cause memory bloat of the server process, but that belongs in Apaches corner.I have been looking at the situations where the SAPI apache2 handler can enter the PHP handling with a PHP context set. These are: (Apache 2.4 only) Client connection does not drop and a previous PHP request has not had its complete output flushed by a new request on the same client connection with sufficient output to bust the buffer. (Apache 2.2 and 2.4) 1. Running "inside" an original PHP handled client request. a. When entering a virtual() of the request b. Abnormal ending of the initial request PHP handling AND Apache has fired an ErrorDocument set to a PHP artefact. 2. Running inside an SSI template a. A virtual() of an initial PHP script call b. Subsequent request to a PHP script or its subrequests BUT there may be no active SAPI yet: This happens when an SSI includes several PHP scripts in series. Each time the processing returns to the host SSI template itself the SAPI is deactivated, but on entering the next PHP script call a context remains visible that was allocated by the last PHP script. In all cases except the specific Apache 2.4 case the SAPI will be activated before using it. But for a 413 ErrorDocument it is tried to reuse the previous SAPI instance. Entering a virtual that has a compile error will segfault. Using the oneline patch solves the Apache 2.4 specific case, it shortens the path of code that SSI templates run through when they have sequential PHP scripts, and it stops the handler from trying to reuse the previous PHP instance in case of a 413 handler in PHP responding to a PHP script that Apache throws a 413 error for. (Setting 413 status yourself does not call the 413 ErrorDocument). But some more rewriting of the handler and the Virtual function is needed.