mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #1735] Large alignments on stack (eg. AVX2) #1149
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#1149
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 (Sep 6, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1735
Originally assigned to: @magnumripper on GitHub.
See also #1731 and http://www.openwall.com/lists/john-dev/2015/09/06/5
Perhaps write an autoconf test that can safely detect whether large stack alignments (i.e. MEM_ALIGN_SIMD for AVX2 and above) work, and if so set SAFE_ALIGN_SIMD or whatever macro. This means we can optimize things currently always using
mem_align(), especially in pseudo_intrinsics.h and simd-intrinsics.c.Actually we could already set that macro for any build where sizeof(vtype) <= 16.
@magnumripper commented on GitHub (Sep 6, 2015):
The AC test need to be very thorough though. I think we've sometimes seen problems surface only under OMP.
@jfoug commented on GitHub (Sep 6, 2015):
This was posted as a line comment
github.com/magnumripper/JohnTheRipper@1bd8d9dc2c (commitcomment-13086395)This is the way to go, not to probe.
However, I have to get it working being integrated into john's code. I have stand alone samples showing it is 100% correct. But I am having issues with john..
What this does is simply add the appropriate value to the memory pointer, based upon it's address. All done without writing anything to any memory location or calling a function.
@jfoug commented on GitHub (Sep 6, 2015):
Think I found the problem. There was a #undef mem_align at bottom of pseudo_intrinsics I missed.
That was it. Building now, and no warnings. That #undef was causing my define to get lost for any SIMD format.
Let me get build done, test it, and check in. Once done, this should close this issue once and for all. For aligned stack values, we build a buffer large enough + the SIMD size (or whatever alignment we are using), then use mem_align(a,b) like always, but it will simply be a simple mathematical adjustment to the pointer, to move it to the next properly aligned location (which may be the actual original starting pointer).
No need to probe or anything else, and have things get missed.
@jfoug commented on GitHub (Sep 6, 2015):
Think I found the problem, I was getting crashes. I have to typecast a to unsigned char before doing the -1
Finally got it (glad I wrote a 'test' app, lol)
@jfoug commented on GitHub (Sep 6, 2015):
here is the test:
It tests different sized buffers, testing each for 16, 32 and 64 byte offsets. This test was against the functional version.
@jfoug commented on GitHub (Sep 6, 2015):
Checked in here. This issue should now be moot.
@magnumripper commented on GitHub (Sep 7, 2015):
The macro is much better.
Solar described more problems though: http://www.openwall.com/lists/john-dev/2015/09/06/5
Re-opening for evaluation.
@jfoug commented on GitHub (Sep 7, 2015):
If you dig more into that thread, Solar and I did talk about bit more about some of these issues. Put no code into play, but there is more ideas bouncing around, good and bad.
@magnumripper commented on GitHub (Sep 7, 2015):
What you suggested in http://www.openwall.com/lists/john-dev/2015/09/06/9 is pretty slick. I'll experiment a little with that.
I wonder though, why we've only seen probems for real in a few formats and only under OpenMP. As far as I know we've never seen problems with explicit vector declarations that ends up in memory due to register spill. Maybe gcc actually handles that properly. If we can confirm that, we can use it:
Instead of:
We'd just do:
@magnumripper commented on GitHub (Sep 8, 2015):
This might be part of a canonical solution:
...but there's more to it than the above. First, we should only do it for AVX2 or higher. Second, it should not always be "5" - it should be the log2 of
sizeof(vtype).Third, this might not help under Windows (at least not MinGW64) unless they fixed that now. So we'd still need alternative code paths like the current mem_align stuff.
@magnumripper commented on GitHub (Sep 8, 2015):
-mpreferred-stack-boundary doesn't seem to help at all, but there are other ways around it:
http://www.openwall.com/lists/john-dev/2015/09/08/14
Oh, and the -mincoming-stack-boundary option isn't even present in gcc-4.9 and later.
@magnumripper commented on GitHub (Sep 8, 2015):
I currently believe this is all a red herring except the case (that we've actually seen IRL) where we declare variables local to an OMP parallel block, and try to use
JTR_ALIGN()(a.k.a__attribute__ ((aligned()))). Unless my theory is debunked we should revert most of1bd8d9d, especially the change tomd5cryptsse().@magnumripper commented on GitHub (Sep 9, 2015):
@jfoug I believe your mem_align macro might actually be optimized away when needed the most:
http://www.openwall.com/lists/john-dev/2015/09/09/3
We'll see - let's remember this in case we see impossibe things happen.
@jfoug commented on GitHub (Sep 9, 2015):
Remembered. However, I fail to see how this ever could be optimized away. It 'may' be when the constants used are known by the compiler to be what the stack already is aligned to, however, since all usages are against char* or unsigned* arrays, the compiler will only be aligning stack to 4 or 8 bytes, so there should be no chance the compiler runs the math, completing the expression and finding that no work is ever being done. If it does optimize it away, it would only be done by bugs in the optimizer, or if we tried to align to 4 bytes or something.
@jfoug commented on GitHub (Sep 9, 2015):
One other huge difference in using the macro is that the way the macro is used, there is always an lparam expression, where your expression was a simple read test that affected nothing in the running environment other than conditional logic.
I am a bit surprised yours was optimized away, but I do understand the optimizer wanting to optimize it away. I would just think it should not. I bet it was optimized away, because it knew that it was always aligning stuff 32 bytes. But then comes along a library that does the stack work, not the compiler, and bam, that 'knowledge' that the compiler had is no longer correct.
I could be wrong however, and it is only due to my expression being complex enough that the current optimizer does not recognize it, and that when newer versions of the compiler are released, they improve the amount of code run simulation being done, and again think there is no reason to emit any code for this macro.
@magnumripper commented on GitHub (Sep 9, 2015):
Did some more tests today. I can reliably see gcc-4.8 optimize away that test (when not in a separate function) but I have yet to see it do so with the macro. So I think we're safe.
@jfoug commented on GitHub (Sep 9, 2015):
I honestly think it is NOT going to reduce the expression all the way out, simply because it is an expression that can not be fully expressed at compile time. Now, if the compiler really got smart, and realized just what the expression was trying to do, and then stripped the emiited code down to
buf = _buf;
then we have problems. I just do not see that, since I have mixed up 2 or 3 pointers, some conversion into an integer (which can NOT be known during compile), and some other stuff. Even though the end result is a simple expression that ends up doing
I just do not see the compiler stripping off the last part.