mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #843] memdbg issues #456
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#456
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 @magnumripper on GitHub (Nov 4, 2014).
Original GitHub issue: https://github.com/openwall/john/issues/843
Originally assigned to: @jfoug on GitHub.
This does not happen with 8xOMP:
It is simply due to mdbg_size being just ARCH_WORD_32. Most other sizes are unsigned long (BTW why not size_t?!).
For keeping alignment as intended in the above struct, we need to change all of the ARCH_WORD_32's to unsigned long (or size_t). BTW I do not understand that comment about non-aligned hw. How would it ever become 6 values? Maybe it describes some earlier version.
Anyway, while changing mdbg_size to unsigned long does fix the above problem, it does not fix the below:
This allocation information output is not printed at all at OMP_NUM_THREADS=1 or when testing fewer formats (eg. -format:pbkdf2*). Looks like the result of unwanted sign extension somewhere:
I even tried changing all ARCH_WORD_32 and unsigned long's as well as some int (idx) to size_t, to no avail. Somewhere we assign a signed int larger than 2G to one of the memdbg variables. Perhaps in memory.c? But I can't find it.
@jfoug commented on GitHub (Nov 4, 2014):
This likely comes from how you did memdbg in the new makefile. YES, I am working to get the 64 bit stuff working better.
I am going to change how you did this. I really do not like it I know it was a pain with memdbg_defines.h, and the biggest pain is GIT itself. What I do not like is the extra checks being turned on by default Extra checks is NOT normal usage. In that mode, it never frees memory, and slows down runtime a lot.
@jfoug commented on GitHub (Nov 4, 2014):
Can you test with
f407415and make sure the numbers look good. NOTE you may have to rebuild to make it crash, usingmake memdbg_ex(after a new ./configure)@jfoug commented on GitHub (Nov 4, 2014):
I got an error on OMP=16 linux (memdbg not memdbg_ex)
@jfoug commented on GitHub (Nov 4, 2014):
some of these huge numbers may not be sign extension, but may be double deletes.
@magnumripper commented on GitHub (Nov 4, 2014):
Like I said I still have the issue at 8xOMP
I agree your problems (which I can't reproduce now btw) doesn't look like sign extension. But this surely does.
@jfoug commented on GitHub (Nov 5, 2014):
Can you retest now that you have fixed many static buffer overwrites (the base64 stuff)
@jfoug commented on GitHub (Nov 5, 2014):
This might be a OMP bug in memdbg, where somehow I need to put in some flags listing that certain other vars are omp dangerous. I will dig into this later today.
@jfoug commented on GitHub (Nov 5, 2014):
These formats are having problems for me, with OMP (and memdbg)
both scrypts (scrypt/django-scrypt) rar and LUKS. All other formats are happy.
I think these are the formats that malloc INSIDE the crypt in the OMP block. I am pretty sure that what we are seeing is that memdbg does not properly critical section itself in all cases. I have been looking, and can not file it. I have tons of debugging stuff, and what happens (scrypt) is that a free is called, (a set of them) and memdbg does not think it has that much memory allocated any more. It is almost like free is being called against the same pointer, BUT I am not seeing crashes from multiple frees, etc. I just do not get this one, and have put in a LOT of debugging. It is almost like the named omp critical sections are NOT working properly.
@jfoug commented on GitHub (Nov 6, 2014):
I 'may' have found this one. I had to add volatile to all of the data within memdbg.c (and some function params). I will see if I need this. Also, if this IS the fix, I will not use volatile, but use a #define that can be turned off for non OMP builds.
@jfoug commented on GitHub (Nov 6, 2014):
So it appears that the OMP crit sections are there now, AND that with the addition of many volatiles, I now have it working properly. I do have LOTS of changes. I am going to back some of them out, testing to make sure things continue to work. But hopefully, this issue will now go away.
@jfoug commented on GitHub (Nov 6, 2014):
Nope, this did not fix. It is a little better, but not fixed. 👎
@magnumripper commented on GitHub (Nov 7, 2014):
From http://stackoverflow.com/questions/10522026/c-openmp-critical-one-way-locking:
"The
#pragma omp atomicand#pragma omp flushdirectives may also be useful.atomiccauses a write to a memory location (lvalue in the expression preceded by the directive) to always be atomic.flushensures that any memory expected to be available to all threads is actually written to all threads, not stored in a processor cache and unavailable where it should be."@magnumripper commented on GitHub (Nov 7, 2014):
This looks like something I should read too: http://www.michaelsuess.net/publications/suess_leopold_common_mistakes_06.pdf
Maybe some of our
#pragma omp criticalfor things likeany_crackedcould be atomic instead of critical.@magnumripper commented on GitHub (Nov 7, 2014):
On a side note that lead to
d557419d@jfoug commented on GitHub (Nov 7, 2014):
OMG! I just found this line in memdbg.c #undef _OPENMP
5982c26is where this undef was added. I am not sure why, but it is causing ALL of the #ifdef _OPENMP code to simply not be compiled in, and thus, no critical sections.@magnumripper commented on GitHub (Nov 7, 2014):
LOL, that might be it!
@jfoug commented on GitHub (Nov 7, 2014):
I am pretty sure that was the problem. I thought I had spent a LOT of time getting OMP safe allocation functions (realloc was the worse). I have done some changes that I do want to keep, so will be adding them also. The problem I am getting is that some ancillary tools now link fail (markov stuff etc). This can be fixed in a couple of ways. 1 is to add OMP to markov IF building jtr in OMP mode. The 2nd is to build memdbg.o a 2nd time without omp.
I am not sure which is the best alternative. I would rather add OMP to the extras, if building in OMP mode. @magnumripper what is your choice? Either way, it will be a change to makefile.in and to the legacy makefile set.
@magnumripper commented on GitHub (Nov 7, 2014):
I too would rather add OMP to the extras. That's a no-op for them so can't hurt.
@jfoug commented on GitHub (Nov 7, 2014):
That was my feeling, and I think safer than trying to build a memdbg 2 ways (with 3 flavors of memdbg already, so that would be 6 flavors). Adding @OMP_CFLAGS@ to the .in file is I think all that needs to be done (other than legacy)
@magnumripper commented on GitHub (Nov 7, 2014):
We could do this only when building memdbg, but I think it's not worth the extra work. Just add it to them.
@jfoug commented on GitHub (Nov 8, 2014):
Worked fine.
This 'audit' of memdbg did turn up one HUGE lacking problem. i checked code, and the only place it was used is in sip2john, BUT that code has problems of its own (I will make a bug report about it). That problem is that calloc is NOT wrapped by memdbg, BUT if used, then free would be used, which IS wrapped. This must have some how gotten dropped when I ported this code, and I simply missed it. I added it (super trivial). Calloc simply calls MEMDBG_malloc (passing in proper file and line), and then memsets the returned pointer and returns that pointer. I can not believe this was missed.
sip2john has a ton of utility functions (including malloc wrappers) in a header file. There was a calloc in there (only place raw calloc is in john right now), BUT it was included prior to memdbg.h since it is a HEADER.
We REALLY need to look long and hard at putting code into headers. That is REALLY bad practice. If anything, if we have code we want to include (simply to keep the strange behavior of all static functions), then we should put it into a *.cx or *.ci or something other than *.h Getting away from the 'C' convention of only having declarations in a .h file is not a good thing to do.
@magnumripper commented on GitHub (Nov 8, 2014):
I think it's totally logical to
#include "salt_hash.c"but apparently that is arguable, https://github.com/magnumripper/JohnTheRipper/issues/809#issuecomment-60796903@jfoug commented on GitHub (Nov 8, 2014):
I have seen .c files included also. It is not 'normal' way, but it is less likely to hide things. The problem with including .c files is when environments want to include it into a build package. One other thing that jumps out as a issue here, is if there are things that should be done to all source (like memdbg.h include). Well, now you have a .c file that does not have that.
I know we have a couple instances where we have shared code for things like valid, BUT have them as static functions in some header. A better way, would be to not have them as static, but make them unique and safe. A function like jtr_PBKDF2_HMAC_SHA1_valid() Put the delcaration in a header, the definition in some c file (or even code it into ONE of the format files), and then put jtr_PBKDF2_HMAC_SHA1_valid into the function pointer part of the format structure in each *fmt.c file. Yes, that one would not be static. But the name is also not going to collide with anything else. The ugliness could even be hidden with a strategically placed
#define valid jtr_PBKDF2_HMAC_SHA1_valid
so that you do not have to use the ugly form.
@magnumripper commented on GitHub (Nov 8, 2014):
The reason we want to use shared functions in headers is function inlining. The way you suggest would ruin that (unless possibly if you run icc with some heavy extra options), and the performance loss can be very signifcant.
I fail to see the problem. Since it's a .c file, you won't miss it when considering to add stuff to all C files. Also, we could change our "memdbg.h must be last" guideline to "memdbg.h must be last .h file but any included .c file must come after that"
@magnumripper commented on GitHub (Nov 10, 2014):
No problem seen with just memdbg, but using memdbg_ex there is a new problem:
Same problem with just -form:descrypt too.
@jfoug commented on GitHub (Nov 10, 2014):
Trivial and stupid bug (copy / paste error). In the MEMDBG_free function, I was not setting the trailing fence post to the deleted signature. I was simply re-setting it back to what is normal alloc signature.
@jfoug commented on GitHub (Nov 10, 2014):
f84508efixes this problem Now I will see if travis sends me an email (I think I registered), or does it only send emails upon failures?@magnumripper commented on GitHub (Nov 10, 2014):
I think you'll get an email under any of these conditions:
For this reason, not even I get an email when someone else commits something that make it fail. I only get it once I commit something and it still fails (no 2 above). This is configurable but I'm not quite sure how.