Commit 9300a6f7ae4 for php
commit 9300a6f7ae4d4be14d66111fd88fca9d81e34491
Author: Arnaud Le Blanc <arnaud.lb@gmail.com>
Date: Sat Nov 14 20:55:25 2026 +0100
Fix GHSA-8mjj-2r7p-4hg2: UAF in debug_backtrace_get_args() on trampoline calls
Extra arguments are moved after CVs and TMPs by i_init_func_execute_data(),
except for trampoline calls, but debug_backtrace_get_args() assumes the usual
argument layout, leading to UAF.
diff --git a/Zend/tests/GHSA-8mjj-2r7p-4hg2.phpt b/Zend/tests/GHSA-8mjj-2r7p-4hg2.phpt
new file mode 100644
index 00000000000..1f5f34faf96
--- /dev/null
+++ b/Zend/tests/GHSA-8mjj-2r7p-4hg2.phpt
@@ -0,0 +1,31 @@
+--TEST--
+GHSA-8mjj-2r7p-4hg2
+--INI--
+fatal_error_backtraces=1
+zend.exception_ignore_args=0
+memory_limit=4M
+opcache.jit=disable
+--SKIPIF--
+<?php
+if (getenv("USE_ZEND_ALLOC") === "0") die("skip requires ZendMM");
+?>
+--FILE--
+<?php
+
+class C {
+ static function __callStatic($name, $args)
+ {
+ }
+}
+
+$a = str_repeat('a', 1*1024*1024);
+
+// Soft OOM during CONCAT will be handled by DO_FCALL
+C::test(1, 2, 3, 4, $a.$a);
+
+?>
+--EXPECTF--
+Fatal error: Allowed memory size of %d bytes exhausted %S(tried to allocate %d bytes) in %s on line 12
+Stack trace:
+#0 %s(12): C::test(1, 2, 3, 4, 'aaaaaaaaaaaaaaa...')
+#1 {main}
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index 10931dd347c..080af3273c1 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -1734,7 +1734,11 @@ static bool debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) /
return false;
}
ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(arg_array)) {
- if (call->func->type == ZEND_USER_FUNCTION) {
+ /* Extra args are moved after CVs and TMPs in user functions, except
+ * for trampoline frames (see i_init_func_execute_data()).
+ */
+ if (call->func->type == ZEND_USER_FUNCTION
+ && !(call->func->op_array.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
uint32_t first_extra_arg = MIN(num_args, call->func->op_array.num_args);
if (UNEXPECTED(ZEND_CALL_INFO(call) & ZEND_CALL_HAS_SYMBOL_TABLE)) {
diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c
index b3c0b3889be..e495b212da5 100644
--- a/sapi/phpdbg/phpdbg.c
+++ b/sapi/phpdbg/phpdbg.c
@@ -121,6 +121,7 @@ static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) /* {{{ */
pg->flags = PHPDBG_DEFAULT_FLAGS;
memset(pg->io, 0, sizeof(pg->io));
pg->frame.num = 0;
+ pg->frame.generator = 0;
pg->sapi_name_ptr = NULL;
pg->unclean_eval = 0;
diff --git a/sapi/phpdbg/phpdbg_frame.c b/sapi/phpdbg/phpdbg_frame.c
index a8f1bf01433..5bb75ba7695 100644
--- a/sapi/phpdbg/phpdbg_frame.c
+++ b/sapi/phpdbg/phpdbg_frame.c
@@ -56,6 +56,12 @@ zend_string *phpdbg_compile_stackframe(zend_execute_data *ex) {
uint32_t i = 0, first_extra_arg = op_array->num_args, num_args = ZEND_CALL_NUM_ARGS(ex);
zval *p = ZEND_CALL_ARG(ex, 1);
+ if (ex->func->op_array.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
+ /* A __call/__callStatic trampoline doesn't move extra args
+ * behind the CVs and TMPs (see i_init_func_execute_data()). */
+ first_extra_arg = num_args;
+ }
+
if (op_array->scope) {
smart_str_append(&s, op_array->scope->name);
smart_str_appends(&s, "::");
@@ -86,6 +92,8 @@ zend_string *phpdbg_compile_stackframe(zend_execute_data *ex) {
smart_str_appends(&s, " [internal function]");
}
+ smart_str_0(&s);
+
return s.s;
}
diff --git a/sapi/phpdbg/tests/GHSA-8mjj-2r7p-4hg2-001.phpt b/sapi/phpdbg/tests/GHSA-8mjj-2r7p-4hg2-001.phpt
new file mode 100644
index 00000000000..67c95706cf2
--- /dev/null
+++ b/sapi/phpdbg/tests/GHSA-8mjj-2r7p-4hg2-001.phpt
@@ -0,0 +1,34 @@
+--TEST--
+GHSA-8mjj-2r7p-4hg2: phpdbg frame display for __call trampoline
+--INI--
+fatal_error_backtraces=0
+zend.exception_ignore_args=1
+--PHPDBG--
+b ZEND_CALL_TRAMPOLINE
+r
+f 1
+f 0
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at ZEND_CALL_TRAMPOLINE]
+prompt> [Breakpoint #0 in ZEND_CALL_TRAMPOLINE at %s:0, hits: 1]
+ 00001: <?php
+ 00002: class C { static function __callStatic($name, $args) {} }
+prompt> [Switched to frame #1: caller() at %s:5]
+>00005: C::test(1, 2, 3, 4);
+ 00006: }
+ 00007:%w
+prompt> [Switched to frame #0: C::test(1, 2, 3, 4) at %s:0]
+ 00001: <?php
+ 00002: class C { static function __callStatic($name, $args) {} }
+prompt>
+--FILE--
+<?php
+class C { static function __callStatic($name, $args) {} }
+
+function caller() {
+ C::test(1, 2, 3, 4);
+}
+
+caller();
diff --git a/sapi/phpdbg/tests/GHSA-8mjj-2r7p-4hg2-002.phpt b/sapi/phpdbg/tests/GHSA-8mjj-2r7p-4hg2-002.phpt
new file mode 100644
index 00000000000..173e58faaa0
--- /dev/null
+++ b/sapi/phpdbg/tests/GHSA-8mjj-2r7p-4hg2-002.phpt
@@ -0,0 +1,31 @@
+--TEST--
+GHSA-8mjj-2r7p-4hg2: phpdbg backtrace for __call trampoline with attached symbol table
+--INI--
+fatal_error_backtraces=0
+zend.exception_ignore_args=0
+--PHPDBG--
+b ZEND_CALL_TRAMPOLINE
+r
+i v
+back
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at ZEND_CALL_TRAMPOLINE]
+prompt> [Breakpoint #0 in ZEND_CALL_TRAMPOLINE at %s:0, hits: 1]
+ 00001: <?php
+ 00002: class C { static function __callStatic($name, $args) {} }
+prompt> [Variables in C::test() (0)]
+prompt> frame #0: C::test(1, 2, 3, 4) at %s:0
+frame #1: caller() at %s:5
+frame #2: {main} at %s:8
+prompt>
+--FILE--
+<?php
+class C { static function __callStatic($name, $args) {} }
+
+function caller() {
+ C::test(1, 2, 3, 4);
+}
+
+caller();