Skip to content

[sysvshm] Clamp shm_get_var chunk length to segment bounds - #290

Open
iliaal wants to merge 1 commit into
PHP-8.4from
fix/sysvshm-getvar-len-trust-84
Open

[sysvshm] Clamp shm_get_var chunk length to segment bounds#290
iliaal wants to merge 1 commit into
PHP-8.4from
fix/sysvshm-getvar-len-trust-84

Conversation

@iliaal

@iliaal iliaal commented Aug 24, 2026

Copy link
Copy Markdown
Owner

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant