fix(prof): crash in ZEND_INIT_ARRAY #3255
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PROF-11814
Description
A PHP application may crash happen if:
The engine currently does not save the opline in ZEND_INIT_ARRAY. Usually if it's out-dated and the line-number is a bit stale, it's not a big deal. But in some cases the opline will be dangling, and in those cases we read invalid memory. This is a bug in the PHP VM that needs to also be fixed upstream: php/php-src#18578. Since PHP 8.1 and 8.2 are in security fixes only, this will go into PHP 8.3 and 8.4, and we'll have to mitigate it on <8.3.
The fix works because by having a user opcode handler the engine will save the opline before it calls the user opcode handler. This has a small performance penalty for this specific opcode.
I do not have a reproducer for this one yet, but we've hit this issue before in other opcodes. I'm fairly confident this needs to be done until there is an upstream fix in PHP, then we can restrict this mitigation to version-specific ranges.
Reviewer checklist