-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Invalid execute_data->opline
pointers in observer fcall handlers when JIT is enabled
#13772
Comments
Confirmed. The tracing JIT doesn't set the proper The problem may be simple reproduced, if we add an assertion that the value of diff --git a/ext/zend_test/observer.c b/ext/zend_test/observer.c
index 3e870de450a..00e6aec877b 100644
--- a/ext/zend_test/observer.c
+++ b/ext/zend_test/observer.c
@@ -347,6 +347,25 @@ PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("zend_test.observer.execute_internal", "0", PHP_INI_SYSTEM, OnUpdateBool, observer_execute_internal, zend_zend_test_globals, zend_test_globals)
PHP_INI_END()
+static void validate_opline_observer_begin(zend_execute_data *ex)
+{
+ if (ZEND_USER_CODE(ex->func->type)) {
+ if (ex->opline) {
+ ZEND_ASSERT(ex->opline >= ex->func->op_array.opcodes
+ && ex->opline < ex->func->op_array.opcodes + ex->func->op_array.last);
+ }
+ }
+}
+
+static void validate_opline_observer_end(zend_execute_data *ex, zval *rval)
+{
+}
+
+static zend_observer_fcall_handlers validate_opline_observer_fcall_init(zend_execute_data *ex)
+{
+ return (zend_observer_fcall_handlers){validate_opline_observer_begin, validate_opline_observer_end};
+}
+
void zend_test_observer_init(INIT_FUNC_ARGS)
{
// Loading via dl() not supported with the observer API
@@ -378,6 +397,8 @@ void zend_test_observer_init(INIT_FUNC_ARGS)
zend_test_prev_execute_internal = zend_execute_internal;
zend_execute_internal = zend_test_execute_internal;
}
+
+ zend_observer_fcall_register(validate_opline_observer_fcall_init);
}
void zend_test_observer_shutdown(SHUTDOWN_FUNC_ARGS) |
Description
When observer fcall handlers are used to observer PHP function calls and tracing JIT is enabled, then
execute_data->opline
pointers in the fcall handler may become unreliable (not NULL and not valid either) causing the PHP process to crash when these pointers are used.A common scenario would be accessing
execute_data->opline->lineno
to get the line number. The following simple observer handler should print out the line number for every called user function:The actual result is that the PHP process crashes due to the
execute_data->opline
pointer being not NULL and not a valid pointer either:Backtrace of the crashing PHP process:
I haven't been able to isolate a simple PHP script that would trigger this issue. The crash above was observed when running an application using Yii framework. @dstogov confirmed the bug and has a
zend_test
patch that reproduces the issue by runningbench.php
.PHP Version
PHP 8.3.4
Operating System
macOS 14.4
The text was updated successfully, but these errors were encountered: