Open YuanchengJiang opened 1 month ago
Tentatively marking as streams issue.
PHP-8.3 is affected as well, and maybe older branches, too.
The report with USE_ZEND_ALLOC=0
is likely more useful:
==1213945==ERROR: AddressSanitizer: heap-use-after-free on address 0x503000020f58 at pc 0x000001583a4c bp 0x7ffcfd951540 sp 0x7ffcfd951538
READ of size 8 at 0x503000020f58 thread T0
#0 0x1583a4b in _build_trace_args /home/ilutov/Developer/php-src/Zend/zend_exceptions.c:510
#1 0x1584c0a in _build_trace_string /home/ilutov/Developer/php-src/Zend/zend_exceptions.c:576
#2 0x15853e6 in zend_trace_to_string /home/ilutov/Developer/php-src/Zend/zend_exceptions.c:602
#3 0x1585919 in zim_Exception_getTraceAsString /home/ilutov/Developer/php-src/Zend/zend_exceptions.c:631
#4 0x15a0070 in zend_call_function /home/ilutov/Developer/php-src/Zend/zend_execute_API.c:1009
#5 0x158686a in zim_Exception___toString /home/ilutov/Developer/php-src/Zend/zend_exceptions.c:676
#6 0x15a0070 in zend_call_function /home/ilutov/Developer/php-src/Zend/zend_execute_API.c:1009
#7 0x15a14b3 in zend_call_known_function /home/ilutov/Developer/php-src/Zend/zend_execute_API.c:1090
#8 0x15784aa in zend_call_known_instance_method /home/ilutov/Developer/php-src/Zend/zend_API.h:860
#9 0x15784e4 in zend_call_known_instance_method_with_0_params /home/ilutov/Developer/php-src/Zend/zend_API.h:866
#10 0x1589be2 in zend_exception_error /home/ilutov/Developer/php-src/Zend/zend_exceptions.c:918
#11 0x1b11fd4 in zend_execute_script /home/ilutov/Developer/php-src/Zend/zend.c:1935
#12 0x10e6d7b in php_execute_script_ex /home/ilutov/Developer/php-src/main/main.c:2578
#13 0x10e72aa in php_execute_script /home/ilutov/Developer/php-src/main/main.c:2618
#14 0x1b197c5 in do_cli /home/ilutov/Developer/php-src/sapi/cli/php_cli.c:935
#15 0x1b1c008 in main /home/ilutov/Developer/php-src/sapi/cli/php_cli.c:1309
#16 0x7fd775e39087 in __libc_start_call_main (/lib64/libc.so.6+0x2a087) (BuildId: 77c77fee058b19c6f001cf2cb0371ce3b8341211)
#17 0x7fd775e3914a in __libc_start_main_alias_1 (/lib64/libc.so.6+0x2a14a) (BuildId: 77c77fee058b19c6f001cf2cb0371ce3b8341211)
#18 0x602864 in _start (/home/ilutov/Developer/php-src/sapi/cli/php+0x602864) (BuildId: 9749d43ca5f1fff9b820d72e2c7562054c225a04)
0x503000020f58 is located 8 bytes inside of 32-byte region [0x503000020f50,0x503000020f70)
freed by thread T0 here:
#0 0x7fd7768f6638 in free.part.0 (/lib64/libasan.so.8+0xf6638) (BuildId: 79824421bd82bb3ef4addf048e1265e2a93cfc64)
#1 0x140b0e4 in __zend_free /home/ilutov/Developer/php-src/Zend/zend_alloc.c:3308
#2 0x1406562 in _efree /home/ilutov/Developer/php-src/Zend/zend_alloc.c:2747
#3 0x1a32ffd in list_entry_destructor /home/ilutov/Developer/php-src/Zend/zend_list.c:182
#4 0x191bd04 in _zend_hash_packed_del_val /home/ilutov/Developer/php-src/Zend/zend_hash.c:1461
#5 0x191fdb8 in zend_hash_index_del /home/ilutov/Developer/php-src/Zend/zend_hash.c:1706
#6 0x1a31fae in zend_list_free /home/ilutov/Developer/php-src/Zend/zend_list.c:58
#7 0x1aeabb6 in rc_dtor_func /home/ilutov/Developer/php-src/Zend/zend_variables.c:57
#8 0x15abc24 in i_zval_ptr_dtor /home/ilutov/Developer/php-src/Zend/zend_variables.h:45
#9 0x15e0e51 in i_free_compiled_variables /home/ilutov/Developer/php-src/Zend/zend_execute.c:4085
#10 0x18a0c4a in execute_ex /home/ilutov/Developer/php-src/Zend/zend_vm_execute.h:58667
#11 0x18bfed7 in zend_execute /home/ilutov/Developer/php-src/Zend/zend_vm_execute.h:64237
#12 0x1b11ea3 in zend_execute_script /home/ilutov/Developer/php-src/Zend/zend.c:1928
#13 0x10e6d7b in php_execute_script_ex /home/ilutov/Developer/php-src/main/main.c:2578
#14 0x10e72aa in php_execute_script /home/ilutov/Developer/php-src/main/main.c:2618
#15 0x1b197c5 in do_cli /home/ilutov/Developer/php-src/sapi/cli/php_cli.c:935
#16 0x1b1c008 in main /home/ilutov/Developer/php-src/sapi/cli/php_cli.c:1309
#17 0x7fd775e39087 in __libc_start_call_main (/lib64/libc.so.6+0x2a087) (BuildId: 77c77fee058b19c6f001cf2cb0371ce3b8341211)
#18 0x7fd775e3914a in __libc_start_main_alias_1 (/lib64/libc.so.6+0x2a14a) (BuildId: 77c77fee058b19c6f001cf2cb0371ce3b8341211)
#19 0x602864 in _start (/home/ilutov/Developer/php-src/sapi/cli/php+0x602864) (BuildId: 9749d43ca5f1fff9b820d72e2c7562054c225a04)
previously allocated by thread T0 here:
#0 0x7fd7768f7997 in malloc (/lib64/libasan.so.8+0xf7997) (BuildId: 79824421bd82bb3ef4addf048e1265e2a93cfc64)
#1 0x140af92 in __zend_malloc /home/ilutov/Developer/php-src/Zend/zend_alloc.c:3280
#2 0x1406423 in _emalloc /home/ilutov/Developer/php-src/Zend/zend_alloc.c:2737
#3 0x1a31a38 in zend_list_insert /home/ilutov/Developer/php-src/Zend/zend_list.c:42
#4 0x1a324bc in zend_register_resource /home/ilutov/Developer/php-src/Zend/zend_list.c:91
#5 0x11624bb in _php_stream_alloc /home/ilutov/Developer/php-src/main/streams/streams.c:314
#6 0x114f1bf in _php_stream_memory_create /home/ilutov/Developer/php-src/main/streams/memory.c:300
#7 0xf35b9f in php_stream_url_wrap_php /home/ilutov/Developer/php-src/ext/standard/php_fopen_wrapper.c:210
#8 0x1175c49 in _php_stream_open_wrapper_ex /home/ilutov/Developer/php-src/main/streams/streams.c:2235
#9 0xe39f3f in zif_fopen /home/ilutov/Developer/php-src/ext/standard/file.c:746
#10 0x16015d9 in ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER /home/ilutov/Developer/php-src/Zend/zend_vm_execute.h:1351
#11 0x18a27ef in execute_ex /home/ilutov/Developer/php-src/Zend/zend_vm_execute.h:58810
#12 0x18bfed7 in zend_execute /home/ilutov/Developer/php-src/Zend/zend_vm_execute.h:64237
#13 0x1b11ea3 in zend_execute_script /home/ilutov/Developer/php-src/Zend/zend.c:1928
#14 0x10e6d7b in php_execute_script_ex /home/ilutov/Developer/php-src/main/main.c:2578
#15 0x10e72aa in php_execute_script /home/ilutov/Developer/php-src/main/main.c:2618
#16 0x1b197c5 in do_cli /home/ilutov/Developer/php-src/sapi/cli/php_cli.c:935
#17 0x1b1c008 in main /home/ilutov/Developer/php-src/sapi/cli/php_cli.c:1309
#18 0x7fd775e39087 in __libc_start_call_main (/lib64/libc.so.6+0x2a087) (BuildId: 77c77fee058b19c6f001cf2cb0371ce3b8341211)
#19 0x7fd775e3914a in __libc_start_main_alias_1 (/lib64/libc.so.6+0x2a14a) (BuildId: 77c77fee058b19c6f001cf2cb0371ce3b8341211)
#20 0x602864 in _start (/home/ilutov/Developer/php-src/sapi/cli/php+0x602864) (BuildId: 9749d43ca5f1fff9b820d72e2c7562054c225a04)
Looks like the resource is released too early.
Description
The following code:
Resulted in this output:
If
USE_ZEND_ALLOC=0
, it causes UAF.PHP Version
PHP 8.4.0-dev
Operating System
ubuntu 22.04