simplesamlphp icon indicating copy to clipboard operation
simplesamlphp copied to clipboard

SEGFAULTs caused by header_register_callback on CentOS 7 / PHP 5.4

Open MrSecure opened this issue 11 years ago • 7 comments

I've recently started using master in a test environment in order to check out the new features.

However, in my testing, I've started to encounter errors like the following at an alarming rate:

[Thu Nov 26 01:26:28.762363 2015] [core:notice] [pid 3611] AH00052: child pid 3642 exit signal Segmentation fault (11)

I've been the only user logging in to the test IdP I'm working with, and I can see errors about 1 in 3 logins. After generating and analyzing a core dump, and doing a bit of googling, it seemed that header_register_callback was to blame. To see how repeatable this is, I used ab to visit simplesaml/module.php/core/frontpage_federation.php 100 times (getting 36 failures).

To confirm a relationship with header_register_callback, I disabled the function in /etc/php.ini, and re-ran the ab test - with no errors. I also extended the ab test to run 20,000 times; again no errors.

To simplify reproducing the error I'm seeing, I have created a simplified vagrant environment to demonstrate the issue. It will install and configure SimpleSAMLphp, run the benchmark, disable header_register_callback and re-run the benchmark.

In reviewing the history of the lib/SimpleSAML/Session.php code where the function appears, it seems this was added as a way to help prevent a different race condition #260.

Is it sufficiently safe to call $session->save() before redirecting in SimpleSAML\Utils\HTTP::redirect() ?

MrSecure avatar Nov 26 '15 02:11 MrSecure

Hi @MrSecure!

I'm afraid calling $session->save() is not enough in this case, because it opens up for programming errors. If we now require programmers to save the session before finishing, sessions won't be saved half of the time. Not to mention abrupt terminations of execution due to an uncaught exception, for example. Besides, we would need to go through every script that can modify the session at some point and save it before it ends.

I've checked my own error log, and while I have a few segmentation faults there, it's only 5 of them since I applied this patch in October. Also, being a segmentation fault and happening apparently randomly, leads me to think this is a bug in PHP. I see one fixed last year indeed, and it could be this very same issue.

What's the result you observe when you get a segmentation fault? What do you see in the browser? If this isn't noticeable by the user in any way, I'm quite tempted to just ignore the problem and recommend anybody suffering it to upgrade PHP, since the only way then to solve this would be to stop calling header_register_callback(), which leads us back to the race condition reported in #260.

jaimeperez avatar Dec 04 '15 10:12 jaimeperez

Hi @MrSecure!

Did you continue to see segfaults in your logs?

I've been running master / 1.14.0-rc1 in a couple machines for some time, and I haven't seen segfaults any more.

jaimeperez avatar Jan 28 '16 15:01 jaimeperez

I am experiencing this with 1.14.0. The user receives this error:

No data received
ERR_EMPTY_RESPONSE

Apache segfaults went away when I disabled header_register_callback in php.ini.

CentOS 6.3 PHP 5.4.12 Apache 2.2.15 SimpleSAMLphp 1.14.0

jsnod avatar Feb 16 '16 22:02 jsnod

Thanks for the feedback @jsnod!

I'm quite sure it's the bug in PHP I was mentioning previously, so the only way to get rid of it is actually upgrading PHP. Of course we could stop calling this function, but as I said doing so would lead to a race condition again.

In the end, you can always disable the callback in php.ini as you did, and rely on the destructor of SimpleSAML_Session. You will still suffer the race condition, but not the segfaults, and hopefully the race condition is less of a problem at this point. Meanwhile you can prepare your infrastructure for an upgrade.

jaimeperez avatar Feb 17 '16 10:02 jaimeperez

We have been experiencing exactly the same issue. Jaime was right; it seems to be a PHP problem

We are using Oracle Linux 7 (rather similar to CentOS, in fact). Our PHP version was 5.4.26 (latest php 5.4 version as rmp available for Oracle linux 7). We have upgraded to 5.6 and the problem is gone.

To perform the upgrade:

yum install yum-plugin-replace yum replace php-common --replace-with=php56w-common

And the segfault messages were gone

edelahozuah avatar Mar 03 '16 14:03 edelahozuah

Hi We are facing same issue eventhough php is 5.6 version Any clue

Issue:

child pid 4494 exit signal Segmentation fault (11), possible coredump in /etc/apache2

php -v

PHP 5.6.30-12~ubuntu16.04.1+deb.sury.org+1 (cli)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
   with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Ze

We are using default simplesamlphp cooke name only

    /*
     * Options to override the default settings for php sessions.
     */
    'session.phpsession.cookiename' => 'SimpleSAML',
    'session.phpsession.savepath' => null,
    'session.phpsession.httponly' => true,
    /*
     * Option to override the default settings for the auth token cookie
     */
    'session.authtoken.cookiename' => 'SimpleSAMLAuthToken',

rameshnaik5521 avatar May 25 '18 04:05 rameshnaik5521

If PHP segfaults that is per definition not a bug in SimpleSAMLphp but in PHP itself.

thijskh avatar May 25 '18 06:05 thijskh