php-src icon indicating copy to clipboard operation
php-src copied to clipboard

segfault in `zend_mm_alloc_small` triggered by call to `unserialize`

Open gnif opened this issue 3 years ago • 20 comments

Description

This is a large WordPress website running some commonly available community plugins. The site was working fine on PHP 7.4 but since upgrading to 8.2.6 and then subsequent 8.2.10 to see if the issue was resolved we are seeing segfaults on multiple servers in the cluster servicing this website.

Every single fault is during a call to unserialize, here is the zbacktrace:

[0x7fb2ac2138e0] unserialize("a:5:{s:3:"AUD";a:8:{s:4:"name";s:3:"AUD";s:4:"rate";d:1;s:6:"symbol";s:3:"AU$";s:8:"position";s:4:"left";s:
9:"is_etalon";i:1;s:10:"hide_cents";i:0;s:11:"description";s:17:"Australian Dollar";s:4:"flag";s:88:"https://www.xxxxxxx.com/wp-content/p
lugins/wooco...") [internal function]
[0x7fb2ac213860] maybe_unserialize("a:5:{s:3:"AUD";a:8:{s:4:"name";s:3:"AUD";s:4:"rate";d:1;s:6:"symbol";s:3:"AU$";s:8:"position";s:4:"le
ft";s:9:"is_etalon";i:1;s:10:"hide_cents";i:0;s:11:"description";s:17:"Australian Dollar";s:4:"flag";s:88:"https://www.xxxxxxx.com/wp-con
tent/plugins/wooco...") /home/xxxxxxx/public_html/wp-includes/functions.php:650 
[0x7fb2ac213650] get_option("woocs", array(2)[0x7fb2ac2136b0]) /home/xxxxxxx/public_html/wp-includes/option.php:253 
[0x7fb2ac2135d0] WOOCS->get_currencies() /home/xxxxxxx/public_html/wp-content/plugins/woocommerce-currency-switcher/index.php:972 
[0x7fb2ac213530] WOOCS->init_no_cents() /home/xxxxxxx/public_html/wp-content/plugins/woocommerce-currency-switcher/index.php:497 
[0x7fb2ac213470] WOOCS->__construct() /home/xxxxxxx/public_html/wp-content/plugins/woocommerce-currency-switcher/index.php:82 
[0x7fb2ac2133e0] (main) /home/xxxxxxx/public_html/wp-content/plugins/woocommerce-currency-switcher/index.php:2213 
[0x7fb2ac213220] (main) /home/xxxxxxx/public_html/wp-settings.php:462 
[0x7fb2ac2131a0] (main) /home/xxxxxxx/public_html/wp-config.php:72 
[0x7fb2ac213100] (main) /home/xxxxxxx/public_html/wp-load.php:50 
[0x7fb2ac213070] (main) /home/xxxxxxx/public_html/wp-blog-header.php:13 
[0x7fb2ac213020] (main) /home/xxxxxxx/public_html/index.php:17

And the PHP backtrace

#0  zend_mm_alloc_small (bin_num=11, heap=0x7fb2ac200040) at ./Zend/zend_alloc.c:1313
#1  zend_mm_alloc_heap (size=<optimized out>, heap=0x7fb2ac200040) at ./Zend/zend_alloc.c:1384
#2  _emalloc (size=<optimized out>) at ./Zend/zend_alloc.c:2601
#3  0x0000556923c3962a in zend_string_alloc (persistent=false, len=88) at ./Zend/zend_string.h:152
#4  zend_string_init (persistent=false, len=88, 
    str=0x7fb2a6e89a92 "https://www.xxxxxxx.com/wp-content/plugins/woocommerce-currency-switcher/img/no_flag.png\";}s:3:\"NZD\";a:8:{s:4:\"name\";s:3:\"NZD\";s:4:\"rate\";d:1.07660000000000000142108547152020037174224853515625;s:6:\"symbol\";s:3:\"NZ$\";s:8:\"position\";s:4:\"left\";s:9:\"is_etalon\";i:0;s:10:\"hide_cents\";i:0;s:11:\"description\";s:18:\"New Zealand Dollar\";s:4:\"flag\";s:88:\"https://www.xxxxxxx.com/wp-content/plugins/woocommerce-currency-switcher/img/no_flag.png\";}s:3:\"GBP\";a:8:{s:4:\"name\";s:3:\"GBP\";s:4:\"rate\";d:0.502499999999999946709294817992486059665679931640625;s:6:\"symbol\";s:7:\"&pound;\";s:8:\"position\";s:4:\"left\";s:9:\"is_etalon\";i:0;s:10:\"hide_cents\";i:0;s:11:\"description\";s:13:\"British Pound\";s:4:\"flag\";s:88:\"https://www.xxxxxxx.com/wp-content/plugins/woocommerce-currency-switcher/img/no_flag.png\";}}") at ./Zend/zend_string.h:174
#5  zend_string_init_fast (len=88, 
    str=0x7fb2a6e89a92 "https://www.xxxxxxx.com/wp-content/plugins/woocommerce-currency-switcher/img/no_flag.png\";}s:3:\"NZD\";a:8:{s:4:\"name\";s:3:\"NZD\";s:4:\"rate\";d:1.07660000000000000142108547152020037174224853515625;s:6:\"symbol\";s:3:\"NZ$\";s:8:\"position\";s:4:\"left\";s:9:\"is_etalon\";i:0;s:10:\"hide_cents\";i:0;s:11:\"description\";s:18:\"New Zealand Dollar\";s:4:\"flag\";s:88:\"https://www.xxxxxxx.com/wp-content/plugins/woocommerce-currency-switcher/img/no_flag.png\";}s:3:\"GBP\";a:8:{s:4:\"name\";s:3:\"GBP\";s:4:\"rate\";d:0.502499999999999946709294817992486059665679931640625;s:6:\"symbol\";s:7:\"&pound;\";s:8:\"position\";s:4:\"left\";s:9:\"is_etalon\";i:0;s:10:\"hide_cents\";i:0;s:11:\"description\";s:13:\"British Pound\";s:4:\"flag\";s:88:\"https://www.xxxxxxx.com/wp-content/plugins/woocommerce-currency-switcher/img/no_flag.png\";}}") at ./Zend/zend_string.h:184
#6  php_var_unserialize_internal (rval=0x7fb2a6e45fa0, p=0x7fff469fb468, max=<optimized out>, var_hash=0x7fff469fb470)
    at ./ext/standard/var_unserializer.c:1798
#7  0x0000556923c39110 in process_nested_array_data (elements=0, ht=0x7fb2a6f0bb28, var_hash=0x7fff469fb470, max=0x7fb2a6e89da2 "", 
    p=0x7fff469fb468, rval=0x7fff469fb2a0) at ./ext/standard/var_unserializer.c:511
#8  php_var_unserialize_internal (rval=0x7fff469fb2a0, p=0x7fff469fb468, max=0x7fb2a6e89da2 "", var_hash=0x7fff469fb470)
    at ./ext/standard/var_unserializer.c:1742
#9  0x0000556923c39110 in process_nested_array_data (elements=2, ht=0x7fb2a6f0ba80, var_hash=0x7fff469fb470, max=0x7fb2a6e89da2 "", 
    p=0x7fff469fb468, rval=0x7fff469fb390) at ./ext/standard/var_unserializer.c:511
#10 php_var_unserialize_internal (rval=0x7fff469fb390, p=0x7fff469fb468, max=0x7fb2a6e89da2 "", var_hash=0x7fff469fb470)
    at ./ext/standard/var_unserializer.c:1742
#11 0x0000556923c3ac47 in php_var_unserialize (rval=<optimized out>, p=<optimized out>, max=<optimized out>, var_hash=<optimized out>)
    at ./ext/standard/var_unserializer.c:853
#12 0x0000556923c29fb4 in php_unserialize_with_options (function_name=0x556923db086e "unserialize", options=<optimized out>, 
    buf_len=1674, 
    buf=0x7fb2a6e89718 "a:5:{s:3:\"AUD\";a:8:{s:4:\"name\";s:3:\"AUD\";s:4:\"rate\";d:1;s:6:\"symbol\";s:3:\"AU$\";s:8:\"position\";s:4:\"left\";s:9:\"is_etalon\";i:1;s:10:\"hide_cents\";i:0;s:11:\"description\";s:17:\"Australian Dollar\";s:4:\"flag\";s:88:\"https://www.xxxxxxx.com/wp-content/plugins/woocommerce-currency-switcher/img/no_flag.png\";}s:3:\"USD\";a:8:{s:4:\"name\";s:3:\"USD\";s:4:\"rate\";d:0.71679999999999999271693695845897309482097625732421875;s:6:\"symbol\";s:3:\"US$\";s:8:\"position\";s:4:\"left\";s:9:\"is_etalon\";i:0;s:10:\"hide_cents\";i:0;s:11:\"description\";s:9:\"US Dollar\";s:4:\"flag\";s:88:\"https://www.xxxxxxx.com/wp-content/plugins/woocommerce-currency-switcher/img/no_flag.png\";}s:3:\"EUR\";a:8:{s:4:\"name\";s:3:\"EUR\";s:4:\"rate\";d:0.6449000000000000287769807982840575277805328369140625;s:6:\"symbol\";s:6:\"&euro;\";s:8:\"position\";s:10:\"left_space\";s:9:\"is_etalon\";i:0;s:10:\"hide_cents\";i:0;s:11:\"description\";s:4:\"Euro\";s:4:\"flag\";s:88:\"https://www.xxxxxxx.com/wp-content/plugins/woocommerce-currency-switcher/img/no_flag.png\";}s:3:\"NZD\";a:8:{s:4:\"name\";s:3:\"NZD\";s:4:\"rate\";d:1.07660000000000000142108547152020037174224853515625;s:6:\"symbol\";s:3:\"NZ$\";s:8:\"position\";s:4:\"left\";s:9:\"is_etalon\";i:0;s:10:\"hide_cents\";i:0;s:11:\"description\";s:18:\"New Zealand Dollar\";s:4:\"flag\";s:88:\"https://www.xxxxxxx.com/wp-content/plugins/woocommerce-currency-switcher/img/no_flag.png\";}s:3:\"GBP\";a:8:{s:4:\"name\";s:3:\"GBP\";s:4:\"rate\";d:0.502499999999999946709294817992486059665679931640625;s:6:\"symbol\";s:7:\"&pound;\";s:8:\"position\";s:4:\"left\";s:9:\"is_etalon\";i:0;s:10:\"hide_cents\";i:0;s:11:\"description\";s:13:\"British Pound\";s:4:\"flag\";s:88:\"https://www.xxxxxxx.com/wp-content/plugins/woocommerce-currency-switcher/img/no_flag.png\";}}", return_value=0x7fb2ac2138c0) at ./ext/standard/var.c:1406
#13 php_unserialize_with_options (return_value=0x7fb2ac2138c0, 
    buf=0x7fb2a6e89718 "a:5:{s:3:\"AUD\";a:8:{s:4:\"name\";s:3:\"AUD\";s:4:\"rate\";d:1;s:6:\"symbol\";s:3:\"AU$\";s:8:\"position\";s:4:\"left\";s:9:\"is_etalon\";i:1;s:10:\"hide_cents\";i:0;s:11:\"description\";s:17:\"Australian Dollar\";s:4:\"flag\";s:88:\"https://www.xxxxxxx.com/wp-content/plugins/woocommerce-currency-switcher/img/no_flag.png\";}s:3:\"USD\";a:8:{s:4:\"name\";s:3:\"USD\";s:4:\"rate\";d:0.71679999999999999271693695845897309482097625732421875;s:6:\"symbol\";s:3:\"US$\";s:8:\"position\";s:4:\"left\";s:9:\"is_etalon\";i:0;s:10:\"hide_cents\";i:0;s:11:\"description\";s:9:\"US Dollar\";s:4:\"flag\";s:88:\"https://www.xxxxxxx.com/wp-content/plugins/woocommerce-currency-switcher/img/no_flag.png\";}s:3:\"EUR\";a:8:{s:4:\"name\";s:3:\"EUR\";s:4:\"rate\";d:0.6449000000000000287769807982840575277805328369140625;s:6:\"symbol\";s:6:\"&euro;\";s:8:\"position\";s:10:\"left_space\";s:9:\"is_etalon\";i:0;s:10:\"hide_cents\";i:0;s:11:\"description\";s:4:\"Euro\";s:4:\"flag\";s:88:\"https://www.xxxxxxx.com/wp-content/plugins/woocommerce-currency-switcher/img/no_flag.png\";}s:3:\"NZD\";a:8:{s:4:\"name\";s:3:\"NZD\";s:4:\"rate\";d:1.07660000000000000142108547152020037174224853515625;s:6:\"symbol\";s:3:\"NZ$\";s:8:\"position\";s:4:\"left\";s:9:\"is_etalon\";i:0;s:10:\"hide_cents\";i:0;s:11:\"description\";s:18:\"New Zealand Dollar\";s:4:\"flag\";s:88:\"https://www.xxxxxxx.com/wp-content/plugins/woocommerce-currency-switcher/img/no_flag.png\";}s:3:\"GBP\";a:8:{s:4:\"name\";s:3:\"GBP\";s:4:\"rate\";d:0.502499999999999946709294817992486059665679931640625;s:6:\"symbol\";s:7:\"&pound;\";s:8:\"position\";s:4:\"left\";s:9:\"is_etalon\";i:0;s:10:\"hide_cents\";i:0;s:11:\"description\";s:13:\"British Pound\";s:4:\"flag\";s:88:\"https://www.xxxxxxx.com/wp-content/plugins/woocommerce-currency-switcher/img/no_flag.png\";}}", buf_len=1674, options=<optimized out>, function_name=0x556923db086e "unserialize")
    at ./ext/standard/var.c:1334
#14 0x0000556930e24644 in ?? ()
#15 0x0000000000000001 in ?? ()
#16 0x0000000000000003 in ?? ()
#17 0x00000004ac200040 in ?? ()
#18 0x00007fff469fb4f0 in ?? ()
#19 0x0000000000000001 in ?? ()
#20 0x0000000000000001 in ?? ()
#21 0x00007fb2a6e45480 in ?? ()
#22 0x0000556900000003 in ?? ()
#23 0x0000000000000002 in ?? ()
#24 0x0000000000000001 in ?? ()
#25 0x0000556925ed44c0 in ?? ()
#26 0x0000000000000001 in ?? ()
#27 0x0000556925ed44c0 in ?? ()
#28 0x3743e960f3c58a00 in ?? ()
#29 0x00007fff469fb870 in ?? ()
#30 0x00007fb2ac277000 in ?? ()
#31 0x00007fb2ac213020 in ?? ()
#32 0x0000556923f3f500 in ?? ()
#33 0x0000000000000000 in ?? ()

And the PHP modules loaded

[PHP Modules]
calendar
cgi-fcgi
Core
ctype
curl
date
dom
exif
FFI
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
igbinary
json
libxml
mbstring
memcache
memcached
msgpack
mysqli
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
random
readline
Reflection
session
shmop
SimpleXML
sockets
sodium
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tidy
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

~~Setting USE_ZEND_ALLOC=0 does not change this behaviour at all.~~ I had set the environment variable improperly, re-testing to see if this prevents the fault.

Edit: USE_ZEND_ALLOC=0 completely eliminates the issue.

PHP Version

8.2.10

Operating System

Debian 11.7

gnif avatar Oct 03 '23 07:10 gnif

Further information, here is the content of heap:

(gdb) print *heap
$5 = {use_custom_heap = 0, storage = 0x0, size = 5134936, peak = 5134936, free_slot = {0x7fb2ac201010, 0x7fb2ac268140, 0x7fb2ac349360, 
    0x7fb2ac344ae0, 0x7fb2a6f6c500, 0x7fb2ac36c4e0, 0x7fb2a6f0bb60, 0x7fb2ac36fcc0, 0x7fb2a7e352d0, 0x7fb2a7e36180, 0x7fb2a7e02150, 
    0x7fb2a7e3718067, 0x7fb2a6fbb6e0, 0x7fb2ac38f840, 0x7fb2a7e38380, 0x7fb2a6f65600, 0x7fb2a6e45fc0, 0x7fb2ac2a8400, 0x7fb2a6ea8540, 
    0x7fb2a6fcd600, 0x7fb2a6fef100, 0x7fb2a7f1b600, 0x7fb2a6fb9380, 0x7fb2ac32c800, 0x7fb2a6ff8100, 0x7fb2ac3fd400, 0x7fb2a6e8ba00, 
    0x7fb2a6ef0800, 0x7fb2a6fd0800, 0x0}, real_size = 14680064, real_peak = 14680064, limit = 134217728, overflow = 0, huge_list = 0x0, 
  main_chunk = 0x7fb2ac200000, cached_chunks = 0x7fb2a7a00000, chunks_count = 3, peak_chunks_count = 3, cached_chunks_count = 4, 
  avg_chunks_count = 6.9375, last_chunks_delete_boundary = 0, last_chunks_delete_count = 0, custom_heap = {std = {_malloc = 0x0, 
      _free = 0x0, _realloc = 0x0}, debug = {_malloc = 0x0, _free = 0x0, _realloc = 0x0}}, tracked_allocs = 0x0}

gnif avatar Oct 03 '23 08:10 gnif

Hi @gnif! Segfaults in Zend memory manager are usually caused by buffer overflows rather than bugs in ZMM itself. Are you using JIT? If so, could you try disabling it? It not, it would be helpful to build PHP with the ./configure --enable-address-sanitizer flag. This will make PHP crash immediately when the buffer overflow occurs. There are also quite a few non-bundled extensions. Can any of them be disabled to see if the error still occurs?

iluuu1994 avatar Oct 03 '23 08:10 iluuu1994

Unfortunately this is a production system, as such rebuilding with ASAN and disabling extensions are not possible here. I am also unable to reliably reproduce the crash in a controlled way as I can not generate enough traffic to trigger the bug.

I will disable JIT and report back if this resolves the issue.

gnif avatar Oct 03 '23 08:10 gnif

One other thing that should be noted, the state of the heap looks good, I don't see odd/strange values there that might indicate corruption that a buffer overflow would cause, however accessing element 11 in the free_slot results in the fault, which indicates it references memory that has been released/freed. Perhaps a garbage collection bug

gnif avatar Oct 03 '23 08:10 gnif

@gnif I suppose you're getting a segfault when dereferencing the pointer in heap->free_slot[11]? That pointer could still have been corrupted I suppose. But it's hard to tell retrospectively. PHP doesn't have a traditional garbage collector. It's just a cycle collector, that then triggers a free in zmm. Other objects are freed with ref-counting (also through zmm).

iluuu1994 avatar Oct 03 '23 08:10 iluuu1994

Understood. FTR so far it seems that disabling opcache.jit has worked.

gnif avatar Oct 03 '23 08:10 gnif

That's good to know, thank you! Unfortunately, JIT bugs are very hard to track down. There's also only one person who fully understands the JITs ins and outs (the person who wrote it). The good news is that a new JIT is in the works that is easier to understand and maintain, and hopefully will lead to fewer and easier to fix bugs. https://wiki.php.net/rfc/jit-ir

iluuu1994 avatar Oct 03 '23 08:10 iluuu1994

Sorry but it's not JIT related, we just had it occur several dozen times with it still disabled.

gnif avatar Oct 03 '23 12:10 gnif

@gnif Is the stack trace more helpful in that case? (without the jit traces)

iluuu1994 avatar Oct 03 '23 12:10 iluuu1994

Stack trace has not changed

gnif avatar Oct 03 '23 13:10 gnif

Correction sorry, yes it has, I was looking at the wrong terminal :)

#0  zend_mm_alloc_small (bin_num=22, heap=0x7fb2ac200040) at ./Zend/zend_alloc.c:1313
1313	./Zend/zend_alloc.c: No such file or directory.
(gdb) bt
#0  zend_mm_alloc_small (bin_num=22, heap=0x7fb2ac200040) at ./Zend/zend_alloc.c:1313
#1  zend_mm_alloc_heap (size=<optimized out>, heap=0x7fb2ac200040) at ./Zend/zend_alloc.c:1384
#2  _emalloc (size=<optimized out>) at ./Zend/zend_alloc.c:2601
#3  0x0000556923c0e1cb in zend_string_safe_alloc (persistent=false, l=<optimized out>, m=73, n=<optimized out>)
    at ./Zend/zend_string.h:163
#4  php_str_to_str_ex (haystack=haystack@entry=0x7fb2a6ea7c40, needle=needle@entry=0x5569255183b0 "../fonts", needle_len=8, 
    str=str@entry=0x7fb2a7104a28 "https://www.xxxxxxx.com/wp-content/plugins/woocommerce-menu-bar-cart/assets/fonts", str_len=81, 
    replace_count=replace_count@entry=0x7fff469fb3a0) at ./ext/standard/string.c:3026
#5  0x0000556923c0f505 in php_str_replace_in_subject (search_str=0x556925518398, search_ht=search_ht@entry=0x0, 
    replace_str=0x7fb2a7104a10, replace_ht=replace_ht@entry=0x0, subject_str=0x7fb2a6ea7c40, result=result@entry=0x7fb2ac213cb0, 
    case_sensitivity=true) at ./ext/standard/string.c:4271
#6  0x0000556923c10103 in php_str_replace_common (execute_data=<optimized out>, return_value=0x7fb2ac213cb0, case_sensitivity=true)
    at ./ext/standard/string.c:4340
#7  0x0000556923d1e135 in ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER () at ./Zend/zend_vm_execute.h:1312
#8  execute_ex (ex=0x7fb2ac200040) at ./Zend/zend_vm_execute.h:56044
#9  0x0000556923d24471 in zend_execute (op_array=0x7fb2ac27a000, return_value=0x0) at ./Zend/zend_vm_execute.h:60408
#10 0x0000556923cb3fcd in zend_execute_scripts (type=type@entry=8, retval=retval@entry=0x0, file_count=file_count@entry=3)
    at ./Zend/zend.c:1833
#11 0x0000556923c4e08e in php_execute_script (primary_file=primary_file@entry=0x7fff469fdb10) at ./main/main.c:2542
#12 0x0000556923ae95ee in main (argc=<optimized out>, argv=<optimized out>) at ./sapi/fpm/fpm/fpm_main.c:1920

Here is the zbacktrace too:

[0x7fb2ac213ce0] str_replace("../fonts", "https://www.xxxxxxx.com/wp-content/plugins/woocommerce-menu-bar-cart/assets/fonts", "@font-face
{font-family:WPMenuCart;src:url(../fonts/WPMenuCart.eot);src:url(../fonts/WPMenuCart.eot?#iefix) format('embedded-opentype'),url(../fonts
/WPMenuCart.woff2) format('woff2'),url(../fonts/WPMenuCart.woff) format('woff'),url(../fonts/WPMenuCart.ttf) ...") [internal function]
[0x7fb2ac213c50] WpMenuCart->get_parsed_font_css() 
/home/xxxxxxx/public_html/wp-content/plugins/woocommerce-menu-bar-cart/wp-menu-cart.php:411 
[0x7fb2ac213ae0] WpMenuCart->load_block_editor_styles(object[0x7fb2ac213b30]) 
/home/xxxxxxx/public_html/wp-content/plugins/woocommerce-menu-bar-cart/wp-menu-cart.php:517 
[0x7fb2ac213a00] WP_Hook->apply_filters(NULL, array(1)[0x7fb2ac213a60]) /home/xxxxxxx/public_html/wp-includes/class-wp-hook.php:310 
[0x7fb2ac213990] WP_Hook->do_action(array(1)[0x7fb2ac2139e0]) /home/xxxxxxx/public_html/wp-includes/class-wp-hook.php:334 
[0x7fb2ac2138d0] do_action_ref_array("wp_default_styles", array(1)[0x7fb2ac213930]) /home/xxxxxxx/public_html/wp-includes/plugin.php:565 
[0x7fb2ac213860] WP_Styles->__construct() /home/xxxxxxx/public_html/wp-includes/class-wp-styles.php:135 
[0x7fb2ac2137f0] wp_styles() /home/xxxxxxx/public_html/wp-includes/functions.wp-styles.php:24 
[0x7fb2ac213740] wp_register_style("powerpress-subscribe-style", "https://www.xxxxxxx.com/wp-content/plugins/powerpress/css/subscribe.css
", array(0)[0x7fb2ac2137b0], "20141021", "all") /home/xxxxxxx/public_html/wp-includes/functions.wp-styles.php:132 
[0x7fb2ac213610] powerpress_init(array(18)[0x7fb2ac213660]) /home/xxxxxxx/public_html/wp-content/plugins/powerpress/powerpress.php:2016 
[0x7fb2ac213530] WP_Hook->apply_filters("", array(1)[0x7fb2ac213590]) /home/xxxxxxx/public_html/wp-includes/class-wp-hook.php:310 
[0x7fb2ac2134c0] WP_Hook->do_action(array(1)[0x7fb2ac213510]) /home/xxxxxxx/public_html/wp-includes/class-wp-hook.php:334 
[0x7fb2ac2133e0] do_action("init") /home/xxxxxxx/public_html/wp-includes/plugin.php:517 
[0x7fb2ac213220] (main) /home/xxxxxxx/public_html/wp-settings.php:632 
[0x7fb2ac2131a0] (main) /home/xxxxxxx/public_html/wp-config.php:72 
[0x7fb2ac213100] (main) /home/xxxxxxx/public_html/wp-load.php:50 
[0x7fb2ac213070] (main) /home/xxxxxxx/public_html/wp-blog-header.php:13 
[0x7fb2ac213020] (main) /home/xxxxxxx/public_html/index.php:17

gnif avatar Oct 03 '23 13:10 gnif

@gnif Since the error now doesn't occur in unserialize anymore it seems the error is unrelated. Unfortunately, this will be hard to diagnose without ASAN. Can you see whether this affects a particular endpoint in your app? If so, maybe it would be possible to trigger this in a dev environment. If that's not possible, then I unfortunately do not now how to proceed.

iluuu1994 avatar Oct 03 '23 13:10 iluuu1994

Does this happen with opcache off too? Also might be worth trying to set opcache.protect_memory=1 and see if it happens more regularly then.

ndossche avatar Oct 03 '23 15:10 ndossche

Thanks guys, I am trying to arrange a build with ASAN and will update this with what I find (if anything)

gnif avatar Oct 04 '23 04:10 gnif

ASAN build is running and faults are occurring as the FPM log reports that children are exiting with code 1, but there are no longer any core dumps, nor is there any output from ASAN even when configuring the ASAN_OPTIONS with log-path.

If I set atexit=true ASAN does give me it's exit status when I terminate the process indicating I am looking in the right place for it's output

Edit: I am now rebuilding the modules with ASAN support also as it occurred to me that the fault may be there which is why ASAN is not catching it.

gnif avatar Oct 04 '23 07:10 gnif

@gnif Great! Thank you for your time investment! I'm guessing you already know, but ASAN will require the USE_ZEND_ALLOC=0 env var to properly catch buffer overflows (because ZMM puts them in shared pages that the application owns).

iluuu1994 avatar Oct 04 '23 08:10 iluuu1994

Unfortunately I can not reproduce the fault with this build as the PHP process ends up consuming so much RAM (90+GB) it gets terminated by the kernel's OOM killer.

gnif avatar Oct 06 '23 02:10 gnif

@gnif Hmm, that's unfortunate. :confused: What ./configure flags did you use? Also, does setting USE_TRACKED_ALLOC=1 (along with USE_ZEND_ALLOC=0 make a difference? ASAN does cause a slowdown of 2-3x but I don't know how much it is expected to affect memory, and how much memory is used without ASAN in your case.

iluuu1994 avatar Oct 09 '23 17:10 iluuu1994

I think I'm seeing the same issue as here, specifically with unserialize causing a segfault in zend_mm_alloc_small. In my case, it seems the free_slot array has an invalid pointer, but of course the segfault doesn't occur until READ, at which point it's not clear what was responsible for writing the pointer in the first place:

(gdb) print heap->free_slot
$3 = {0xffffb1001d60, 0xffffa50a6c90, 0xffff9f83a858, 0xffffa4e0d4c0, 0xffffa4e1f488, 0xffffa41466c0, 0xffff9fb27dc8, 0xffff9faa8640, 0xffff9fa93fa0, 
  0xffff9fa908a0, 0xffffa4e967e0, 0xffffa4965d80, 0xffff9fa5e6e0, 0xffff9fa94600, 0xffff9fb207e0, 0xffff9fa11700, 0xffffffff00000000, 0xffff9fa40e00, 
  0xffffa4f5b700, 0xffff9fb24200, 0xffffa41e8a80, 0xffffa4ffd500, 0xffff9fa58500, 0xffffa51f6400, 0xffff9fad8800, 0xffff9fa3be00, 0xffffb1102f00, 
  0xffffa4234000, 0xffff9faf7e00, 0xffffa4f11c00}

(See address 0xffffffff00000000).

I've tried using USE_ZEND_ALLOC=0 and address-sanitizer but that doesn't of course trigger the same code path and I can't reliably produce the segfaults / exits that way.

joehoyle avatar Oct 25 '23 09:10 joehoyle

It has been 3 years and we were unable to arrive at a reproducer with ASAN. I will close this issue as cannot reproduce. Since this issue has been raised many fixes landed including a new JIT. Please retest with the latest version to see if this is still happening.

kamil-tekiela avatar Nov 08 '26 17:11 kamil-tekiela