Whissi / realpath_turbo

When PHP's open_basedir restriction is set, PHP disables the realpath cache for security reasons. This may hurt your application performance. The realpath_turbo PHP extension re-enables the realpath cache. Warning: This could be a security problem in your environment! Please read the README for further information.
BSD 2-Clause "Simplified" License
45 stars 13 forks source link

phpinfo() give me segmentation fault #1

Closed jjone closed 8 years ago

jjone commented 9 years ago

HI, Whissi

After installing turbo_realpath, phpinfo() gives me segmentation fault my system is centos 7, php 5.4.16. Is this compatible with centos 7, php 5.4.16 ? thank you very much for your help.

Justin

Whissi commented 9 years ago

Hello Justin. I just checked PHP 5.4.38 with turbo_realpath v1.3 and it is working fine for me. I didn't tried CentOS (I am using Gentoo) but I expect that your PHP is crashing for another reason, not realpath_turbo related.

jjone commented 9 years ago

Hi, Thomas Very strange. I commented out this extension then my phpinfo() works with no segmentation fault. I installed turbo_realpath by following your github install guide but I will double check my php setting again later on. again, thank you very much for your time and help. justin

Sent from Acompli

_____________________________

From: Thomas D. notifications@github.com Sent: Sunday, February 22, 2015 4:43 PM Subject: Re: [realpath_turbo] phpinfo() give me segmentation fault (#1) To: Whissi/realpath_turbo realpath_turbo@noreply.github.com Cc: jjone justinxia@hotmail.com

Hello Justin. I just checked PHP 5.4.38 with turbo_realpath v1.3 and it is working fine for me. I didn't tried CentOS (I am using Gentoo) but I expect that your PHP is crashing for another reason, not realpath_turbo related.

Is your installation really working and only crashing when you add extension=turbo_realpath.so

(=not crashing without this line)?

You are using realpath_turbo v1.3, aren't you?

— Reply to this email directly or view it on GitHub.

jjone commented 9 years ago

Hi, Thomas

my /etc/php.d/turbo_realpath.ini

extension=turbo_realpath.so realpath_cache_security = 1 realpath_cache_basedir = "" open_basedir = ""

when i run php -i here is the output :

Turbo Real Path => enabled Description => Solves performance problems with PHP applications and NFS storage Extension version => 1.3 RealPath basedir path => RealPath safe mode => RealPath basedir security => Segmentation fault

i think RealPath basedir security is giving me the problem. i want set open_basedir to none. i don't know if it was set correctly in my turbo_realpath.ini.

Thank you very much.

Jusitn

Whissi commented 9 years ago

OK, I was able to reproduce your problem: Remove realpath_cache_security option for the moment or set to 0. Seems like this option is causing problems (I don't use this option, instead I use disable_functions).

Will see if I can fix that...

jjone commented 9 years ago

Hi, Thomas

I set it to 0 and it works nicely.

one more issue, i checked my realpath cache with this php function, var_dump(realpath_cache_size()); var_dump(realpath_cache_get()); the 1st time output looks good. it give me a list of cached directory links.

However, here is the 2nd time and next time output from my php-fpm dedicated server,

int(221) array(3) { ["/etc"]=> array(4) { ["key"]=> float(1.6714350287265E+19) ["is_dir"]=> bool(true) ["realpath"]=> string(4) "/etc" ["expires"]=> int(1424647280) } ["/etc/php.d"]=> array(4) { ["key"]=> float(1.6027146195387E+19) ["is_dir"]=> bool(true) ["realpath"]=> string(10) "/etc/php.d" ["expires"]=> int(1424647280) } ["/etc/php.d/opcache-default.blacklist"]=> array(4) { ["key"]=> int(3088552834067437318) ["is_dir"]=> bool(false) ["realpath"]=> string(36) "/etc/php.d/opcache-default.blacklist" ["expires"]=> int(1424647280) } }

the cached directory are no longer there. Looks like it works only the 1st time and then the realpath cache disappeared somehow. Is my output normal?

Thank you very much.

Justin

Whissi commented 9 years ago

Hard to tell...

First, remember what the extension is doing: While patching https://bugs.php.net/bug.php?id=52312 the PHP team decided to set realpath_cache_size_limit = 0 (which disables the realpath cache) when _safemode or _openbasedir restriction is active.

realpath_turbo just uses the fact that the check happens before the extension loads. That's why you should unset open_basedir when using realpath_turbo, so that PHP won't disable the realpath cache. When the extension finally load, it will enable open_basedir like PHP would have done but without running through the check which would disable the realpath cache.

If you keep this in mind it is more likely that you are running a PHP application which clears the cache (i.e. with clearstatcache(true)).

If you want to use open_basedir restriction for /home/example.org/htdocs make sure to load realpath_turbo and set

php_admin_value[open_basedir] = ""
php_admin_value[realpath_cache_basedir] = "/home/example.org/htdocs:/usr/share/php"

in the used PHP fpm pool.

This will make sure turbo_realpath will prevent PHP from disabling the realpath cache and open_basedir restrictions are still working.

Now if no script is clearing your cache your realpath cache should grow and stay. Just tested on my servers.

jjone commented 9 years ago

HI, Thomas

I run magento on this dedicated php-fpm server. I don’t know if magento will clear the realpath cache.

I set the following in my php-fpm pool setting,

php_admin_value[open_basedir] = none php_admin_value[realpath_cache_basedir] =none

Here are the 3 functions that I used to check the cache, I put it in a test.php file. it works only the 1st time.

var_dump(realpath_cache_size()); var_dump(realpath_cache_get()); phpinfo();

Thank you very much

Justin

From: Thomas D. Sent: Sunday, February 22, 2015 5:59 PM To: Whissi/realpath_turbo Cc: jjone Subject: Re: [realpath_turbo] phpinfo() give me segmentation fault (#1)

Hard to tell...

First, remember what the extension is doing: While patching https://bugs.php.net/bug.php?id=52312 the PHP team decided to set realpath_cache_size_limit = 0 (which disables the realpath cache) when safe_mode or open_basedir restriction is active.

realpath_turbo just uses the fact that the check happens before the extension loads. That's why you should unset open_basedir when using realpath_turbo, so that PHP won't disable the realpath cache. When the extension finally load, it will enable open_basedir like PHP would have done but without running through the check which would disable the realpath cache.

If you keep this in mind it is more likely that you are running a PHP application which clears the cache (i.e. with clearstatcache(true)).

If you want to use open_basedir restriction for /home/example.org/htdocs make sure to load realpath_turbo and set

php_admin_value[open_basedir] = "" php_admin_value[realpath_cache_basedir] = "/home/example.org/htdocs:/usr/share/php"in the used PHP fpm pool.

This will make sure turbo_realpath will prevent PHP from disabling the realpath cache and open_basedir restrictions are still working.

Now if no script is clearing your cache your realpath cache should grow and stay. Just tested on my servers.

— Reply to this email directly or view it on GitHub.

Whissi commented 9 years ago

Justin, I don't understand why you are using realpath_turbo when you don't set open_basedir at all. If you don't want _openbasedir restriction you don't need this extension. If you want _openbasedir restriction use this extension to set the restriction with realpath_cache_basedir instead of open_basedir.

Now you are basically not using this extension. In other words: Any problems you maybe experience have nothing to do with this extension.

PS: Also make sure that your application doesn't disable realpath_cache.

jjone commented 9 years ago

Hi, Thomas

Thank you very much for your help.

It worked. I tested it again this morning. the real path cache array is a big list now.

Justin

From: Thomas D. Sent: Monday, February 23, 2015 7:05 AM To: Whissi/realpath_turbo Cc: jjone Subject: Re: [realpath_turbo] phpinfo() give me segmentation fault (#1)

Justin, I don't understand why you are using realpath_turbo when you don't set open_basedir at all. If you don't want open_basedir restriction you don't need this extension. If you want open_basedir restriction use this extension to set the restriction with realpath_cache_basedir instead of open_basedir.

Now you are basically not using this extension. In other words: Any problems you maybe experience have nothing to do with this extension.

PS: Also make sure that your application doesn't disable realpath_cache.

— Reply to this email directly or view it on GitHub.

vpal commented 9 years ago

Hi Whissi,

I would suggest to remove the feature if it causes crashes.

Thanks