[GH-ISSUE #704] Thin formats fail after format enumeration due to nested mess of init() #349

Closed
opened 2026-10-14 03:02:27 +07:00 by bsakaguchi · 19 comments
Owner

Originally created by @magnumripper on GitHub (Jul 24, 2014).
Original GitHub issue: https://github.com/openwall/john/issues/704

Originally assigned to: @jfoug on GitHub.

These formats fail in Test Suite...

$ ./jtrts.pl -passthru "--fork=2" -noprel -q
(...)
form=mediawiki                    guesses:    0 unk unk : Expected count(s) (1500)  [!!!FAILED!!!]
Self test failed (get_hash[0](0))
Self test failed (get_hash[0](0))
form=PHPS                         guesses:    0 unk unk : Expected count(s) (1500)  [!!!FAILED!!!]
Self test failed (get_hash[0](0))
Self test failed (get_hash[0](0))
(...)

...but not in --test:

$ ../run/john --test --form:phps
Benchmarking: PHPS [md5(md5($p).$s) 128/128 AVX 10x4x3]... DONE
Many salts: 31583K c/s real, 31583K c/s virtual
Only one salt:  10573K c/s real, 10573K c/s virtual

$ ../run/john --test --form:mediawiki
Benchmarking: MediaWiki [md5($s.md5($p)) 128/128 AVX 10x4x3]... DONE
Many salts: 18334K c/s real, 18334K c/s virtual
Only one salt:  9573K c/s real, 9573K c/s virtual

Very likely related to recent changes.

Originally created by @magnumripper on GitHub (Jul 24, 2014). Original GitHub issue: https://github.com/openwall/john/issues/704 Originally assigned to: @jfoug on GitHub. These formats fail in Test Suite... ``` $ ./jtrts.pl -passthru "--fork=2" -noprel -q (...) form=mediawiki guesses: 0 unk unk : Expected count(s) (1500) [!!!FAILED!!!] Self test failed (get_hash[0](0)) Self test failed (get_hash[0](0)) form=PHPS guesses: 0 unk unk : Expected count(s) (1500) [!!!FAILED!!!] Self test failed (get_hash[0](0)) Self test failed (get_hash[0](0)) (...) ``` ...but not in --test: ``` $ ../run/john --test --form:phps Benchmarking: PHPS [md5(md5($p).$s) 128/128 AVX 10x4x3]... DONE Many salts: 31583K c/s real, 31583K c/s virtual Only one salt: 10573K c/s real, 10573K c/s virtual $ ../run/john --test --form:mediawiki Benchmarking: MediaWiki [md5($s.md5($p)) 128/128 AVX 10x4x3]... DONE Many salts: 18334K c/s real, 18334K c/s virtual Only one salt: 9573K c/s real, 9573K c/s virtual ``` Very likely related to recent changes.
bsakaguchi 2026-10-14 03:02:27 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@jfoug commented on GitHub (Jul 24, 2014):

your --test does NOT test using --fork.

NOTE, I am still pretty sure that for some reason, when running under --fork, that either split or prepare is NOT always being called.

<!-- gh-comment-id:50083425 --> @jfoug commented on GitHub (Jul 24, 2014): your --test does NOT test using --fork. NOTE, I am still pretty sure that for some reason, when running under --fork, that either split or prepare is NOT always being called.
Author
Owner

@magnumripper commented on GitHub (Jul 25, 2014):

I am still pretty sure that for some reason, when running under --fork, that either split or prepare is NOT always being called.

I can't picture how that could be possible at all. But it should be easy to prove with some debug code.

<!-- gh-comment-id:50203940 --> @magnumripper commented on GitHub (Jul 25, 2014): > I am still pretty sure that for some reason, when running under --fork, that either split or prepare is NOT always being called. I can't picture how that could be possible at all. But it should be easy to prove with some debug code.
Author
Owner

@magnumripper commented on GitHub (Jul 25, 2014):

Hmm --test is supported with MPI, which mostly uses the same code as --fork. So I should test that.

<!-- gh-comment-id:50204136 --> @magnumripper commented on GitHub (Jul 25, 2014): Hmm --test is supported with MPI, which mostly uses the same code as --fork. So I should test that.
Author
Owner

@jfoug commented on GitHub (Jul 25, 2014):

The reason I claim this is because HEX leaking into dynas salt. There should be no way that happens either, but it does for fork.

<!-- gh-comment-id:50210151 --> @jfoug commented on GitHub (Jul 25, 2014): The reason I claim this is because HEX leaking into dynas salt. There should be no way that happens either, but it does for fork.
Author
Owner

@magnumripper commented on GitHub (Jul 25, 2014):

Not triggered with MPI and --test.

But it is reproducible using the TS command line, replacing fork with MPI:

$ mpirun -np 2 ../run/john -ses=./tst -pot=./tst.pot mediawiki_tst.in --wordlist=pw.dic
Self test failed (get_hash[0](0))
Loaded 1500 password hashes with no different salts (MediaWiki [md5($s.md5($p)) 128/128 AVX 6x4x5])
Node numbers 1-2 of 2 (MPI)
Self test failed (get_hash[0](0))
-------------------------------------------------------
Primary job  terminated normally, but 1 process returned
a non-zero exit code.. Per user-direction, the job has been aborted.
-------------------------------------------------------
--------------------------------------------------------------------------
mpirun detected that one or more processes exited with non-zero status, thus causing
the job to be terminated. The first process to do so was:

  Process name: [[53970,1],1]
  Exit code:    1
--------------------------------------------------------------------------
<!-- gh-comment-id:50211636 --> @magnumripper commented on GitHub (Jul 25, 2014): Not triggered with MPI and --test. But it _is_ reproducible using the TS command line, replacing fork with MPI: ``` $ mpirun -np 2 ../run/john -ses=./tst -pot=./tst.pot mediawiki_tst.in --wordlist=pw.dic Self test failed (get_hash[0](0)) Loaded 1500 password hashes with no different salts (MediaWiki [md5($s.md5($p)) 128/128 AVX 6x4x5]) Node numbers 1-2 of 2 (MPI) Self test failed (get_hash[0](0)) ------------------------------------------------------- Primary job terminated normally, but 1 process returned a non-zero exit code.. Per user-direction, the job has been aborted. ------------------------------------------------------- -------------------------------------------------------------------------- mpirun detected that one or more processes exited with non-zero status, thus causing the job to be terminated. The first process to do so was: Process name: [[53970,1],1] Exit code: 1 -------------------------------------------------------------------------- ```
Author
Owner

@magnumripper commented on GitHub (Jul 25, 2014):

That makes it even stranger. This means --node must be affected too... yep it is.

$ ../run/john -node=1/2 -ses=./tst -pot=./tst.pot mediawiki_tst.in --wordlist=pw.dic
Loaded 1500 password hashes with no different salts (MediaWiki [md5($s.md5($p)) 128/128 AVX 6x4x5])
Node number 1 of 2
Self test failed (get_hash[0](0))

$ ../run/john -node=2/2 -ses=./tst -pot=./tst.pot mediawiki_tst.in --wordlist=pw.dic
Loaded 1500 password hashes with no different salts (MediaWiki [md5($s.md5($p)) 128/128 AVX 6x4x5])
Node number 2 of 2
Self test failed (get_hash[0](0))
<!-- gh-comment-id:50211771 --> @magnumripper commented on GitHub (Jul 25, 2014): That makes it even stranger. This means --node must be affected too... yep it is. ``` $ ../run/john -node=1/2 -ses=./tst -pot=./tst.pot mediawiki_tst.in --wordlist=pw.dic Loaded 1500 password hashes with no different salts (MediaWiki [md5($s.md5($p)) 128/128 AVX 6x4x5]) Node number 1 of 2 Self test failed (get_hash[0](0)) $ ../run/john -node=2/2 -ses=./tst -pot=./tst.pot mediawiki_tst.in --wordlist=pw.dic Loaded 1500 password hashes with no different salts (MediaWiki [md5($s.md5($p)) 128/128 AVX 6x4x5]) Node number 2 of 2 Self test failed (get_hash[0](0)) ```
Author
Owner

@magnumripper commented on GitHub (Jul 25, 2014):

The good thing about it is it's easier to debug. Just use --node=1/2 and debug one single threaded process.

<!-- gh-comment-id:50211834 --> @magnumripper commented on GitHub (Jul 25, 2014): The good thing about it is it's easier to debug. Just use --node=1/2 and debug one single threaded process.
Author
Owner

@magnumripper commented on GitHub (Aug 4, 2014):

The split/prepare issue was fixed but this issue remains.

<!-- gh-comment-id:51009293 --> @magnumripper commented on GitHub (Aug 4, 2014): The split/prepare issue was fixed but this issue remains.
Author
Owner

@magnumripper commented on GitHub (Aug 8, 2014):

Bug does not surface if --format is given explicitly - I suspect this is a fmt_init() problem.

<!-- gh-comment-id:51637108 --> @magnumripper commented on GitHub (Aug 8, 2014): Bug does not surface if `--format` is given explicitly - I suspect this is a fmt_init() problem.
Author
Owner

@magnumripper commented on GitHub (Aug 8, 2014):

Same bug, different test case (no node/fork/MPI)

$ echo '$P$9.3kFP.wbT.DTzPtf8qGlTqRWC55Jr0' > test.john
$ ../run/john test.john
Loaded 1 password hash (phpass [phpass ($P$ or $H$) 32/64 1x2  (MD5_body)])
Self test failed (get_hash[1](0))
<!-- gh-comment-id:51640410 --> @magnumripper commented on GitHub (Aug 8, 2014): Same bug, different test case (no node/fork/MPI) ``` $ echo '$P$9.3kFP.wbT.DTzPtf8qGlTqRWC55Jr0' > test.john $ ../run/john test.john Loaded 1 password hash (phpass [phpass ($P$ or $H$) 32/64 1x2 (MD5_body)]) Self test failed (get_hash[1](0)) ```
Author
Owner

@magnumripper commented on GitHub (Aug 8, 2014):

@jfoug I try to understand the thin dynamic formats. For prepare(), valid() and split() to support being called before init(), they call each format's own get_ptr() function which sets the function pointers but also calls dynamic_THIN_FORMAT_LINK() which in turn does call dynamic_fmt's init(). I think the normal mechanism that prevents executing init() more than once is circumvented this way but that may be OK here. Or not?

Is there no better way to ensure all thin pre-init functions' pointers (and params.label etc) are initialized very early? Like in dynamic_Register_formats() or something?

<!-- gh-comment-id:51647623 --> @magnumripper commented on GitHub (Aug 8, 2014): @jfoug I try to understand the thin dynamic formats. For prepare(), valid() and split() to support being called before init(), they call each format's own get_ptr() function which sets the function pointers but also calls dynamic_THIN_FORMAT_LINK() which in turn does call dynamic_fmt's init(). I think the normal mechanism that prevents executing init() more than once is circumvented this way but that may be OK here. Or not? Is there no better way to ensure all thin pre-init functions' pointers (and params.label etc) are initialized very early? Like in dynamic_Register_formats() or something?
Author
Owner

@magnumripper commented on GitHub (Aug 8, 2014):

With some debug prints:

$ ../run/john test.john
dynamic_THIN_FORMAT_LINK() calling init(dynamic_61)
init(dynamic_61)
dynamic_THIN_FORMAT_LINK() calling init(dynamic_4)
init(dynamic_4)
dynamic_THIN_FORMAT_LINK() calling init(dynamic_6)
init(dynamic_6)
dynamic_THIN_FORMAT_LINK() calling init(dynamic_20)
init(dynamic_20)
dynamic_THIN_FORMAT_LINK() calling init(dynamic_9)
init(dynamic_9)
dynamic_THIN_FORMAT_LINK() calling init(dynamic_17)
init(dynamic_17)
ldr_split_line() calling fmt_init(phpass)
thin_phpassmd5_init(phpass)
dynamic_THIN_FORMAT_LINK() calling init(dynamic_19)
init(dynamic_19)
our_split(phpass)
john_load() calling fmt_init(phpass)
Loaded 1 password hash (phpass [phpass ($P$ or $H$) 32/64 1x2  (MD5_body)])
our_split(phpass)
our_split(phpass)
Self test failed (get_hash[1](0))

What's with that last init(dynamic_19)? That is probably the problem but why does it happen?
EDIT: It's because we enumerate alternative formats for this ciphertext, because --format was not given.

EDIT no, the last init() is phpass from john_load() so that should not be a big deal.

<!-- gh-comment-id:51648621 --> @magnumripper commented on GitHub (Aug 8, 2014): With some debug prints: ``` $ ../run/john test.john dynamic_THIN_FORMAT_LINK() calling init(dynamic_61) init(dynamic_61) dynamic_THIN_FORMAT_LINK() calling init(dynamic_4) init(dynamic_4) dynamic_THIN_FORMAT_LINK() calling init(dynamic_6) init(dynamic_6) dynamic_THIN_FORMAT_LINK() calling init(dynamic_20) init(dynamic_20) dynamic_THIN_FORMAT_LINK() calling init(dynamic_9) init(dynamic_9) dynamic_THIN_FORMAT_LINK() calling init(dynamic_17) init(dynamic_17) ldr_split_line() calling fmt_init(phpass) thin_phpassmd5_init(phpass) dynamic_THIN_FORMAT_LINK() calling init(dynamic_19) init(dynamic_19) our_split(phpass) john_load() calling fmt_init(phpass) Loaded 1 password hash (phpass [phpass ($P$ or $H$) 32/64 1x2 (MD5_body)]) our_split(phpass) our_split(phpass) Self test failed (get_hash[1](0)) ``` What's with that last `init(dynamic_19)`? That is probably the problem but why does it happen? _EDIT:_ It's because we enumerate alternative formats for this ciphertext, because --format was not given. _EDIT_ no, the last init() is phpass from john_load() so that should not be a big deal.
Author
Owner

@magnumripper commented on GitHub (Aug 8, 2014):

...and using --format

$ ../run/john --format=phpass test.john 
dynamic_THIN_FORMAT_LINK() calling init(dynamic_17)
init(dynamic_17)
ldr_split_line() calling fmt_init(phpass)
thin_phpassmd5_init(phpass)
our_split(phpass)
john_load() calling fmt_init(phpass)
Loaded 1 password hash (phpass [phpass ($P$ or $H$) 32/64 1x2  (MD5_body)])
our_split(phpass)
(...)
john_log_format() calling fmt_init(phpass)
Press 'q' or Ctrl-C to abort, almost any other key for status
0g 0:00:00:23  2/3 0g/s 3389p/s 3389c/s 3389C/s 2miranda..2miriam
Session aborted

Bug does not surface because we do not enumerate alternate formats.

<!-- gh-comment-id:51649192 --> @magnumripper commented on GitHub (Aug 8, 2014): ...and using `--format` ``` $ ../run/john --format=phpass test.john dynamic_THIN_FORMAT_LINK() calling init(dynamic_17) init(dynamic_17) ldr_split_line() calling fmt_init(phpass) thin_phpassmd5_init(phpass) our_split(phpass) john_load() calling fmt_init(phpass) Loaded 1 password hash (phpass [phpass ($P$ or $H$) 32/64 1x2 (MD5_body)]) our_split(phpass) (...) john_log_format() calling fmt_init(phpass) Press 'q' or Ctrl-C to abort, almost any other key for status 0g 0:00:00:23 2/3 0g/s 3389p/s 3389c/s 3389C/s 2miranda..2miriam Session aborted ``` Bug does not surface because we do not enumerate alternate formats.
Author
Owner

@magnumripper commented on GitHub (Aug 8, 2014):

EDIT no, the last init() is phpass from john_load() so that should not be a big deal.

But that IS the problem. Because the THIN_FORMAT_LINK() overrides the "format already initialized" but fmt_init() does not. So the last fmt_init(phpass) is a NO-OP and dynamic remains (half?) initialized for dynamic 19 instead of 17.

<!-- gh-comment-id:51650449 --> @magnumripper commented on GitHub (Aug 8, 2014): > _EDIT_ no, the last init() is phpass from john_load() so that should not be a big deal. But that IS the problem. Because the THIN_FORMAT_LINK() overrides the "format already initialized" but fmt_init() does not. So the last fmt_init(phpass) is a NO-OP and dynamic remains (half?) initialized for dynamic 19 instead of 17.
Author
Owner

@magnumripper commented on GitHub (Aug 10, 2014):

This bug is caused by 6cbc3065 alone.

<!-- gh-comment-id:51702442 --> @magnumripper commented on GitHub (Aug 10, 2014): This bug is caused by 6cbc3065 alone.
Author
Owner

@jfoug commented on GitHub (Aug 18, 2014):

I believe this is fixed in bb1b1aa

<!-- gh-comment-id:52502608 --> @jfoug commented on GitHub (Aug 18, 2014): I believe this is fixed in bb1b1aa
Author
Owner

@jfoug commented on GitHub (Aug 18, 2014):

--test=0 works
Running a PHPS hash without using --format works (also works if you use the --format=phps)
test suite works.
tested cygwin32/64 and ubuntu64.

Also, we now properly link salt/prepare, etc early. This was the reason for the change before. We had 'work around' code to skip some stuff for dyna formats. We hopefully can remove that now. Their functions which should work prior to init now 'should' work, even for thin dynas. That was not an easy task to get done, but I think it now IS done. There are a lot of nuances within john, where things get done, dont get done, etc, depending upon modes, on loading a file, loading a pot, etc, etc. Hopefully now that dyna is there, we can start to remove some of these.

I am leaving bug open, until magnum can validate that he's happy with this. Hmm, I never closed this, but github may have done so, based upon my comments.

<!-- gh-comment-id:52505161 --> @jfoug commented on GitHub (Aug 18, 2014): --test=0 works Running a PHPS hash without using --format works (also works if you use the --format=phps) test suite works. tested cygwin32/64 and ubuntu64. Also, we now properly link salt/prepare, etc early. This was the reason for the change before. We had 'work around' code to skip some stuff for dyna formats. We hopefully can remove that now. Their functions which should work prior to init now 'should' work, even for thin dynas. That was not an easy task to get done, but I think it now IS done. There are a lot of nuances within john, where things get done, dont get done, etc, depending upon modes, on loading a file, loading a pot, etc, etc. Hopefully now that dyna is there, we can start to remove some of these. I am leaving bug open, until magnum can validate that he's happy with this. Hmm, I never closed this, but github may have done so, based upon my comments.
Author
Owner

@magnumripper commented on GitHub (Aug 18, 2014):

Seems fine to me.

How come this is needed though? The thin formats have a normal format struct (though not fully populated) that already initializes eg. valid() to our_valid(). So why do we need link_funcs()? I can see it is needed but I do not really get why.

<!-- gh-comment-id:52521325 --> @magnumripper commented on GitHub (Aug 18, 2014): Seems fine to me. How come this is needed though? The thin formats have a normal format struct (though not fully populated) that already initializes eg. valid() to our_valid(). So why do we need link_funcs()? I can see it is needed but I do not really get why.
Author
Owner

@jfoug commented on GitHub (Aug 18, 2014):

Within the call to link_dyna, the dyna code copies pointers from the 'built in' dyna format. All of those method pointers are to canned dyna functions. In the original code I had, I was setting our thin methods (salt, binary, etc) in the init of the thin format. I moved that code into the get_ptr, but it was only called the first time. However, the linkage was being done also in init. This would reset the format structure's methods to default dyna. THIS was the bug.

So I pulled that code out and put it into a function. Now get_ptr calls this function after calling the dyna_link function with the 'also call init' flag clear. This will give us our pointer AND set all the methods to be part of the thin. So now things like split/prepare will properly work using the thin methods (if thin overrides them). Then when init is called, the dyna_link is also called settingthe 'also call init' flag to set.

<!-- gh-comment-id:52535988 --> @jfoug commented on GitHub (Aug 18, 2014): Within the call to link_dyna, the dyna code copies pointers from the 'built in' dyna format. All of those method pointers are to canned dyna functions. In the original code I had, I was setting our thin methods (salt, binary, etc) in the init of the thin format. I moved that code into the get_ptr, but it was only called the first time. However, the linkage was being done also in init. This would reset the format structure's methods to default dyna. THIS was the bug. So I pulled that code out and put it into a function. Now get_ptr calls this function after calling the dyna_link function with the 'also call init' flag clear. This will give us our pointer AND set all the methods to be part of the thin. So now things like split/prepare will properly work using the thin methods (if thin overrides them). Then when init is called, the dyna_link is also called settingthe 'also call init' flag to set.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#349
No description provided.