Repository navigation
Harden core engine against integer overflows, allocator canary recovery, and SSA shift range unsoundness #24590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1034,19 +1034,21 @@ static zend_always_inline void zend_mm_chunk_init(zend_mm_heap *heap, zend_mm_ch | |
| static zend_always_inline zend_mm_chunk *zend_mm_encode_cached_chunk(const zend_mm_heap *heap, const void *holder, const zend_mm_chunk *next) | ||
| { | ||
| #ifdef WORDS_BIGENDIAN | ||
| return (zend_mm_chunk*)((uintptr_t)next ^ heap->shadow_key ^ (uintptr_t)holder); | ||
| uintptr_t p = (uintptr_t)next; | ||
| #else | ||
| return (zend_mm_chunk*)(BSWAPPTR((uintptr_t)next) ^ heap->shadow_key ^ (uintptr_t)holder); | ||
| uintptr_t p = BSWAPPTR((uintptr_t)next); | ||
| #endif | ||
| /* ARX (Addition-XOR) non-linear mixing prevents linear algebraic shadow_key recovery */ | ||
| return (zend_mm_chunk*)((p + heap->shadow_key) ^ (uintptr_t)holder); | ||
|
Comment on lines
+1041
to
+1042
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain this change? |
||
| } | ||
|
|
||
| static zend_always_inline zend_mm_chunk *zend_mm_decode_cached_chunk_key(uintptr_t key, const void *holder, const zend_mm_chunk *encoded) | ||
| { | ||
| #ifdef WORDS_BIGENDIAN | ||
| zend_mm_chunk *next = (zend_mm_chunk*)((uintptr_t)encoded ^ key ^ (uintptr_t)holder); | ||
| #else | ||
| zend_mm_chunk *next = (zend_mm_chunk*)(BSWAPPTR((uintptr_t)encoded ^ key ^ (uintptr_t)holder)); | ||
| uintptr_t p = ((uintptr_t)encoded ^ (uintptr_t)holder) - key; | ||
| #ifndef WORDS_BIGENDIAN | ||
| p = BSWAPPTR(p); | ||
| #endif | ||
| zend_mm_chunk *next = (zend_mm_chunk*)p; | ||
|
|
||
| ZEND_MM_CHECK(ZEND_MM_ALIGNED_OFFSET(next, ZEND_MM_CHUNK_SIZE) == 0, "zend_mm_heap corrupted"); | ||
| return next; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -421,7 +421,10 @@ static zend_always_inline gc_root_buffer* gc_decompress(zend_refcounted *ref, ui | |
|
|
||
| while (1) { | ||
| idx += GC_MAX_UNCOMPRESSED; | ||
| ZEND_ASSERT(idx < GC_G(first_unused)); | ||
| if (UNEXPECTED(idx >= GC_G(first_unused))) { | ||
| zend_error_noreturn(E_CORE_ERROR, "GC root buffer corruption detected: unable to resolve compressed address"); | ||
| return NULL; | ||
| } | ||
|
Comment on lines
+424
to
+427
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain when this happens? |
||
| root = GC_IDX2PTR(idx); | ||
| if (GC_GET_PTR(root->ref) == ref) { | ||
| return root; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -612,6 +612,9 @@ static ssize_t php_userstreamop_write(php_stream *stream, const char *buf, size_ | |
| } else { | ||
| convert_to_long(&retval); | ||
| didwrite = Z_LVAL(retval); | ||
| if (didwrite < 0) { | ||
| didwrite = -1; | ||
|
Comment on lines
+615
to
+616
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please submit this as a separate PR on the PHP-8.4 branch with a test |
||
| } | ||
| } | ||
|
|
||
| /* don't allow strange buffer overruns due to bogus return */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please submit this as a separate PR on the PHP-8.4 branch with a test: