mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #1246] Memory leak in pfx format #785
Labels
No labels
bug
core branch
documentation
enhancement
enhancement
fixed - pending verify
fuzz bug
good first issue
invalid
invalid
maintenance/cleanup
new cracking mode
new format
new tool
non-trivial
notes/external issues
portability
question
RFC / discussion
testing
WONTFIX
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
openwall/john#785
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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:
An OMP build with ASan an memdbg produces
These are the culprits:
Apparently, d2i_PKCS12_bio points to newly allocated memory.
@jfoug commented on GitHub (Jun 25, 2015):
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
bbd1213Note 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.
@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'.
@frank-dittrich commented on GitHub (Jun 25, 2015):
/usr/include/openssl/pkcs12.h has
May be that can be used to get p12 from bp, so there would be no need to store all those pointers separately.
@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.
@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...
@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)