[php-src] PR #14803: [WIP] Attempt to fix opcache_reset() races

From: Date: Thu, 04 Jul 2024 00:00:17 +0000
Subject: [php-src] PR #14803: [WIP] Attempt to fix opcache_reset() races
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-27013@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/14803 Author: nielsdos This is related to both https://github.com/php/php-src/issues/8739 and https://github.com/php/php-src/issues/14471. In particular to the latter. I observe that there are data races possible against &ZCSG(hash) between zend_accel_hash_find_entry and zend_accel_add_key. We use the bucket return value from zend_accel_hash_find_entry and use it as a data pointer for zend_accel_add_key. However, if the &ZCSG(hash) table is modified in between those calls, then we end up with inconsistent data in the hash table. This is possible for example with opcache_reset(). We can observe this is the case by adding memset(accel_hash->hash_entries, 0xf0, sizeof(zend_accel_hash_entry )*accel_hash->max_num_entries); at the bottom of zend_accel_hash_clean which causes a dereference at address 0xf0f0f0f0f0f0f110 when walking the bucket chain in zend_accel_hash_find_entry. I ran the test from GH-14471 with opcache.interned_strings_buffer=0 and it is much more stable. Prior to this patch it would constantly crash after a while. With the interned strings buffer not zero I still observe crashes. Even with the buffer size 0, not all issues are fixed yet, see https://github.com/php/php-src/issues/8739#issuecomment-2207343834 for example. I would need some feedback or guidance. One problem I think is still there is when returning a string from the hash table with zend_string *str = zend_string_copy(persistent_script->script.filename);, if that string is in the interned hash table then nothing is preventing a restart from clearing out the filename string.

« previous php.git-pulls (#27013) next »