mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #2065] *** buffer overflow detected *** on qemu-arm #1385
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#1385
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 @lei-april on GitHub (Feb 24, 2016).
Original GitHub issue: https://github.com/openwall/john/issues/2065
Originally assigned to: @lei-april on GitHub.
When I run
john --teston qemu-arm, it aborts at format 'xsha512' and printsBut when I try to run
john --test --format=xsha512and the remaining formats individually, everything just goes fine.Ideas?
@magnumripper commented on GitHub (Feb 24, 2016):
You could test individual format using
-test-full=0and see if it triggers something. Or a smaller subsets of "many" formats with-test -form:x*. Also, if you can build with ASan that is likely to help nailing it.@lei-april commented on GitHub (Feb 24, 2016):
Building with ASan does re-trigger the
*** buffer overflow detected ***error on xsha512, apart from which it gives no other useful info.It's theoretically possible to remotely debug john in QEMU, which seems a bit painful though...
@frank-dittrich commented on GitHub (Feb 24, 2016):
On my Raspberry Pi 2, I also get a segfault. I am sure I ran the --test successfully not too long ago. So I think it must be a recent regression. Will bisect and see if I can get a useful backtrace from an ASan build.
@magnumripper commented on GitHub (Feb 24, 2016):
That sounds like you don't actually get ASan but perhaps only -Og or -O1 or something. The configure script doesn't handle "no ASan supported" very well - it's silently ignored.
@lei-april commented on GitHub (Feb 25, 2016):
I think I did get ASan enabled. I upgraded the cross-compiler to gcc 5.2 to get this feature, and there is indeed a
-fsanitize=addressoption in Makefile after configuring.@magnumripper commented on GitHub (Feb 25, 2016):
OK. But what's the actual origin of the message
*** buffer overflow detected ***? Is it libc? Apparently it actually stops us from getting an ASan diagnose because it bails out before buffers are actually getting thrashed.@frank-dittrich commented on GitHub (Feb 25, 2016):
@zzlei Does
./john --list=build-infoprintASanin theBuild:line?@magnumripper
git grepon latest glibc:@lei-april commented on GitHub (Feb 25, 2016):
Yep.
@frank-dittrich commented on GitHub (Feb 25, 2016):
@zzlei can you run the self test in gdb and see if you get a useful stack?
When I run the test, I always get a corrupted stack. But it looks like your build has
-D_FORTIFY_SOURCE=1 -fstack-protectoror something similar included.May be I'll get a useful backtrace when I try to add
to ./configure.
If it helps to get a useful backtrace, we should add -fstack-protector to all debug builds.
@frank-dittrich commented on GitHub (Feb 25, 2016):
Still without
CFLAGS_EXTRA="-D_FORTIFY_SOURCE=1 -fstack-protector", I tested the top 18 recent commits. 9 of those ended with a segfault, 9 didn't. The pattern looks somewhat random.I couldn't reproduce the segfaults for recent commits when I tried to add --enable-memdbg or --enable-asan to ./configure.
@frank-dittrich commented on GitHub (Feb 25, 2016):
Here's a backtrace
This is with 1.8.0-jumbo-1-4690-g16aa93b, using
./configure CFLAGS_EXTRA="-D_FORTIFY_SOURCE=1 -fstack-protector"@lei-april commented on GitHub (Feb 25, 2016):
OK.
But as I'm running john in QEMU (user mode), remote debugging is the only way, which probably need some setup first.
@lei-april commented on GitHub (Feb 25, 2016):
I find no
-fstack-proctectorin Makefile. But even after I recompiled XSHA512_fmt_plug.c with this option and then rebuilt john, I still get this error.@frank-dittrich commented on GitHub (Feb 25, 2016):
@zzlei Since I got the backtrace on my Raspberry Pi 2, I think you don't need to do this anymore.
For some reason, your build envoronment must have used -fstack-protector or -D_FORTIFY_SOURCE=1 or -D_FORTIFY_SOURCE=2 (see man 7 feature_test_macros).
After I used
I also got the
*** buffer overflow detected ***: /home/pi/git/JtR/run/john terminatedoutput.(I probably could have used gdb to get a back trace even without this CFLAGS_EXTRA change.
I would just have needed to
continueafter gdb detected the illegal statement caused by OpenSSL's CPU probing.)So, the error is in the strcpy in line 203 of XSHA512_fmt_plug.c
To reproduce, an architecture where ARCH_ALLOWS_UNALIGNED isn't true is needed.
(Not sure if you could use
CFLAGS_EXTRA="-DARCH_ALLOWS_UNALIGNED=0"to reproduce this on x86-64.)@lei-april commented on GitHub (Feb 25, 2016):
buf_alignedis a local array of sizePLAINTEXT + 1, andPLAINTEXT_LENGTHis just 107 in this context. I'm not sure if this is big enough to cause buffer overflow...I'll try tinkering with
ARCH_ALLOWS_UNALIGNEDin an x86 build then.UPDATE: I do get a buffer overflow in a x86-64 build with
-DARCH_ALLOWS_UNALIGNED=0.@frank-dittrich commented on GitHub (Feb 25, 2016):
I just added an assert(strlen(key+4) <= PLAINTEXT_LEN).
With just testing xsha512, everything is fine.
Now I test everything and see if that assert fails.
If so, I'll repeat this from within gdb. (It's just that testing all formats on Raspberry Pi 2 takes a while.)
@lei-april commented on GitHub (Feb 25, 2016):
Curiously, after inserting
assert(strlen(key+4) <= PLAINTEXT_LEN);before the problematicstrcpy, ASan kicks in right whenstrlenis executed and reports a heap buffer overflow.So it's not likely that
keyis too long, since it could only cause a stack overflow. I'm even more confused now...@lei-april commented on GitHub (Feb 25, 2016):
Oh I see. The problem is that
key + 4is not necessary null-terminated.We could change
strcpy(buf_aligned, key+4)tomemcpy(buf_aligned, key + 4, PLAINTEXT_SIZE + 1)ormemcpy(buf_aligned, key + 4, max(strlen(key) - 4, 0)).@frank-dittrich commented on GitHub (Feb 25, 2016):
What is the purpose of that key+4, anyway?
If the password candidate has a strlen of 1 or 2, key+4 points to some random memory location.
@jfoug commented on GitHub (Feb 25, 2016):
Try this:
(Note, this was handed edited a couple times, so take the diff from this post, not what may have been emailed out. The length >= 4 vs length > 4 is critical.)
@jfoug commented on GitHub (Feb 25, 2016):
key+4 gets us to the next 8 byte aligned spot in the key buffer. There is 4 bytes already loaded for salt, we load the next 4 using one-sy inserts, then we can roll into using 64 byte faster copy logic.
This was an obvious bug, but untested, since if key WAS aligned, then k+4 is NOT aligned, and we would blindly do a strcpy of data which may or may not be part of the key. So when key was < 4 bytes long, we would start strcpying random data, and since we had no idea what it was, buffer overflow...
@frank-dittrich commented on GitHub (Feb 25, 2016):
@jfoug will test your change with that commit
github.com/frank-dittrich/JohnTheRipper@a090d91ffbon top of it.(Fixing a syntax error and compiler warnings.)
Once that's tested, I'll push my commit upstream.
@frank-dittrich commented on GitHub (Feb 25, 2016):
With commit
c8ad432d38, the segfault / buffer overflow is gone.@zzlei If you still see any problems, please reopen.
@jfoug commented on GitHub (Feb 25, 2016):
I had no real way to test this, so the original commit was done blind. @frank-dittrich thanks for correcting the code. The 'logic' was right, and it was pretty easy to see that the strcpy should only OPTIONALLY be called, and that if the strlen was <= 3, that the 1-off byte copying would goto the end, skipping any usage of that buf_aligned data, so skipping the strcpy was 100% valid in that situation.
Good this bug is smoked.
@frank-dittrich commented on GitHub (Feb 25, 2016):
Should we add
-D_FORTIFY_SOURCE=1 -fstack-protectorto debug builds (memdbg, ASan, UbSan), because it hopefully detects problems which might bot be found or harder to find otherwise?BTW: Do we need to
#include <features.h>? Seeman 7 feature_test_macros.So far, only the (copied) config.guess uses features.h:
@magnumripper commented on GitHub (Feb 25, 2016):
Unless I missed something here, those options were the reason Lei didn't get a proper ASan crash report. So I would say definitely not!
@jfoug commented on GitHub (Feb 25, 2016):
I fully agree. This would have shown up much easier with ASAN, than buried deep in the clib. This would be an option that would hinder more than help