mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #1044] Cygwin fails (deadlock) for -fork=x #643
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#643
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 @jfoug on GitHub (Feb 6, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1044
Currently, we disable (forcibly) within the configure script because it is well know to be broken.
However, I did some work (I will document here), and it was also documented here: #1043 and have actually gotten cygwin to work 'better' with -fork, but it is still busted. Now with some of the other debugging we have in the logger.c, it is becoming pretty appearent that with our current code, cygwin is failing with some form of race condition / deadlock within the flock() function, interaction between 2 processes. Possibly we can get this working in some other way (there are other things than flock), or possibly we can escalate this up to the cygwin folks, showing that there IS a problem on their end.
@magnumripper commented on GitHub (Feb 6, 2015):
Sounds like first thing to try is just commenting out all flock() calls and see how well it behaves. I presume O_APPEND on a non-network file system is 100.0% safe under Windows.
@jfoug commented on GitHub (Feb 6, 2015):
That should be VERY easy to check. AND simple to implement (#ifndef CYGWIN32 wrappers)
Is log file also opened in append mode?
@jfoug commented on GitHub (Feb 6, 2015):
FU. worked first time. You suk! lol.
at least my flock-tst script is working just fine. I still need to test more.
@jfoug commented on GitHub (Feb 6, 2015):
I guess the 'non-trivial' may not have been a proper label,
@magnumripper commented on GitHub (Feb 6, 2015):
Ha ha, that was too easy after the brain massage in #1043
@magnumripper commented on GitHub (Feb 6, 2015):
So then it's just a matter of documenting that you've gotta run on a local drive. Everyone will do that anyway but just for good measure.
@jfoug commented on GitHub (Feb 6, 2015):
Agreed, but we would not have gotten there, without the back/forth work trying to explain to each other just wtf was happening.
There are other changes for getting cygwin to fork, but those are trivial, and are already in my testing stuff.
The problem is that cygwin DOES have an flock, so AC finds it. but (at least the way we are using it), deadlocks.
@jfoug commented on GitHub (Feb 6, 2015):
I am also ONLY running under the cygwin shell. I need to make sure this also works from a windows cmd prompt. (and also works for cygwin32). BUT this has not been like this before, that is for sure.
@magnumripper commented on GitHub (Feb 6, 2015):
I bet after a night's sleep one or both of us will come up with an idea regarding those flocks. Maybe we can keep them, with some twist. But as we learnt in #1043 the flock() is not needed at all on a local drive.
@jfoug commented on GitHub (Feb 6, 2015):
my cygwin64 build is absolutely using the -fork, and absolutely working. NOTE, we can not simply turn off FLOCK in AC, or we get an error message listing to NOT use --fork. We have to build with it, but then make sure we do NOT use it in cygwin.
@jfoug commented on GitHub (Feb 6, 2015):
That is a damn good point. and it actually might speed things up (probably not too much). I wonder how hard it would be to detect the FS underlying the file itself ?
@magnumripper commented on GitHub (Feb 6, 2015):
Like you said somewhere it's as easy as wrapping them like this (pseudo diff, not sure what macro to use)
@jfoug commented on GitHub (Feb 6, 2015):
First, before I go too deep, I need to back out some other changes. On thing is I commented out some code (needed code), getting to the point where cygwin worked at all. The call to rec_save in crk_init() is one such thing. So cygwin working may still be a little premature.
@jfoug commented on GitHub (Feb 6, 2015):
I will be a night-ranger quiet-riot concert tonite, and the babysitting in morning, so I doubt it will be me that has any thing close to an 'idea', lol.
@jfoug commented on GitHub (Feb 6, 2015):
Pretty much exact code I have (but in 2 places)
@magnumripper commented on GitHub (Feb 6, 2015):
You should probably put them in cracker.c too around the LOCK_SH calls
@magnumripper commented on GitHub (Feb 6, 2015):
Oh, and recovery.c too. But if they don't deadlock maybe you can keep them.
@jfoug commented on GitHub (Feb 6, 2015):
I had to comment out rec_save at one time. Now, I have it back in code with no problems.
I really think it is best to comment them all out (for cygwin), until they can show that the code works ALL the time. There certainly could be cases/places where these will fail (even though not failing now). NOTE, there is very little recovery.c testing done in the TS. I am not sure how to auto do that.
@jfoug commented on GitHub (Feb 6, 2015):
Note, I will probalby have to test a much longer run, to make sure things like recovery, and cracker (pot reload), works with no problems, once I add the
&& !__CYGWIN__wrapper to the FLOCK code.@jfoug commented on GitHub (Feb 6, 2015):
I did get a deadlock in cygwin build, but that was before I commented out the flocks in cracker/recovery. I am re-running the TS now, after changing those.
@jfoug commented on GitHub (Feb 6, 2015):
c54daecis many changes. NOTE, I still want to test this some more (and do not have time for a while), before calling this good. I need to test more on cygwin64, and have not tested at all on cygwin32.Also needing tested is running this outside of a cygwin bash shell.
@magnumripper commented on GitHub (Feb 7, 2015):
Good Stuff. I saw you added a debug print right before trying to lock, that was one thing I was going to suggest. Another thing one could try is something like this:
Current code
Debug code
Well, something like this. This will be awfully slow, always waits a full second before retrying, but you will see whether this one too deadlocks, or if it's just blocking lock calls that do.
@magnumripper commented on GitHub (Feb 7, 2015):
Note also that we need to answer this question: Are we really sure Windows has an atomic O_APPEND? Some googling indicates it does not. Cygwin may emulate it with just a non-atomic seek-to-end before write, but that will lead to guaranteed file corruption unless we can find out how to lock files properly.
For locking, we could try fcntl() instead. Or perhaps lockf()? Or even some Windows-specific code - maybe that is the safest bet and we'll have it -D__CYGWIN__ anyway.
@magnumripper commented on GitHub (Feb 7, 2015):
http://www.perlmonks.org/?node_id=486488 (a thread from 2005)
Note that Win32 doesn't do the seek-then-write atomicly, so you should lock if your code might be/is run on Win32. Also note that if you didn't use binmode (which is likely true and usually for good reason), then the order of things is seek, then newline conversion, then write, which makes the race even racier.
@magnumripper commented on GitHub (Feb 7, 2015):
Better news from 2009: https://cygwin.com/cygwin-ug-net/ov-new1.7.html
What's new and what changed from 1.5 to 1.7
...
Implement atomic O_APPEND mode.
@magnumripper commented on GitHub (Feb 7, 2015):
Also some info on what is "supposed" from POSIX: http://stackoverflow.com/questions/1154446/is-file-append-atomic-in-unix
That also includes someone saying
I wrote a script to empirically test the maximum atomic append size. As @freiheit mentioned, on Linux you can write up to 4096 bytes atomically. On Windows, the maximum size is 1024
...which indicates we really want locking anyway. On the other hand, it's not the end of the world (at all) if two processes' pot file writes are interleaved as long as they are interleaved at line boundaries. I'm not sure Solar's code (write_loop() in misc.c) take care of that - it doesn't seem to.
@magnumripper commented on GitHub (Feb 7, 2015):
Oh, and here's a test script!
http://www.notthewizard.com/2014/06/17/are-files-appends-really-atomic/
@magnumripper commented on GitHub (Feb 7, 2015):
OSX only seem to have a 256 byte max without locking
@jfoug commented on GitHub (Feb 7, 2015):
I've been warning folks that this type fork code is VERY tricky. That some OS's babysit u does not mean it's great code for general purpose. It is good we have been digging in to learn the good and the ugly. Btw, Quiet Riot just got done. Waiting for Night Ranger.
@jfoug commented on GitHub (Feb 7, 2015):
I will work with that test script later
@jfoug commented on GitHub (Feb 7, 2015):
Here is a run under cygwin64 (updated pretty recently, last Dec I think). NOTE, this only allows for testing under cygwin bash terminal. It does not allow testing a native cygwin 'program' that is run under Win32 (64) cmd shell. While they are similar, there are some differences which I am not fully aware of. It could be for this case that there is no difference at all. A HUGE amount of differences are due to nuances in the shells.
One note to cygwin, I am not 100% sure that processes launched with the & in a loop like that, are not all completed fast enough, so that there is no overlapped running of processes. Well, now I am more sure cygwin 'IS' working properly, since adding 1 byte to length in cygwin32 did show the problem perfectly.
@jfoug commented on GitHub (Feb 7, 2015):
I think that is very good idea. During a TS run, I actually locked up the machine, It was still working, but even the mouse would only move a few dozen pixels ever 20-30s or so. Something had enough threads hard locked and busy, and was not even giving it up to the OS. So it 'almost' works, without any locking, but really not good enough. I really think fcntl() may be the way to do (but it could be the lockf() ) The cygwin page you found DID list that each of these API implementations WAS independent of the others.
@jfoug commented on GitHub (Feb 7, 2015):
I am doing fcntl() for cywin in logger.c to see how things go. But from this page:
http://www.informit.com/articles/article.aspx?p=23618&seqNum=4
So we may really want to look at this, along with ask Solar on to why his choice for that BSD flock() interface?? It may be that it is available on my platforms. BUT as per that statment, it sounds like this 'may' be a much better way to go, even handling NFS (possibly).
@jfoug commented on GitHub (Feb 7, 2015):
Ok, I implemented a 'simple' fcntl. simply following exact same instructions as on
http://www.informit.com/articles/article.aspx?p=23618&seqNum=4
fcntl() is working (I hope, I have more testing to do).
Ok, I have checked in logger.c
7a9d98e. It ONLY does this code for cygwin, but shows the simplisity, and we certainly should relay this information upstream to Solar. The simple fact that he could get -fork working properly in cygwin on core should be an indication to him that it is something to look at, along with that statement (unverified), that fcntl() works with NFS (newer ones).@magnumripper commented on GitHub (Feb 7, 2015):
This is very outdated information (2001!). I know flock() works fine in Linux w/ NFS and has done so for six years or more.
@magnumripper commented on GitHub (Feb 7, 2015):
I presume Solar picked flock() for a good reason, since fcntl() is more portable if I got things right. We should simply ask him.
@magnumripper commented on GitHub (Feb 7, 2015):
I doubt that. If it does, you would get zero failures regardless of size - you should be able to run it with 65536 and it would still not fail.
@magnumripper commented on GitHub (Feb 7, 2015):
05b51935wraps up Jim's initial work and makes fcntl() the default locking scheme. After testing, we can hopefully close this.