[GH-ISSUE #2679] CPU fallback might break in some builds. #1733

Closed
opened 2026-10-15 04:23:45 +07:00 by bsakaguchi · 11 comments
Owner

Originally created by @magnumripper on GitHub (Aug 16, 2017).
Original GitHub issue: https://github.com/openwall/john/issues/2679

f7235fca13 broke CPU detection/fallback in certain cases. Jim put the CRC32_Init_tab() in john.c and it may end up containing eg. AVX2 instructions. See https://github.com/magnumripper/JohnTheRipper/issues/2674#issuecomment-322801462

Originally created by @magnumripper on GitHub (Aug 16, 2017). Original GitHub issue: https://github.com/openwall/john/issues/2679 f7235fca13 broke CPU detection/fallback in certain cases. Jim put the CRC32_Init_tab() in john.c and it may end up containing eg. AVX2 instructions. See https://github.com/magnumripper/JohnTheRipper/issues/2674#issuecomment-322801462
bsakaguchi 2026-10-15 04:23:45 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@solardiz commented on GitHub (Aug 17, 2017):

Strictly speaking, jumbo's calling sig_preinit() and path_init() before CPU fallback is also a bug, until/unless we build signals.c and path.c without CPU type specific optimizations (like I think/hope we do for john.c, or don't we?) We're just "lucky" the compiler doesn't yet use (advanced) SIMD instructions in those functions.

I've just verified that none of this is in core, where CPU_detect_or_fallback() is reached without those external files' function calls. I don't know why we introduced/moved them in jumbo - I am not sure that was sound reasoning, but OTOH I don't rule out that core might have needed to do it for some reason I am unaware of. The core tree's CPU fallback works just fine in the Owl package.

<!-- gh-comment-id:323135434 --> @solardiz commented on GitHub (Aug 17, 2017): Strictly speaking, jumbo's calling `sig_preinit()` and `path_init`() before CPU fallback is also a bug, until/unless we build `signals.c` and `path.c` without CPU type specific optimizations (like I think/hope we do for `john.c`, or don't we?) We're just "lucky" the compiler doesn't yet use (advanced) SIMD instructions in those functions. I've just verified that none of this is in core, where `CPU_detect_or_fallback()` is reached without those external files' function calls. I don't know why we introduced/moved them in jumbo - I am not sure that was sound reasoning, but OTOH I don't rule out that core might have needed to do it for some reason I am unaware of. The core tree's CPU fallback works just fine in the Owl package.
Author
Owner

@solardiz commented on GitHub (Aug 17, 2017):

without CPU type specific optimizations (like I think/hope we do for john.c, or don't we?)

We do (or at least can) in core, due to these lines in Makefile:

john.o: john.c
        $(CC) $(CFLAGS_MAIN) $(OPT_NORMAL) $*.c

Owl's john.spec in some cases manages CFLAGS_MAIN separately.

<!-- gh-comment-id:323136734 --> @solardiz commented on GitHub (Aug 17, 2017): > without CPU type specific optimizations (like I think/hope we do for john.c, or don't we?) We do (or at least can) in core, due to these lines in `Makefile`: ``` john.o: john.c $(CC) $(CFLAGS_MAIN) $(OPT_NORMAL) $*.c ``` Owl's `john.spec` in some cases manages `CFLAGS_MAIN` separately.
Author
Owner

@ghost commented on GitHub (Aug 17, 2017):

Strictly speaking, jumbo's calling [...] path_init() before CPU fallback is also a bug

Jumbo uses path_expand("$JOHN/" CPU_FALLBACK_BINARY) inside CPU_detect_or_fallback(); so, if you do not do path_init() before it, you do not have $JOHN properly expanded and JTR will fail.

BTW: fallback works nicely on Linux (maybe also on Windows, I can't remember). On Linux, I've been packaging/testing it every week or so. Note, only for gcc.

<!-- gh-comment-id:323142826 --> @ghost commented on GitHub (Aug 17, 2017): > Strictly speaking, jumbo's calling [...] path_init() before CPU fallback is also a bug Jumbo uses `path_expand("$JOHN/" CPU_FALLBACK_BINARY)` inside `CPU_detect_or_fallback()`; so, if you do not do path_init() before it, you do not have $JOHN properly expanded and JTR will fail. BTW: fallback works nicely on Linux (maybe also on Windows, I can't remember). On Linux, I've been packaging/testing it every week or so. Note, only for gcc.
Author
Owner

@magnumripper commented on GitHub (Aug 17, 2017):

So we should build signals.o and path.o with same CFLAGS as john.o. This should be really trivial. Reopening for this.

<!-- gh-comment-id:323171211 --> @magnumripper commented on GitHub (Aug 17, 2017): So we should build signals.o and path.o with same CFLAGS as john.o. This should be really trivial. Reopening for this.
Author
Owner

@magnumripper commented on GitHub (Aug 17, 2017):

The move of sig_init (now sig_preinit) was caused by #798 where Frank came up with some pretty ridiculous test cases that I couldn't really rule out as not having any significance.

<!-- gh-comment-id:323173522 --> @magnumripper commented on GitHub (Aug 17, 2017): The move of sig_init (now sig_preinit) was caused by #798 where Frank came up with some pretty ridiculous test cases that I couldn't really rule out as not having any significance.
Author
Owner

@magnumripper commented on GitHub (Aug 21, 2017):

So we should build signals.o and path.o with same CFLAGS as john.o. This should be really trivial.

It's not quite that trivial. We may build path.o and signals.o using CFLAGS_MAIN but then path.o in turn call memory.o and so on so it's still not 100% safe. Jumbo's early path_init() is for being able to know fallback binary path (basically, define $JOHN) when using fallback without SYSTEMWIDE (which core John doesn't allow). Maybe instead we could simply use something like dirname(argv[0]) and concatenate it with CPU_FALLBACK_BINARY (and a slash inbetween).

For sig_preinit() I'm pretty sure just building signals.o with CFLAGS_MAIN is enough though.

<!-- gh-comment-id:323809836 --> @magnumripper commented on GitHub (Aug 21, 2017): > So we should build signals.o and path.o with same CFLAGS as john.o. This should be really trivial. It's not quite that trivial. We may build path.o and signals.o using CFLAGS_MAIN but then path.o in turn call memory.o and so on so it's still not 100% safe. Jumbo's early path_init() is for being able to know fallback binary path (basically, define `$JOHN`) when using fallback without SYSTEMWIDE (which core John doesn't allow). Maybe instead we could simply use something like `dirname(argv[0])` and concatenate it with CPU_FALLBACK_BINARY (and a slash inbetween). For sig_preinit() I'm pretty sure just building signals.o with CFLAGS_MAIN is enough though.
Author
Owner

@ghost commented on GitHub (Dec 15, 2018):

Bug closed as:

  • Low Priority - They have a tendency to become high priority if enough of the users complain.

  • Business Priority - Obsolete hardware and software. Hardware nobody owns, etc.

  • Fixed - It was fixed.

<!-- gh-comment-id:447587932 --> @ghost commented on GitHub (Dec 15, 2018): Bug closed as: * **Low Priority** - They have a tendency to become high priority if enough of the users complain. * **Business Priority** - Obsolete hardware and software. Hardware nobody owns, etc. * **Fixed** - It was fixed.
Author
Owner

@magnumripper commented on GitHub (Dec 15, 2018):

I just hope the very recent change to -O1 doesn't break it (but that particular thing shouldn't AFAIK)

<!-- gh-comment-id:447592988 --> @magnumripper commented on GitHub (Dec 15, 2018): I just hope the very recent change to `-O1` doesn't break it (but that particular thing shouldn't AFAIK)
Author
Owner

@magnumripper commented on GitHub (Apr 6, 2020):

Reopening due to #4245. Not sure what's happening but we should build wpapcap2john.o (maybe all symlink binaries) without CPU type specific optimizations - are we not? Does core john? Aren't we falling back before calling the "symlink main"?

Also, I'm assuming building signals.o without CPU type specific optimizations wouldn't result in a performance issue, so we should. We should also implement the simpler "dirname" stuff (actually somethin' like strrchr(argv[0], '/')) I mentioned above.

Finally we could/should add comments to any function below main() in john.c that needs to be fallback-safe.

<!-- gh-comment-id:609510658 --> @magnumripper commented on GitHub (Apr 6, 2020): Reopening due to #4245. Not sure what's happening but we should build wpapcap2john.o (maybe all symlink binaries) without CPU type specific optimizations - are we not? Does core john? Aren't we falling back before calling the "symlink main"? Also, I'm assuming building signals.o without CPU type specific optimizations wouldn't result in a performance issue, so we should. We should also implement the simpler "dirname" stuff (actually somethin' like `strrchr(argv[0], '/')`) I mentioned above. Finally we could/should add comments to any function below `main()` in john.c that needs to be fallback-safe.
Author
Owner

@solardiz commented on GitHub (May 25, 2024):

jumbo's calling sig_preinit() and path_init() before CPU fallback is also a bug, until/unless we build signals.c and path.c without CPU type specific optimizations

We no longer call sig_preinit before CPU fallback, but we still do call path_init, which I still think is a bug.

<!-- gh-comment-id:2130565954 --> @solardiz commented on GitHub (May 25, 2024): > jumbo's calling `sig_preinit()` and `path_init`() before CPU fallback is also a bug, until/unless we build `signals.c` and `path.c` without CPU type specific optimizations We no longer call `sig_preinit` before CPU fallback, but we still do call `path_init`, which I still think is a bug.
Author
Owner

@solardiz commented on GitHub (May 25, 2024):

See @claudioandre-br's work in #2277 and #2280. The problem is in jumbo we sometimes use $JOHN for the fallback path:

#ifdef JOHN_SYSTEMWIDE_EXEC
#define CPU_FALLBACK_PATHNAME JOHN_SYSTEMWIDE_EXEC "/" CPU_FALLBACK_BINARY
#else
#define CPU_FALLBACK_PATHNAME path_expand("$JOHN/" CPU_FALLBACK_BINARY)
#endif

This was introduced by @magnumripper in 9852e5e88c, And we currently use that functionality in some of our binary builds, right?

So it looks like we need to make path_init safe to call before fallback, rather than avoid that call.

<!-- gh-comment-id:2130601748 --> @solardiz commented on GitHub (May 25, 2024): See @claudioandre-br's work in #2277 and #2280. The problem is in jumbo we sometimes use `$JOHN` for the fallback path: ```c #ifdef JOHN_SYSTEMWIDE_EXEC #define CPU_FALLBACK_PATHNAME JOHN_SYSTEMWIDE_EXEC "/" CPU_FALLBACK_BINARY #else #define CPU_FALLBACK_PATHNAME path_expand("$JOHN/" CPU_FALLBACK_BINARY) #endif ``` This was introduced by @magnumripper in 9852e5e88c5ef48fd5fc1fe7fbdc3aa70a07d614, And we currently use that functionality in some of our binary builds, right? So it looks like we need to make `path_init` safe to call before fallback, rather than avoid that call.
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#1733
No description provided.