Repository navigation
Fix GH-24319: opcache hash entries can be seen before they are initialised - #24320
iloveleon19 wants to merge 1 commit into
Conversation
…tialised zend_accel_hash_update() fills a new entry and links it into the bucket with plain stores while holding the SHM lock, but zend_accel_hash_find_ex() reads the hash without that lock. On weakly ordered CPUs a reader can reach an entry whose key, indirect or data stores are not visible yet. Publish with a release fence before the bucket store (and before updating data/indirect of an existing entry), and use an acquire fence after loading a non-NULL bucket head in zend_accel_hash_find_ex() and accelerator_get_scripts().
|
@iluuu1994 and @iloveleon19: There are broader issues here that fences won't fix. The writer does this: entry->data = target_entry; // data now points to a hash entry
entry->indirect = true; // announces that interpretationOPcache writers block other writers but not readers. Even if x86_64/aarch64 made those stores visible in exactly that order, another core can run between them. No memory reordering is necessary for the issue: There is also a less localized race:
I verified these problems on both aarch64 and x86_64. We can use a tagged pointer to fix this, since we only need a flag for "Is this direct or indirect?" and OPcache already aligns |
|
Prepared with an AI assistant; I reviewed it. The text below is AI-generated (quoted, as asked in CONTRIBUTING.md).
|
|
@iloveleon19 I already prepared a PR for it: #25258. |
Fixes #24319.
Prepared with an AI assistant; I reviewed the change and the test results. The text below is AI-generated (quoted, as asked in CONTRIBUTING.md).