mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #2372] JtR MinGW builds (seem to) have memory corruptions #1585
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#1585
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 @ghost on GitHub (Jan 2, 2017).
Original GitHub issue: https://github.com/openwall/john/issues/2372
Steps to reproduce
--testor--test-fulloptions.Workaround
--test-full=0).System configuration
Other information
Seems NOT related to:
BTW: printf definitions, e.g. "LLu", have problems on 32bits.
@jfoug commented on GitHub (Jan 2, 2017):
What environment are you building with? The "LLu" works just fine, BUT it likely does not work for a very old compiler like VC6.
I build with 32 bit VC all the time, but I have to really hack the system to do it (build numerous files with mingw or cygwin and link in the .o files, like all the DES crap with inline asm code).
I would recommend just building with cygwin. You get a native Win32 or Win64 binary.
@ghost commented on GitHub (Jan 2, 2017):
MSYS2: mingw64 and mingw32.
It is possible to build using VC (using a sln file), but I can't hack the system.
@jfoug commented on GitHub (Jan 2, 2017):
Try installing cygwin (if you can). Mingw is a pain in the ass. I have not worked on any porting issues for mingw for years. @kholia did get me to look into it as a cross compiler for Fedora (for the CI). But the end result exe is worthless. It runs under the CI (under wine), BUT crashes miserably when run on real windows. Cygwin has none of these issues, BUT it can not be run under linux (wine).
Oh, BTW, the "LLu" probably does not work under mingw. Mingw bases it's printf syntax on VC6 (one of the reasons I walked away from mingw a while back). VC6 does not know %llu only %I64u and mingw is the same in that regard.
The VC build is really hard. You have to pre-compile all of the .o files you want to use that have inline asm. You have to get the proper tools (mingw or cygwin), setup and 'configured' to have exactly the same config as will be used in the VC build. Then copy the generated .o files (tihings like x86.o). Then you have to get openssl with VC linkages, along with any other libs required (zlib might be the only other one).
I can send you the sln, but even with that, you would likely have to start over on your own env. NOTE, I use VC when debugging. You can not beat the debugger for speed of finding bugs. The debugger does have some limitations (no where near as powerful as some others), BUT it is super convenient and fast to use if you know how.
@jfoug commented on GitHub (Jan 2, 2017):
Pretty much ANY win32/64 build is a one off, do it yourself, OTHER than a properly setup cygwin. The cygwin environment gives you a 99% Posix compliant environment, and it builds jtr very well (including GPU support with proper dev-libs installed). But other windows builds, you are sort of on your own. Mingw 'used' to work, but things have gone bad on that end. VC has never been officially supported, but I build under it, AND I thing @crioux also builds under it for his jtr_dll (not sure on that however). But the port to VC is definitely a one-off.
@ghost commented on GitHub (Jan 2, 2017):
Since I'm just interested in do CI on Windows targeting a pure Windows, I'll keep the workaround on.
@solardiz commented on GitHub (Jan 2, 2017):
Jim, I think we should seriously consider building with midipix, and fixing whatever issues with that remain.
@jfoug commented on GitHub (Jan 2, 2017):
@solardiz I looked at that a while back and it is NOT prime time at all.
Why is cygwin getting the cold shoulder? It is well supported, easy to install and maintain, works well for john, and is mostly OS (might be fully OS, I have never looked into it).
@solardiz commented on GitHub (Jan 2, 2017):
@jfoug I am not saying midipix is ready for its prime time, but it may be close to becoming good enough for use for JtR, especially with its maintainer interested in that (something we don't have for Cygwin, nor for any other similar project).
I like Cygwin, but I think builds with midipix may be closer to native Windows, with less library code. I think you experimented with MinGW and MSVC for similar reasons.
As you point out, Cygwin doesn't work in Wine. I think it also doesn't work in ReactOS, although this may be worth re-testing. (Arguably, these are also shortcomings of Wine and ReactOS, but the result in the same.) This prevents us from doing automated builds/CI for Windows on non-Windows and without needing a Windows license. We could try to avoid this issues with midipix, in cooperation with its maintainer.
We should also continue to support Cygwin.
@jfoug commented on GitHub (Jan 2, 2017):
Yes, that was exactly why I was using mingw. It did not carry the baggage of cygwin, BUT it simply started falling way short of things. A lot of new code has been added that are cool bells/whistles under *nix, but are not trivial to deal with. In VC usually you are pretty much out of luck on a lot of them (until they want to native support in the comipler). Mingw was VERY similar to VC, so a lot of that was also a road block. With cygwin, 'most' things worked just fine, and almost all the others had proper work arounds that used a few ugly #ifdefs, BUT they worked.
One big thing I was using mingw for, was for building libs (.a and .dll.a) to use with VC. However, I have since figured out how to do this with cygwin by linking in a couple of core .o files (clib and startup stuff), so I can now use cygwin to compile posix code where I need to do a 'configure' which was not capable of doing without a lot of work under VC (things like libgmp, libssl, libssh2, libcurl, etc). Yes, some of those 'do' have people that maintain a windows port. But I would rather start from non hacked 'current' code, simply do a ./configure && make or CMake (or whatever normal make proceedure is needed), and be able to link in something I built from sources.
I have been keeping my eye on midipix, and it 'may' be a good replacement for what mingw does (thin interface directly into win32 API). But I have not had time to do much more than 'know' it is there.
@jfoug commented on GitHub (Jan 2, 2017):
Yes, the lack of build ability under Linux was why we resurrected the mingw building stuff. That DID perform a good win32 CI test. Works fine, and has certainly caught numerous bugs so far.
HOWEVER, while the resultant executable files run just fine on the CI (under wine on linux), they do not run well at all outside of wine. Yes, there are a few formats which do work, but a LARGE number of them, simply core. It is possibly DLL related (like libz, libgmp, libeay32), but I have looked into it. The CI 'work' was being done well, we just did not have a robot to build a 'release' executable.
@ghost commented on GitHub (Jan 18, 2017):
There is a bug in code.
I volunteer to submit a patch, but we should think about it a little. For example:
RFC
@magnumripper commented on GitHub (Jan 18, 2017):
Can we just avoid using __mingw_aligned_malloc() at all? Are we not falling back ultimately to something very portable but perhaps slow or wasteful? I can't remember the details.
@magnumripper commented on GitHub (Jan 18, 2017):
Aha...
I presume MinGW doesn't have _aligned_malloc so the alternative with current code would be the compiler error/bailout?
@magnumripper commented on GitHub (Jan 18, 2017):
Just talking without thinking here, but how about this: For MinGW builds, ensure all allocs are using __mingw_aligned_malloc (perhaps defaulting to align == sizeof(long long) although we can probably just use 1) and then we can simply always use __mingw_aligned_free for all calls to MEM_FREE(). Could it be that simple?
It will be slightly wasteful for non-aligned allocs but it's not often used in hot code and who cares about that miserable platform anyway.
Also, this would (in my mind) be a tiny fix in memory.[ch] that should just solve it for good.
@jfoug commented on GitHub (Jan 18, 2017):
That is correct.
This is exactly what was done with VC, since it has it's own non-portable way to do aligned allocs. So in a VC build, ALL allocation is done aligned, and ALL frees are done with the aligned free. libc free CAN NOT be used on VC's aligned frees. The only way I was able to get it working was to do just like you mention here.
NOTE, this is more than simply MEM_FREE. You also have to define free at the proper location, to be the aligned_free (also have to deal with a wrapper for strdup, etc, IIRC). But it has been done on VC, so 'should' be able to be handled in the same manner for mingw. Actually mingw 'may' have the same function used for VC (since it uses the mscrt.dll), 'so' that VC specific code 'might' be able to simply be used for VC and mingw (untested).
@ghost commented on GitHub (Jan 18, 2017):
Like VC. Indeed, a patch like this works.
@jfoug commented on GitHub (Jan 18, 2017):
That likely is all there is to it. The one caveat function I had was that strdup. Since it handles this already, simply using the MinGW defines to also enter that code, and then getting the proper mingw_aligned alloc and free functions setup and re-defining alloc, free and realloc to use the aligned stuff, I 'think' it should work.
Do we want to 'force' this to 16? I did that for VC, and if all we deal with is data needing 16 byte alignment (SIMD SSE type stuff), then all is well. The VC build is not really a 'production' type build. I mostly use it for debugging and writing 'new' code (better edit/build/test environment for me). But that wrapping of all mallocs into aligned stuff does not seem to impact performance at all. Memory footprint is only a little bit worse. BUT I bet there would be formats where memory usage could be considerably worse. However, the alternative is to never allow SIMD logic in mingw, or anything that would require aligned allocations.
@magnumripper commented on GitHub (Jan 18, 2017):
Not sure what you mean. If the original code was an actual mem_alloc_align then we obviously use the
alignthat was supplied. If the original call was just malloc, then we can default to sizeof(long long) or 1 or whatever else could be sensible.@ghost commented on GitHub (Jan 19, 2017):
I'll PR.
@ghost commented on GitHub (Dec 20, 2017):
This bug is back. Even to be able to use the workaround, I had to remove problematic formats.
BTW: that said, I guess the GitHub Windows build could be also broken.
Dozens formats are passing, I'm just bored to remove one by one.
@frank-dittrich commented on GitHub (Dec 20, 2017):
You should be able to do
and be able to find all failing formats this way, no?
@ghost commented on GitHub (Dec 20, 2017):
It is windows: I have to convert to PS and do the equivalent
|| truesince I'm inside CI.@ghost commented on GitHub (Dec 21, 2017):
I bet the GitHub Windows build is broken. It has to be.
There is a bug in
551e468b70.Not sure who is using it, but, since the build itself cannot be properly tested, it might be a bad idea to offer it as a official stuff.
@magnumripper commented on GitHub (Dec 21, 2017):
We should at least clearly mark it as a "bleeding edge snapshot" build.
@kholia commented on GitHub (Dec 21, 2017):
I believe that I may have introduced this problem in commit
551e468(as hinted by @claudioandre).@claudioandre Does reverting this commit solves the memory corruption problem in MinGW builds?
@ghost commented on GitHub (Dec 21, 2017):
Yes (as seen in Win 2012)
@kholia commented on GitHub (Dec 22, 2017):
The recent memory corruption issue was fixed in https://github.com/magnumripper/JohnTheRipper/pull/3043. Closing this bug now.