[packages/php/PHP_5_6] Rel 45. Backport the GHSA-68fq-fh7h-f8gr fix
arekm
arekm at pld-linux.org
Thu Nov 19 23:19:36 CET 2026
commit ff04a7915a81002e87a4f905917ad9252d72cf60
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Thu Nov 19 20:28:34 2026 +0100
Rel 45. Backport the GHSA-68fq-fh7h-f8gr fix
Read the openssl_sign() result before freeing it, so OpenSSL signed
phar archives no longer fall back to SHA-1 at random.
Fixes CVE-2026-128090.
php-cve-2026-128090.patch | 168 ++++++++++++++++++++++++++++++++++++++++
php-phar-openssl-sign-uaf.patch | 25 ++++++
php.spec | 7 +-
3 files changed, 199 insertions(+), 1 deletion(-)
---
diff --git a/php.spec b/php.spec
index 2ab250c..0bdb3b2 100644
--- a/php.spec
+++ b/php.spec
@@ -155,7 +155,7 @@ ERROR: You need to select at least one Apache SAPI to build shared modules.
%undefine with_filter
%endif
-%define rel 44
+%define rel 45
%define orgname php
%define ver_suffix 56
%define php_suffix %{!?with_default_php:%{ver_suffix}}
@@ -382,6 +382,9 @@ Patch442: php-cve-2026-129506.patch
Patch443: php-cve-2026-128064.patch
Patch444: php-cve-2026-127960.patch
Patch445: php-cve-2026-129481.patch
+Patch446: php-cve-2026-128090.patch
+# PLD-only: openssl_sign() result read after efree() (5.x-only code)
+Patch447: php-phar-openssl-sign-uaf.patch
URL: https://www.php.net/
%{?with_interbase:%{!?with_interbase_inst:BuildRequires: Firebird-devel >= 1.0.2.908-2}}
%{?with_pspell:BuildRequires: aspell-devel >= 2:0.50.0}
@@ -2440,6 +2443,8 @@ exit 1
%patch -P443 -p1
%patch -P444 -p1
%patch -P445 -p1
+%patch -P446 -p1
+%patch -P447 -p1
sed -E -i -e '1s,#!\s*/usr/bin/env\s+(.*),#!%{__bindir}\1,' \
run-tests.php
diff --git a/php-cve-2026-128090.patch b/php-cve-2026-128090.patch
new file mode 100644
index 0000000..265b824
--- /dev/null
+++ b/php-cve-2026-128090.patch
@@ -0,0 +1,168 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Alexandre Daubois <alex.daubois at gmail.com>
+Date: Fri, 13 Nov 2026 08:33:23 +0100
+Subject: [PATCH] Fix GHSA-68fq-fh7h-f8gr: refuse keyless phar signature when
+ .pubkey exists
+
+The signature type is not covered by the signature, so an OpenSSL signed
+phar could be downgraded to a keyless hash algorithm.
+
+Fixes GHSA-68fq-fh7h-f8gr
+Fixes CVE-2026-128090
+Backport of https://github.com/php/php-src/commit/7050cf338092a93e7d4caa4b7dc0bb8771f52a01
+
+5.6: PHAR_SIG_OPENSSL is the only OpenSSL signature type; test without PHP 7 syntax.
+---
+diff --git a/ext/phar/tests/ghsa-68fq-fh7h-f8gr.phpt b/ext/phar/tests/ghsa-68fq-fh7h-f8gr.phpt
+new file mode 100644
+--- /dev/null
++++ b/ext/phar/tests/ghsa-68fq-fh7h-f8gr.phpt
+@@ -0,0 +1,121 @@
++--TEST--
++GHSA-68fq-fh7h-f8gr (OpenSSL signature bypass by downgrading the algorithm to a keyless one)
++--SKIPIF--
++<?php
++if (!extension_loaded('phar')) die('skip phar extension not loaded');
++if (!extension_loaded('openssl')) die('skip openssl extension not loaded');
++if (!in_array("OpenSSL", Phar::getSupportedSignatures())) die("skip openssl support required");
++?>
++--INI--
++phar.readonly=0
++phar.require_hash=1
++--FILE--
++<?php
++$base = dirname(__FILE__) . '/' . basename(__FILE__, '.php');
++$private = openssl_pkey_get_private(file_get_contents(dirname(__FILE__) . '/files/private.pem'));
++$pkey = '';
++openssl_pkey_export($private, $pkey, null, array('config' => dirname(__FILE__) . '/files/openssl.cnf'));
++$pubkey = openssl_pkey_get_details($private)['key'];
++
++function build($file, $pkey)
++{
++ $phar = new Phar($file);
++ $phar['main.php'] = '<?php echo "GENUINE\n";';
++ $phar->setStub('<?php __HALT_COMPILER();');
++ $phar->setSignatureAlgorithm(Phar::OPENSSL, $pkey);
++
++ return file_get_contents($file);
++}
++
++// a phar built in this process comes back from the cache, so each case is read under its own name
++function open($file, $archive, $pubkey)
++{
++ file_put_contents($file, $archive);
++ if ($pubkey !== null) {
++ file_put_contents($file . '.pubkey', $pubkey);
++ }
++
++ try {
++ echo (new Phar($file))->getSignature()['hash_type'], "\n";
++ } catch (UnexpectedValueException $e) {
++ echo $e->getMessage(), "\n";
++ }
++}
++
++function downgrade_phar($archive)
++{
++ // the last 12 bytes are [length][algorithm]["GBMB"], the signature sits just before them
++ $siglen = unpack('V', substr($archive, -12, 4))[1];
++ $message = substr($archive, 0, strlen($archive) - 12 - $siglen);
++
++ return $message . hash('sha1', $message, true) . pack('V', 0x0002) . 'GBMB'; // 0x0002 is PHAR_SIG_SHA1, which needs no ext/hash
++}
++
++function downgrade_tar($archive)
++{
++ for ($offset = 0; $offset + 512 <= strlen($archive); ) {
++ $size = (int) octdec(trim(substr($archive, $offset + 124, 12), " \0")); // octal size field of a 512 byte header
++
++ if (rtrim(substr($archive, $offset, 100), "\0") === '.phar/signature.bin') {
++ // the signed message stops at this header, so rewriting the entry content leaves it alone
++ $blob = pack('VV', 0x0002, 20) . hash('sha1', substr($archive, 0, $offset), true); // [algorithm][digest length][digest]
++
++ return substr_replace($archive, str_pad($blob, $size, "\0"), $offset + 512, $size);
++ }
++
++ $offset += 512 + (($size + 511) & ~511);
++ }
++
++ throw new RuntimeException('no signature entry');
++}
++
++function downgrade_zip($archive)
++{
++ $eocd = strrpos($archive, "PK\x05\x06");
++ $cdir = unpack('V', substr($archive, $eocd + 16, 4))[1]; // the eocd holds the directory offset at +16 and the archive comment length at +20
++ $comment = substr($archive, $eocd + 22, unpack('v', substr($archive, $eocd + 20, 2))[1]);
++
++ for ($record = $cdir; substr($archive, $record, 4) === "PK\x01\x02"; ) {
++ $namelen = unpack('v', substr($archive, $record + 28, 2))[1];
++
++ if (substr($archive, $record + 46, $namelen) === '.phar/signature.bin') {
++ $size = unpack('V', substr($archive, $record + 24, 4))[1];
++ $local = unpack('V', substr($archive, $record + 42, 4))[1];
++ $content = $local + 30 + unpack('v', substr($archive, $local + 26, 2))[1] + unpack('v', substr($archive, $local + 28, 2))[1];
++ // the signed message is everything before the local entry plus the directory up to this record
++ $message = substr($archive, 0, $local) . substr($archive, $cdir, $record - $cdir) . $comment;
++ $blob = pack('VV', 0x0002, 20) . hash('sha1', $message, true);
++
++ return substr_replace($archive, str_pad($blob, $size, "\0"), $content, $size);
++ }
++
++ $record += 46 + $namelen + unpack('v', substr($archive, $record + 30, 2))[1] + unpack('v', substr($archive, $record + 32, 2))[1];
++ }
++
++ throw new RuntimeException('no signature entry');
++}
++
++foreach (array('phar' => 'downgrade_phar', 'phar.tar' => 'downgrade_tar', 'phar.zip' => 'downgrade_zip') as $suffix => $downgrade) {
++ $archive = build($base . '.source.' . $suffix, $pkey);
++ open($base . '.signed.' . $suffix, $archive, $pubkey);
++ open($base . '.tampered.' . $suffix, $downgrade($archive), $pubkey);
++ open($base . '.nokey.' . $suffix, $downgrade($archive), null);
++}
++?>
++--CLEAN--
++<?php
++$base = dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php');
++foreach (glob($base . '.*.phar*') as $file) {
++ unlink($file);
++}
++?>
++--EXPECTF--
++OpenSSL
++phar "%stampered.phar" SHA1 signature could not be verified: openssl public key found, but the signature does not use openssl
++SHA-1
++OpenSSL
++phar error: tar-based phar "%stampered.phar.tar" signature cannot be verified: openssl public key found, but the signature does not use openssl
++SHA-1
++OpenSSL
++phar error: signature cannot be verified: openssl public key found, but the signature does not use openssl in zip-based phar "%stampered.phar.zip"
++SHA-1
+diff --git a/ext/phar/util.c b/ext/phar/util.c
+--- a/ext/phar/util.c
++++ b/ext/phar/util.c
+@@ -1566,6 +1566,23 @@ int phar_verify_signature(php_stream *fp, size_t end_of_phar, php_uint32 sig_typ
+
+ php_stream_rewind(fp);
+
++ if (sig_type != PHAR_SIG_OPENSSL) {
++ php_stream_statbuf ssb;
++ char *pfile;
++ zend_bool has_pubkey;
++
++ spprintf(&pfile, 0, "%s.pubkey", fname);
++ has_pubkey = php_stream_stat_path_ex(pfile, PHP_STREAM_URL_STAT_QUIET, &ssb, NULL) == 0;
++ efree(pfile);
++
++ if (has_pubkey) {
++ if (error) {
++ spprintf(error, 0, "openssl public key found, but the signature does not use openssl");
++ }
++ return FAILURE;
++ }
++ }
++
+ switch (sig_type) {
+ case PHAR_SIG_OPENSSL: {
+ #ifdef PHAR_HAVE_OPENSSL
diff --git a/php-phar-openssl-sign-uaf.patch b/php-phar-openssl-sign-uaf.patch
new file mode 100644
index 0000000..4485687
--- /dev/null
+++ b/php-phar-openssl-sign-uaf.patch
@@ -0,0 +1,25 @@
+Subject: [PATCH] phar: read the openssl_sign() result before freeing it
+
+phar_call_openssl_signverify() freed the return value of openssl_sign() before
+testing it, so OpenSSL phar signing failed at random and fell back to SHA-1.
+---
+diff -up a/ext/phar/util.c b/ext/phar/util.c
+--- a/ext/phar/util.c
++++ b/ext/phar/util.c
+@@ -1530,14 +1530,15 @@ static int phar_call_openssl_signverify(
+ efree(retval_ptr);
+ return FAILURE;
+ case IS_BOOL:
+- efree(retval_ptr);
+ if (Z_BVAL_P(retval_ptr)) {
++ efree(retval_ptr);
+ *signature = estrndup(Z_STRVAL_P(zsig), Z_STRLEN_P(zsig));
+ *signature_len = Z_STRLEN_P(zsig);
+ zval_dtor(zsig);
+ efree(zsig);
+ return SUCCESS;
+ }
++ efree(retval_ptr);
+ zval_dtor(zsig);
+ efree(zsig);
+ return FAILURE;
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/php.git/commitdiff/ff04a7915a81002e87a4f905917ad9252d72cf60
More information about the pld-cvs-commit
mailing list