php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66942 memory leak in openssl_seal()
Submitted: 2014-03-22 21:28 UTC Modified: 2014-03-24 13:07 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:0 of 1 (0.0%)
From: chuanm at gmail dot com Assigned:
Status: Closed Package: OpenSSL related
PHP Version: 5.4.26 OS: centos 6.4
Private report: No CVE-ID: None
 [2014-03-22 21:28 UTC] chuanm at gmail dot com
Description:
------------
### Compiled with:

./confgiure --with-openssl --with-openssl-dir=/usr/lib64/openssl

### create keys
openssl genrsa -out privkey.pem 2048
openssl rsa -pubout -in privkey.pem -out pubkey.pem

Test script:
---------------
<?php
$data = 'this is test';

$cert = <<<ABC
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA01/7gxSlhLff2iKBNBIA
N77U+cdLl2g/YaJNjp4TQI33QY+P5VtP7coBxY2KyfhZAValyGmCzugSt4IlG/Jd
5FT+JSosUbbKSuSs4lia8mge0h7V5ius5ZvWTIqxtMtoxx36HLoaj4KQ32ToZjYM
/wI2ZMW9KD8WTFdezW7IKzc89DJ3AaoZaobRvUOjZVg8giLvsAFk4T3oWPS37Zed
uE4LkFdTnLxQ5y1rFWELpqm7E2itB+nLxHEq1Sb1w22iyXGqQSmaXC/b4SmjDLVw
W1lPjmYJt4NGNTgi3EAGWpCHnn9z1ERcOYX8lg+vTGftvejDgv/zvAuoWKiUO9lk
ywIDAQAB
-----END PUBLIC KEY-----
ABC;
$pk1 = openssl_get_publickey($cert);
openssl_seal($data, $sealed, $ekeys, array($pk1));

Expected result:
----------------
valgrind run should not complain about memory leak.

Actual result:
--------------
bash-4.1# valgrind --leak-check=full php openssl.php
==25769== Memcheck, a memory error detector
==25769== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==25769== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==25769== Command: php openssl.php
==25769==
==25769==
==25769== HEAP SUMMARY:
==25769==     in use at exit: 84,649 bytes in 2,704 blocks
==25769==   total heap usage: 15,468 allocs, 12,764 frees, 3,234,966 bytes allocated
==25769==
==25769== 1,032 bytes in 1 blocks are definitely lost in loss record 64 of 87
==25769==    at 0x4C279EE: malloc (vg_replace_malloc.c:270)
==25769==    by 0x614AB2D: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1e)
==25769==    by 0x61CA808: EVP_CipherInit_ex (in /usr/lib64/libcrypto.so.1.0.1e)
==25769==    by 0x45E46B: zif_openssl_seal (openssl.c:4318)
==25769==    by 0x6FD7A9: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:643)
==25769==    by 0x6F1BAF: execute (zend_vm_execute.h:410)
==25769==    by 0x68BD4D: zend_execute_scripts (zend.c:1315)
==25769==    by 0x631BED: php_execute_script (main.c:2502)
==25769==    by 0x7320D2: do_cli (php_cli.c:989)
==25769==    by 0x7327C3: main (php_cli.c:1365)
==25769==
==25769== 1,032 bytes in 1 blocks are definitely lost in loss record 65 of 87
==25769==    at 0x4C279EE: malloc (vg_replace_malloc.c:270)
==25769==    by 0x614AB2D: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1e)
==25769==    by 0x61CA808: EVP_CipherInit_ex (in /usr/lib64/libcrypto.so.1.0.1e)
==25769==    by 0x61D0B7C: EVP_SealInit (in /usr/lib64/libcrypto.so.1.0.1e)
==25769==    by 0x45E58D: zif_openssl_seal (openssl.c:4331)
==25769==    by 0x6FD7A9: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:643)
==25769==    by 0x6F1BAF: execute (zend_vm_execute.h:410)
==25769==    by 0x68BD4D: zend_execute_scripts (zend.c:1315)
==25769==    by 0x631BED: php_execute_script (main.c:2502)
==25769==    by 0x7320D2: do_cli (php_cli.c:989)
==25769==    by 0x7327C3: main (php_cli.c:1365)
==25769==
==25769== LEAK SUMMARY:
==25769==    definitely lost: 2,064 bytes in 2 blocks
==25769==    indirectly lost: 0 bytes in 0 blocks
==25769==      possibly lost: 0 bytes in 0 blocks
==25769==    still reachable: 82,585 bytes in 2,702 blocks
==25769==         suppressed: 0 bytes in 0 blocks
==25769== Reachable blocks (those to which a pointer was found) are not shown.
==25769== To see them, rerun with: --leak-check=full --show-reachable=yes
==25769==
==25769== For counts of detected and suppressed errors, rerun with: -v
==25769== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 6 from 6)

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-03-23 02:23 UTC] chuanm at gmail dot com
In ext/openssl/openssl.c, adding
         EVP_CIPHER_CTX_cleanup(&ctx);
at the end of the openssl_seal() function only removes one block of the memory leak. The following block still remains:

==30008==
==30008== HEAP SUMMARY:
==30008==     in use at exit: 83,617 bytes in 2,703 blocks
==30008==   total heap usage: 15,469 allocs, 12,766 frees, 3,235,070 bytes allocated
==30008==
==30008== 1,032 bytes in 1 blocks are definitely lost in loss record 64 of 86
==30008==    at 0x4C279EE: malloc (vg_replace_malloc.c:270)
==30008==    by 0x614AB2D: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1e)
==30008==    by 0x61CA808: EVP_CipherInit_ex (in /usr/lib64/libcrypto.so.1.0.1e)
==30008==    by 0x45E50B: zif_openssl_seal (openssl.c:4318)
==30008==    by 0x6FD4C9: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:643)
==30008==    by 0x6F18CF: execute (zend_vm_execute.h:410)
==30008==    by 0x68BA6D: zend_execute_scripts (zend.c:1315)
==30008==    by 0x63190D: php_execute_script (main.c:2502)
==30008==    by 0x731DF2: do_cli (php_cli.c:989)
==30008==    by 0x7324E3: main (php_cli.c:1365)
==30008==
==30008== LEAK SUMMARY:
==30008==    definitely lost: 1,032 bytes in 1 blocks
==30008==    indirectly lost: 0 bytes in 0 blocks
==30008==      possibly lost: 0 bytes in 0 blocks
==30008==    still reachable: 82,585 bytes in 2,702 blocks
==30008==         suppressed: 0 bytes in 0 blocks
==30008== Reachable blocks (those to which a pointer was found) are not shown.
==30008== To see them, rerun with: --leak-check=full --show-reachable=yes
==30008==
==30008== For counts of detected and suppressed errors, rerun with: -v
==30008== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 6 from 6)
 [2014-03-24 13:07 UTC] chuanm at gmail dot com
A similar memory leak on openssl_encrypt() was reported in https://bugs.php.net/bug.php?id=54060
 [2014-04-14 20:29 UTC] stas@php.net
Automatic comment on behalf of Chuan.Ma@avidlifemedia.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a186312832207437e4783024dcdece5232ac6c39
Log: Fix #66942: openssl_seal() memory leak
 [2014-04-14 20:29 UTC] stas@php.net
-Status: Open +Status: Closed
 [2014-04-14 20:38 UTC] stas@php.net
Automatic comment on behalf of Chuan.Ma@avidlifemedia.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a186312832207437e4783024dcdece5232ac6c39
Log: Fix #66942: openssl_seal() memory leak
 [2014-04-14 20:38 UTC] stas@php.net
Automatic comment on behalf of Chuan.Ma@avidlifemedia.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f413a77b3ddca0abcf4552db070618af635c4bc1
Log: Fix #66942: openssl_seal() memory leak
 [2014-04-14 20:38 UTC] stas@php.net
Automatic comment on behalf of Chuan.Ma@avidlifemedia.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8d05a777adc13f12cc6504120d43b1cc020cfba3
Log: Fix #66942: openssl_seal() memory leak
 [2014-04-15 12:04 UTC] ab@php.net
Automatic comment on behalf of Chuan.Ma@avidlifemedia.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f413a77b3ddca0abcf4552db070618af635c4bc1
Log: Fix #66942: openssl_seal() memory leak
 [2014-04-15 12:04 UTC] ab@php.net
Automatic comment on behalf of Chuan.Ma@avidlifemedia.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a186312832207437e4783024dcdece5232ac6c39
Log: Fix #66942: openssl_seal() memory leak
 [2014-04-15 13:05 UTC] ab@php.net
Automatic comment on behalf of Chuan.Ma@avidlifemedia.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8d05a777adc13f12cc6504120d43b1cc020cfba3
Log: Fix #66942: openssl_seal() memory leak
 [2014-04-15 13:05 UTC] ab@php.net
Automatic comment on behalf of Chuan.Ma@avidlifemedia.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f413a77b3ddca0abcf4552db070618af635c4bc1
Log: Fix #66942: openssl_seal() memory leak
 [2014-04-15 13:05 UTC] ab@php.net
Automatic comment on behalf of Chuan.Ma@avidlifemedia.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a186312832207437e4783024dcdece5232ac6c39
Log: Fix #66942: openssl_seal() memory leak
 [2014-05-01 14:59 UTC] tyrael@php.net
Automatic comment on behalf of Chuan.Ma@avidlifemedia.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f413a77b3ddca0abcf4552db070618af635c4bc1
Log: Fix #66942: openssl_seal() memory leak
 [2014-05-01 14:59 UTC] tyrael@php.net
Automatic comment on behalf of Chuan.Ma@avidlifemedia.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=a186312832207437e4783024dcdece5232ac6c39
Log: Fix #66942: openssl_seal() memory leak
 [2014-10-07 23:15 UTC] stas@php.net
Automatic comment on behalf of Chuan.Ma@avidlifemedia.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=a186312832207437e4783024dcdece5232ac6c39
Log: Fix #66942: openssl_seal() memory leak
 [2014-10-07 23:26 UTC] stas@php.net
Automatic comment on behalf of Chuan.Ma@avidlifemedia.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=a186312832207437e4783024dcdece5232ac6c39
Log: Fix #66942: openssl_seal() memory leak
 [2016-07-20 11:40 UTC] davey@php.net
Automatic comment on behalf of Chuan.Ma@avidlifemedia.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8d05a777adc13f12cc6504120d43b1cc020cfba3
Log: Fix #66942: openssl_seal() memory leak
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 10:01:29 2024 UTC