Bug #76542 [NEW]: Memory leak during verify_peer_name validation of a SAN SSL certificate
| From: | php at lvl dot fastmail dot com | Date: | Thu, 28 Jun 2018 22:20:35 +0000 |
| Subject: | Bug #76542 [NEW]: Memory leak during verify_peer_name validation of a SAN SSL certificate | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-216025@lists.php.net to get a copy of this message | ||
From: php at lvl dot fastmail dot com
Operating system: Ubuntu 18.04
PHP version: 7.2.7
Package: OpenSSL related
Bug Type: Bug
Bug description:Memory leak during verify_peer_name validation of a SAN SSL certificate
Description:
------------
Originally discovered here:
https://github.com/reactphp/http-client/issues/134.
Verified with
version 7.2.7-1+ubuntu18.04.1+deb.sury.org+1 on Ubuntu 18.04, libssl
1.1.0g.
There's a memory leak in PHP's validation of SSL certificates when that
SSL certificate contains SAN entries. Since nearly every real world SSL
certificate uses SAN, this means every long-running PHP script that acts
as a HTTPS client will eventually run out of memory.
To reproduce, first create a self-signed certificate with SAN:
openssl req \
-newkey rsa:2048 \
-x509 \
-nodes \
-keyout server.key \
-new \
-out server.crt \
-subj /CN=127.0.0.1 \
-reqexts SAN \
-extensions SAN \
-config <(cat /etc/ssl/openssl.cnf \
<(printf '[SAN]\nsubjectAltName=DNS:127.0.0.1,DNS:127.0.0.2'))
\
-sha256 \
-days 3650
Then configure for example nginx to use this certificate:
server {
listen 443 ssl;
ssl_certificate /etc/nginx/server.crt;
ssl_certificate_key /etc/nginx/server.key;
return 201;
}
Finally run the test script below and observe using "top" that PHP's
memory usage is quickly increasing. Calls to memory_get_usage() will
*not* show signs of the leak though.
Running this test with a SSL certificate without the subjectAltName
entry will *not* trigger the memory leak.
Add ['verify_peer_name' => false] to the ssl context options and there
will *not* be a leak.
Test script:
---------------
<?php
$options = [
'ssl' => [
'verify_peer' => false
]
];
while (true) {
$response = file_get_contents('https://127.0.0.1', false,
stream_context_create($options));
}
--
Edit bug report at https://bugs.php.net/bug.php?id=76542&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76542&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76542&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76542&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76542&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76542&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76542&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76542&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76542&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76542&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76542&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76542&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76542&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76542&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76542&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76542&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76542&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76542&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76542&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76542&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76542&r=mysqlcfg