[sysvshm] Clamp shm_get_var chunk length to segment bounds - #290
Open
iliaal wants to merge 1 commit into
Open
Conversation
shm_get_var() trusted the sysvshm_chunk->length field read straight from the shared memory segment and handed it to php_var_unserialize() as the end bound: a hostile segment claiming a multi-gigabyte length made the parser read past ptr->end and past the end of the SysV mapping. Reject a negative or out-of-bounds length with the existing corruption warning and harden php_check_shm_data() so a chain walk never dereferences a chunk header that does not fully fit before ptr->end. Sibling audit: php_remove_shm_data() only memmoves when memcpy_len > 0, which bounds it to [shm_varpos, old end), and sysvmsg unserializes exactly msgrcv()'s kernel-bounded byte count, so both are unaffected.
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.
shm_get_var() trusted the sysvshm_chunk->length field read straight from the shared memory segment and handed it to php_var_unserialize() as the end bound, so a hostile segment claiming a multi-gigabyte length makes the parser walk past ptr->end and past the end of the SysV mapping before failing. The fix rejects a negative or out-of-bounds length with the existing corruption warning and hardens php_check_shm_data() so a chain walk never dereferences a chunk header that does not fully fit before ptr->end. Siblings audited: php_remove_shm_data() only memmoves when memcpy_len > 0 which bounds it to the old end, and sysvmsg unserializes exactly msgrcv()'s kernel-bounded byte count, so both are unaffected. A regression test crafts a hostile segment in-process via FFI and fails on the unpatched build.