Repository navigation
Fix GH-25528: Phar::setSignatureAlgorithm(): OpenSSL signing reads a freed private key - #25529
Closed
ArtUkrainskiy wants to merge 1 commit into
Closed
ArtUkrainskiy wants to merge 1 commit into
ArtUkrainskiy wants to merge 1 commit into
Conversation
LamentXU123
requested changes
Nov 17, 2026
| if (PHAR_G(openssl_privatekey)) { | ||
| efree(PHAR_G(openssl_privatekey)); | ||
| } | ||
| PHAR_G(openssl_privatekey) = key ? estrndup(key, key_len) : NULL; |
Member
There was a problem hiding this comment.
Can you use zend_string * here so we can use zend_string_copy and zend_string_release for better performance? (i.e. don't need to allocate a second buffer for privateKey)
Contributor
Author
There was a problem hiding this comment.
Done, thanks! It's a zend_string now, held with zend_string_copy() and released when the key is replaced and in RSHUTDOWN.
PHAR_G(openssl_privatekey) pointed into the key argument. Once that string was freed, the next flush of an OpenSSL-signed phar read freed memory to sign it, in the same request or in a later one. Keep the key as a zend_string with its own reference, and release it when it is replaced and at the end of the request.
ArtUkrainskiy
force-pushed
the
phar-openssl-key
branch
from
November 17, 2026 21:03
d1439ae to
c1eed28
Compare
ArtUkrainskiy
marked this pull request as ready for review
November 17, 2026 21:07
LamentXU123
approved these changes
Nov 18, 2026
Member
There was a problem hiding this comment.
LGTM. I want to wait for another people to have a look tho :) /cc @iliaal
iliaal
approved these changes
Nov 22, 2026
| mounted entries). (Lazizbek Ergashev) | ||
| . Fixed bug GH-24531 (Crash when modifying a zip-based phar whose file was | ||
| renamed). (Ilia Alshanetsky) | ||
| . Fixed bug GH-25528 (Phar::setSignatureAlgorithm(): OpenSSL signing reads a |
Member
There was a problem hiding this comment.
8.4.28 has already shipped. Could you move this entry to a new Phar section under 8.4.29?
Member
There was a problem hiding this comment.
Its fine I will do this when I merge up later.
iliaal
pushed a commit
to iliaal/php-src
that referenced
this pull request
Nov 22, 2026
* PHP-8.4: Fix phpGH-25528: Retain the Phar OpenSSL signing key (php#25529)
iliaal
pushed a commit
to iliaal/php-src
that referenced
this pull request
Nov 22, 2026
* PHP-8.5: Fix phpGH-25528: Retain the Phar OpenSSL signing key (php#25529)
arnaud-lb
added a commit
to bm1549/php-src
that referenced
this pull request
Nov 24, 2026
* PHP-8.5: (25 commits) [skip ci] Add APP_DEBUG=0 for Symfony Preloading test streams: fix stale readbuflen after stream_filter_remove() on a read filter Update NEWS for phpGH-20920 LibreSSL build fix Fix phpGH-20920: do not use OPENSSL_strndup() for peer CN matching Simplify php_openssl_load_all_certs_from_file() Fix phpGH-20920: only register PKCS7_NO_DUAL_CONTENT when it is defined Fix phpGH-20920: guard ENGINE_cleanup() with OPENSSL_NO_ENGINE again ext/soap: Fix NULL dereference on empty Body with matching SOAPAction (phpGH-25661) ext/dom: Fix use-after-free in getElementById() after removing an ID attribute ext/reflection: Don't call destructor when constructor is not public in newInstance(Args)() ext/phar: unset() of an entry with an open handle use-after-free. ext/intl: Fix IntlCalendar::setTime() build on PHP 8.5 and later ext/intl: Reject non-finite timestamps in IntlCalendar::setTime() (php#25668) [skip ci] Speed up community build [skip ci] Backport test-suite.yml changes from master Fix propagation of public(set) of readonly trait property Make test accept different outputs Fix phpGH-25528: Retain the Phar OpenSSL signing key (php#25529) ext/pdo_sqlite: Fix use-after-free of bound string and LOB parameters ext/opcache: Fix JIT ASSIGN_DIM undefined OP_DATA and dim reporting on non-array containers (phpGH-24665) ...
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.
Fixes GH-25528
UPDATED 17.11: after review, the key is a
zend_stringreference instead of a copy.Phar::setSignatureAlgorithm()stores a pointer into its$privateKeyargument inPHAR_G(openssl_privatekey)and doesn't copy the string. Every later write to the phar signs it again with that key. If the key string has been freed by then, signing reads freed memory. Afile_get_contents()result passed directly is enough:This keeps the key as a
zend_stringwith its own reference and releases it when the key is replaced and in RSHUTDOWN.The test passes the key the same way, then allocates a string of the same size so the freed block gets reused. Without the fix it fails on a normal build too, with "unable to process private key". ext/phar tests pass, also with ASan and ZTS. The merge up to 8.5 and later has a small conflict in util.c, at the phar_call_openssl_signverify() call this changes.