-
Notifications
You must be signed in to change notification settings - Fork 8k
Fix potential memory issue with USE_ZEND_ALLOC=0 #2120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The PHP core and extensions are written with the assumption that memory allocation either succeeds, or the allocator bails out (i.e. the allocator is infallible). Therefore the result of emalloc() and friends are not checked for NULL values. However, with USE_ZEND_ALLOC=0, malloc() and friends are used as allocators, but these are fallible, i.e. they return NULL instead of bailing out if they fail. This easily leads to invalid memory accesses in the following, such as in <https://bugs.php.net/73032>. Some of these cases may constitute exploitable vulnerabilities. Therefore we make the infallible __zend_alloc() and friends the default for USE_ZEND_ALLOC=0.
|
Looks reasonable. The only downside is that we waste one stack frame in valgrind :) |
|
Note, that I consider the current behavior a serious bug, unless it would be documented that fallible memory managers must not be used for production environments. But even in this case, we probably can avoid a lot of (security) bug reports (such as https://bugs.php.net/73032) by simply using an infallible memory allocator. Furthermore, the PHP manual should make it clear that custom memory managers are supposed to be also infallible. |
--num-callers to the rescue. :-) |
|
The failing Travis check is unrelated to this PR. |
|
cc @dstogov |
|
looks fine. BTW USE_ZEND_ALLOC=0 was introduced (and should be used) for debugging memory problems only. |
I'll adjust the documentation accordingly. Nonetheless, I consider the current behavior to be a bug, and therefore have targetted the PR to PHP 5.6. If there are no objections, I'm going to merge in a week. |
See <php/php-src#2120 (comment)>. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@340021 c90b9560-bf6c-de11-be94-00142212c4b1
See <php/php-src#2120 (comment)>. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@340021 c90b9560-bf6c-de11-be94-00142212c4b1
See <php/php-src#2120 (comment)>. git-svn-id: http://svn.php.net/repository/phpdoc/en@340021 c90b9560-bf6c-de11-be94-00142212c4b1
The PHP core and extensions are written with the assumption that memory
allocation either succeeds, or the allocator bails out (i.e. the allocator
is infallible). Therefore the result of emalloc() and friends are not checked
for NULL values.
However, with USE_ZEND_ALLOC=0, malloc() and friends are used as allocators,
but these are fallible, i.e. they return NULL instead of bailing out if they
fail. This easily leads to invalid memory accesses in the following, such as
in https://bugs.php.net/73032. Some of these cases may constitute
exploitable vulnerabilities.
Therefore we make the infallible __zend_alloc() and friends the default for
USE_ZEND_ALLOC=0.