Repository navigation
Conversation
shm_put_var() advanced the end of the data before shrinking the free space, and removing a variable grew the free space before moving the end back. A process killed between the two stores, by SIGKILL or the OOM killer, left a segment whose free space overstated what was left. The segment outlives the process, so later shm_put_var() calls wrote past its end. Order the stores so that the free space never exceeds what is left. A kill in the middle of a removal can still leave the moved variables inconsistent. Found while working on the removal of Zend Signals in php#25627.
A writer killed while removing a variable leaves bytes that look like chunks: the stale tail after the moved chunks, or a half moved chunk. The lookup trusted their sizes, so reading or replacing such a chunk read past the segment or moved its end out of bounds. Stop the lookup at the first chunk whose size or length does not fit the used area.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
While I was working on the removal of Zend Signals (#25627), @bukka found an atomicity problem with interned strings. I looked for similar patterns in the code base.
shm_put_var()advanced the end of the data before shrinking the free space, and removing a variable grew the free space before moving the end back. A process killed between the two stores, by SIGKILL or the OOM killer, left a segment whose free space overstated what was left. The segment outlives the process, so latershm_put_var()calls wrote past its end.This is independent of Zend Signals: sysvshm never blocked interruptions, and SIGKILL can't be deferred.
This PR orders the stores so that the free space never exceeds what is left. It also stops the lookup at the first chunk whose size or length doesn't fit in the used area, because a writer killed during a removal leaves stale bytes after the moved variables, and the lookup trusted the sizes it read there.
Reproduced on PHP-8.4 with gdb by sending SIGKILL between the two stores; the new test covers the lookup with a chunk corrupted through shmop.