mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #2868] Formats failing on big endian system / Mem-aligned systems. #1822
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#1822
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 @kholia on GitHub (Nov 10, 2017).
Original GitHub issue: https://github.com/openwall/john/issues/2868
These formats are failing on my emulated Debian 8 PPC64 VM.
We are already tracking
leetin issue https://github.com/magnumripper/JohnTheRipper/issues/2414.The
POMELOcode is terrible, and hard to read.@jfoug commented on GitHub (Nov 10, 2017):
Yup, on my BE system, the only one left is Pomelo, and it is ugly as can be. I will allow someone else to play with that one. I looked a bit (dumping out data buffers), and something in the macros is very wrong, when used on BE systems. Yuk!
@kholia commented on GitHub (Nov 10, 2017):
For some reason,
mscashis failing on my PPC64 VM. Themscashcode isn't too beautiful either ;)@solardiz commented on GitHub (Nov 10, 2017):
We should be able to drop the POMELO format. Chances are no one will ever use it. It was a PHC finalist (one of many), which in the end was not selected.
@kholia commented on GitHub (Nov 10, 2017):
@solardiz Thanks! I will open a PR for doing so soon.
@jfoug commented on GitHub (Nov 10, 2017):
This is on my sparc box, but that is a 32 bit binary.
I can not build OMP on that sparc (using gcc). But it appears you also are not using OMP and yours fails.
@kholia commented on GitHub (Nov 10, 2017):
On my PPC64 VM,
NOTE: The userland is 32-bit.
@kholia commented on GitHub (Nov 11, 2017):
POMELO was disabled for BE machines in https://github.com/magnumripper/JohnTheRipper/pull/2872.
@jfoug commented on GitHub (Nov 12, 2017):
Now building on PPC64 box (with 32 bit compiler), I also see the mscash format failing. Good. Now I can work myself to figure this thing out. Btw, I am running an OMP build. My sparc box I could not do OMP. I could only get john to build using gcc, not using CC (sun studio compiler), and for gcc, I could not figure out how to build a working binary with OMP.
@jfoug commented on GitHub (Nov 13, 2017):
mscash1 fixed here
1f1832edbThis had nothing to do with endianity. It was already correct. This had to do with mixing 16 bit and 32 bit access (in the swapping of getsalt).Note, Pomelo is only candidate likely left, but since it is disabled, once we are happy with that disable, this issue is completed (for now ;) It always seems to need addressed every 6 months or so.
@jfoug commented on GitHub (Nov 13, 2017):
NOTE, the QEMU install of PPC64 may not show all alignment crashes :( It does show that the endianity logic is correct.
@kholia commented on GitHub (Nov 13, 2017):
Thanks @jfoug 👍
This issue can be closed now.
@kholia commented on GitHub (Nov 17, 2017):
I had my suspicions around this too.
https://stackoverflow.com/questions/25785392/generate-unaligned-memory-access-exception-in-powerpc is a relevant read.
It depends on your POWERPC processor. High end server processors like POWER8 will almost never generate alignment exceptions. That being said, often there is a HID SPR bit to make alignment exceptions occur more often. Either way, under Linux, the kernel will handle them and the user won't see it, other than a performance loss. You can set the prctl(PR_UNALIGN_SIGBUS) and this will make the kernel generate a SIGBUS, rather than handle them. (Michael Neuling).
My takeaways,
Instead of emulating POWER8 (via QEMU flags
-M pseries -cpu POWER8E) we can emulate an older PPC CPU. Maybe this can help? To do this, simply remove the-M pseries -cpu POWER8E -smp 4 -m 2G --accel tcg,thread=multiarguments from the QEMU command.Experiment with
prctl(PR_UNALIGN_SIGBUS)stuff a bit to see if it makes a difference.@kholia commented on GitHub (Nov 17, 2017):
No luck crashing the following program,
I tried this on QEMU emulated POWER7 and POWER8 platforms. Maybe QEMU doesn't emulate such hardware functionality?
@jfoug Does this program crash on your real big-endian hardware?
Update: Fixed OOB read in the code.
@jfoug commented on GitHub (Nov 17, 2017):
sounds like ARM is a good source to generate not-aligned faults. I think MIPS is also good. I wonder if we can setup QEMU for these chips and deal with finding these problems.
Also, I am going to do some tests using
-Wcast-alignand see if it is any good at really finding the problems. We have already identified many such problems. i will do a sparc build, with that flag, AND removing the john unaligned flag within the arch.h for the build, and make sure it catches EVERY instance which we have caught. If so, then that is pretty easily our answer going forward. But I would strongly bet that it does not catch them all.@jfoug commented on GitHub (Nov 17, 2017):
Very possible, since the underlying real iron does not generate them at all. Btw, you overflow the buffer in your test case ;) Should have been array of size 6
Try that with long long (and memory to fit) I bet you might get a crash then.
@kholia commented on GitHub (Nov 17, 2017):
http://antirez.com/news/111 seems very relevant to this discussion. Maybe we can use Raspberry Pi for catching unaligned access patterns?
@kholia commented on GitHub (Nov 17, 2017):
Oh, yes! ;)
@kholia commented on GitHub (Nov 17, 2017):
No luck crashing the following program either.
Next things to try -> Emulate SPARC under QEMU (IIRC I have done this before). Experiment with Raspberry Pi.
Update:
Some random notes on MIPS -> https://github.com/kholia/mips-hacking
@jfoug commented on GitHub (Nov 17, 2017):
I tried them both (at once), AND I also added this to the printf(s)
Also, %ld is not right for long long ;) but that is not a problem, The *p would trip the bug. i tested (fully) int and long long, and neither tripped a trap for either 32 bit (default) or -m64 builds
Looks like either we can use the extra warning, OR try to emulate a hardware that cores, OR just build on the RBPI3 (which I have a drawer full of them), and build WITHOUT align required, and watch for it to crash. If that env works, we can always run on it to crash test for alignment.
@jfoug commented on GitHub (Nov 17, 2017):
I changed title, and am going to re-open this bug. Too much good discussion to simply have it fall off the end of time.
@jfoug commented on GitHub (Nov 17, 2017):
Also, I am going to see if I can pick up an old sparc box from work, before I hit the door at end of year. Trust me, you get a 15-20 year old sparc, and that F'er will crash all over the place at ANY mis aligned access.
@kholia commented on GitHub (Nov 17, 2017):
LOL, nice! All the best for getting the box 👍
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/arm/mem_alignment is relevant for ARM machines. Now I just need to figure out where I kept my Raspberry Pi 2.
@kholia commented on GitHub (Nov 17, 2017):
On Raspberry Pi 2, I see a
Bus errorwhen trying to deference a misalignedlong longpointer but no problem occurs when dereferencing a misalignedintpointer.I did
echo 5 > /proc/cpu/alignmentto enable trapping for alignment errors.@kholia commented on GitHub (Nov 17, 2017):
From http://elixir.free-electrons.com/linux/latest/source/arch/arm/mm/alignment.c,
This explains my observations (i.e. no trap for misaligned int pointer deference). Raspberry Pi 2 is using an ARMv7 processor.
I also tested the QEMU emulated SPARC machine running Debian 8. No trap for misaligned int pointer deference. So it is not helpful for our requirements.
@jfoug commented on GitHub (Nov 17, 2017):
I am 90% sure the problem stems from the 'REAL' cpu being x86, which does not even send a signal at all on un-aligned, except for SIMD (and newer chips are starting to not issue those either). Thus without the hardware help, QEMU simply had to not honor that ability.
I bet if you ran QEMU on a Sparc box, and emulated x86, you would probably need to compile john with ALLOW_UNALIGNED as 0 ;)
I wonder if there is any Linux setting that can be done to enhance the RPi to trap more errors ? Again, if I can get a 15 year old Sparc iron, I think we should have no problems finding those issues in the future (until that box chooses to not startup when I need it). No WAY am I running a Sparc full time, just to have it available a couple times a year for un-align testing.
@kholia commented on GitHub (Nov 17, 2017):
I was thinking about the same but it does not seems to be possible. The underlying hardware does not generate faults for simple misaligned "loads / stores" up to the word size.
@jfoug commented on GitHub (Nov 17, 2017):
What about ARM v6 ? the RPi 1 uses that chip family
@kholia commented on GitHub (Nov 17, 2017):
I am not sure. According to the comment in the Linux kernel code,
ARMv6 and later CPUs can perform unaligned accesses for most single load and store instructions up to word size. LDM, STM, LDRD and STRD still need to be handled. So it seems that we won't have much luck with RPi 1 either.@jfoug commented on GitHub (Nov 17, 2017):
No help:
from http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka15414.html
So it looks like ARM9 or older is needed to get the full level of unaligned traps.
@kholia commented on GitHub (Nov 19, 2017):
It seems that Parallela has an
ARM A9processor. I am not sure if it is the same thing as anARM9processor. I am guessing not.@jfoug commented on GitHub (Nov 19, 2017):
Hopefully, I can snag a ancient Sparc box. If I can do that, we will have an unaligned system, until the day that unit fails to boot, lol
@kholia commented on GitHub (Nov 20, 2017):
This topic is really interesting.
https://patchwork.ozlabs.org/patch/550535/ (target-arm: raise exception on misaligned LDREX operands).
@kholia commented on GitHub (Nov 20, 2017):
I might have a solution!
The
-fsanitize=alignmentflag seems to be great. I am running GCC 7.2.1 on Fedora 25 here.See https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html for more goodies.
@kholia commented on GitHub (Nov 20, 2017):
I am not sure if the following are false positives,
Here is my JtR Jumbo patch to enable this behavior,
After applying this patch, build JtR with
make clean; ./configure --enable-ubsan; make -j8.@kholia commented on GitHub (Nov 20, 2017):
We may need to turn off
ARCH_ALLOWS_UNALIGNEDwhen using the-fsanitize=alignmentflag.@kholia commented on GitHub (Nov 20, 2017):
Patch to fix alignment problem in
config.c,@jfoug commented on GitHub (Nov 20, 2017):
yes, but can this catch alignment problems from allocated variables? Probably not. Almost all of our work is on allocated variables, and MANY of them come from the 'tiny' allocator, which does not do allocation, but which simply returns a pointer to within a larger pre-allocated buffer.
So yes, this command line switch is nice, but I am almost certain it is very limited in usage for john.
@jfoug commented on GitHub (Nov 20, 2017):
Now that I see what you are doing, absolutely, we have to turn that off, so that john will force help us. we are looking ONLY for instances where we do not properly handle alignment WHEN that unaligned flag is set to 0.
@kholia commented on GitHub (Nov 20, 2017):
Some testing with
malloc(my understanding of "allocated variables" phrase),@jfoug commented on GitHub (Nov 20, 2017):
That bug in config.c should be put into bleeding ASAP. It IS a bug as far as unaligned machines go. Really, it should be put into code using the
#if ARCH_ALLOWS_UNALIGNEDwrapper, keeping the original code@jfoug commented on GitHub (Nov 20, 2017):
No, my misunderstanding was that you are using UBSAN AND using runtime checks. This should catch all usages of memory, for same size > greater alignment.
@kholia commented on GitHub (Nov 20, 2017):
Oh. I forgot to mention that UBSan itself is providing these runtime checks. I believe that UBSan does some compile-time instrumentation do provide this "runtime" functionality. I am testing this stuff on a standard AMD64 Linux box running Fedora 25.
@kholia commented on GitHub (Nov 20, 2017):
Why do we need to use
#if ARCH_ALLOWS_UNALIGNEDat all? Can't we simply domem_alloc_tiny(..., MEM_ALIGN_WORD), which will work on all machines? Are there some disadvantages of usingMEM_ALIGN_WORDeverywhere? One possible problem could be internal fragmentation (space wastage) in themem_alloc_tinyallocator?@jfoug commented on GitHub (Nov 20, 2017):
That is the reason for allowing things like single byte alignment (and with no allocation record structure or 2 like you get with malloc and its family). The mem_alloc_tiny() family is a fantastic tool for reducing memory footprint. ALSO, for things which are absolute zero impact on runtime (like the configuration file loaded in memory), reducing every byte possible is not a bad thing. For items which DO play an impact in the 'warm' path, then byte alignments should be looked at. For the HOT path, byte alignments must be addressed, even on machines which allow them just fine. Until the most recent Core CPUs, even CPUs which allowed byte alignment still payed a penalty, so when the speed matters (hot inner loop), we should make sure our alignment is good.
But for this, having 1 byte alignment simply based upon a #define is not a bad thing. There can be 100's to even 1000' of lines read from the config file. Solar has done lots (more in the past) to keep johns memory footprint small. This is just one tiny step. Yes, if you simply change this to align on machine word, then there is little 'lost' This one is your bug find, your call ;)
@kholia commented on GitHub (Nov 20, 2017):
I have now applied the following patch,
@kholia commented on GitHub (Nov 20, 2017):
Patch for OpenVMS format,
This is required as the salt structure has a member with type
long.@jfoug commented on GitHub (Nov 20, 2017):
These are the type of patches which are easy, and which HOPEFULLY we can find easily.
This one was missed by me, since I think I have to comment out OpenVMS on my Sparc box, so it never crashed there.
Your fix it 100% correct. 4 was certainly wrong. The worst thing, is that 4 would have passed tests on my Sparc anyway, since it is a 32 bit system. But now with the new UBSAN testing, we should be able to find ALL of these, along with other bugs like what is listed above. I am currently working down that list, to see what is needing fixed, what is easily fixable, etc.
@jfoug commented on GitHub (Nov 20, 2017):
Can you test to see if this patch fixes the dynamic problem?
@kholia commented on GitHub (Nov 20, 2017):
@jfoug That patch indeed fixes the alignment problem with dynamic. Nice 👍
I will open a new PR (in your name) for this patch.
@jfoug commented on GitHub (Nov 20, 2017):
There are a lot of not so nice problems.
Here is an example (I bet there are more like this)
The problem boils down to crypt_struct->cptr array stuff does NOT point to a even 32 bit aligned value (it can, but it is not required to). I think in crypt_sha256, it will be 2 byte aligned (I think). This basically where the prior crypt results are jammed into the next iteration.
Up to now, this code was ONLY in SIMD_COEF_32 which was assumed to be on a LE system (until recently), and also assumed to run ONLY on ARCH_ALLOWS_UNALIGNED systems. Well, it looks like we are going to have to handle this byte by byte (using GETPOS() type macros), and also handle endianty conversions (and probably want to keep the move by uint32_t* when we have allow-unalgiend.
Your addition to the UBSan work, has turned up a lot of things we need to address. Keep in mind, these formats like WOULD crash on a real PP64 system (not on our QEMU), so we must now start to address these!!!
@jfoug commented on GitHub (Nov 20, 2017):
here is how I plan on working around this in cryptsha256,
This will allow the unaligned REQUIRE machines to still use the faster code, IF alignment is right (it will e a lot), and it only requires an if aligned check. Let me get you a full patch, and have you try that and see what you see with your UBSAN build.
@jfoug commented on GitHub (Nov 20, 2017):
@kholia can you try this patch under UBSAN and see if the before/after is broken/fixed ? (Note, code is 100% untested on the new part)
@kholia commented on GitHub (Nov 20, 2017):
The compiler is complaining that it does not know
sse_outpandGETPOS. I did "s/sse_outp/sse_out" to solve the first problem but I don't know which version ofGETPOSto use. If I use the one fromdynamic_fmt.c, the format fails withFAILED (cmp_all(2)). I really don't understand this macro ;(@jfoug commented on GitHub (Nov 20, 2017):
Try this patch. The s/sse_outp/sse_out/ was my typing mistake. I was not aware that the GETPOS was not even added into cryptsha256, but I have put the right one in there.
@jfoug commented on GitHub (Nov 20, 2017):
If you want to understand the GETPOS stuff, I can write up some sample code to show you. It actually is pretty easy. It simply loads SIMD_COEF_X set of adjoining buffers. So if SIMD_COEF_32 is 4 (SSE2), then it will load unsigned[0] then unsigned[4] then unsigned[8], etc putting first 4 bytes into unsigned[0]. then next 4, etc.
The GETPOS() macro was also written to properly assign bytes based upon endinanty. So if the format is supposed to be LE order, then unsignedp[0] will load the 4 bytes into that unsigned into the 'proper' byte slot.
That is really all that the GETPOS macros do.
If you look at the changes I have been doing for a BE port, almost every one of them will use a different GETPOS macro. The difference is that GETPOS will be written to either keep the endianity, OR to to reverse it. So for an LE machine, working on an LE format, we want to keep the native endianity. BUT if a BE machine is working on an LE format (md5, etc), then that BE machine will need to have the data placed in swapped format. This is because our SIMD code works on the data uint32_t at a time. So if we built our SIMD buffer, but used 'native' byte ordering, then when the BE machine accessed it, it would be in BE format which is wrong for MD5. So on the BE 'machine' for MD5, we would byte swap.
The opposite is the case for the BE formats (SHA flavors). For them, when running on an LE machine the GETPOS will also byte swap. This is so that when on that LE machine, the data is accessed uint32_t at a time, we get the PROPER expected endianity of the data. HOWEVER, if we built on a BE system, then all of the SHA? algorithms are in NATIVE byte ordering, so our GETPOS would NOT byte swap.
That is really how to look at GETPOS. It is a pretty simple macro. There are several parts to it. on part does the byte ordering within the uint32_t (or uint64_t) bytes. The next skips to the right uint32_t for THIS index (i.e. index0 is uint32_t[0], index1 is uint32_t[1], etc). The next will skip to the proper SIMD*sizeof(1 item) bytes (i.e. skip to the next starting of a full SIMD buffer). The last is only used if there is more than 1 SIMD buffer worked on. Most formats will operate on 100s or 1000s of them at one time, and openmp makes it even a bit more complex, as you work on only parts). BUT this is all hidden, within a single part of the macro making adjustments for starting at the proper location of the start of each SIMD full-block buffer.
@kholia commented on GitHub (Nov 20, 2017):
Alignment patch for
ethereumformat,It is not pretty. Do you have a more cleaner looking patch @jfoug?
The
cur_salt->ctis accessed via a uint64_t pointer by the Keccak code internally.@kholia commented on GitHub (Nov 20, 2017):
Regarding the
sha256cryptpatch. The code compiles, and the format works. However, the alignment error remains.Line 781 contains
*o++ = JOHNSWAP(sse_out[(j*SIMD_COEF_32)+(k...code.It appears that both the
if (!is_aligned(crypt_struct->cptr[k][idx], 4))block and the associated else block are getting executed.@kholia commented on GitHub (Nov 20, 2017):
Quick note,
The
dynamic_370is exhibiting alignment problems on Raspberry Pi 2 with the Clang UBSan build. This format uses Keccak code which expects data beuint64_taligned. The same format works fine (without any alignment problems) on standard AMD64 Linux builds.@frank-dittrich commented on GitHub (Nov 20, 2017):
@jfoug
What if you change the
typedef struct cryptloopstruct_tdefinition so thatunsigned char buf[8*2*64*BLKS](currently the first component) becomes the last component?@jfoug commented on GitHub (Nov 20, 2017):
For cryptsha256, try this:
change
if (!is_aligned(crypt_struct->cptr[k][idx], 4)) {
to
if (!is_aligned(crypt_struct->cptr[0][idx], 4)) {
@jfoug commented on GitHub (Nov 20, 2017):
@frank, that problem is that for some data, on 'some' of the crypt loops, the location of the CRYPT buffer (i.e. this rounds results get processed on the next buffer), will NOT be word aligned. MANY are word aligned, so losing the uint32_t* = uint32_t* usage WILL slow things down. If we only do the byte copying when we detect alignment issues, yes we do get a hit, but we are trying to minimize how often that byte/byte code path is taken. This has nothing to do with the location OF the pointer itself. This is what the pointer is POINTING to (unaligned data). There is no way to work around that issue. We have 42 buffers. Each one gets filled up with the prior item's results That is all.
@jfoug commented on GitHub (Nov 20, 2017):
@frank, there just seems like a lot of activity this morning. This actually IS expected.
Forever, we have been working under these 2 assumptions.
Now, for #2, the actual SIMD buffers do require alignment, but all other alignment requirements were assumed to not exist.
So breaking both of those assumptions is what is triggering a LARGE amount of this work right now. Bot the BE endianity porting (I have about 30 formats left), Now, we have found a way to get GREAT runtime detection of non-alignment. Since we have lost our assumption that SIMD code can work unaligned (for the CPU work), we will see a lot of alignment issues WITHIN
#ifdef SIMD_COEF_32 .... #endifblocks. Now, not all of what @kholia has found has been within SIMD_COEF_X blocks. Some of it was alignment issues MISSED by the machine/complier I have been using (the Sparc, but under 32 bit). So some of those will show up also. But all of this porting, is due in part to working on PPC64 SIMD porting.@kholia commented on GitHub (Nov 20, 2017):
No luck with that patch @jfoug :-(
This is the complete patch I am testing.
Maybe we can move to other targets, and come back to this one later :-)
@kholia commented on GitHub (Nov 20, 2017):
I will be going offline pretty soon. Happy bug hunting. See you guys tomorrow! :)
@jfoug commented on GitHub (Nov 20, 2017):
Bummer. I will see if I can get a build env setup to use the patch you have get the UBSan stuff working on my own. It is much easier to fix, if I can compile the code, and then start to output debugging stuff to find just wtf is not working....
@jfoug commented on GitHub (Nov 20, 2017):
I actually am going to continue on with the BE base porting, and will pick up these unaligned problems once that is completed.
@kholia commented on GitHub (Nov 20, 2017):
I have published the build hack(s) required at https://github.com/kholia/JohnTheRipper/tree/alignment (top commit).
The standard GCC compiler that comes with Fedora 25 (or higher) works great for this. Even Debian 9 and modern Ubuntu distributions should just work.
@jfoug commented on GitHub (Nov 20, 2017):
I am pretty surprised the alignment code was not working. I made this change to my code, and it should runtime fail the !is_aligned() from the prior patch was wrong. NOTE, it could be that the code BEING done in my !is_aligned() code is not right. I will test that next. But this is the code that would go BOOM and exit if the alignment logic was not right.
@kholia commented on GitHub (Nov 20, 2017):
Yes,
BOOMis hit.@jfoug commented on GitHub (Nov 20, 2017):
Ok, one more try (actually simplified a bit) I really hope this one works. I have tested out the code as best I can on my LE system. the byte/byte code is working. The problem stems from different elements of the array being at diffent alignment. I thought all of them within 1 step were the same (I thought we sorted out based upon password), BUT we group several length passwords up, so that actual buffer can float around a bit within the next input block.
@jfoug commented on GitHub (Nov 20, 2017):
DO NOT TRY that one. I already see a bug!!
@jfoug commented on GitHub (Nov 20, 2017):
Ok, this should do it (I hope)
@jfoug commented on GitHub (Nov 20, 2017):
Note, all of the *-crypt algos using SIMD will probably have the same sort of alignment bug needing to be fixed. But once we get one, the others will fall easily ;) That is like the BE endianity porting. Once I got one of them (and a hard one with a @magnum enhanced set_key function), then rest were much easier to fix, since there was much code re-use
@jfoug commented on GitHub (Nov 20, 2017):
The last patch fixes the UBSAN in shas256crypt, yea.
oh, btw, I got a virtualbox Fedora working again, and chagned the configure.ac, and patched x86-64.h to force unaligned access required. :)
@jfoug commented on GitHub (Nov 20, 2017):
I got every error you listed (in a -test=0) I also got another block (have to track down the format) when doing a --test-full=0 They were all the same item:
The failing format is panama
@jfoug commented on GitHub (Nov 21, 2017):
Note, most of these alignment issues are very trivial (many are just salt undersizes) They all 'passed' on my Sparc box (i.e. no crashes), since it was 32 bit.
@kholia commented on GitHub (Nov 21, 2017):
Cool. Your latest
sha256cryptpatch works great. I have opened a PR in your name with that patch.@kholia commented on GitHub (Nov 21, 2017):
@jfoug It seems that
sha512cryptcan be fixed very similarly to thesha256cryptformat. I just need the properGETPOSmacros forsha512cryptformat.@kholia commented on GitHub (Nov 21, 2017):
Quick note,
I am also interested in testing the various hash extraction utilities for alignment correctness.
@kholia commented on GitHub (Nov 21, 2017):
Here is a patch for the
panamaformat,It is not pretty but gets the job done.
@jfoug commented on GitHub (Nov 21, 2017):
I replied to your PR for the panama fix. It is much simpler than that. Simply do not allow the stored passwords to get out of alignment. The all allocated, so will be in alignment. They only got out of alignment because the buffers were 31.5 uint32_t. Make them an even 32 and things are fine.
@jfoug commented on GitHub (Nov 21, 2017):
These are all that are left:
Oracle11
SAPB
SAPH
@jfoug commented on GitHub (Nov 21, 2017):
And input modes (wordlist, rules, inc, mask, markov, etc).
There is much more than just doing a -test=0 ;) The -test=0 just gets your foot in the door. Now that we have test bed machines (BE and alignment), we can flush out a LOT of things which were more difficult to do before.
@kholia commented on GitHub (Nov 21, 2017):
Cool! :-)
Also
sha512crypthas an alignment problem,The problem seems to be very similar to the one in
sha256crypt. I just need to know whichGETPOSmacros to use here.@jfoug commented on GitHub (Nov 21, 2017):
Do a pull. I checked that in a bit ago. I had it done last nite, but fell asleep myself, lol. Exact same change (but using 64 bit logic) that was done in sha256crypt.
That sha1crypt did not have problems (or md5crypt) surprises me some. Possibly they do NOT get data unaligned like the bigger crypts do.
@solardiz commented on GitHub (Nov 21, 2017):
On Tue, Nov 21, 2017 at 11:29:51AM +0000, jfoug wrote:
I don't know sha1crypt, but our SIMD md5crypt looks safe: mmxput() uses chars, mmxput2() uses memcpy(), and mmxput3() uses efficient logic via BITALIGN() macro defined nearby (I implemented that after playing with similar stuff in md5crypt-opencl). Maybe our sha*crypt could benefit from that kind of logic, too.
@jfoug commented on GitHub (Nov 21, 2017):
Actually, I think the current mmxputX() code would work just find in the SHA crypts FOR BE machines. We would simply have to reverse the BE porting code I did. So for an SHA* format, what we were using on LE machines (default until my port), would be the code for a BE machine, and the port code would be used for LE (at least in theory). (NOTE, sha256 code. The sha512 would be different, being it is 64 bit words)
I am not sure, (and DO NOT LIKE IT), that the md5crypt code was placed into simd-intricisics.c source file. That was bad form, IMHO. However, that may have been the only way to use those mmxput functions/macros, by controlling the other macros b4 and after.
BUT, I think that coding could be looked at for the other formats. HOWEVER, unless it is one hell of an improvement, then I would really ask to NOT put code that complex into the other formats. Porting to BE is NOT easy. The md5crypt was one of the worst. putting too much emphasis on performance coding, if it is only gaining a percent or 2, and then having that either lost, or causing other problems when porting, is really not an ideal situation.
Now take for instance, the key_load code @magnumripper did. For some formats, it was huge (10-40% improvement). So there it is great, and the extra time and effort spent doing the BE porting was well worth it. BUT he then placed that code all over the place. On many formats, he got a gain, but only a percent or 2, since the format was not so bound up on the key_load code (i.e. salted, had more hashing functions, etc). In that case, it was a thorn, to spend an hour or 2 to figure things out, just to port to BE, when there was no real gain in the obfuscation of the simple key loader. Also, without this 'special' code, there is NO porting at all. If passwords are placed into the buffers using the GETPOS macros, one byte at a time, there is never a LE/BE porting issue, NOR is there any alignment issues. Simply change the GETPOS macro, and the alignment is not a concern, since the CPU is just writing bytes. SO, for that 1% gain, we had to deal with both BE porting, AND alignment concerns. Not a good ROI IMHO.
@jfoug commented on GitHub (Nov 21, 2017):
Oracle11 fixed (both here, and BE porting)
@kholia commented on GitHub (Nov 21, 2017):
Some new alignments issues in OpenCL formats,
The OpenCL self-tests are running very slowly on this Intel GPU. I will test on a proper GPU system soon.
Update: Added more results.
@jfoug commented on GitHub (Nov 21, 2017):
Those will be your issues. I only have a Fedora utilizing UBSan running in a VM,and I can not access openCL at all in that build env.
Note, we also need to test -enc=utf8 and -enc=cp737 to make sure we get encodings
@jfoug commented on GitHub (Nov 21, 2017):
I think these are new (using -enc=utf8)
@solardiz commented on GitHub (Nov 21, 2017):
Not a big deal, but FWIW I disagree about
#if'ing that one. We already have that#ifinsidemem_alloc_tiny()for the highest memory saving level. Perhaps for the config file we could afford it performance-wise when running without memory saving as well, but then there are two kinds of items in the config file: either not too numerous where the savings are tiny or very numerous where runtime performance could matter (e.g., a large ruleset applied against a fast unsalted hash). So I think reserving this tiny optimization for a memory saving level makes sense.Jim mentioned "thousands of lines". This would be the case where performance could matter, but moreover it's also a case not relevant to that code Dhiru was patching. There are two separate struct's: for lines (already allocated with
MEM_ALIGN_WORDalignment) and for name=value params (the one where we now got that IMHO unneeded#if, and inconsistently so as I think the first list element is allocated separately and with different alignment).I suggest that we consistently allocate those struct's with natural alignment, except where
mem_alloc_tiny()itself chooses to override that.IIRC "natural" alignment is a term sometimes used in CPU instruction set architecture manuals, and it typically means aligned to a boundary that is a multiple of the data access size. That's what we've been doing by aligning struct's to match the largest basic member size - integer, pointer, or SIMD vector. In JtR core, I've been using
MEM_ALIGN_WORDfor both integers and pointers, so let's continue with that for now, except that when we know we only have e.g. anintor anuint32_t, we can better usesizeofthat.@solardiz commented on GitHub (Nov 22, 2017):
I agree, but IIRC this happened because as initially contributed by Simon this file (called
sse-intrinsics.cthen) provided only md5crypt.@kholia commented on GitHub (Nov 22, 2017):
Quick note so that I don't forget,
This output is associated with,
This machine has a NVIDIA 1050 Ti GPU and it is running
NVIDIA binary driver - version 375.66.@magnumripper commented on GitHub (Nov 22, 2017):
You may be right, that was many years ago (I think 2011). As far as I can remember I only added it when it actually made a difference tho.
"Salted" is not a disqualifier at all, we may attack a single salt.
@jfoug commented on GitHub (Nov 22, 2017):
I have been having a few 'ah-ha' moments in some of this porting. It may be time to look at well crafted common 'helper' code for some of this.
@magnumripper commented on GitHub (Nov 22, 2017):
I had exactly the same thought. Well-crafted is the thing. We use too little shared code, we have obscene amounts of identical code copied all over the place.
@jfoug commented on GitHub (Nov 22, 2017):
The really BIG problems is that the code 'should' be identical, BUT it is not. This will make finding this common code more difficult.
This is NOT a small undertaking, at all. BUT it could be done in a many small bite portions, just like the SIMD porting to BE. That was a pretty huge task. BUT taken 1 at a time, and simply continuing to work on outstanding non-handled formats, it HAS BEEN something that was done. The common code could be the same thing. I think I am going to start a bug on this one. IT should be talked about quite a bit, prior to any work being done. Just to get a list of what we should try to achieve, and then 'how'.....
@jfoug commented on GitHub (Nov 24, 2017):
I think with
39c357792, we have gotten them all. Please validate on your end, before closing the bug.@kholia commented on GitHub (Nov 25, 2017):
Nice @jfoug.
I think we still need to fix alignment problems for
-enc=options, and one or two OpenCL formats.@kholia commented on GitHub (Nov 25, 2017):
This was found by you earlier.
Remaining OpenCL findings,
@kholia commented on GitHub (Nov 25, 2017):
Patch for
raw-md5-openclformat,Patch for
ethereum-openclformat,Patch for
zip-openclformat,After these patches only the
-encalignment problem remains.@jfoug commented on GitHub (Nov 25, 2017):
Those are your (or @magnumripper 's) babies. I can not run open CL on a system with UBSan I can 'look' at tests and send diffs, but I can not be sure I fixed anything.
@jfoug commented on GitHub (Nov 25, 2017):
I have looked at the RAR3 item. Ugly sob. That one really needs @magnumripper to look at. He ported that mess, and may know it a lot better than most.
@jfoug commented on GitHub (Nov 29, 2017):
@kholia commented on GitHub (Nov 29, 2017):
This is hilarious. I tested this format quite a bit, and I missed this completely. Will fix soon!
@jfoug commented on GitHub (Nov 29, 2017):
I am working on a configure that allows ubsan-alignment NOTE, I made 2 ubsan enables (mutually exclusive) There is --enable-ubsan and --enable-ubsanalign (only 1 can be used at a time). The --enable-ubsanalign works by forcing unaligned not ok build (even on x86). I patched the arch.h files, so that they do not set ARCH_ALLOWS_UNALIGNED=1 IF that variable is already defined. Then within configure, I add a -DARCH_ALLOWS_UNALIGNED=0 to the build line where required.
BUT I was not able to get the unaligned checks added along with the existing UBSan testing. Once I get the configure changed and checked in, some else might be able to figure out how to get all of it working at the same time. BUT with the new target, it does allow us to easily do a ./configure --enable-ubsanalign and do alignment testing easily.
@jfoug commented on GitHub (Nov 29, 2017):
This is why it would be nice to get alignment testing added to some CI at some time. Just like BE testing (or even non-SIMD testing). Yes, formats get tested well, BUT when run on a non-standard system, if we do not test for things, then bugs like this can creep in over time.
@kholia commented on GitHub (Nov 29, 2017):
Same experience here. That is why I disabled the existing UBSan checks and only enabled alignment checks in my hacky
alignmentbranch.I agree that we need two configure options (--enable-ubsan and --enable-ubsanalign). Can we come up with a better name than
--enable-ubsanalignthough? Naming is really hard ;)@jfoug commented on GitHub (Nov 29, 2017):
Already checked in with
--enable-ubsanalignNOTE, I am not sure that--enable-ubsanis working AT ALL. The bug I had to get alignment testing working was what I was looking for.There is some strangeness in teh --enable-ubsan as it exists. But I did not add that, nor do I understand some of the command flags. IT may be that the version of Fedora I am using is too old, so I have simply left it as it was.
@jfoug commented on GitHub (Nov 29, 2017):
NOTE ./configure --help spells out the difference between the 2 options, so I am not sure there is a problem with the new one.
@kholia commented on GitHub (Dec 6, 2017):
Update: Only the
-encalignment problem remains now.@jfoug commented on GitHub (Dec 6, 2017):
is that the rar format?
@jfoug commented on GitHub (Dec 6, 2017):
finally figured out stack dumping for ubsan. Here is where we are at with rar:
@jfoug commented on GitHub (Dec 6, 2017):
Btw, if you do not have stack dumping on UBSan, to do it:
@jfoug commented on GitHub (Dec 6, 2017):
This fixes the UBSan problem, BUT I do not like this much at all. These are pointers. They will also get used in other places (read from). This does fix the problem for -enc=xxx testing, BUT I bet depending upon the data provided, there are other lurking out there. This format may be better to simply be turned off for ARCH_ALLOWS_UNALIGNED=0 until we can really figure out what the underlying problem is.
One area I looked at during digging, that looks 'fishy', is the sub_allocator_split_block() function. Usage of a void* converting to (char*), then doing pointer math on it, really screams of getting into alignment problems. Problem is I really do not know what it does, or how it is used. Very likely changing that, would require a deep change across several functions.
@jfoug commented on GitHub (Dec 6, 2017):
What are others opinions about simply disabling rar for now on a alignment-required build? That should be pretty easy to do. IMHO, it is better to disable rar by iteself, than release it and have it core unexpectedly. Then when someone gets motivated to investigate WHY it fails, and gets it fully fixed, we can then re-enable it.
@jfoug commented on GitHub (Dec 6, 2017):
This type change will disable the format (code is still built, format just disabled). I will commit this later, if I do not hear objections.
@frank-dittrich commented on GitHub (Dec 6, 2017):
Can you add a preprocessor warning for the disabled format?
@frank-dittrich commented on GitHub (Dec 6, 2017):
E.g., something similar to this:
Update:
To avoid two warnings, the last change needs to be before the
@jfoug commented on GitHub (Dec 6, 2017):
Certainly.
KEEP in mind. #pragma message(xxx) is NOT universal. I have to change this every time someone does this, lol If building with gcc, #pragma message(xxx) works. For VC, I use #warning. For other systems, there is no message, I do not know how to do it.
This would be a good place for a 'logic hider' inside of some header, so we simply could use something like:
@frank-dittrich commented on GitHub (Dec 6, 2017):
And then there is also
-fsanitize=undefined -fsanitize-undefined-trap-on-errorinstead of just-fsanitize=undefined:@jfoug commented on GitHub (Dec 6, 2017):
Did that make it back into configure, grrr.
@jfoug commented on GitHub (Dec 6, 2017):
@frank-dittrich if you are saying that
-fsanitize-undefined-trap-on-errorhas been removed, then yes, it has. With that flag, I was getting a number of formats that crashed (same with @kholia ) Once it was changed to just-fsanatized=undefined(and the proper define for ARCH_ALLOWS_UNALIGNED=0 added to the command line), these crashes went away.@kholia commented on GitHub (Dec 6, 2017):
Yes,
-fsanitize-undefined-trap-on-errorproduces undesirable results. Let's not introduce it back.@magnumripper commented on GitHub (Dec 6, 2017):
Fine by me for sure. We nicked the unrar code from ClamAV and it's almost certainly written without the slightest care for non-x86.
@frank-dittrich commented on GitHub (Dec 6, 2017):
@jfoug I think it would be useful to optionally enable
-fsanitize-undefined-trap-on-error.If you want to detect ubsan warnings in a script,
is easier than
(If you want to find all formats with ubsan problems, you can either modify your script and process each format individually, or temporarily exclude each "failing" format in the config.)
@jfoug commented on GitHub (Dec 6, 2017):
We have it working for BE. But the alignment requirement may be a MUCH harder hurdle to overcome. Disabling the format on requires alignment is very easy. Then if someone ON a requires-alignment want to get it running then they can do the heavy lifting and get it ported. Once ported, again, 5 minute fix and it is enabled again. But until then, disabling it makes it release ready, without having to worry about a crash.
@jfoug commented on GitHub (Dec 6, 2017):
I had 2 variants of ubsan a bit ago (when I could not get ubsan working with ubsan-alignment), then merged into 1 after finding and nixing the trap on error.
Now, if I go ahead and re-add that, is there any trap on error that should be enabled for ASAN (I think it traps all the time right now).
@frank-dittrich, start a new bug topic with the examination you have above, and we can get it back in. However, especially now with finding out how to dump stack traces, having the thing run, IMHO is a better solution. But we certainly can do both/either
@frank-dittrich commented on GitHub (Dec 6, 2017):
@jfoug
Doesn't work on ubuntu 16.04:
What distribution do you have?
@ghost commented on GitHub (Dec 6, 2017):
Just taking note:
@frank-dittrich commented on GitHub (Dec 7, 2017):
Looks like ubuntu 16.04 has llvm-symbolizer installed:
But
export UBSAN_OPTIONS=print_stacktrace=1didn't cause stack trace output on ubsan warnings.Later this week I might have time to check whether the additional symbolic link(s) suggested here will help:
https://stackoverflow.com/questions/38079761/why-does-asan-symbolizer-path-no-longer-work-with-version-adorned-binaries
@jfoug commented on GitHub (Dec 7, 2017):
@frank-dittrich I am using fedora for all my asan/ubsan stuff (seems MUCH better working than ubuntu was). the llvm-symbolizer was not installed on my box. Once i did, and set the env var, boom, great stack traces on ubsan.
asan has always given good stack trace (on fedora), and I think it crashes like you like ;)
@jfoug commented on GitHub (Dec 7, 2017):
The above issue is an ASAN issue (I believe). They stack dump differently than the UBSan stuff.
@frank-dittrich , all I can say is it works on my box, I was so happy when it did, that I comments on what steps I followed to make it work, lol. ymmv
@jfoug commented on GitHub (Dec 7, 2017):
Frank, how about allowing ubsan to be 'disabled' / 'enabled' / 'trap'. Then change the enabled switch to take an optional flag (like --enable-ubsan or --enable-ubsan-trap). Both --enable-ubsan and --enable-ubsan-trap would turn it on. The *_trap would also add the trap flag to crash it for you.
Should be pretty easy to do, and pretty easy to explain on the help page, if that logic is ok with you.
The only problem I see, is if someone does something stupid like --enable-ubsan --disable-ubsan-trap
I would rather either not code for such things, OR simply put code in like I did last time, saying they options are mutually exclusive, and simply fail. So something 'valid', such as --enable-ubsan --enable-ubsan-trap would fail with mutual-exclusion of the switches and that may seem a bit strange, BUT it makes for the logic internally to be simpler (at least I think so).
@jfoug commented on GitHub (Dec 7, 2017):
@claudioandre thanks for the opencl UBSan stuff. I have no way of using ubsan on opencl (other than possibly a memory device). so having others test the UB stuff is needed.
@frank-dittrich commented on GitHub (Dec 7, 2017):
@jfoug I like the suggestion of having --enable-ubsan and --enable-ubsan-trap (implying --enable-ubsan).
I doubt that there is a compiler which supports --fsanitize=ubsan, but doesn't support -fsanitize-undefined-trap-on-error. But if there is, I think configure should fail on --enable-ubsan-trap, and suggest to use --enable-ubsan instead.
@jfoug commented on GitHub (Dec 7, 2017):
@frank-dittrich currently we do not 'flag check' one at a time when adding ubsan. We simply add them all, if it builds, we call it good and use them.
Yes, the --enable-ubsan-trap does imply --enable-ubsan It just crashes upon any failure, so you can scrip[t it, get error return values, etc, and know that this run was the bad one. Plain --enable-ubsan simply runs, outputs information (and for me stack traces), but keeps right no running, AS LONG as the UB does not trigger a crash. as far as --enable-asan, it also dumps stack for me, but traps every time. I know of no way to make it continue forward.
the different usages are pretty important. For doing porting test/building where there may be numerous issues, I much prefer the --enable-ubsan (especially when a run may take 30 minutes to an hour on a emulated system, yuck). I want to have the run complete, and then have a list of all items to fix. I then set around to fixing each of them. For your case, where you are fuzzing, you are already assuming that the build will test clean, and run over all valid input cleanly. You are not expecting any UB errors. So when one happens, you want to make damn sure you catch it.
Very different usages. Both very valid for sure. i will try to get the 2 flavors added to configure today.
@jfoug commented on GitHub (Dec 7, 2017):
New configure:
28bf52d2eWith trap, the configure status shows:
@jfoug commented on GitHub (Dec 7, 2017):
With the rar3 format disabled, is this bug now completed? I think so, unless there are some OpenCL open issues.
Looks like
rar-openclon req-alignment andlm-openclstill have issues.rar-openclshould probably just be disabled (like the CPU version, unless it also does rar5). I have no idea about thelm-openclcode.@magnumripper commented on GitHub (Jan 8, 2018):
If someone actually having a BE or mem-align system with GPU reports having problems, we'll open a new issue for it.