[GH-ISSUE #1246] Memory leak in pfx format #785

Closed
opened 2026-10-14 03:23:50 +07:00 by bsakaguchi · 6 comments
Owner

Originally created by @frank-dittrich on GitHub (Apr 29, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1246

This is on Fedora 22 Beta 3, a non-OMP build without ASan and memdbg:

$ valgrind --leak-check=full ../run/john --test=0 --format=pfx
==16767== Memcheck, a memory error detector
==16767== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==16767== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==16767== Command: ../run/john --test=0 --format=pfx
==16767== 
Testing: PFX, PKCS12 (.pfx, .p12) [32/64]... PASS
==16767== 
==16767== HEAP SUMMARY:
==16767==     in use at exit: 146,671 bytes in 3,583 blocks
==16767==   total heap usage: 4,060 allocs, 477 frees, 2,666,926 bytes allocated
==16767== 
==16767== 3,098 (24 direct, 3,074 indirect) bytes in 1 blocks are definitely lost in loss record 649 of 661
==16767==    at 0x4C28C0F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==16767==    by 0x510B3C7: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A60C3: ??? (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A8B38: ASN1_item_ex_d2i (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A913A: ASN1_item_d2i (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x519D586: ASN1_item_d2i_bio (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x57E026: valid (pfx_fmt_plug.c:153)
==16767==    by 0x5DD71A: fmt_self_test_body (formats.c:223)
==16767==    by 0x5DD71A: fmt_self_test (formats.c:691)
==16767==    by 0x5D2F24: benchmark_format.part.1 (bench.c:248)
==16767==    by 0x5D3CC3: benchmark_all (bench.c:660)
==16767==    by 0x5E50EA: john_run (john.c:1319)
==16767==    by 0x5E5CD3: main (john.c:1697)
==16767== 
==16767== 6,007 (48 direct, 5,959 indirect) bytes in 2 blocks are definitely lost in loss record 652 of 661
==16767==    at 0x4C28C0F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==16767==    by 0x510B3C7: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A60C3: ??? (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A8B38: ASN1_item_ex_d2i (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A913A: ASN1_item_d2i (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x519D586: ASN1_item_d2i_bio (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x57DBF5: get_salt (pfx_fmt_plug.c:200)
==16767==    by 0x5D3198: benchmark_format.part.1 (bench.c:272)
==16767==    by 0x5D3CC3: benchmark_all (bench.c:660)
==16767==    by 0x5E50EA: john_run (john.c:1319)
==16767==    by 0x5E5CD3: main (john.c:1697)
==16767== 
==16767== 8,014 (72 direct, 7,942 indirect) bytes in 3 blocks are definitely lost in loss record 654 of 661
==16767==    at 0x4C28C0F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==16767==    by 0x510B3C7: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A60C3: ??? (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A8B38: ASN1_item_ex_d2i (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A913A: ASN1_item_d2i (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x519D586: ASN1_item_d2i_bio (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x57E026: valid (pfx_fmt_plug.c:153)
==16767==    by 0x5DD9E2: fmt_self_test_body (formats.c:310)
==16767==    by 0x5DD9E2: fmt_self_test (formats.c:691)
==16767==    by 0x5D2F24: benchmark_format.part.1 (bench.c:248)
==16767==    by 0x5D3CC3: benchmark_all (bench.c:660)
==16767==    by 0x5E50EA: john_run (john.c:1319)
==16767==    by 0x5E5CD3: main (john.c:1697)
==16767== 
==16767== 8,014 (72 direct, 7,942 indirect) bytes in 3 blocks are definitely lost in loss record 655 of 661
==16767==    at 0x4C28C0F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==16767==    by 0x510B3C7: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A60C3: ??? (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A8B38: ASN1_item_ex_d2i (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A913A: ASN1_item_d2i (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x519D586: ASN1_item_d2i_bio (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x57DBF5: get_salt (pfx_fmt_plug.c:200)
==16767==    by 0x5DDB1C: fmt_self_test_body (formats.c:394)
==16767==    by 0x5DDB1C: fmt_self_test (formats.c:691)
==16767==    by 0x5D2F24: benchmark_format.part.1 (bench.c:248)
==16767==    by 0x5D3CC3: benchmark_all (bench.c:660)
==16767==    by 0x5E50EA: john_run (john.c:1319)
==16767==    by 0x5E5CD3: main (john.c:1697)
==16767== 
==16767== 8,014 (72 direct, 7,942 indirect) bytes in 3 blocks are definitely lost in loss record 656 of 661
==16767==    at 0x4C28C0F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==16767==    by 0x510B3C7: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A60C3: ??? (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A8B38: ASN1_item_ex_d2i (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A913A: ASN1_item_d2i (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x519D586: ASN1_item_d2i_bio (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x57DBF5: get_salt (pfx_fmt_plug.c:200)
==16767==    by 0x5DE57F: fmt_self_test_body (formats.c:413)
==16767==    by 0x5DE57F: fmt_self_test (formats.c:691)
==16767==    by 0x5D2F24: benchmark_format.part.1 (bench.c:248)
==16767==    by 0x5D3CC3: benchmark_all (bench.c:660)
==16767==    by 0x5E50EA: john_run (john.c:1319)
==16767==    by 0x5E5CD3: main (john.c:1697)
==16767== 
==16767== 8,014 (72 direct, 7,942 indirect) bytes in 3 blocks are definitely lost in loss record 657 of 661
==16767==    at 0x4C28C0F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==16767==    by 0x510B3C7: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A60C3: ??? (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A8B38: ASN1_item_ex_d2i (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A913A: ASN1_item_d2i (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x519D586: ASN1_item_d2i_bio (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x57DBF5: get_salt (pfx_fmt_plug.c:200)
==16767==    by 0x5DDBF2: fmt_self_test_body (formats.c:435)
==16767==    by 0x5DDBF2: fmt_self_test (formats.c:691)
==16767==    by 0x5D2F24: benchmark_format.part.1 (bench.c:248)
==16767==    by 0x5D3CC3: benchmark_all (bench.c:660)
==16767==    by 0x5E50EA: john_run (john.c:1319)
==16767==    by 0x5E5CD3: main (john.c:1697)
==16767== 
==16767== 8,014 (72 direct, 7,942 indirect) bytes in 3 blocks are definitely lost in loss record 658 of 661
==16767==    at 0x4C28C0F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==16767==    by 0x510B3C7: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A60C3: ??? (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A8B38: ASN1_item_ex_d2i (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x51A913A: ASN1_item_d2i (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x519D586: ASN1_item_d2i_bio (in /usr/lib64/libcrypto.so.1.0.1k)
==16767==    by 0x57DBF5: get_salt (pfx_fmt_plug.c:200)
==16767==    by 0x5DDC50: fmt_self_test_body (formats.c:470)
==16767==    by 0x5DDC50: fmt_self_test (formats.c:691)
==16767==    by 0x5D2F24: benchmark_format.part.1 (bench.c:248)
==16767==    by 0x5D3CC3: benchmark_all (bench.c:660)
==16767==    by 0x5E50EA: john_run (john.c:1319)
==16767==    by 0x5E5CD3: main (john.c:1697)
==16767== 
==16767== LEAK SUMMARY:
==16767==    definitely lost: 432 bytes in 18 blocks
==16767==    indirectly lost: 48,743 bytes in 328 blocks
==16767==      possibly lost: 0 bytes in 0 blocks
==16767==    still reachable: 97,496 bytes in 3,237 blocks
==16767==         suppressed: 0 bytes in 0 blocks
==16767== Reachable blocks (those to which a pointer was found) are not shown.
==16767== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==16767== 
==16767== For counts of detected and suppressed errors, rerun with: -v
==16767== ERROR SUMMARY: 7 errors from 7 contexts (suppressed: 0 from 0)

An OMP build with ASan an memdbg produces

Will run 4 OpenMP threads
Testing: PFX, PKCS12 (.pfx, .p12) [32/64]... (4xOMP) PASS
At Program Exit
MemDbg_Validate level 0 checking Passed

=================================================================
==31274==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 792 byte(s) in 33 object(s) allocated from:
    #0 0x7fe4d1250a0a in malloc (/lib64/libasan.so.2+0x98a0a)
    #1 0x7fe4d0bcc3c7 in CRYPTO_malloc (/lib64/libcrypto.so.10+0x693c7)

Indirect leak of 88453 byte(s) in 603 object(s) allocated from:
    #0 0x7fe4d1250a0a in malloc (/lib64/libasan.so.2+0x98a0a)
    #1 0x7fe4d0bcc3c7 in CRYPTO_malloc (/lib64/libcrypto.so.10+0x693c7)

SUMMARY: AddressSanitizer: 89245 byte(s) leaked in 636 allocation(s).

These are the culprits:

==16767==    by 0x57E026: valid (pfx_fmt_plug.c:153)
if(!(p12 = d2i_PKCS12_bio(bp, NULL)))

==16767==    by 0x57DBF5: get_salt (pfx_fmt_plug.c:200)
if(!(p12 = d2i_PKCS12_bio(bp, NULL)))

Apparently, d2i_PKCS12_bio points to newly allocated memory.

Originally created by @frank-dittrich on GitHub (Apr 29, 2015). Original GitHub issue: https://github.com/openwall/john/issues/1246 This is on Fedora 22 Beta 3, a non-OMP build without ASan and memdbg: ``` $ valgrind --leak-check=full ../run/john --test=0 --format=pfx ==16767== Memcheck, a memory error detector ==16767== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==16767== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info ==16767== Command: ../run/john --test=0 --format=pfx ==16767== Testing: PFX, PKCS12 (.pfx, .p12) [32/64]... PASS ==16767== ==16767== HEAP SUMMARY: ==16767== in use at exit: 146,671 bytes in 3,583 blocks ==16767== total heap usage: 4,060 allocs, 477 frees, 2,666,926 bytes allocated ==16767== ==16767== 3,098 (24 direct, 3,074 indirect) bytes in 1 blocks are definitely lost in loss record 649 of 661 ==16767== at 0x4C28C0F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==16767== by 0x510B3C7: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A60C3: ??? (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A8B38: ASN1_item_ex_d2i (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A913A: ASN1_item_d2i (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x519D586: ASN1_item_d2i_bio (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x57E026: valid (pfx_fmt_plug.c:153) ==16767== by 0x5DD71A: fmt_self_test_body (formats.c:223) ==16767== by 0x5DD71A: fmt_self_test (formats.c:691) ==16767== by 0x5D2F24: benchmark_format.part.1 (bench.c:248) ==16767== by 0x5D3CC3: benchmark_all (bench.c:660) ==16767== by 0x5E50EA: john_run (john.c:1319) ==16767== by 0x5E5CD3: main (john.c:1697) ==16767== ==16767== 6,007 (48 direct, 5,959 indirect) bytes in 2 blocks are definitely lost in loss record 652 of 661 ==16767== at 0x4C28C0F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==16767== by 0x510B3C7: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A60C3: ??? (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A8B38: ASN1_item_ex_d2i (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A913A: ASN1_item_d2i (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x519D586: ASN1_item_d2i_bio (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x57DBF5: get_salt (pfx_fmt_plug.c:200) ==16767== by 0x5D3198: benchmark_format.part.1 (bench.c:272) ==16767== by 0x5D3CC3: benchmark_all (bench.c:660) ==16767== by 0x5E50EA: john_run (john.c:1319) ==16767== by 0x5E5CD3: main (john.c:1697) ==16767== ==16767== 8,014 (72 direct, 7,942 indirect) bytes in 3 blocks are definitely lost in loss record 654 of 661 ==16767== at 0x4C28C0F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==16767== by 0x510B3C7: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A60C3: ??? (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A8B38: ASN1_item_ex_d2i (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A913A: ASN1_item_d2i (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x519D586: ASN1_item_d2i_bio (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x57E026: valid (pfx_fmt_plug.c:153) ==16767== by 0x5DD9E2: fmt_self_test_body (formats.c:310) ==16767== by 0x5DD9E2: fmt_self_test (formats.c:691) ==16767== by 0x5D2F24: benchmark_format.part.1 (bench.c:248) ==16767== by 0x5D3CC3: benchmark_all (bench.c:660) ==16767== by 0x5E50EA: john_run (john.c:1319) ==16767== by 0x5E5CD3: main (john.c:1697) ==16767== ==16767== 8,014 (72 direct, 7,942 indirect) bytes in 3 blocks are definitely lost in loss record 655 of 661 ==16767== at 0x4C28C0F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==16767== by 0x510B3C7: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A60C3: ??? (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A8B38: ASN1_item_ex_d2i (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A913A: ASN1_item_d2i (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x519D586: ASN1_item_d2i_bio (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x57DBF5: get_salt (pfx_fmt_plug.c:200) ==16767== by 0x5DDB1C: fmt_self_test_body (formats.c:394) ==16767== by 0x5DDB1C: fmt_self_test (formats.c:691) ==16767== by 0x5D2F24: benchmark_format.part.1 (bench.c:248) ==16767== by 0x5D3CC3: benchmark_all (bench.c:660) ==16767== by 0x5E50EA: john_run (john.c:1319) ==16767== by 0x5E5CD3: main (john.c:1697) ==16767== ==16767== 8,014 (72 direct, 7,942 indirect) bytes in 3 blocks are definitely lost in loss record 656 of 661 ==16767== at 0x4C28C0F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==16767== by 0x510B3C7: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A60C3: ??? (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A8B38: ASN1_item_ex_d2i (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A913A: ASN1_item_d2i (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x519D586: ASN1_item_d2i_bio (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x57DBF5: get_salt (pfx_fmt_plug.c:200) ==16767== by 0x5DE57F: fmt_self_test_body (formats.c:413) ==16767== by 0x5DE57F: fmt_self_test (formats.c:691) ==16767== by 0x5D2F24: benchmark_format.part.1 (bench.c:248) ==16767== by 0x5D3CC3: benchmark_all (bench.c:660) ==16767== by 0x5E50EA: john_run (john.c:1319) ==16767== by 0x5E5CD3: main (john.c:1697) ==16767== ==16767== 8,014 (72 direct, 7,942 indirect) bytes in 3 blocks are definitely lost in loss record 657 of 661 ==16767== at 0x4C28C0F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==16767== by 0x510B3C7: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A60C3: ??? (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A8B38: ASN1_item_ex_d2i (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A913A: ASN1_item_d2i (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x519D586: ASN1_item_d2i_bio (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x57DBF5: get_salt (pfx_fmt_plug.c:200) ==16767== by 0x5DDBF2: fmt_self_test_body (formats.c:435) ==16767== by 0x5DDBF2: fmt_self_test (formats.c:691) ==16767== by 0x5D2F24: benchmark_format.part.1 (bench.c:248) ==16767== by 0x5D3CC3: benchmark_all (bench.c:660) ==16767== by 0x5E50EA: john_run (john.c:1319) ==16767== by 0x5E5CD3: main (john.c:1697) ==16767== ==16767== 8,014 (72 direct, 7,942 indirect) bytes in 3 blocks are definitely lost in loss record 658 of 661 ==16767== at 0x4C28C0F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==16767== by 0x510B3C7: CRYPTO_malloc (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A60C3: ??? (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A8B38: ASN1_item_ex_d2i (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x51A913A: ASN1_item_d2i (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x519D586: ASN1_item_d2i_bio (in /usr/lib64/libcrypto.so.1.0.1k) ==16767== by 0x57DBF5: get_salt (pfx_fmt_plug.c:200) ==16767== by 0x5DDC50: fmt_self_test_body (formats.c:470) ==16767== by 0x5DDC50: fmt_self_test (formats.c:691) ==16767== by 0x5D2F24: benchmark_format.part.1 (bench.c:248) ==16767== by 0x5D3CC3: benchmark_all (bench.c:660) ==16767== by 0x5E50EA: john_run (john.c:1319) ==16767== by 0x5E5CD3: main (john.c:1697) ==16767== ==16767== LEAK SUMMARY: ==16767== definitely lost: 432 bytes in 18 blocks ==16767== indirectly lost: 48,743 bytes in 328 blocks ==16767== possibly lost: 0 bytes in 0 blocks ==16767== still reachable: 97,496 bytes in 3,237 blocks ==16767== suppressed: 0 bytes in 0 blocks ==16767== Reachable blocks (those to which a pointer was found) are not shown. ==16767== To see them, rerun with: --leak-check=full --show-leak-kinds=all ==16767== ==16767== For counts of detected and suppressed errors, rerun with: -v ==16767== ERROR SUMMARY: 7 errors from 7 contexts (suppressed: 0 from 0) ``` An OMP build with ASan an memdbg produces ``` Will run 4 OpenMP threads Testing: PFX, PKCS12 (.pfx, .p12) [32/64]... (4xOMP) PASS At Program Exit MemDbg_Validate level 0 checking Passed ================================================================= ==31274==ERROR: LeakSanitizer: detected memory leaks Direct leak of 792 byte(s) in 33 object(s) allocated from: #0 0x7fe4d1250a0a in malloc (/lib64/libasan.so.2+0x98a0a) #1 0x7fe4d0bcc3c7 in CRYPTO_malloc (/lib64/libcrypto.so.10+0x693c7) Indirect leak of 88453 byte(s) in 603 object(s) allocated from: #0 0x7fe4d1250a0a in malloc (/lib64/libasan.so.2+0x98a0a) #1 0x7fe4d0bcc3c7 in CRYPTO_malloc (/lib64/libcrypto.so.10+0x693c7) SUMMARY: AddressSanitizer: 89245 byte(s) leaked in 636 allocation(s). ``` These are the culprits: ``` ==16767== by 0x57E026: valid (pfx_fmt_plug.c:153) if(!(p12 = d2i_PKCS12_bio(bp, NULL))) ==16767== by 0x57DBF5: get_salt (pfx_fmt_plug.c:200) if(!(p12 = d2i_PKCS12_bio(bp, NULL))) ``` Apparently, d2i_PKCS12_bio points to newly allocated memory.
bsakaguchi 2026-10-14 03:23:50 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@jfoug commented on GitHub (Jun 25, 2015):

==16767== by 0x57DBF5: get_salt (pfx_fmt_plug.c:200)
if(!(p12 = d2i_PKCS12_bio(bp, NULL)))

That one can not be 'fixed' unless we make a list of pointers to all we have allocated, and then call PKCS12_free() on all of those pointers in the done() method. Just not worth the ROI. These 'leaks' simply are memory not properly freed prior to program exit. It does not 'leak', because they are only allocated one time (during get_salt), and from then on, ARE needed to compute the hash.

The leak in valid is an easy fix, and has been done so in bbd1213

Note the leak in get_salt() is listed as an 'indirect leak' That simply is listed because we have not cleaned up the memory prior to exit. During the working mode of john, we did have usable pointers to the data. The leak in valid WAS a leak. I had added that code to valid, so that if we got a failure, it happened there, under the assumption that if it was OK there, then it would always be OK in get_salt. I had copied logic from get_salt, not knowing about the PKCS12_free() function.

I am not closing this bug, since there still is a leak report, BUT it really is gone.

<!-- gh-comment-id:115237192 --> @jfoug commented on GitHub (Jun 25, 2015): > ==16767== by 0x57DBF5: get_salt (pfx_fmt_plug.c:200) > if(!(p12 = d2i_PKCS12_bio(bp, NULL))) That one can not be 'fixed' unless we make a list of pointers to all we have allocated, and then call PKCS12_free() on all of those pointers in the done() method. Just not worth the ROI. These 'leaks' simply are memory not properly freed prior to program exit. It does not 'leak', because they are only allocated one time (during get_salt), and from then on, ARE needed to compute the hash. The leak in valid is an easy fix, and has been done so in bbd1213 Note the leak in get_salt() is listed as an 'indirect leak' That simply is listed because we have not cleaned up the memory prior to exit. During the working mode of john, we did have usable pointers to the data. The leak in valid WAS a leak. I had added that code to valid, so that if we got a failure, it happened there, under the assumption that if it was OK there, then it would always be OK in get_salt. I had copied logic from get_salt, not knowing about the PKCS12_free() function. I am not closing this bug, since there still is a leak report, BUT it really is gone.
Author
Owner

@jfoug commented on GitHub (Jun 25, 2015):

The usage of PKCS12_free() only reduces some of the leaks. There must be others, or other things needing freed up. On a -test run, the number of leak items dropped from 23 to 18 (there were 5 calls to the PKCS12_free() so that seems to be the reduction by 5).

It may be that on a failure, there is a leak, which we can not 'fix'.

<!-- gh-comment-id:115244484 --> @jfoug commented on GitHub (Jun 25, 2015): The usage of PKCS12_free() only reduces some of the leaks. There must be others, or other things needing freed up. On a -test run, the number of leak items dropped from 23 to 18 (there were 5 calls to the PKCS12_free() so that seems to be the reduction by 5). It may be that on a failure, there is a leak, which we can not 'fix'.
Author
Owner

@frank-dittrich commented on GitHub (Jun 25, 2015):

/usr/include/openssl/pkcs12.h has

int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12);

May be that can be used to get p12 from bp, so there would be no need to store all those pointers separately.

<!-- gh-comment-id:115245041 --> @frank-dittrich commented on GitHub (Jun 25, 2015): /usr/include/openssl/pkcs12.h has ``` int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12); ``` May be that can be used to get p12 from bp, so there would be no need to store all those pointers separately.
Author
Owner

@jfoug commented on GitHub (Jun 25, 2015):

Nope, all others come from the 'need to leak' from get_salt. I added a simple array of 200 pointers and a int counter. Then added pointers to that array in get_salt, and called PKCS12_free() within done, and the problem goes away. So all other leaks were in get_salt.

Note, the bp's are all freed, so they are of no use. We simply have to postpone the PKCS12_free() calls until done, but then track the pointers.

<!-- gh-comment-id:115247749 --> @jfoug commented on GitHub (Jun 25, 2015): Nope, all others come from the 'need to leak' from get_salt. I added a simple array of 200 pointers and a int counter. Then added pointers to that array in get_salt, and called PKCS12_free() within done, and the problem goes away. So all other leaks were in get_salt. Note, the bp's are all freed, so they are of no use. We simply have to postpone the PKCS12_free() calls until done, but then track the pointers.
Author
Owner

@frank-dittrich commented on GitHub (Jun 25, 2015):

Yes, you are right.To be able to free the p12 memory, we would need to use separate mallocs for all malloced p12 components, and then copy the contents of these components.
Then we could free p12.
May be there is more important stuff to be done...

<!-- gh-comment-id:115253182 --> @frank-dittrich commented on GitHub (Jun 25, 2015): Yes, you are right.To be able to free the p12 memory, we would need to use separate mallocs for all malloced p12 components, and then copy the contents of these components. Then we could free p12. May be there is more important stuff to be done...
Author
Owner

@jfoug commented on GitHub (Jun 25, 2015):

It was an easy fix. Once I did the quick/dirty method using a simple array (and index counter), to prove that this fixed the problem and would work, then turning it into a list was pretty trivial. Only took a couple minutes, and now it 'is' leak free.

The same type method may be needed in other areas, where we allocate and hold on to oSSL objects (I see gpg also has leaks). Using this type method does allow the format to do the costly allocations and setup one time (in salt), and then use them, but then properly clean itself up in the end (with the done() function)

<!-- gh-comment-id:115255413 --> @jfoug commented on GitHub (Jun 25, 2015): It was an easy fix. Once I did the quick/dirty method using a simple array (and index counter), to prove that this fixed the problem and would work, then turning it into a list was pretty trivial. Only took a couple minutes, and now it 'is' leak free. The same type method may be needed in other areas, where we allocate and hold on to oSSL objects (I see gpg also has leaks). Using this type method does allow the format to do the costly allocations and setup one time (in salt), and then use them, but then properly clean itself up in the end (with the done() function)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#785
No description provided.