[php-src] master: ext/openssl: scrub symmetric key material before freeing (#23778)
| From: | Julien Voisin via GitHub | Date: | Sun, 20 Sep 2026 12:21:11 +0000 |
| Subject: | [php-src] master: ext/openssl: scrub symmetric key material before freeing (#23778) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141307@lists.php.net to get a copy of this message | ||
Author: Julien Voisin (jvoisin)
Committer: GitHub (web-flow)
Pusher: Girgias
Date: 2026-09-20T13:21:08+01:00
Commit: https://github.com/php/php-src/commit/5188744ef76b01b54474c881a536b5dfbc1492f6
Raw diff: https://github.com/php/php-src/commit/5188744ef76b01b54474c881a536b5dfbc1492f6.diff
ext/openssl: scrub symmetric key material before freeing (#23778)
When the supplied key is shorter than the cipher's key length,
php_openssl_cipher_init() allocates a heap buffer, copies the key into
it and zero-pads it to the required length. openssl_encrypt() and
openssl_decrypt() then efree() this buffer without wiping it, leaving
the raw symmetric key in a reclaimed heap chunk where it can later be
exposed through an uninitialized-heap read, a core dump or /proc.
Scrub the buffer with ZEND_SECURE_ZERO() before freeing it, matching
what ext/hash, ext/standard/crypt* and ext/sodium already do for key
material. At the free site password_len has already been set to the
full allocation size, so the whole buffer is cleared.
Changed paths:
M ext/openssl/openssl_backend_common.c
Diff:
diff --git a/ext/openssl/openssl_backend_common.c b/ext/openssl/openssl_backend_common.c
index 8adf1ac813f1..2ebee973ff86 100644
--- a/ext/openssl/openssl_backend_common.c
+++ b/ext/openssl/openssl_backend_common.c
@@ -1974,6 +1974,8 @@ PHP_OPENSSL_API zend_string* php_openssl_encrypt(
}
if (free_password) {
+ /* password points at a heap copy of the symmetric key; scrub it before freeing */
+ ZEND_SECURE_ZERO((void *) password, password_len);
efree((void *) password);
}
if (free_iv) {
@@ -2052,6 +2054,8 @@ PHP_OPENSSL_API zend_string* php_openssl_decrypt(
}
if (free_password) {
+ /* password points at a heap copy of the symmetric key; scrub it before freeing */
+ ZEND_SECURE_ZERO((void *) password, password_len);
efree((void *) password);
}
if (free_iv) {