Skip to content

ext/openssl: scrub symmetric key material before freeing - #23778

Merged
Girgias merged 1 commit into
php:masterfrom
jvoisin:zerossl
Sep 20, 2026
Merged

Girgias merged 1 commit into
php:masterfrom
jvoisin:zerossl

Conversation

@jvoisin

@jvoisin jvoisin commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

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.

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.

@Girgias Girgias left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems sensible

@Girgias
Girgias merged commit 5188744 into php:master Sep 20, 2026
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants