mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #1043] -fork may be borking .pot file (and other FILE io) on jumbo. #645
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#645
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 5, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1043
Issue found with TS. Started as a stdout only problem, but appears to be .pot file being truncated when -fork is being used.
a fflush() was needed for the stdout problem. That may be the issue needed on all FILE io when in fork mode. Time will tell.
This is an example showing the symptom:
In this case, the -show only gave us 752, which was what was in the .pot file. Upon the .pot check, it also shows us that only 752 lines were in the .pot, and on re-run john worked with them, so this does not appear to be any 'bug' in the test suite. This only appears to happen in -fork mode.
@jfoug commented on GitHub (Feb 5, 2015):
Ok, I ran again, with -stop on the command line. The .pot was truncated to 1049 entries, a wc on the .pot file shows 1050 lines, and I found this in the .pot file (showing why only 1049)
That is the same 'classic' corrupted file sign we were seeing on the stdout problem fixed by a fflush() call after printing the found guess.
@jfoug commented on GitHub (Feb 5, 2015):
We do have flock(pot_fd, LOCK_SH) within cracker??? But that is ONLY during reload pot.
COULD that be the problem???? In the TS, things happen fast. It could be that one process has already written into the .pot file, the other starts up, and blows the lock type by trying to load the .pot file??? Just a theory, since flock is a new function to me. The function make sense, since it is simply a mutex like function @magnumripper, is there any reason why we are using LOCK_SH in the flock within the .pot file reload? I would think exclusive would be just fine there. It would mean john blocks allowing only one process to access the .pot file at once during startup, BUT that is really the way it should be, on a multi-processing system, especially by reading the man page, listing that a call of a shared lock will pretty much zonk all of the exclusives being waited upon.
@jfoug commented on GitHub (Feb 5, 2015):
Changing the flock in cracker to LOCK_EX did not change the problem. I have kept it for now at LOCK_SH
@jfoug commented on GitHub (Feb 5, 2015):
Ok, here is a decent looking example:
Then at very bottom of tst.pot file:
So what appears to have happened here, is that the first 754 line crack wrote data. Then the 746 line fork wrote data right over the top, starting at tope of file. There was a bit more data (1 full line, and a partial) that was longer in the file so it still shows up.
I am also surprised about 754/746 counts. Usually it is 750/750 for fork.
@jfoug commented on GitHub (Feb 5, 2015):
This one is not so easy to determine reason why (it is 100 lines 'short' in the .pot file)
@magnumripper commented on GitHub (Feb 5, 2015):
I set LOCK_SH for reading, LOCK_EX for writing.
What good would a LOCK_EX do in pot sync? Pot sync only reads so it uses LOCK_SH. Other processes can set a LOCK_SH simultaneously and sync too, without waiting. That's the idea of a shared lock.
Any process wanting LOCK_EX for writing new pot entries will obviously wait for those LOCK_SH before it gets its lock.
@magnumripper commented on GitHub (Feb 5, 2015):
Only process A (or perhaps a subthread of process A but we don't have threads doing file IO) can blow its own lock the way you describe. Otherwise we could give up locking completely.
If process A has a lock, process B can not blow it.
@jfoug commented on GitHub (Feb 5, 2015):
Yes, but a LOCK_SH will blow away (change) any lock waiting in LOCK_EX. (edit, so that is only threads in the process?? If so, then i would 'assume' this would be ok. It is outside of the OMP loop, correct)
I have a printf in the reload_pot, and it is not being called anyway.
Here is some new information. I added some logging to the flush pot stuff. It looks like all data in the flush made it out, and to the 'proper' location. Could this bug be something totally different, in that the last process sometimes does not write out it's final data???
@jfoug commented on GitHub (Feb 5, 2015):
This was what I was hoping to see (at some time). This shows that for whatever reason, the locking is not always working:
@magnumripper commented on GitHub (Feb 5, 2015):
That sounds more plausible to me. So why would that happen? Are all processes really completing? I recently changed a bunch of
exit()intoerror()because that's a very much better way to abort a job.@jfoug commented on GitHub (Feb 5, 2015):
The above looks ALMOST like 2 totally separate file descriptors, but acting on the same file.
@jfoug commented on GitHub (Feb 5, 2015):
This is the code I am using
@magnumripper commented on GitHub (Feb 5, 2015):
After a fork() any file descriptors are like duplicated. In order for locking to work we need to (re)open the pot and log files after forking. But that I'm pretty sure we do.
@magnumripper commented on GitHub (Feb 5, 2015):
Add a debug print showing you indeed execute code within that
#if OS_FLOCKblock. That goes for pot sync too.@jfoug commented on GitHub (Feb 5, 2015):
I agree. looking at the "***In log_file_flush..." messages, it looks like almost always this is hte case.
But it is HARD to explain away the output I show a few messages up. There are 2 distinct instances, as shown by the lseek(end) and the counts printed. BUT they are writing to the same file.
I am going to make a simple script that gets the TS out of the way, that will simply hammer away on a known fast input item until the .pot file comes up short. All data will be logged to a file, and the temp stuff cleaned up between each run (if things are good). Should be pretty easy to do, and once done, will be a real quick way to get all the 'testing' we need.
@jfoug commented on GitHub (Feb 5, 2015):
Will do.
NOTE, I have debug output for pot reload, and that code is never executed. Is that the -reload-pot stuff (where you use the .pot as the input file?) If so, it is nowhere near the exe path we are using anyway.
@magnumripper commented on GitHub (Feb 5, 2015):
That pot reload is executed on signals and on timers. For short jobs, it's often called very late if at all.
@jfoug commented on GitHub (Feb 5, 2015):
I have not seen it called 'yet'. I certainly have not seen it called on the ones that have been failing, so for now, it is not on my radar.
@magnumripper commented on GitHub (Feb 5, 2015):
It only reads so it shouldn't be able to do much harm. Actually it could probably do fine without locking at all.
@jfoug commented on GitHub (Feb 5, 2015):
Ok, new script:
Ran this a couple times, til I got a failed.
Here are the relevant lines:
I am done for the night. I have to sleep sometime.
@jfoug commented on GitHub (Feb 5, 2015):
Btw, here is a 'good' test of the flock-tst script:
NOTE, I am not sure why bug.stdout is short. I would think it was 1500+ also.
NOTE the stdout is getting overwrites ??? I thought that was fixed.
@jfoug commented on GitHub (Feb 5, 2015):
here is a bug.stderr for one that worked
Updated (I only output successful FLOCK_EX, if it is a pot file)
@jfoug commented on GitHub (Feb 5, 2015):
Here is a bug.stderr from a failure (FLOCK_EX only printed for pot file locks)
And some info about the .pot file:
@frank-dittrich commented on GitHub (Feb 5, 2015):
I guess it is related to these john.conf settings:
This also explains why it doesn't happen in core.
@magnumripper commented on GitHub (Feb 5, 2015):
I ran these tests over and over again on Linux as well as OSX and can't reproduce. Apparently your system's flock() returns OK but does not lock the file. What system is this? What filesystem are you on?
With
6a749a162and -DLOCK_DEBUG and running a 1000x larger test I can see the processes getting in line for locking, and waiting for each other.(Here's running without that debug)
Also tried fork=4 and higher. Never any problem. I also tried the above with "Save = 1" in john.conf. This means pot-sync will infere a whole lot more with the process. It still did not miss a beat.
@magnumripper commented on GitHub (Feb 5, 2015):
Latest commit adds a little test script,
unused/locktest.sh. It uses flock(1) which is a command for using flock(2). flock(1) is available on Linux, OpenBSD and some others. For OSX I used this one. Try it!Here's "good" output:
@magnumripper commented on GitHub (Feb 5, 2015):
Try latest commit with -DLOCK_DEBUG and re-run until you get the same situation. Does the first process release the lock before 2nd process get a "successful" one?
@jfoug commented on GitHub (Feb 5, 2015):
The system is a win8.1 laptop, running virtualbox VM, with Ubuntu 64 running on it. The actual file system is:
C_DRIVE on /media/sf_C_DRIVE type vboxsf (gid=999,rw)
This is an NTFS drive mounted by virutal box. Now, I can easily move the TS to this mount (on the virtual box VM)
/dev/sda1 on / type ext4 (rw,errors=remount-ro)
but I have no idea what a ext4 type means.
I will rebuild with latest locking and see if it is better, or show the problem.
@jfoug commented on GitHub (Feb 5, 2015):
Here is the 'first' failure.
@magnumripper commented on GitHub (Feb 5, 2015):
OK, so unless these fprint's to unbuffered stderr happens to end up in some other order than they REALLY happened, all things happen in correct order and YET process 1 get the wrong figure!? I have absolutely no idea what is going on but I write it off as your virtual environment having serious problems until you can show this happening on real gear.
ext4 is the current standard Linux filesystem, it does support locking.
@magnumripper commented on GitHub (Feb 5, 2015):
Do try that locktest.sh script!
@jfoug commented on GitHub (Feb 5, 2015):
I did try locktest. It was happy to work right on my vboxfs fs. I did run it multiple times, and it was happy to say it was working.
I will copy all the TS stuff to the ext4 system and test there.
@magnumripper commented on GitHub (Feb 5, 2015):
On a side note I did heavy testing of these things all day today and I did find some interesting (frightening) facts. For example, a bog standard NFS share with Linux server and Linux clients: Client could lock, other clients would see the lock. But the server's native filesystem (at "same" directory) would NOT see clients' locks nor share its locks with the clients. This means you can run over NFS (required for MPI) just fine but you must NOT run any JtR process on the NFS server itself.
@magnumripper commented on GitHub (Feb 5, 2015):
The fact locktest.sh worked fine indicates we have some other problem than we thought. I just can't fathom what it could be. It's kind of impossible... well, unless it's file caching inconsistency!?
@magnumripper commented on GitHub (Feb 5, 2015):
You could try this just for... trying it :-P
@jfoug commented on GitHub (Feb 5, 2015):
Well, using -v -v -stop on the vboxfs, it made it past dyna_16 (2 files or more for each dyna). Before it was not making it nearly that far before dieing. I may get rid of the -v -v and simply run and see if the problem is gone. (Note, I restarted, since I was not 100% sure I used -stop on that run).
Damn, I took -v -v out, and it stopped almost instantly. But it does seem to vary per run. Some run with almost no errors for a while, then 'get into' them. Others simply start having every 3 to 5th run be an error.
I will also test more on the ext4 fs.
Running -v -v 'may' make it just a bit harder to trigger, since the screen IS being updated more. However, I thought the screen was only updated when jtr was not running. It may be that giving it a few extra 100 ms between each run was helping to 'calm' things down. But now I have another run without -v -v going, and am up past dynamic_12 (doubled) So I had 2 bad runs in a row, and now it is working 'better'. I will let it go and see.
Nope, died
@magnumripper commented on GitHub (Feb 5, 2015):
That
fsync()is not going to be committed though, unless you can come up with a sensible #ifdef to surround it with. We are chasing issues with a virtual environment as far as I can tell.@jfoug commented on GitHub (Feb 5, 2015):
Yes, I think so also, BUT it would certainly benefit us to know 'why'. Finding out why may allow things like cygwin (which has a much larger audience than someone using a VM like this). Cygwin has fork, and it 'claims' usable, but things go to shit, and I think this may be the reason.
NOTE, on this vm, I am running on that ext4 main fs, and things are running fine. There was an error on my 'new' dyna_25 run, but the numbers were right. I am not sure the error, it could be some line 'looking' like a pw, but not being one (i.e. ending with ) and having a " (" string in it). I hope that dyna_25 if run by itself will show the problem (in -v -v mode).
But as far as I can see now, the normal non NFS type fs is working at least much better right now. It is up to dyna-77 (doubled).
@magnumripper commented on GitHub (Feb 5, 2015):
Did you try running on the ext4 fs without the extra fsync()? I would guess it works fine without it.
On another note you should try compiling that flock(1) utility and see how locktest.sh manages under Cygwin, on a normal "cygwin drive". I guess it will run just fine but it would be good to know it does.
@jfoug commented on GitHub (Feb 5, 2015):
flock is a command already built into cygwin. (at least cygwin64)
$ ./locktest.sh
File initially not locked.
Locking file exclusively, using flock(2) for 5 seconds.
Confirmed, file is locked. Waiting for shared lock...
Got it, now releasing.
It has no problem. I will run it multiple times.
NOTE, that example does not actually write anything, so just because a file 'gets' locked, does not seem to be enough to KNOW that multiple writes between processes will be done in a synchronous manner. We are seeing that with the vboxfs file system (or possibly other NFS type mounts).
It would be nice to have a stress test tool that would tell someone quickly (10-20 minutes at most), that some setup is NOT running properly to use john --fork=xx on, vs having them lose a shit load of work. That is why in cygwin we FORCED fork to fail. It was (is or appears) to be a known system where it simply fails.
@magnumripper commented on GitHub (Feb 5, 2015):
True, it only checks locking. Testing cache coherence is much harder and probably can't be done at all with a simple script like that. OTOH I would not expect Cygwin to have any file cache problems that NTFS in general doesn't have - and I don't know of any.
@jfoug commented on GitHub (Feb 5, 2015):
I do not either, BUT keep this in mind, the vboxfs has it's real parent being an NTFS file system. vboxfs is simply visualization to allow unix to 'think' it can use it natively, but I would be 90% under the hood passes through to NTFS. That along with Cygwin having known bad forking usage under JtR leads me to believe that possibly NTFS does not cache/lock the way we 'think' it should.
In many of the bad issues we are seeing now, it almost appears that the OS is NOT associating file handles between the 2 processes against the same file as BEING associated with same file (so that locking happens). If you look at the 'bad' runs, each process locks it's own file, starts at 0, writes bytes, then writes more to the end (which was what it wrote the first time), etc, etc. BUT there is only 1 file. So for -fork=2, I am seeing a lot of 748/751/753 type runs (just about half, and depends upon who wrote first). Each are seeing their own file handle, and NOT associating it with a share file between processes. So, I am not sold that caching is the problem. I really do not know enough of how this is really implemented to know how it is supposed to work under the hood.
@jfoug commented on GitHub (Feb 5, 2015):
Question:
what if the lock was obtained on the 2nd process PRIOR to the file itself actually being created by the first???? Created might mean created and the inode being flushed to disk. In this case, both processes 'might' think they are the sole owner. Again, just a theory, I do not know shit about under the hood plumbing of this crap. But if that is the case, I wonder if we could do lock, if not exist create, close lock, and regain a lock?? I think that would ONLY have to happen if the file does not yet exist, so should be a zero impact on speed.
One bad thing, is I have NOT been able to get core to fail against the vboxfs (when run on the ubuntu VM). BUT there are not many formats there either. I did put a fflush in, and core works like a champ for the new (1500 val-pwd) testing (i.e. the stdout bug).
@magnumripper commented on GitHub (Feb 5, 2015):
The file is created in log_file_init(), way before this happens. I'm pretty sure this is about cache coherence and I'm not very surprised - unless I'm confused that file system is really not meant for things like this. It's mostly meant for easy file transfer between host and vm, no?
On the other hand - if it's NOT about cache coherence, it looks like a really bad bug in vbox.
@magnumripper commented on GitHub (Feb 5, 2015):
The fact you can't reproduce this with core John bugs me. I think you should concentrate on that. Try thousands of dummy hashes and verify that you see this problem with Jumbo. Then do the exact same using core.
@jfoug commented on GitHub (Feb 5, 2015):
I made a simple change in log_file_init() and it 'may' have fixed things
this is the chagne:
This simply means that the file pointer being used is NEVER one that actually created the file. I think there is caching going on, in that we are NOT locked, and the OS is caching the acutal flush out of the inode is being delayed.
NOPE, at dyna-29, I got a failure (614 vs 1229, so this is amost exactly half, and is 2 processes both thinking they are the only ones).
@magnumripper commented on GitHub (Feb 5, 2015):
Oh, and leave TS out of it, it just adds confusion. Do something similar to https://github.com/magnumripper/JohnTheRipper/issues/1043#issuecomment-73090668 but with dummy instead of plaintext.
@jfoug commented on GitHub (Feb 5, 2015):
One huge thing, is in jumbo, we fdopen (get a STDIO buffered handle) of the .pot file. In core, that file is WRITE ONLY, and never gets opened by anything other than a raw file handle.
But as far as I could tell, that pot reload code (where the FILE * handle is created/used) was not being called. I might have been wrong on that, but that was what I thought.
@jfoug commented on GitHub (Feb 5, 2015):
With the open/close/open in there, it is much harder to get a failure. I am still working on jumbo (1000 dummies). I think more is not going to show this problem any better. I think fewer is 'better'.
@magnumripper commented on GitHub (Feb 5, 2015):
What if you fsync() right after open instead of close-reopen?
@jfoug commented on GitHub (Feb 5, 2015):
Right now, I am actually having a very hard time (with 'simple' script) to find the problem. I made a loop in my flock-tst script, and am simply looping until it fails, I am up to 100 runs (dyna_1 test again)
But running the TS, I was able to 'finally' have it chop the .pot file in half (2 forks). That was the only failure I have seen. This (along with fsync), is certainly much harder to corrupt. But that could also be because things have been slowed down. Hard to say for sure, unless I can comment out new stuff, rebuild, and have it go to hell again.
@jfoug commented on GitHub (Feb 5, 2015):
It may be the fsync() that is making it hard to show this problem. I will build without that.
Nope at loop 31, it failed.
failed again at loop 9.
So without the open() / close() / open() it is easy to fail. I have rebuilt, and will continue testing, to see if I can get this 'simple' script to fail.
@jfoug commented on GitHub (Feb 5, 2015):
Ok, I have done 4 runs of 75 loops, with open()/close()/open() and I am not able to get failures. I do think this is the underlying FS simply not providing a file inode (or whatever it is) to other processes quickly enough.
Now why core works, I do not know.
@magnumripper commented on GitHub (Feb 6, 2015):
OK try this then: With
09b03324you can completely disable pot resync just editing john.conf. Set all of them to N and see if it still behaves different than core. It really should not.@magnumripper commented on GitHub (Feb 6, 2015):
Disregarding the pot sync and reviewing a
git diff origin/master logger.c, I see one slight difference between jumbo and core: In jumbo we do an actuallseek(fd, 0, SEEK_END). Core doesn't, since the file is opened in O_APPEND anyway. Maybe this triggers some weird bug somewhere.@magnumripper commented on GitHub (Feb 6, 2015):
...and if you turn pot sync off in john.conf, you could try to comment out both lseek's just for ruling them out.
@magnumripper commented on GitHub (Feb 6, 2015):
Hmm wait a minute. Yes, we are opening with O_APPEND. So regardless of whether we seek or not, and wherever we seek to, and even without support from any file locking(!), the write is supposedly guaranteed to be atomically appending. Now THAT make your problems indicate a severe bug, wherever it actually lives (I still guess it's in your vboxfs but I have no idea how these low level things are implemented).
I always wondered why Solar doesn't even emit a warning if OS_FLOCK is not there. This is why.
@magnumripper commented on GitHub (Feb 6, 2015):
I jumped the gun there. From some Linux man page: O_APPEND may lead to corrupted files on NFS file systems if more than one process appends data to a file at once. This is because NFS does not support appending to a file, so the client kernel has to simulate it, which can't be done without a race condition.
"NFS file systems" can of course be replaced with "some file systems". It's a good idea using O_APPEND backed up with flock() but apparently it's not enough in this case.
@jfoug commented on GitHub (Feb 6, 2015):
I am seeing the open()/close()/open() work wonders.
Now, the TS is somewhat of a 'ugly' beast. It does some things which are not always what you would 'see' in the wild. One of these, is to always start off with an empty .pot file. Many times (probably most of the time), jtr runs go where there is an existing john.pot (or whatever .pot file name) already on disk. I am going to make some changes to the TS to make sure that the .pot file is already there, written and flushed to disk. Now, the file will be a zero byte file, which on nix (and ntfs, I think), is just an inode. I will back out the open()/close()/open() code back to just open, and make sure that the fsync is not there, and start testing.
But I have been testing with existing open()/close()/open() and it is pretty damn stable. Yes, I did see one 1/2 sized .pot file, but only one. I Have not been able to make it fail since then. But if I remove that open()/close()/open(), it fails quickly, at a somewhat scary percentage. Again, the bug as I see it, is that both processes get that file handle, but there is no dependance at the OS level between them. With the file there, that problem appears to go away. That one failure could still be deemed to be some race condition, and I have not been able to replicate it. Having the file already there, prior to either JtR running might solve this.
_If that is the case, then we might be able to handle this with warning documentation within the -fork section, OR by having JtR create the .pot file early_, simply an open(create|append);close() during the john_init() or sometime like that. to make sure the file is there, prior to ever getting to any forking code.
I am also going to open this back up on cygwin and see if it works.
@jfoug commented on GitHub (Feb 6, 2015):
Ok, I made this change to the TS. After every unlink($pot), except when at the bottom of the loop, and we REALLY want to clean it up, I call this sub
Now, the ubuntu-64 build, on the vm, using the vboxfs location of the test suite is running fine. I am going to build Cygwin with fork enabled, and see if now works in the TS. The reason we stopped using it before was it was having all sorts of problems. Possibly THIS is it. If not, it gives me more things to look into.
This is NOT the fix. It is just a work around to a newly discovered (we hope) problem on some non ext4-fs systems. Also, this likely is not the ONLY issue. There may be other systems we do not have our hooks into that have other issues with fork. Again, _the 'FIX', may be documentation, or it may be JtR always creates and closes the .pot file early on every run, or a combo of both._
OK, this did pop up in the ubuntu run with the changed TS. I have seen a couple of these, and I do not know exacty what the TS is complaining about.
Here everything on screen print checks out, but the TS still complains. I see these every once in a while and I am not sure why. I need to change my !!!FAILED!!! to be !!!FAILED1!!! !!!FAILED2!!! etc so I know at least what statement failed them. Here i have a pretty good idea, since the (1500 val-pwd) is listed, and I think there is only 1 failure point with that on it. Something in the if statement is not 'happy', BUT is not printed on screen.
@jfoug commented on GitHub (Feb 6, 2015):
Also note, the .pot file may not be the ONLY culprit here. Any files written to during the fork may behave like this. The .pot, the .log, etc. I am not sure about session files. Do we have a single one, or does each process get it's own? If a singleton, then yes, the session files also.
@jfoug commented on GitHub (Feb 6, 2015):
Ok, for cygwin, if I run it, it will start fork=2 processes, but they just hang. If i kill one of of them, the other proccess will complete. the .pot file will contain only the hashes cracked by that half (assuming fork=2). Also, the tty is hosed, and i have to run
stty echoto get any screen IO (happens sometimes on JtR screw ups where screen is not released from raw mode).So cygwin bug was not this one (goes beyond). But I may look into that a bit and see if it is some not 'too' hard. Likely it is both processes deadlocked on something (possibly the flock). Tried re-running with LOCK_DEBUG and I get no extra output, so cygwin may be deadlocked prior to getting to the .pot file stuff.
@jfoug commented on GitHub (Feb 6, 2015):
@magnumripper how does rec_save type stuff work for forked processes (recovery record crap) ?
Ok, tested on ubuntu (working), and i see this:
So I see xxx.rec and xxx.2.rec That answers my question. But I have been slowly drilling down in cygwin, and it may be in the record save that cygwin is having problems. There is a special ftruncate code in there. I am not sure if that is the problem or not.
@jfoug commented on GitHub (Feb 6, 2015):
Why do we do lseek(end) on the .pot file, but NOT on the log file??? Is that simply for that 'pot reload' logic??
@jfoug commented on GitHub (Feb 6, 2015):
On my ubuntu system, not having _john.log_ there, ALSO _triggers the same disjoint file handle_ for locking the log file. NOTE on this run, neither file existed. Here is results after. The .pot should be 1500 lines, the .log 15xx (about 1520 or so I think).
I am going to make a 'simple' script and start looking for this one also.
As for cygwin, I have made progress, but I am about ready to throw in the towel. Now I have it working (for a while), but it seems to deadlock often in the flock(LOCK_UN) call, or possibly some race condition between 2 processes doing flock(LOCK_UN)/flock(LOCK_EX). I do have some simplification to the log_flush function however, and will be getting that checked in, once I have it tested better. I removed some of the if(fd==&pot) stuff, and simply always print stuff (to debug the true calls to that locking stuff). Also, the crk_pot_pos logic is simplified (now that I understand just wtf it was used for). We still do a SEEK_END on the .pot (but not .log). I am not 100% sure WHY we do that. I really think that should be a SEEK_CUR, and allow the append mode logic to work, BUT you mentioned that something about NFS having issues. BUT if that is the case, then I would think we would ALWAYS SEEK_END, both for the .pot and .log file ??? Rereading that, it appears that possibly using APPEND open with flock 'may' allow the system to simulate proper appending (which was what you found out about corruption).
All this is hard to tell, BUT overall, this is an exercise we have needed to do, trying to figure out how better to handle this. I still may not be able to get cygwin working (I have somewhat given up). BUT this is also testing a lot with the files not already existing on disk. Once i get my script updated (to look at both log and pot file line counts), I will also see if cygwin will work, if the files are 'always' there and flushed to disk, prior to jtr running. _THAT_ has pretty much eliminated the problem on the vboxfs for ubuntu running on virtualbox. I still get an error now and again on the TS, BUT those errors are 'invalid' password, and I think what is happening is something in screen IO is getting corrupted in the stderr stuff, triggering a 'looks like' situation for a password. BUT every time I get one of those errors, there also are 1500 GOOD matching passwords (or the correct amount), so this 'bad password' is spurious from somewhere else.
@jfoug commented on GitHub (Feb 6, 2015):
Ok, here is my 'test' script (to run without worry about JtRTS crap)
Not really clean, but works for me.
@magnumripper commented on GitHub (Feb 6, 2015):
Yep, it's just for getting the position before/after writing. We don't have to seek for the write, the O_APPEND guarantees a seek to end when writing anyway. Except for vboxsf...
@magnumripper commented on GitHub (Feb 6, 2015):
Why? It's just the exact same symptoms from the exact same vboxsf bug. IMHO time would be better spent trying to create a good isolated test case and report this to Oracle or whoever is the author of vbox.
@magnumripper commented on GitHub (Feb 6, 2015):
Current what!? Who's current position? What we are doing here is 1. Remember the eof-position after WE wrote to the pot file, and 2. next time we write, first check if a SEEK_END now show a different figure. If it does, someone else wrote to the pot file so we need a pot sync.
The O_APPEND totally ignores where we seek. You can seek to pos 0 before writing and it will still write to the end of file. The seeks are solely for keeping track of what we did vs. what someone else possibly did.
We are opening with O_APPEND. That's core code.
@jfoug commented on GitHub (Feb 6, 2015):
Ok, I had to go out and left the above script on. It was at 3600 when I returned, and no problems.
Without the creation of the files (empty but there), prior to calling JtR, that script will die very quickly when run, from 1st run, to 10th run about 90% of the time, usually on 1st or 2nd run.
So I would say this is _the problem_ seen on -fork=x on vboxfs, and possibly on other file systems.
I am going to spend time on core. It may be that the TS does not smoke the .pot or .log file the same way for core. The code to handle that is very different than the code for jumbo. I will be testing core using a 'simple' script like we have on this page. I am still pretty concerned that we see this problem on jumbo but NOT on core. The code for logging should be somewhat similar. There is no 2nd opening of the log file with fopen/fdopen, no lseek(END), etc. It is pretty much the same crap. And I was seeing the .log file failing also, not just the .pot file.
@magnumripper commented on GitHub (Feb 6, 2015):
Oh, and another detail: If we need a pot sync, we are not always just doing that from the start of the file! We are doing it from the last known "synced" position. The code might look weird unless you know why.
@magnumripper commented on GitHub (Feb 6, 2015):
OK, now I re-read what you wrote :-P Yes, as I understand it, the O_APPEND alone is enough to be virtually 100% safe on a non-network, non virtual, file system. Or perhaps more generally speaking, one where we own the actual block device. So the flock() is a second-layer protection for network filesystems and other situations where O_APPEND is not 100% safe.
@jfoug commented on GitHub (Feb 6, 2015):
I think you are wrong on this one. The file handle used for the read is not the same as for the write. The write is at the end, I am using SEEK_CUR for that, and I believe it is 100% happy (on vboxsf!)
@magnumripper commented on GitHub (Feb 6, 2015):
I can't believe I'm wrong. If someone else writes to the file, my "current" will not change. See?
@jfoug commented on GitHub (Feb 6, 2015):
Sorry, I posted the above while catching up, prior to reading your last comment.
I changed to a SEEK_CUR to get the current offset (keeps the same logic for when/how much to reload), and the code is working 100% on vboxfs (with the files there).
That is the KEY for vboxfs. I think I can try to test this on an NFS mount at work. It possibly is the same problem. That once the file is 'there' and we flock(), then the APPEND mode gets non-corrupted files.
@jfoug commented on GitHub (Feb 6, 2015):
The current WILL change (in SEEK_CUR). Keep in mind, the APPEND mode. I am running that way right now, works fine. Try it out, you will (i think) be surprised ;) put the debugging on, so that you can follow the file offsets and lengths.
We are not using 'buffered' file stuff, where the CRTL will (or possibly) not hit the OS level. Here we are using 'raw' files. So we lock and get exclusive access, do a seek_cur, and the OS will seek to end of file, and give us the length. It sounds 'funny', but that is what is happening.
I have not tested this on cygwin yet. I will do a head slap if cygwin all of a sudden magically works, lol.
@magnumripper commented on GitHub (Feb 6, 2015):
Think again. We seek to end before writing.
What do you mean "works fine"? Does pot sync work fine? That is ALL this is about.
@jfoug commented on GitHub (Feb 6, 2015):
No, I am saying that the return from lseek for SEEK_CUR and SEEK_END are the same. But under the hood, I am not sure they are the same. With the return being the same, the other logic (determining that some other process has dropped a hunk of .pot that we need to re-read) should be the same as it was before.
@magnumripper commented on GitHub (Feb 6, 2015):
Of course they are, until someone else writes to the file.
@jfoug commented on GitHub (Feb 6, 2015):
Nope. Again, lseek(fp, SEEK_CUR) IF fp was opened in APPEND mode, does not give a shit about what the value was last time it checked. It will hit the OS and return the current end of file location. Now, if the file is exclusive locked, then the lseek(cur) will be the same location that we now write to. We then unlock. If 5 other processes add 500k of data to the file, and we later get exclusive to the file and lseek(cur), the value returned will still be the end of the file (500k bytes past the end of our last write).
@jfoug commented on GitHub (Feb 6, 2015):
It probably does not matter either way. This made no change at all to either cygwin or to vboxsf systems (NFS is still to be seen). We can certainly keep the SEEK_END, but it does not matter at all.
@magnumripper commented on GitHub (Feb 6, 2015):
Some implementation may work like you say (but that would waste resources), but that's not the spec. I hope you are not using vboxsf as any kind of reference as we have established it's very b0rken.
@magnumripper commented on GitHub (Feb 6, 2015):
What you say is guaranteed AFTER writing and BEFORE releasing the lock. But not BEFORE writing, and that's where we do have the SEEK_END you questioned.
@jfoug commented on GitHub (Feb 6, 2015):
I have only made a local change, and since it improved nothing, there is absolutely no reason to commit. I have been trying quite a bit to try to get cygwin working. vboxsf is not nearly as b0rked as cygwin. I 'can' get some runs to work out of it, but very few. Probably 75% of the time, a TS run will get part way through and deadlock.
@magnumripper commented on GitHub (Feb 6, 2015):
I have a feeling you should open a separate issue for Cygwin and keep this one solely for vboxsf. We are confused enough without mixing them in one :-)
@jfoug commented on GitHub (Feb 6, 2015):
Ok. I doubt cygwin will get fixed, but an issue certainly is not a bad thing. At least it gives me a place to dump WHAT I have seen and tried, even if I do not get it, someone else that wants it enough, may pick it up and continue.
@magnumripper commented on GitHub (Feb 6, 2015):
With all we learnt here I think we could track down the actual problem in Cygwin. If nothing else, we should be able to describe the exact problem. It's just a matter of establishing exactly when things are starting to go bad.
@magnumripper commented on GitHub (Feb 7, 2015):
Who knows, maybe the new fcntl() locking fixes your problem with vboxsf too.
@magnumripper commented on GitHub (Feb 7, 2015):
😄
@jfoug commented on GitHub (Feb 7, 2015):
😲
@magnumripper commented on GitHub (Feb 7, 2015):
Quoting RFC 1925: With sufficient thrust, pigs fly just fine.
@jfoug commented on GitHub (Feb 8, 2015):
Still failing. But I just checked build-info, and yes locking is fcntl(), BUT I also am built with memdbg=on and asan on. I will remove those and recheck.
Nope, fails just as bad, with or without memdbg and ASAN.
@jfoug commented on GitHub (Feb 8, 2015):
But when quoting that truth, only telling a 1/3 truth is unwise:
(3) With sufficient thrust, pigs fly just fine. However, this is
not necessarily a good idea. It is hard to be sure where they
are going to land, and it could be dangerous sitting under them
as they fly overhead.
@jfoug commented on GitHub (Feb 8, 2015):
I am just glad cygwin is working. I still am getting a machine lock up, but i think it is in the same format. I will lock the machine up again and make sure that the TS window is on top, so I can watch it ;)
I think it is one of the formats that has a flock in it (dmg_format ?) Nope, not that one. Well, I will run and make sure I write down where it crashed (after saving my desktop for quick restart, lol).
@magnumripper commented on GitHub (Feb 8, 2015):
dmg format has locking in some debug code iirc, not otherwise.
@jfoug commented on GitHub (Feb 8, 2015):
Are we happy with this issue?
The original problem I made this issue for still stands, but now we KNOW the work around. That is the corrupted files on vboxfs. That is Oracle's problem. If we run with the .pot file (and .log file) being on disk, then vboxfs works just fine. So that being the case, we really can not do much to fix John to fix this problem, other than creating and closing a zero byte .pot/.log file when john starts, IF they do not exist prior to the forking code launching children.
@magnumripper commented on GitHub (Feb 8, 2015):
Yes. It should be reported to Oracle and I think we can close this. You could add some text in doc/BUGS if you like, describing the known issue and workaround.
@magnumripper commented on GitHub (Feb 9, 2015):
Just in case some random googler find this: The above was 100% fixed when we switched to fcntl() locks instead of flock().
@jfoug commented on GitHub (Feb 9, 2015):
That is really good to hear that fcntl() works better. I was hoping that was the case, once I found the older documentation listing that it handled NFS correctly. I think the older BSD flock interface simply has not been given the same usage as fcntl, and thus bugs are not fixed as frequently.
Looking back, this was a pretty long thread over a bug. One of our longer ones. Both of us had to unlearn a few things we thought were true and also learn a few things we did not know about.
@magnumripper commented on GitHub (Feb 9, 2015):
Learning is easy, unlearning is the tricky shit! I was almost sure there would be no difference because I thought flock() was using fcntl() for NFS (at least). But this is now unlearned. I'm glad I tested it.
BTW I wrote a clone of flock(1) that was using fcntl instead just for testing. Maybe I should publish it somewhere.
@magnumripper commented on GitHub (Feb 9, 2015):
Heck, why not! https://github.com/magnumripper/fcntl-lock