[GH-ISSUE #2868] Formats failing on big endian system / Mem-aligned systems. #1822

Closed
opened 2026-10-15 04:25:39 +07:00 by bsakaguchi · 141 comments
Owner

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.

$ make -f Makefile.legacy linux-ppc32

$ ../run/john --test=0
...
Testing: leet [SHA-512(32/32 OpenSSL) + Whirlpool(OpenSSL/32)]... FAILED (get_hash[0](0) e!=8)
Testing: mscash, MS Cache Hash (DCC) [MD4 32/32]... FAILED (cmp_all(2))
Testing: pomelo [POMELO 32/32]... FAILED (cmp_all(1))

We are already tracking leet in issue https://github.com/magnumripper/JohnTheRipper/issues/2414.

The POMELO code is terrible, and hard to read.

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. ``` $ make -f Makefile.legacy linux-ppc32 $ ../run/john --test=0 ... Testing: leet [SHA-512(32/32 OpenSSL) + Whirlpool(OpenSSL/32)]... FAILED (get_hash[0](0) e!=8) Testing: mscash, MS Cache Hash (DCC) [MD4 32/32]... FAILED (cmp_all(2)) Testing: pomelo [POMELO 32/32]... FAILED (cmp_all(1)) ``` We are already tracking `leet` in issue https://github.com/magnumripper/JohnTheRipper/issues/2414. The `POMELO` code is terrible, and hard to read.
bsakaguchi 2026-10-15 04:25:39 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@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!

<!-- gh-comment-id:343468777 --> @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!
Author
Owner

@kholia commented on GitHub (Nov 10, 2017):

For some reason, mscash is failing on my PPC64 VM. The mscash code isn't too beautiful either ;)

<!-- gh-comment-id:343471121 --> @kholia commented on GitHub (Nov 10, 2017): For some reason, `mscash` is failing on my PPC64 VM. The `mscash` code isn't too beautiful either ;)
Author
Owner

@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.

<!-- gh-comment-id:343471177 --> @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.
Author
Owner

@kholia commented on GitHub (Nov 10, 2017):

@solardiz Thanks! I will open a PR for doing so soon.

<!-- gh-comment-id:343473580 --> @kholia commented on GitHub (Nov 10, 2017): @solardiz Thanks! I will open a PR for doing so soon.
Author
Owner

@jfoug commented on GitHub (Nov 10, 2017):

This is on my sparc box, but that is a 32 bit binary.

bash-3.2$ ../run/john -test-full=0 -form=mscash
Testing: mscash, MS Cache Hash (DCC) [MD4 32/32]... PASS

I can not build OMP on that sparc (using gcc). But it appears you also are not using OMP and yours fails.

<!-- gh-comment-id:343505858 --> @jfoug commented on GitHub (Nov 10, 2017): This is on my sparc box, but that is a 32 bit binary. ``` bash-3.2$ ../run/john -test-full=0 -form=mscash Testing: mscash, MS Cache Hash (DCC) [MD4 32/32]... PASS ``` I can not build OMP on that sparc (using gcc). But it appears you also are not using OMP and yours fails.
Author
Owner

@kholia commented on GitHub (Nov 10, 2017):

On my PPC64 VM,

$ ../run/john -test-full=0 -form=mscash
Testing: mscash, MS Cache Hash (DCC) [MD4 32/32]... FAILED (cmp_all(512))

$ ../run/john -test -form=mscash
Benchmarking: mscash, MS Cache Hash (DCC) [MD4 32/32]... FAILED (cmp_all(2))

NOTE: The userland is 32-bit.

$ file ../run/john
../run/john: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), ...
<!-- gh-comment-id:343506997 --> @kholia commented on GitHub (Nov 10, 2017): On my PPC64 VM, ``` $ ../run/john -test-full=0 -form=mscash Testing: mscash, MS Cache Hash (DCC) [MD4 32/32]... FAILED (cmp_all(512)) $ ../run/john -test -form=mscash Benchmarking: mscash, MS Cache Hash (DCC) [MD4 32/32]... FAILED (cmp_all(2)) ``` NOTE: The userland is 32-bit. ``` $ file ../run/john ../run/john: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), ... ```
Author
Owner

@kholia commented on GitHub (Nov 11, 2017):

POMELO was disabled for BE machines in https://github.com/magnumripper/JohnTheRipper/pull/2872.

<!-- gh-comment-id:343641735 --> @kholia commented on GitHub (Nov 11, 2017): POMELO was disabled for BE machines in https://github.com/magnumripper/JohnTheRipper/pull/2872.
Author
Owner

@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.

<!-- gh-comment-id:343767064 --> @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.
Author
Owner

@jfoug commented on GitHub (Nov 13, 2017):

mscash1 fixed here 1f1832edb This 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.

<!-- gh-comment-id:343859621 --> @jfoug commented on GitHub (Nov 13, 2017): mscash1 fixed here 1f1832edb This 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.
Author
Owner

@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.

<!-- gh-comment-id:343864339 --> @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.
Author
Owner

@kholia commented on GitHub (Nov 13, 2017):

Thanks @jfoug 👍

This issue can be closed now.

<!-- gh-comment-id:343892218 --> @kholia commented on GitHub (Nov 13, 2017): Thanks @jfoug 👍 This issue can be closed now.
Author
Owner

@kholia commented on GitHub (Nov 17, 2017):

NOTE, the QEMU install of PPC64 may not show all alignment crashes.

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,

  1. 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=multi arguments from the QEMU command.

  2. Experiment with prctl(PR_UNALIGN_SIGBUS) stuff a bit to see if it makes a difference.

<!-- gh-comment-id:345167475 --> @kholia commented on GitHub (Nov 17, 2017): > NOTE, the QEMU install of PPC64 may not show all alignment crashes. 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, 1. 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=multi` arguments from the QEMU command. 2. Experiment with `prctl(PR_UNALIGN_SIGBUS)` stuff a bit to see if it makes a difference.
Author
Owner

@kholia commented on GitHub (Nov 17, 2017):

No luck crashing the following program,

$ cat alignment.c 
#include <stdio.h>
#include <sys/prctl.h>

int main()
{
	prctl (PR_SET_UNALIGN, PR_UNALIGN_SIGBUS, 0, 0, 0);

	unsigned char arr[6] = { 'A', 'A', 0, 0, 0, 0  };
	int i;

        for (i = 0; i < 3; i++) {
	 	int *p = (int *)&arr[i];

		printf("p -> %d\n", *p);
		*p = 123;
	}

	return 0;
}

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.

<!-- gh-comment-id:345220931 --> @kholia commented on GitHub (Nov 17, 2017): No luck crashing the following program, ``` $ cat alignment.c #include <stdio.h> #include <sys/prctl.h> int main() { prctl (PR_SET_UNALIGN, PR_UNALIGN_SIGBUS, 0, 0, 0); unsigned char arr[6] = { 'A', 'A', 0, 0, 0, 0 }; int i; for (i = 0; i < 3; i++) { int *p = (int *)&arr[i]; printf("p -> %d\n", *p); *p = 123; } return 0; } ``` 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.
Author
Owner

@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-align and 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.

<!-- gh-comment-id:345221148 --> @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-align``` and 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.
Author
Owner

@jfoug commented on GitHub (Nov 17, 2017):

tried this on QEMU emulated POWER7 and POWER8 platforms. Maybe QEMU doesn't emulate such hardware functionality?

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.

<!-- gh-comment-id:345221508 --> @jfoug commented on GitHub (Nov 17, 2017): > tried this on QEMU emulated POWER7 and POWER8 platforms. Maybe QEMU doesn't emulate such hardware functionality? 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.
Author
Owner

@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?

<!-- gh-comment-id:345221980 --> @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?
Author
Owner

@kholia commented on GitHub (Nov 17, 2017):

You overflow the buffer in your test case.

Oh, yes! ;)

<!-- gh-comment-id:345222171 --> @kholia commented on GitHub (Nov 17, 2017): > You overflow the buffer in your test case. Oh, yes! ;)
Author
Owner

@kholia commented on GitHub (Nov 17, 2017):

Try that with long long (and memory to fit) I bet you might get a crash then.

No luck crashing the following program either.

$ cat alignment.c 
#include <stdio.h>
#include <sys/prctl.h>

int main()
{
	prctl (PR_SET_UNALIGN, PR_UNALIGN_SIGBUS);

	unsigned char arr[64] = { 'A', 'A', 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
	int i;

        for (i = 0; i < 3; i++) {
	 	long long *p = (long long *)&arr[i];

		printf("p -> %ld\n", *p);
		*p = 123;
	}

	return 0;
}

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

<!-- gh-comment-id:345223715 --> @kholia commented on GitHub (Nov 17, 2017): > Try that with long long (and memory to fit) I bet you might get a crash then. No luck crashing the following program either. ``` $ cat alignment.c #include <stdio.h> #include <sys/prctl.h> int main() { prctl (PR_SET_UNALIGN, PR_UNALIGN_SIGBUS); unsigned char arr[64] = { 'A', 'A', 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int i; for (i = 0; i < 3; i++) { long long *p = (long long *)&arr[i]; printf("p -> %ld\n", *p); *p = 123; } return 0; } ``` 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
Author
Owner

@jfoug commented on GitHub (Nov 17, 2017):

I tried them both (at once), AND I also added this to the printf(s)

printf ("p -> %d  addr -> %llx\n", *p, (unsigned long long)p);

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.

<!-- gh-comment-id:345225221 --> @jfoug commented on GitHub (Nov 17, 2017): I tried them both (at once), AND I also added this to the printf(s) ```c printf ("p -> %d addr -> %llx\n", *p, (unsigned long long)p); ``` 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.
Author
Owner

@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.

<!-- gh-comment-id:345225390 --> @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.
Author
Owner

@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.

<!-- gh-comment-id:345229754 --> @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.
Author
Owner

@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.

<!-- gh-comment-id:345230538 --> @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.
Author
Owner

@kholia commented on GitHub (Nov 17, 2017):

On Raspberry Pi 2, I see a Bus error when trying to deference a misaligned long long pointer but no problem occurs when dereferencing a misaligned int pointer.

I did echo 5 > /proc/cpu/alignment to enable trapping for alignment errors.

<!-- gh-comment-id:345240984 --> @kholia commented on GitHub (Nov 17, 2017): On Raspberry Pi 2, I see a `Bus error` when trying to deference a misaligned `long long` pointer but no problem occurs when dereferencing a misaligned `int` pointer. I did `echo 5 > /proc/cpu/alignment` to enable trapping for alignment errors.
Author
Owner

@kholia commented on GitHub (Nov 17, 2017):

From http://elixir.free-electrons.com/linux/latest/source/arch/arm/mm/alignment.c,

/*
 * 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.
 *
 * Ignoring the alignment fault is not an option on these
 * CPUs since we spin re-faulting the instruction without
 * making any progress.
 */

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.

<!-- gh-comment-id:345246154 --> @kholia commented on GitHub (Nov 17, 2017): From http://elixir.free-electrons.com/linux/latest/source/arch/arm/mm/alignment.c, ``` /* * 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. * * Ignoring the alignment fault is not an option on these * CPUs since we spin re-faulting the instruction without * making any progress. */ ``` 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.
Author
Owner

@jfoug commented on GitHub (Nov 17, 2017):

I also tested the QEMU emulated SPARC

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.

<!-- gh-comment-id:345252496 --> @jfoug commented on GitHub (Nov 17, 2017): > I also tested the QEMU emulated SPARC 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.
Author
Owner

@kholia commented on GitHub (Nov 17, 2017):

I wonder if there is any Linux setting that can be done to enhance the RPi to trap more errors?

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.

<!-- gh-comment-id:345255472 --> @kholia commented on GitHub (Nov 17, 2017): > I wonder if there is any Linux setting that can be done to enhance the RPi to trap more errors? 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.
Author
Owner

@jfoug commented on GitHub (Nov 17, 2017):

What about ARM v6 ? the RPi 1 uses that chip family

<!-- gh-comment-id:345255894 --> @jfoug commented on GitHub (Nov 17, 2017): What about ARM v6 ? the RPi 1 uses that chip family
Author
Owner

@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.

<!-- gh-comment-id:345256598 --> @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.
Author
Owner

@jfoug commented on GitHub (Nov 17, 2017):

No help:

from http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka15414.html

The ARMv6 architecture introduced the first hardware support for unaligned accesses

On older processors, such as ARM9 family based processors, an unaligned load had to be synthesised in software. Typically by doing a series of small accesses, and combining the results.

So it looks like ARM9 or older is needed to get the full level of unaligned traps.

<!-- gh-comment-id:345256723 --> @jfoug commented on GitHub (Nov 17, 2017): No help: from http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka15414.html > The ARMv6 architecture introduced the first hardware support for unaligned accesses > On older processors, such as ARM9 family based processors, an unaligned load had to be synthesised in software. Typically by doing a series of small accesses, and combining the results. So it looks like ARM9 or older is needed to get the full level of unaligned traps.
Author
Owner

@kholia commented on GitHub (Nov 19, 2017):

It seems that Parallela has an ARM A9 processor. I am not sure if it is the same thing as an ARM9 processor. I am guessing not.

<!-- gh-comment-id:345512339 --> @kholia commented on GitHub (Nov 19, 2017): It seems that Parallela has an `ARM A9` processor. I am not sure if it is the same thing as an `ARM9` processor. I am guessing not.
Author
Owner

@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

<!-- gh-comment-id:345518126 --> @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
Author
Owner

@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).

<!-- gh-comment-id:345604143 --> @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).
Author
Owner

@kholia commented on GitHub (Nov 20, 2017):

I might have a solution!

$ cat alignment.c 
#include <stdio.h>

int main()
{
	unsigned char arr[64] = { 'A', 'A', 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
	int i;

        for (i = 0; i < 3; i++) {
	 	int *q = (int *)&arr[i];
	 	long long *p = (long long *)&arr[i];

		printf ("q -> %d, addr -> %p\n", *q, q);
		printf ("p -> %lld, addr -> %p\n", *p, p);
		*p = 123;
	}

	return 0;
}
$ gcc -Wall -fsanitize=alignment alignment.c
$ ./a.out 
q -> 16705, addr -> 0x7ffede531ab0
p -> 216736831578849601, addr -> 0x7ffede531ab0
alignment.c:12:3: runtime error: load of misaligned address 0x7ffede531ab1 for type 'int', which requires 4 byte alignment
0x7ffede531ab1: note: pointer points here
 00 00 00  7b 00 00 00 00 00 00 00  04 05 06 07 08 09 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00
              ^ 
q -> 0, addr -> 0x7ffede531ab1
alignment.c:13:3: runtime error: load of misaligned address 0x7ffede531ab1 for type 'long long int', which requires 8 byte alignment
0x7ffede531ab1: note: pointer points here
 00 00 00  7b 00 00 00 00 00 00 00  04 05 06 07 08 09 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00
              ^ 
p -> 288230376151711744, addr -> 0x7ffede531ab1
alignment.c:14:6: runtime error: store to misaligned address 0x7ffede531ab1 for type 'long long int', which requires 8 byte alignment
0x7ffede531ab1: note: pointer points here
 00 00 00  7b 00 00 00 00 00 00 00  04 05 06 07 08 09 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00
              ^ 
q -> 0, addr -> 0x7ffede531ab2
p -> 360287970189639680, addr -> 0x7ffede531ab2

The -fsanitize=alignment flag 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.

<!-- gh-comment-id:345605006 --> @kholia commented on GitHub (Nov 20, 2017): I might have a solution! ``` $ cat alignment.c #include <stdio.h> int main() { unsigned char arr[64] = { 'A', 'A', 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int i; for (i = 0; i < 3; i++) { int *q = (int *)&arr[i]; long long *p = (long long *)&arr[i]; printf ("q -> %d, addr -> %p\n", *q, q); printf ("p -> %lld, addr -> %p\n", *p, p); *p = 123; } return 0; } ``` ``` $ gcc -Wall -fsanitize=alignment alignment.c ``` ``` $ ./a.out q -> 16705, addr -> 0x7ffede531ab0 p -> 216736831578849601, addr -> 0x7ffede531ab0 alignment.c:12:3: runtime error: load of misaligned address 0x7ffede531ab1 for type 'int', which requires 4 byte alignment 0x7ffede531ab1: note: pointer points here 00 00 00 7b 00 00 00 00 00 00 00 04 05 06 07 08 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ q -> 0, addr -> 0x7ffede531ab1 alignment.c:13:3: runtime error: load of misaligned address 0x7ffede531ab1 for type 'long long int', which requires 8 byte alignment 0x7ffede531ab1: note: pointer points here 00 00 00 7b 00 00 00 00 00 00 00 04 05 06 07 08 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ p -> 288230376151711744, addr -> 0x7ffede531ab1 alignment.c:14:6: runtime error: store to misaligned address 0x7ffede531ab1 for type 'long long int', which requires 8 byte alignment 0x7ffede531ab1: note: pointer points here 00 00 00 7b 00 00 00 00 00 00 00 04 05 06 07 08 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ q -> 0, addr -> 0x7ffede531ab2 p -> 360287970189639680, addr -> 0x7ffede531ab2 ``` The `-fsanitize=alignment` flag 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.
Author
Owner

@kholia commented on GitHub (Nov 20, 2017):

I am not sure if the following are false positives,

$ ../run/john --test
config.c:93:13: runtime error: member access within misaligned address 0x000001981ffc for type 'struct cfg_param', which requires 8 byte alignment
0x000001981ffc: note: pointer points here
  31 00 59 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
              ^ 
config.c:94:13: runtime error: member access within misaligned address 0x000001981ffc for type 'struct cfg_param', which requires 8 byte alignment
0x000001981ffc: note: pointer points here
  31 00 59 00 00 96 87 01  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
              ^ 
config.c:95:14: runtime error: member access within misaligned address 0x000001981ffc for type 'struct cfg_param', which requires 8 byte alignment
0x000001981ffc: note: pointer points here
  31 00 59 00 00 96 87 01  00 00 00 00 f0 1f 98 01  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
              ^ 
config.c:82:9: runtime error: member access within misaligned address 0x000001981ffc for type 'struct cfg_param', which requires 8 byte alignment
0x000001981ffc: note: pointer points here
  31 00 59 00 00 96 87 01  00 00 00 00 f0 1f 98 01  00 00 00 00 fa 1f 98 01  00 00 00 00 00 00 00 00
              ^ 
config.c:87:7: runtime error: member access within misaligned address 0x000001981ffc for type 'struct cfg_param', which requires 8 byte alignment
0x000001981ffc: note: pointer points here
  31 00 59 00 00 96 87 01  00 00 00 00 f0 1f 98 01  00 00 00 00 fa 1f 98 01  00 00 00 00 00 00 00 00
              ^ 
config.c:84:15: runtime error: member access within misaligned address 0x000001981ffc for type 'struct cfg_param', which requires 8 byte alignment
0x000001981ffc: note: pointer points here
  31 00 59 00 00 96 87 01  00 00 00 00 f0 1f 98 01  00 00 00 00 fa 1f 98 01  00 00 00 00 fc 1f 98 01
              ^ 
config.c:381:6: runtime error: member access within misaligned address 0x000001982044 for type 'struct cfg_param', which requires 8 byte alignment
0x000001982044: note: pointer points here
  00 00 00 00 2c 20 98 01  00 00 00 00 60 1f 98 01  00 00 00 00 77 1f 98 01  00 00 00 00 24 4a 4f 48
              ^ 
config.c:388:26: runtime error: member access within misaligned address 0x000001982044 for type 'struct cfg_param', which requires 8 byte alignment
0x000001982044: note: pointer points here
  00 00 00 00 2c 20 98 01  00 00 00 00 60 1f 98 01  00 00 00 00 77 1f 98 01  00 00 00 00 24 4a 4f 48
              ^ 
config.c:387:23: runtime error: member access within misaligned address 0x000001981ffc for type 'struct cfg_param', which requires 8 byte alignment
0x000001981ffc: note: pointer points here
  31 00 59 00 00 96 87 01  00 00 00 00 f0 1f 98 01  00 00 00 00 fa 1f 98 01  00 00 00 00 fc 1f 98 01
              ^ 
Will run 4 OpenMP threads
...
Benchmarking: dynamic_4 [md5($s.$p) (OSC) 256/256 AVX2 8x3]... dynamic_fmt.c:2461:6: runtime error: load of misaligned address 0x000001ef894e for type 'uint32_t', which requires 4 byte alignment
0x000001ef894e: note: pointer points here
 35 36 30 34 30 30  30 30 31 32 33 34 30 35  30 30 30 30 61 61 61 61  61 00 00 00 00 00 00 00  00 00
             ^ 
dynamic_fmt.c:1198:6: runtime error: load of misaligned address 0x000001ef8942 for type 'uint32_t', which requires 4 byte alignment
0x000001ef8942: note: pointer points here
 00 00  30 36 30 30 30 30 31 32  33 34 35 36 30 34 30 30  30 30 31 32 33 34 30 35  30 30 30 30 61 61
              ^ 
dynamic_fmt.c:3217:24: runtime error: load of misaligned address 0x000001ef8946 for type 'uint32_t', which requires 4 byte alignment
0x000001ef8946: note: pointer points here
 30 30 30 30 31 32  33 34 35 36 30 34 30 30  30 30 31 32 33 34 30 35  30 30 30 30 61 61 61 61  61 00
             ^ 

Here is my JtR Jumbo patch to enable this behavior,

diff --git a/src/configure b/src/configure
index 8533059..070018b 100755
--- a/src/configure
+++ b/src/configure
@@ -5953,8 +5953,8 @@ if test "x$ubsan" = xyes ; then
    CFLAGS_EX=""
    LDFLAGS_BAK=${LDFLAGS}
      if test "1" = 1; then :
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -DWITH_UBSAN -fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error" >&5
-$as_echo_n "checking if $CC supports -DWITH_UBSAN -fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error... " >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -DWITH_UBSAN -fsanitize=alignment" >&5
+$as_echo_n "checking if $CC supports -DWITH_UBSAN -fsanitize=alignment... " >&6; }
 fi
   ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
@@ -5963,7 +5963,7 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
   ac_saved_cflags="$CFLAGS"
-  CFLAGS="-Werror -DWITH_UBSAN -fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error"
+  CFLAGS="-Werror -DWITH_UBSAN -fsanitize=alignment"
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
@@ -5980,7 +5980,7 @@ if ac_fn_c_try_link "$LINENO"; then :
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 fi
-      CFLAGS_EX="$CFLAGS_EX -DWITH_UBSAN -fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error"
+      CFLAGS_EX="$CFLAGS_EX -DWITH_UBSAN -fsanitize=alignment"
 
 else
   if test "1" = 1; then :
@@ -6005,7 +6005,7 @@ $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
 as_fn_error $? "Could not find all required UBSAN components
 See \`config.log' for more details" "$LINENO" 5; }
    else
-      LDFLAGS="-fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error $LDFLAGS"
+      LDFLAGS="-fsanitize=alignment $LDFLAGS"
    fi
    LDFLAGS=${LDFLAGS_BAK}
 fi
@@ -13814,8 +13814,8 @@ fi
 if test "x$ubsan" = xyes ; then
    CFLAGS=`echo $CFLAGS | sed 's/-g //g; s/-O2 //g'`
    CFLAGS=`echo $CFLAGS | sed 's/-g$//g; s/-O2$//g'`
-   CFLAGS="-g $O_DEBUG -DWITH_UBSAN -fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error --param=max-vartrack-size=0 $CFLAGS"
-   LDFLAGS="-fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error $LDFLAGS"
+   CFLAGS="-g $O_DEBUG -DWITH_UBSAN -fsanitize=alignment --param=max-vartrack-size=0 $CFLAGS"
+   LDFLAGS="-fsanitize=alignment $LDFLAGS"
 fi
 
 #add ARCH_LITTLE_ENDIAN to command line, IF we know it is big or little
diff --git a/src/configure.ac b/src/configure.ac
index 2cbaf1c..6f63e62 100644
--- a/src/configure.ac
+++ b/src/configure.ac
@@ -211,11 +211,11 @@ fi
 if test "x$ubsan" = xyes ; then
    CFLAGS_EX=""
    LDFLAGS_BAK=${LDFLAGS}
-   JTR_FLAG_CHECK_LINK([-DWITH_UBSAN -fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error], 1)
+   JTR_FLAG_CHECK_LINK([-DWITH_UBSAN -fsanitize=alignment], 1)
    if test "x${CFLAGS_EX}" = x ; then
       AC_MSG_FAILURE([Could not find all required UBSAN components])
    else
-      LDFLAGS="-fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error $LDFLAGS"
+      LDFLAGS="-fsanitize=alignment $LDFLAGS"
    fi
    LDFLAGS=${LDFLAGS_BAK}
 fi
@@ -852,8 +852,8 @@ fi
 if test "x$ubsan" = xyes ; then
    CFLAGS=`echo $CFLAGS | sed 's/-g //g; s/-O2 //g'`
    CFLAGS=`echo $CFLAGS | sed 's/-g$//g; s/-O2$//g'`
-   CFLAGS="-g $O_DEBUG -DWITH_UBSAN -fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error --param=max-vartrack-size=0 $CFLAGS"
-   LDFLAGS="-fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error $LDFLAGS"
+   CFLAGS="-g $O_DEBUG -DWITH_UBSAN -fsanitize=alignment --param=max-vartrack-size=0 $CFLAGS"
+   LDFLAGS="-fsanitize=alignment $LDFLAGS"
 fi
 
 #add ARCH_LITTLE_ENDIAN to command line, IF we know it is big or little

After applying this patch, build JtR with make clean; ./configure --enable-ubsan; make -j8.

<!-- gh-comment-id:345608339 --> @kholia commented on GitHub (Nov 20, 2017): I am not sure if the following are false positives, ``` $ ../run/john --test config.c:93:13: runtime error: member access within misaligned address 0x000001981ffc for type 'struct cfg_param', which requires 8 byte alignment 0x000001981ffc: note: pointer points here 31 00 59 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ config.c:94:13: runtime error: member access within misaligned address 0x000001981ffc for type 'struct cfg_param', which requires 8 byte alignment 0x000001981ffc: note: pointer points here 31 00 59 00 00 96 87 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ config.c:95:14: runtime error: member access within misaligned address 0x000001981ffc for type 'struct cfg_param', which requires 8 byte alignment 0x000001981ffc: note: pointer points here 31 00 59 00 00 96 87 01 00 00 00 00 f0 1f 98 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ config.c:82:9: runtime error: member access within misaligned address 0x000001981ffc for type 'struct cfg_param', which requires 8 byte alignment 0x000001981ffc: note: pointer points here 31 00 59 00 00 96 87 01 00 00 00 00 f0 1f 98 01 00 00 00 00 fa 1f 98 01 00 00 00 00 00 00 00 00 ^ config.c:87:7: runtime error: member access within misaligned address 0x000001981ffc for type 'struct cfg_param', which requires 8 byte alignment 0x000001981ffc: note: pointer points here 31 00 59 00 00 96 87 01 00 00 00 00 f0 1f 98 01 00 00 00 00 fa 1f 98 01 00 00 00 00 00 00 00 00 ^ config.c:84:15: runtime error: member access within misaligned address 0x000001981ffc for type 'struct cfg_param', which requires 8 byte alignment 0x000001981ffc: note: pointer points here 31 00 59 00 00 96 87 01 00 00 00 00 f0 1f 98 01 00 00 00 00 fa 1f 98 01 00 00 00 00 fc 1f 98 01 ^ config.c:381:6: runtime error: member access within misaligned address 0x000001982044 for type 'struct cfg_param', which requires 8 byte alignment 0x000001982044: note: pointer points here 00 00 00 00 2c 20 98 01 00 00 00 00 60 1f 98 01 00 00 00 00 77 1f 98 01 00 00 00 00 24 4a 4f 48 ^ config.c:388:26: runtime error: member access within misaligned address 0x000001982044 for type 'struct cfg_param', which requires 8 byte alignment 0x000001982044: note: pointer points here 00 00 00 00 2c 20 98 01 00 00 00 00 60 1f 98 01 00 00 00 00 77 1f 98 01 00 00 00 00 24 4a 4f 48 ^ config.c:387:23: runtime error: member access within misaligned address 0x000001981ffc for type 'struct cfg_param', which requires 8 byte alignment 0x000001981ffc: note: pointer points here 31 00 59 00 00 96 87 01 00 00 00 00 f0 1f 98 01 00 00 00 00 fa 1f 98 01 00 00 00 00 fc 1f 98 01 ^ Will run 4 OpenMP threads ... Benchmarking: dynamic_4 [md5($s.$p) (OSC) 256/256 AVX2 8x3]... dynamic_fmt.c:2461:6: runtime error: load of misaligned address 0x000001ef894e for type 'uint32_t', which requires 4 byte alignment 0x000001ef894e: note: pointer points here 35 36 30 34 30 30 30 30 31 32 33 34 30 35 30 30 30 30 61 61 61 61 61 00 00 00 00 00 00 00 00 00 ^ dynamic_fmt.c:1198:6: runtime error: load of misaligned address 0x000001ef8942 for type 'uint32_t', which requires 4 byte alignment 0x000001ef8942: note: pointer points here 00 00 30 36 30 30 30 30 31 32 33 34 35 36 30 34 30 30 30 30 31 32 33 34 30 35 30 30 30 30 61 61 ^ dynamic_fmt.c:3217:24: runtime error: load of misaligned address 0x000001ef8946 for type 'uint32_t', which requires 4 byte alignment 0x000001ef8946: note: pointer points here 30 30 30 30 31 32 33 34 35 36 30 34 30 30 30 30 31 32 33 34 30 35 30 30 30 30 61 61 61 61 61 00 ^ ``` Here is my JtR Jumbo patch to enable this behavior, ``` diff diff --git a/src/configure b/src/configure index 8533059..070018b 100755 --- a/src/configure +++ b/src/configure @@ -5953,8 +5953,8 @@ if test "x$ubsan" = xyes ; then CFLAGS_EX="" LDFLAGS_BAK=${LDFLAGS} if test "1" = 1; then : - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -DWITH_UBSAN -fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error" >&5 -$as_echo_n "checking if $CC supports -DWITH_UBSAN -fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -DWITH_UBSAN -fsanitize=alignment" >&5 +$as_echo_n "checking if $CC supports -DWITH_UBSAN -fsanitize=alignment... " >&6; } fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -5963,7 +5963,7 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu ac_saved_cflags="$CFLAGS" - CFLAGS="-Werror -DWITH_UBSAN -fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error" + CFLAGS="-Werror -DWITH_UBSAN -fsanitize=alignment" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -5980,7 +5980,7 @@ if ac_fn_c_try_link "$LINENO"; then : { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } fi - CFLAGS_EX="$CFLAGS_EX -DWITH_UBSAN -fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error" + CFLAGS_EX="$CFLAGS_EX -DWITH_UBSAN -fsanitize=alignment" else if test "1" = 1; then : @@ -6005,7 +6005,7 @@ $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "Could not find all required UBSAN components See \`config.log' for more details" "$LINENO" 5; } else - LDFLAGS="-fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error $LDFLAGS" + LDFLAGS="-fsanitize=alignment $LDFLAGS" fi LDFLAGS=${LDFLAGS_BAK} fi @@ -13814,8 +13814,8 @@ fi if test "x$ubsan" = xyes ; then CFLAGS=`echo $CFLAGS | sed 's/-g //g; s/-O2 //g'` CFLAGS=`echo $CFLAGS | sed 's/-g$//g; s/-O2$//g'` - CFLAGS="-g $O_DEBUG -DWITH_UBSAN -fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error --param=max-vartrack-size=0 $CFLAGS" - LDFLAGS="-fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error $LDFLAGS" + CFLAGS="-g $O_DEBUG -DWITH_UBSAN -fsanitize=alignment --param=max-vartrack-size=0 $CFLAGS" + LDFLAGS="-fsanitize=alignment $LDFLAGS" fi #add ARCH_LITTLE_ENDIAN to command line, IF we know it is big or little diff --git a/src/configure.ac b/src/configure.ac index 2cbaf1c..6f63e62 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -211,11 +211,11 @@ fi if test "x$ubsan" = xyes ; then CFLAGS_EX="" LDFLAGS_BAK=${LDFLAGS} - JTR_FLAG_CHECK_LINK([-DWITH_UBSAN -fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error], 1) + JTR_FLAG_CHECK_LINK([-DWITH_UBSAN -fsanitize=alignment], 1) if test "x${CFLAGS_EX}" = x ; then AC_MSG_FAILURE([Could not find all required UBSAN components]) else - LDFLAGS="-fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error $LDFLAGS" + LDFLAGS="-fsanitize=alignment $LDFLAGS" fi LDFLAGS=${LDFLAGS_BAK} fi @@ -852,8 +852,8 @@ fi if test "x$ubsan" = xyes ; then CFLAGS=`echo $CFLAGS | sed 's/-g //g; s/-O2 //g'` CFLAGS=`echo $CFLAGS | sed 's/-g$//g; s/-O2$//g'` - CFLAGS="-g $O_DEBUG -DWITH_UBSAN -fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error --param=max-vartrack-size=0 $CFLAGS" - LDFLAGS="-fsanitize=undefined -fno-sanitize=alignment -fsanitize-undefined-trap-on-error $LDFLAGS" + CFLAGS="-g $O_DEBUG -DWITH_UBSAN -fsanitize=alignment --param=max-vartrack-size=0 $CFLAGS" + LDFLAGS="-fsanitize=alignment $LDFLAGS" fi #add ARCH_LITTLE_ENDIAN to command line, IF we know it is big or little ``` After applying this patch, build JtR with `make clean; ./configure --enable-ubsan; make -j8`.
Author
Owner

@kholia commented on GitHub (Nov 20, 2017):

We may need to turn off ARCH_ALLOWS_UNALIGNED when using the -fsanitize=alignment flag.

<!-- gh-comment-id:345613135 --> @kholia commented on GitHub (Nov 20, 2017): We may need to turn off `ARCH_ALLOWS_UNALIGNED` when using the `-fsanitize=alignment` flag.
Author
Owner

@kholia commented on GitHub (Nov 20, 2017):

Patch to fix alignment problem in config.c,

diff --git a/src/config.c b/src/config.c
index ec82423..1fde01f 100644
--- a/src/config.c
+++ b/src/config.c
@@ -89,7 +89,7 @@ static int cfg_merge_local_section() {
                if (!found) {
                        // add a new item. NOTE, fixes bug #767
                        // https://github.com/magnumripper/JohnTheRipper/issues/767
-                       struct cfg_param *p3 = (struct cfg_param*)mem_alloc_tiny(sizeof(struct cfg_param), 1);
+                       struct cfg_param *p3 = (struct cfg_param*)mem_alloc_tiny(sizeof(struct cfg_param), MEM_ALIGN_WORD);
                        p3->next = parent->params;
                        p3->name = p1->name;
                        p3->value = p1->value;
<!-- gh-comment-id:345641171 --> @kholia commented on GitHub (Nov 20, 2017): Patch to fix alignment problem in `config.c`, ``` diff diff --git a/src/config.c b/src/config.c index ec82423..1fde01f 100644 --- a/src/config.c +++ b/src/config.c @@ -89,7 +89,7 @@ static int cfg_merge_local_section() { if (!found) { // add a new item. NOTE, fixes bug #767 // https://github.com/magnumripper/JohnTheRipper/issues/767 - struct cfg_param *p3 = (struct cfg_param*)mem_alloc_tiny(sizeof(struct cfg_param), 1); + struct cfg_param *p3 = (struct cfg_param*)mem_alloc_tiny(sizeof(struct cfg_param), MEM_ALIGN_WORD); p3->next = parent->params; p3->name = p1->name; p3->value = p1->value; ```
Author
Owner

@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.

<!-- gh-comment-id:345659366 --> @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.
Author
Owner

@jfoug commented on GitHub (Nov 20, 2017):

We may need to turn off ARCH_ALLOWS_UNALIGNED when using the -fsanitize=alignment flag.

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.

<!-- gh-comment-id:345661913 --> @jfoug commented on GitHub (Nov 20, 2017): > We may need to turn off ARCH_ALLOWS_UNALIGNED when using the -fsanitize=alignment flag. 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.
Author
Owner

@kholia commented on GitHub (Nov 20, 2017):

Some testing with malloc (my understanding of "allocated variables" phrase),

$ cat alignment-malloc.c 
#include <stdio.h>
#include <stdlib.h>

int main()
{
	unsigned char *arr = (unsigned char*)malloc(64);
	int i;

        for (i = 0; i < 3; i++) {
	 	int *q = (int *)&arr[i];
	 	long long *p = (long long *)&arr[i];

		printf ("q -> %d, addr -> %p\n", *q, q);
		printf ("p -> %lld, addr -> %p\n", *p, p);
		*p = 123;
	}

	return 0;
}
$ gcc -fsanitize=alignment alignment-malloc.c
$ ./a.out 
q -> 0, addr -> 0x1bd7c20
p -> 0, addr -> 0x1bd7c20
alignment-malloc.c:13:3: runtime error: load of misaligned address 0x000001bd7c21 for type 'int', which requires 4 byte alignment
0x000001bd7c21: note: pointer points here
 00 00 00  7b 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00
              ^ 
q -> 0, addr -> 0x1bd7c21
alignment-malloc.c:14:3: runtime error: load of misaligned address 0x000001bd7c21 for type 'long long int', which requires 8 byte alignment
0x000001bd7c21: note: pointer points here
 00 00 00  7b 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00
              ^ 
p -> 0, addr -> 0x1bd7c21
alignment-malloc.c:15:6: runtime error: store to misaligned address 0x000001bd7c21 for type 'long long int', which requires 8 byte alignment
0x000001bd7c21: note: pointer points here
 00 00 00  7b 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00
              ^ 
q -> 0, addr -> 0x1bd7c22
p -> 0, addr -> 0x1bd7c22
<!-- gh-comment-id:345664201 --> @kholia commented on GitHub (Nov 20, 2017): Some testing with `malloc` (my understanding of "allocated variables" phrase), ``` $ cat alignment-malloc.c #include <stdio.h> #include <stdlib.h> int main() { unsigned char *arr = (unsigned char*)malloc(64); int i; for (i = 0; i < 3; i++) { int *q = (int *)&arr[i]; long long *p = (long long *)&arr[i]; printf ("q -> %d, addr -> %p\n", *q, q); printf ("p -> %lld, addr -> %p\n", *p, p); *p = 123; } return 0; } ``` ``` $ gcc -fsanitize=alignment alignment-malloc.c ``` ``` $ ./a.out q -> 0, addr -> 0x1bd7c20 p -> 0, addr -> 0x1bd7c20 alignment-malloc.c:13:3: runtime error: load of misaligned address 0x000001bd7c21 for type 'int', which requires 4 byte alignment 0x000001bd7c21: note: pointer points here 00 00 00 7b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ q -> 0, addr -> 0x1bd7c21 alignment-malloc.c:14:3: runtime error: load of misaligned address 0x000001bd7c21 for type 'long long int', which requires 8 byte alignment 0x000001bd7c21: note: pointer points here 00 00 00 7b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ p -> 0, addr -> 0x1bd7c21 alignment-malloc.c:15:6: runtime error: store to misaligned address 0x000001bd7c21 for type 'long long int', which requires 8 byte alignment 0x000001bd7c21: note: pointer points here 00 00 00 7b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ q -> 0, addr -> 0x1bd7c22 p -> 0, addr -> 0x1bd7c22 ```
Author
Owner

@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_UNALIGNED wrapper, keeping the original code

<!-- gh-comment-id:345664218 --> @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_UNALIGNED``` wrapper, keeping the original code
Author
Owner

@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.

<!-- gh-comment-id:345664537 --> @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.
Author
Owner

@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.

<!-- gh-comment-id:345665336 --> @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.
Author
Owner

@kholia commented on GitHub (Nov 20, 2017):

It should be put into code using the #if ARCH_ALLOWS_UNALIGNED wrapper, keeping the original code.

Why do we need to use #if ARCH_ALLOWS_UNALIGNED at all? Can't we simply do mem_alloc_tiny(..., MEM_ALIGN_WORD), which will work on all machines? Are there some disadvantages of using MEM_ALIGN_WORD everywhere? One possible problem could be internal fragmentation (space wastage) in the mem_alloc_tiny allocator?

<!-- gh-comment-id:345668754 --> @kholia commented on GitHub (Nov 20, 2017): > It should be put into code using the #if ARCH_ALLOWS_UNALIGNED wrapper, keeping the original code. Why do we need to use ` #if ARCH_ALLOWS_UNALIGNED` at all? Can't we simply do `mem_alloc_tiny(..., MEM_ALIGN_WORD)`, which will work on all machines? Are there some disadvantages of using `MEM_ALIGN_WORD` everywhere? One possible problem could be internal fragmentation (space wastage) in the `mem_alloc_tiny` allocator?
Author
Owner

@jfoug commented on GitHub (Nov 20, 2017):

One possible problem could be internal fragmentation (space wastage)

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 ;)

<!-- gh-comment-id:345670717 --> @jfoug commented on GitHub (Nov 20, 2017): > One possible problem could be internal fragmentation (space wastage) 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 ;)
Author
Owner

@kholia commented on GitHub (Nov 20, 2017):

I have now applied the following patch,

diff --git a/src/x86-64.h b/src/x86-64.h
index 7451ee8..ae2b87f 100644
--- a/src/x86-64.h
+++ b/src/x86-64.h
@@ -34,7 +34,7 @@
 #define ARCH_INT_GT_32                 0
 #endif
 
-#define ARCH_ALLOWS_UNALIGNED          1
+#define ARCH_ALLOWS_UNALIGNED          0
 #define ARCH_INDEX(x)                  ((unsigned int)(unsigned char)(x))
 
 #define CPU_DETECT                     0
$ ../run/john --test=0
...
Testing: dynamic_1 [md5($p.$s) (joomla) 256/256 AVX2 8x3]... dynamic_fmt.c:3217:24: runtime error: load of misaligned address 0x000001923d69 for type 'uint32_t', which requires 4 byte alignment
0x000001923d69: note: pointer points here
 30 31 61  44 4e 4e 6f 6a 59 47 53  63 37 70 53 7a 63 64 78  4b 78 68 62 71 76 4c 74  45 65 34 64 65
              ^

Testing: sha256crypt, crypt(3) $5$ (rounds=5000) [SHA256 256/256 AVX2 8x]... (4xOMP) cryptsha256_fmt_plug.c:766:12: runtime error: store to misaligned address 0x7ffcb1d6909e for type 'uint32_t', which requires 4 byte alignment
0x7ffcb1d6909e: note: pointer points here
 1d d0 a3 45 70 c1  92 55 0e c8 90 78 e7 9f  0d 72 a1 42 af 3d 27 41  79 f4 e2 d5 76 c6 07 c1  90 c9
             ^ 

Testing: sha512crypt, crypt(3) $6$ (rounds=5000) [SHA512 256/256 AVX2 4x]... (4xOMP) cryptsha512_fmt_plug.c:754:12: runtime error: store to misaligned address 0x7ffcb1d69ebe for type 'uint64_t', which requires 8 byte alignment
0x7ffcb1d69ebe: note: pointer points here
 cc f0 54 c0 8e be  62 97 00 e5 99 26 f9 cd  f8 96 37 a1 5c f8 8a 19  36 5b 6f d4 74 d6 3e 50  3e 01
             ^
Testing: ethereum, Ethereum Wallet [PBKDF2-SHA256/scrypt Keccak 256/256 AVX2 8x]... (4xOMP) KeccakF-1600-opt64.c:79:12: runtime error: load of misaligned address 0x000001852d7c for type 'UINT64', which requires 8 byte alignment
0x000001852d7c: note: pointer points here
  20 00 00 00 53 18 b4 d5  bc d2 8d e6 4e e5 55 9e  67 13 53 e1 6f 07 5e ca  e9 f9 9c 7a 79 a3 8a f5
              ^ 

Testing: fde, Android FDE [PBKDF2-SHA1 256/256 AVX2 8x SHA256/AES]... (4xOMP) androidfde_fmt_plug.c:261:29: runtime error: member access within misaligned address 0x0000018755c4 for type 'struct custom_salt', which requires 8 byte alignment
0x0000018755c4: note: pointer points here
  98 50 56 e9 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 10 00 00 00  00 00 00 00 10 00 00 00
              ^ 
androidfde_fmt_plug.c:273:44: runtime error: member access within misaligned address 0x0000018755c4 for type 'struct custom_salt', which requires 8 byte alignment
0x0000018755c4: note: pointer points here
  98 50 56 e9 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 10 00 00 00  00 00 00 00 10 00 00 00
              ^ 
androidfde_fmt_plug.c:224:35: runtime error: member access within misaligned address 0x0000018755c4 for type 'struct custom_salt', which requires 8 byte alignment
0x0000018755c4: note: pointer points here
  98 50 56 e9 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 10 00 00 00  00 00 00 00 10 00 00 00
              ^ 
androidfde_fmt_plug.c:232:35: runtime error: member access within misaligned address 0x0000018755c4 for type 'struct custom_salt', which requires 8 byte alignment
0x0000018755c4: note: pointer points here
  98 50 56 e9 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 10 00 00 00  00 00 00 00 10 00 00 00

Testing: hdaa, HTTP Digest access authentication [MD5 256/256 AVX2 8x3]... HDAA_fmt_plug.c:480:29: runtime error: member access within misaligned address 0x000001889fb4 for type 'struct reqinfo_t', which requires 8 byte alignment
0x000001889fb4: note: pointer points here
  78 4f 56 e9 0d 00 00 00  00 00 00 00 81 00 00 00  00 00 00 00 75 73 65 72  3a 6d 79 72 65 61 6c 6d
              ^ 
HDAA_fmt_plug.c:482:15: runtime error: member access within misaligned address 0x000001889fb4 for type 'struct reqinfo_t', which requires 8 byte alignment
0x000001889fb4: note: pointer points here
  78 4f 56 e9 0d 00 00 00  00 00 00 00 81 00 00 00  00 00 00 00 75 73 65 72  3a 6d 79 72 65 61 6c 6d
              ^ 
HDAA_fmt_plug.c:517:21: runtime error: member access within misaligned address 0x000001889fb4 for type 'struct reqinfo_t', which requires 8 byte alignment
0x000001889fb4: note: pointer points here
  78 4f 56 e9 0d 00 00 00  00 00 00 00 81 00 00 00  00 00 00 00 75 73 65 72  3a 6d 79 72 65 61 6c 6d
              ^ 
HDAA_fmt_plug.c:519:15: runtime error: member access within misaligned address 0x000001889fb4 for type 'struct reqinfo_t', which requires 8 byte alignment
0x000001889fb4: note: pointer points here
  78 4f 56 e9 0d 00 00 00  00 00 00 00 81 00 00 00  00 00 00 00 75 73 65 72  3a 6d 79 72 65 61 6c 6d
Testing: hMailServer [sha256($s.$p) 256/256 AVX2 8x]... dynamic_fmt.c:2447:4: runtime error: load of misaligned address 0x000001c91e74 for type 'long unsigned int', which requires 8 byte alignment
0x000001c91e74: note: pointer points here
  58 4b 56 e9 6f 4d 92 01  00 00 00 00 00 00 00 00  10 53 62 03 00 00 00 00  e0 6d 9c 01 00 00 00 00
              ^ 
dynamic_fmt.c:1193:9: runtime error: load of misaligned address 0x000001c91e74 for type 'unsigned char *', which requires 8 byte alignment
0x000001c91e74: note: pointer points here
  58 4b 56 e9 6f 4d 92 01  00 00 00 00 00 00 00 00  10 53 62 03 00 00 00 00  e0 6d 9c 01 00 00 00 00
              ^
Testing: oracle11, Oracle 11g [SHA1 256/256 AVX2 8x]... oracle11_fmt_plug.c:357:5: runtime error: load of misaligned address 0x0000019c6312 for type 'uint32_t', which requires 4 byte alignment
0x0000019c6312: note: pointer points here
 00 00  90 36 03 f2 c5 2e d1 b4  d6 42 00 00 00 00 00 00  00 00 00 00 00 00 00 00  c1 00 00 00 00 00
              ^ 
oracle11_fmt_plug.c:360:5: runtime error: load of misaligned address 0x0000019c6316 for type 'uint32_t', which requires 4 byte alignment
0x0000019c6316: note: pointer points here
 03 f2 c5 2e d1 b4  d6 42 00 00 00 00 00 00  00 00 00 00 00 00 00 00  c1 00 00 00 00 00 00 00  e8 4b
             ^ 
oracle11_fmt_plug.c:366:5: runtime error: load of misaligned address 0x0000019c6311 for type 'uint32_t', which requires 4 byte alignment
0x0000019c6311: note: pointer points here
 00 00 00  97 63 fc f0 d5 4d a6 67  d4 e6 00 00 00 00 00 00  00 00 00 00 00 00 00 00  c1 00 00 00 00
              ^ 
oracle11_fmt_plug.c:369:5: runtime error: load of misaligned address 0x0000019c6315 for type 'uint32_t', which requires 4 byte alignment
0x0000019c6315: note: pointer points here
 63 fc f0 d5 4d a6 67  d4 e6 00 00 00 00 00 00  00 00 00 00 00 00 00 00  c1 00 00 00 00 00 00 00  e8
             ^ 
Testing: phpass ($P$9) [phpass ($P$ or $H$) 256/256 AVX2 8x3]... (4xOMP) phpassMD5_fmt_plug.c:337:9: runtime error: load of misaligned address 0x000001bbad44 for type 'long int', which requires 8 byte alignment
0x000001bbad44: note: pointer points here
  58 4b 56 e9 61 61 61 61  61 53 58 42 39 7f 00 00  12 ad 24 b8 dd 12 b7 51  b4 46 cd 94 56 4f c5 94
              ^ 
Testing: PKZIP [32/64]... (4xOMP) formats.c:1770:23: runtime error: load of misaligned address 0x000001a8be14 for type 'struct dyna_salt_john_core *', which requires 8 byte alignment
0x000001a8be14: note: pointer points here
  58 4b 56 e9 90 38 bc 01  00 00 00 00 e2 7f 00 00  0a d2 78 a5 b0 4e 41 80  7a e9 fc 35 36 37 38 00
              ^ 
pkzip_fmt_plug.c:533:9: runtime error: load of misaligned address 0x000001a8be14 for type 'struct PKZ_SALT *', which requires 8 byte alignment
0x000001a8be14: note: pointer points here
  58 4b 56 e9 90 38 bc 01  00 00 00 00 e2 7f 00 00  0a d2 78 a5 b0 4e 41 80  7a e9 fc 35 36 37 38 00
              ^ 
dyna_salt.c:90:24: runtime error: load of misaligned address 0x000001a8be14 for type 'struct dyna_salt_john_core *', which requires 8 byte alignment
0x000001a8be14: note: pointer points here
  58 4b 56 e9 90 38 bc 01  00 00 00 00 e2 7f 00 00  0a d2 78 a5 b0 4e 41 80  7a e9 fc 35 36 37 38 00
              ^ 
dyna_salt.c:56:24: runtime error: load of misaligned address 0x000001a8be14 for type 'struct dyna_salt_john_core *', which requires 8 byte alignment
0x000001a8be14: note: pointer points here
  58 4b 56 e9 90 38 bc 01  00 00 00 00 e2 7f 00 00  0a d2 78 a5 b0 4e 41 80  7a e9 fc 35 36 37 38 00

Testing: sapb, SAP CODVN B (BCODE) [MD5 256/256 AVX2 8x3]... (4xOMP) sapB_fmt_plug.c:481:36: runtime error: store to misaligned address 0x7fe2df5a9d05 for type 'unsigned int', which requires 4 byte alignment
0x7fe2df5a9d05: note: pointer points here
 00 32 00 19 00 00 00  ff 2f 00 00 00 00 00 00  bc 6a 61 03 00 00 00 00  04 00 00 00 08 00 00 00  00
             ^ 

Testing: sapg, SAP CODVN F/G (PASSCODE) [SHA1 256/256 AVX2 8x]... (4xOMP) sapG_fmt_plug.c:559:55: runtime error: load of misaligned address 0x000000a0ccea for type 'uint32_t', which requires 4 byte alignment
0x000000a0ccea: note: pointer points here
 ae dd  16 f2 4b 8d 2c e1 d4 dc  b0 cb df 9d d4 70 6d 17  f9 4d 42 3f 9b 1b 11 94  9f 5b c1 9b 06 05
              ^ 

Testing: saph, SAP CODVN H (PWDSALTEDHASH) (SHA1x1024) [SHA-1/SHA-2 256/256 AVX2 8x]... (4xOMP) sapH_fmt_plug.c:318:15: runtime error: store to misaligned address 0x7ffcb1d6c5f7 for type 'uint32_t', which requires 4 byte alignment
0x7ffcb1d6c5f7: note: pointer points here
 30 31 32 33 8a  21 27 a4 ab 16 e8 e7 09  35 5d 20 48 37 6a eb b0  6a ed 06 80 00 00 00 00  00 00 00
             ^ 
sapH_fmt_plug.c:390:15: runtime error: store to misaligned address 0x7ffcb1d6c626 for type 'uint32_t', which requires 4 byte alignment
0x7ffcb1d6c626: note: pointer points here
 6f 62 6f 6f b2 6d  27 89 5b 9c bc e8 7b 13  2e 36 11 d7 f2 af 03 77  81 46 39 42 5b 2c 77 27  e0 bc
             ^ 
sapH_fmt_plug.c:463:15: runtime error: store to misaligned address 0x7ffcb1d6c6a6 for type 'uint64_t', which requires 8 byte alignment
0x7ffcb1d6c6a6: note: pointer points here
 6f 62 6f 6f 35 01  f7 03 40 88 d4 ef 9c 89  cb 2a 37 28 60 50 db ea  7a 98 27 e4 5a 3c 23 af  e7 65
             ^ 
sapH_fmt_plug.c:535:15: runtime error: store to misaligned address 0x7ffcb1d6c6a6 for type 'uint64_t', which requires 8 byte alignment
0x7ffcb1d6c6a6: note: pointer points here
 6f 62 6f 6f e6 b7  6a 34 b9 94 3d c5 17 33  da ce 35 54 23 6e d1 15  9a 7b 1b 2e e7 97 e4 91  69 06

Testing: OpenVMS, Purdy [32/64]... (4xOMP) uaf_encode.c:543:13: runtime error: member access within misaligned address 0x000002a29a54 for type 'struct uaf_hash_info', which requires 8 byte alignment
0x000002a29a54: note: pointer points here
  78 4b 56 e9 64 90 61 55  0a 32 2a d1 00 00 00 00  00 00 00 00 a5 fb 03 00  8d 96 0b 7e 10 00 00 00
              ^ 
uaf_encode.c:560:30: runtime error: member access within misaligned address 0x000002a29a54 for type 'struct uaf_hash_info', which requires 8 byte alignment
0x000002a29a54: note: pointer points here
  78 4b 56 e9 64 90 61 55  0a 32 2a d1 00 00 00 00  00 00 00 00 a5 fb 03 00  8d 96 0b 7e 10 00 00 00
              ^ 
uaf_encode.c:560:20: runtime error: member access within misaligned address 0x000002a29a54 for type 'struct uaf_hash_info', which requires 8 byte alignment
0x000002a29a54: note: pointer points here
  78 4b 56 e9 64 90 61 55  0a 32 2a d1 00 00 00 00  00 00 00 00 a5 fb 03 00  8d 96 0b 7e 10 00 00 00
              ^ 
uaf_encode.c:565:13: runtime error: member access within misaligned address 0x000002a29a54 for type 'struct uaf_hash_info', which requires 8 byte alignment
0x000002a29a54: note: pointer points here
  78 4b 56 e9 64 90 61 55  0a 32 2a d1 00 00 00 00  00 00 00 00 a5 fb 03 00  8d 96 0b 7e 10 00 00 00
              ^ 
uaf_encode.c:569:10: runtime error: member access within misaligned address 0x000002a29a54 for type 'struct uaf_hash_info', which requires 8 byte alignment
0x000002a29a54: note: pointer points here
  78 4b 56 e9 64 90 61 55  0a 32 2a d1 00 00 00 00  00 00 00 00 a5 fb 03 00  8d 96 0b 7e 10 00 00 00

<!-- gh-comment-id:345684536 --> @kholia commented on GitHub (Nov 20, 2017): I have now applied the following patch, ``` diff diff --git a/src/x86-64.h b/src/x86-64.h index 7451ee8..ae2b87f 100644 --- a/src/x86-64.h +++ b/src/x86-64.h @@ -34,7 +34,7 @@ #define ARCH_INT_GT_32 0 #endif -#define ARCH_ALLOWS_UNALIGNED 1 +#define ARCH_ALLOWS_UNALIGNED 0 #define ARCH_INDEX(x) ((unsigned int)(unsigned char)(x)) #define CPU_DETECT 0 ``` ``` $ ../run/john --test=0 ... Testing: dynamic_1 [md5($p.$s) (joomla) 256/256 AVX2 8x3]... dynamic_fmt.c:3217:24: runtime error: load of misaligned address 0x000001923d69 for type 'uint32_t', which requires 4 byte alignment 0x000001923d69: note: pointer points here 30 31 61 44 4e 4e 6f 6a 59 47 53 63 37 70 53 7a 63 64 78 4b 78 68 62 71 76 4c 74 45 65 34 64 65 ^ Testing: sha256crypt, crypt(3) $5$ (rounds=5000) [SHA256 256/256 AVX2 8x]... (4xOMP) cryptsha256_fmt_plug.c:766:12: runtime error: store to misaligned address 0x7ffcb1d6909e for type 'uint32_t', which requires 4 byte alignment 0x7ffcb1d6909e: note: pointer points here 1d d0 a3 45 70 c1 92 55 0e c8 90 78 e7 9f 0d 72 a1 42 af 3d 27 41 79 f4 e2 d5 76 c6 07 c1 90 c9 ^ Testing: sha512crypt, crypt(3) $6$ (rounds=5000) [SHA512 256/256 AVX2 4x]... (4xOMP) cryptsha512_fmt_plug.c:754:12: runtime error: store to misaligned address 0x7ffcb1d69ebe for type 'uint64_t', which requires 8 byte alignment 0x7ffcb1d69ebe: note: pointer points here cc f0 54 c0 8e be 62 97 00 e5 99 26 f9 cd f8 96 37 a1 5c f8 8a 19 36 5b 6f d4 74 d6 3e 50 3e 01 ^ Testing: ethereum, Ethereum Wallet [PBKDF2-SHA256/scrypt Keccak 256/256 AVX2 8x]... (4xOMP) KeccakF-1600-opt64.c:79:12: runtime error: load of misaligned address 0x000001852d7c for type 'UINT64', which requires 8 byte alignment 0x000001852d7c: note: pointer points here 20 00 00 00 53 18 b4 d5 bc d2 8d e6 4e e5 55 9e 67 13 53 e1 6f 07 5e ca e9 f9 9c 7a 79 a3 8a f5 ^ Testing: fde, Android FDE [PBKDF2-SHA1 256/256 AVX2 8x SHA256/AES]... (4xOMP) androidfde_fmt_plug.c:261:29: runtime error: member access within misaligned address 0x0000018755c4 for type 'struct custom_salt', which requires 8 byte alignment 0x0000018755c4: note: pointer points here 98 50 56 e9 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 10 00 00 00 ^ androidfde_fmt_plug.c:273:44: runtime error: member access within misaligned address 0x0000018755c4 for type 'struct custom_salt', which requires 8 byte alignment 0x0000018755c4: note: pointer points here 98 50 56 e9 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 10 00 00 00 ^ androidfde_fmt_plug.c:224:35: runtime error: member access within misaligned address 0x0000018755c4 for type 'struct custom_salt', which requires 8 byte alignment 0x0000018755c4: note: pointer points here 98 50 56 e9 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 10 00 00 00 ^ androidfde_fmt_plug.c:232:35: runtime error: member access within misaligned address 0x0000018755c4 for type 'struct custom_salt', which requires 8 byte alignment 0x0000018755c4: note: pointer points here 98 50 56 e9 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 10 00 00 00 Testing: hdaa, HTTP Digest access authentication [MD5 256/256 AVX2 8x3]... HDAA_fmt_plug.c:480:29: runtime error: member access within misaligned address 0x000001889fb4 for type 'struct reqinfo_t', which requires 8 byte alignment 0x000001889fb4: note: pointer points here 78 4f 56 e9 0d 00 00 00 00 00 00 00 81 00 00 00 00 00 00 00 75 73 65 72 3a 6d 79 72 65 61 6c 6d ^ HDAA_fmt_plug.c:482:15: runtime error: member access within misaligned address 0x000001889fb4 for type 'struct reqinfo_t', which requires 8 byte alignment 0x000001889fb4: note: pointer points here 78 4f 56 e9 0d 00 00 00 00 00 00 00 81 00 00 00 00 00 00 00 75 73 65 72 3a 6d 79 72 65 61 6c 6d ^ HDAA_fmt_plug.c:517:21: runtime error: member access within misaligned address 0x000001889fb4 for type 'struct reqinfo_t', which requires 8 byte alignment 0x000001889fb4: note: pointer points here 78 4f 56 e9 0d 00 00 00 00 00 00 00 81 00 00 00 00 00 00 00 75 73 65 72 3a 6d 79 72 65 61 6c 6d ^ HDAA_fmt_plug.c:519:15: runtime error: member access within misaligned address 0x000001889fb4 for type 'struct reqinfo_t', which requires 8 byte alignment 0x000001889fb4: note: pointer points here 78 4f 56 e9 0d 00 00 00 00 00 00 00 81 00 00 00 00 00 00 00 75 73 65 72 3a 6d 79 72 65 61 6c 6d Testing: hMailServer [sha256($s.$p) 256/256 AVX2 8x]... dynamic_fmt.c:2447:4: runtime error: load of misaligned address 0x000001c91e74 for type 'long unsigned int', which requires 8 byte alignment 0x000001c91e74: note: pointer points here 58 4b 56 e9 6f 4d 92 01 00 00 00 00 00 00 00 00 10 53 62 03 00 00 00 00 e0 6d 9c 01 00 00 00 00 ^ dynamic_fmt.c:1193:9: runtime error: load of misaligned address 0x000001c91e74 for type 'unsigned char *', which requires 8 byte alignment 0x000001c91e74: note: pointer points here 58 4b 56 e9 6f 4d 92 01 00 00 00 00 00 00 00 00 10 53 62 03 00 00 00 00 e0 6d 9c 01 00 00 00 00 ^ Testing: oracle11, Oracle 11g [SHA1 256/256 AVX2 8x]... oracle11_fmt_plug.c:357:5: runtime error: load of misaligned address 0x0000019c6312 for type 'uint32_t', which requires 4 byte alignment 0x0000019c6312: note: pointer points here 00 00 90 36 03 f2 c5 2e d1 b4 d6 42 00 00 00 00 00 00 00 00 00 00 00 00 00 00 c1 00 00 00 00 00 ^ oracle11_fmt_plug.c:360:5: runtime error: load of misaligned address 0x0000019c6316 for type 'uint32_t', which requires 4 byte alignment 0x0000019c6316: note: pointer points here 03 f2 c5 2e d1 b4 d6 42 00 00 00 00 00 00 00 00 00 00 00 00 00 00 c1 00 00 00 00 00 00 00 e8 4b ^ oracle11_fmt_plug.c:366:5: runtime error: load of misaligned address 0x0000019c6311 for type 'uint32_t', which requires 4 byte alignment 0x0000019c6311: note: pointer points here 00 00 00 97 63 fc f0 d5 4d a6 67 d4 e6 00 00 00 00 00 00 00 00 00 00 00 00 00 00 c1 00 00 00 00 ^ oracle11_fmt_plug.c:369:5: runtime error: load of misaligned address 0x0000019c6315 for type 'uint32_t', which requires 4 byte alignment 0x0000019c6315: note: pointer points here 63 fc f0 d5 4d a6 67 d4 e6 00 00 00 00 00 00 00 00 00 00 00 00 00 00 c1 00 00 00 00 00 00 00 e8 ^ Testing: phpass ($P$9) [phpass ($P$ or $H$) 256/256 AVX2 8x3]... (4xOMP) phpassMD5_fmt_plug.c:337:9: runtime error: load of misaligned address 0x000001bbad44 for type 'long int', which requires 8 byte alignment 0x000001bbad44: note: pointer points here 58 4b 56 e9 61 61 61 61 61 53 58 42 39 7f 00 00 12 ad 24 b8 dd 12 b7 51 b4 46 cd 94 56 4f c5 94 ^ Testing: PKZIP [32/64]... (4xOMP) formats.c:1770:23: runtime error: load of misaligned address 0x000001a8be14 for type 'struct dyna_salt_john_core *', which requires 8 byte alignment 0x000001a8be14: note: pointer points here 58 4b 56 e9 90 38 bc 01 00 00 00 00 e2 7f 00 00 0a d2 78 a5 b0 4e 41 80 7a e9 fc 35 36 37 38 00 ^ pkzip_fmt_plug.c:533:9: runtime error: load of misaligned address 0x000001a8be14 for type 'struct PKZ_SALT *', which requires 8 byte alignment 0x000001a8be14: note: pointer points here 58 4b 56 e9 90 38 bc 01 00 00 00 00 e2 7f 00 00 0a d2 78 a5 b0 4e 41 80 7a e9 fc 35 36 37 38 00 ^ dyna_salt.c:90:24: runtime error: load of misaligned address 0x000001a8be14 for type 'struct dyna_salt_john_core *', which requires 8 byte alignment 0x000001a8be14: note: pointer points here 58 4b 56 e9 90 38 bc 01 00 00 00 00 e2 7f 00 00 0a d2 78 a5 b0 4e 41 80 7a e9 fc 35 36 37 38 00 ^ dyna_salt.c:56:24: runtime error: load of misaligned address 0x000001a8be14 for type 'struct dyna_salt_john_core *', which requires 8 byte alignment 0x000001a8be14: note: pointer points here 58 4b 56 e9 90 38 bc 01 00 00 00 00 e2 7f 00 00 0a d2 78 a5 b0 4e 41 80 7a e9 fc 35 36 37 38 00 Testing: sapb, SAP CODVN B (BCODE) [MD5 256/256 AVX2 8x3]... (4xOMP) sapB_fmt_plug.c:481:36: runtime error: store to misaligned address 0x7fe2df5a9d05 for type 'unsigned int', which requires 4 byte alignment 0x7fe2df5a9d05: note: pointer points here 00 32 00 19 00 00 00 ff 2f 00 00 00 00 00 00 bc 6a 61 03 00 00 00 00 04 00 00 00 08 00 00 00 00 ^ Testing: sapg, SAP CODVN F/G (PASSCODE) [SHA1 256/256 AVX2 8x]... (4xOMP) sapG_fmt_plug.c:559:55: runtime error: load of misaligned address 0x000000a0ccea for type 'uint32_t', which requires 4 byte alignment 0x000000a0ccea: note: pointer points here ae dd 16 f2 4b 8d 2c e1 d4 dc b0 cb df 9d d4 70 6d 17 f9 4d 42 3f 9b 1b 11 94 9f 5b c1 9b 06 05 ^ Testing: saph, SAP CODVN H (PWDSALTEDHASH) (SHA1x1024) [SHA-1/SHA-2 256/256 AVX2 8x]... (4xOMP) sapH_fmt_plug.c:318:15: runtime error: store to misaligned address 0x7ffcb1d6c5f7 for type 'uint32_t', which requires 4 byte alignment 0x7ffcb1d6c5f7: note: pointer points here 30 31 32 33 8a 21 27 a4 ab 16 e8 e7 09 35 5d 20 48 37 6a eb b0 6a ed 06 80 00 00 00 00 00 00 00 ^ sapH_fmt_plug.c:390:15: runtime error: store to misaligned address 0x7ffcb1d6c626 for type 'uint32_t', which requires 4 byte alignment 0x7ffcb1d6c626: note: pointer points here 6f 62 6f 6f b2 6d 27 89 5b 9c bc e8 7b 13 2e 36 11 d7 f2 af 03 77 81 46 39 42 5b 2c 77 27 e0 bc ^ sapH_fmt_plug.c:463:15: runtime error: store to misaligned address 0x7ffcb1d6c6a6 for type 'uint64_t', which requires 8 byte alignment 0x7ffcb1d6c6a6: note: pointer points here 6f 62 6f 6f 35 01 f7 03 40 88 d4 ef 9c 89 cb 2a 37 28 60 50 db ea 7a 98 27 e4 5a 3c 23 af e7 65 ^ sapH_fmt_plug.c:535:15: runtime error: store to misaligned address 0x7ffcb1d6c6a6 for type 'uint64_t', which requires 8 byte alignment 0x7ffcb1d6c6a6: note: pointer points here 6f 62 6f 6f e6 b7 6a 34 b9 94 3d c5 17 33 da ce 35 54 23 6e d1 15 9a 7b 1b 2e e7 97 e4 91 69 06 Testing: OpenVMS, Purdy [32/64]... (4xOMP) uaf_encode.c:543:13: runtime error: member access within misaligned address 0x000002a29a54 for type 'struct uaf_hash_info', which requires 8 byte alignment 0x000002a29a54: note: pointer points here 78 4b 56 e9 64 90 61 55 0a 32 2a d1 00 00 00 00 00 00 00 00 a5 fb 03 00 8d 96 0b 7e 10 00 00 00 ^ uaf_encode.c:560:30: runtime error: member access within misaligned address 0x000002a29a54 for type 'struct uaf_hash_info', which requires 8 byte alignment 0x000002a29a54: note: pointer points here 78 4b 56 e9 64 90 61 55 0a 32 2a d1 00 00 00 00 00 00 00 00 a5 fb 03 00 8d 96 0b 7e 10 00 00 00 ^ uaf_encode.c:560:20: runtime error: member access within misaligned address 0x000002a29a54 for type 'struct uaf_hash_info', which requires 8 byte alignment 0x000002a29a54: note: pointer points here 78 4b 56 e9 64 90 61 55 0a 32 2a d1 00 00 00 00 00 00 00 00 a5 fb 03 00 8d 96 0b 7e 10 00 00 00 ^ uaf_encode.c:565:13: runtime error: member access within misaligned address 0x000002a29a54 for type 'struct uaf_hash_info', which requires 8 byte alignment 0x000002a29a54: note: pointer points here 78 4b 56 e9 64 90 61 55 0a 32 2a d1 00 00 00 00 00 00 00 00 a5 fb 03 00 8d 96 0b 7e 10 00 00 00 ^ uaf_encode.c:569:10: runtime error: member access within misaligned address 0x000002a29a54 for type 'struct uaf_hash_info', which requires 8 byte alignment 0x000002a29a54: note: pointer points here 78 4b 56 e9 64 90 61 55 0a 32 2a d1 00 00 00 00 00 00 00 00 a5 fb 03 00 8d 96 0b 7e 10 00 00 00 ```
Author
Owner

@kholia commented on GitHub (Nov 20, 2017):

Patch for OpenVMS format,

diff --git a/src/vms_fmt_plug.c b/src/vms_fmt_plug.c
index 80776ce..e1ae371 100644
--- a/src/vms_fmt_plug.c
+++ b/src/vms_fmt_plug.c
@@ -65,7 +65,7 @@ static int omp_t = 1;
 #define BINARY_SIZE                    8
 #define BINARY_ALIGN           4
 #define SALT_SIZE                      sizeof(struct uaf_hash_info)
-#define SALT_ALIGN                     4
+#define SALT_ALIGN                     sizeof(long)
 
 #define MIN_KEYS_PER_CRYPT             1
 #define MAX_KEYS_PER_CRYPT             1

This is required as the salt structure has a member with type long.

struct uaf_hash_info {
    uaf_qword hash;                     /* UAI$_PWd */
    long flags;
    ...
}
<!-- gh-comment-id:345689380 --> @kholia commented on GitHub (Nov 20, 2017): Patch for OpenVMS format, ``` diff diff --git a/src/vms_fmt_plug.c b/src/vms_fmt_plug.c index 80776ce..e1ae371 100644 --- a/src/vms_fmt_plug.c +++ b/src/vms_fmt_plug.c @@ -65,7 +65,7 @@ static int omp_t = 1; #define BINARY_SIZE 8 #define BINARY_ALIGN 4 #define SALT_SIZE sizeof(struct uaf_hash_info) -#define SALT_ALIGN 4 +#define SALT_ALIGN sizeof(long) #define MIN_KEYS_PER_CRYPT 1 #define MAX_KEYS_PER_CRYPT 1 ``` This is required as the salt structure has a member with type `long`. ``` struct uaf_hash_info { uaf_qword hash; /* UAI$_PWd */ long flags; ... } ```
Author
Owner

@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.

<!-- gh-comment-id:345690529 --> @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.
Author
Owner

@jfoug commented on GitHub (Nov 20, 2017):

Can you test to see if this patch fixes the dynamic problem?

$ git diff dynamic_fmt.c
diff --git a/src/dynamic_fmt.c b/src/dynamic_fmt.c
index 4f609e83e..98200d079 100644
--- a/src/dynamic_fmt.c
+++ b/src/dynamic_fmt.c
@@ -3186,7 +3186,7 @@ static void __SSE_append_string_to_input(unsigned char *IPB, unsigned int idx_mo
        unsigned char *cpO;
        // if our insertion point is on an 'even' DWORD, then we use DWORD * copying, as long as we can
        // This provides quite a nice speedup.
-#if ARCH_LITTLE_ENDIAN
+#if ARCH_LITTLE_ENDIAN && ARCH_ALLOWS_UNALIGNED
        // if big-endian, we gain nothing from this function (since we would have to byte swap)
        if (len>3&&(bf_ptr&3)) {
                cpO = &IPB[GETPOS(bf_ptr, idx_mod)];
<!-- gh-comment-id:345693961 --> @jfoug commented on GitHub (Nov 20, 2017): Can you test to see if this patch fixes the dynamic problem? ```diff $ git diff dynamic_fmt.c diff --git a/src/dynamic_fmt.c b/src/dynamic_fmt.c index 4f609e83e..98200d079 100644 --- a/src/dynamic_fmt.c +++ b/src/dynamic_fmt.c @@ -3186,7 +3186,7 @@ static void __SSE_append_string_to_input(unsigned char *IPB, unsigned int idx_mo unsigned char *cpO; // if our insertion point is on an 'even' DWORD, then we use DWORD * copying, as long as we can // This provides quite a nice speedup. -#if ARCH_LITTLE_ENDIAN +#if ARCH_LITTLE_ENDIAN && ARCH_ALLOWS_UNALIGNED // if big-endian, we gain nothing from this function (since we would have to byte swap) if (len>3&&(bf_ptr&3)) { cpO = &IPB[GETPOS(bf_ptr, idx_mod)]; ```
Author
Owner

@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.

<!-- gh-comment-id:345695081 --> @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.
Author
Owner

@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)

	// from cryptsha256_fmt.c
	for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) {
		uint32_t *o = (uint32_t *)crypt_struct->cptr[k][idx];
		for (j = 0; j < 8; ++j)
#if ARCH_LITTLE_ENDIAN==1
			*o++ = JOHNSWAP(sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32]);
#else
			*o++ = sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32];
#endif
	}

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!!!

<!-- gh-comment-id:345697931 --> @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) ```c // from cryptsha256_fmt.c for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) { uint32_t *o = (uint32_t *)crypt_struct->cptr[k][idx]; for (j = 0; j < 8; ++j) #if ARCH_LITTLE_ENDIAN==1 *o++ = JOHNSWAP(sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32]); #else *o++ = sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32]; #endif } ``` 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!!!
Author
Owner

@jfoug commented on GitHub (Nov 20, 2017):

here is how I plan on working around this in cryptsha256,

			{
				unsigned int j, k;
#if !ARCH_ALLOWS_UNALIGNED
				if (!is_aligned(crypt_struct->cptr[k][idx], 4)) {
					// byte by byte shit here (in both BE and LE code)
				} else {

#endif
				for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) {
					uint32_t *o = (uint32_t *)crypt_struct->cptr[k][idx];
					for (j = 0; j < 8; ++j)
#if ARCH_LITTLE_ENDIAN==1
						*o++ = JOHNSWAP(sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32]);
#else
						*o++ = sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32];
#endif
#if !ARCH_ALLOWS_UNALIGNED
				}
#endif
				}
			}

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.

<!-- gh-comment-id:345699365 --> @jfoug commented on GitHub (Nov 20, 2017): here is how I plan on working around this in cryptsha256, ```c { unsigned int j, k; #if !ARCH_ALLOWS_UNALIGNED if (!is_aligned(crypt_struct->cptr[k][idx], 4)) { // byte by byte shit here (in both BE and LE code) } else { #endif for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) { uint32_t *o = (uint32_t *)crypt_struct->cptr[k][idx]; for (j = 0; j < 8; ++j) #if ARCH_LITTLE_ENDIAN==1 *o++ = JOHNSWAP(sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32]); #else *o++ = sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32]; #endif #if !ARCH_ALLOWS_UNALIGNED } #endif } } ``` 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.
Author
Owner

@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)

$ git diff cryptsha256_fmt_plug.c
diff --git a/src/cryptsha256_fmt_plug.c b/src/cryptsha256_fmt_plug.c
index dbb303ad9..341c8709f 100644
--- a/src/cryptsha256_fmt_plug.c
+++ b/src/cryptsha256_fmt_plug.c
@@ -759,6 +759,17 @@ static int crypt_all(int *pcount, struct db_salt *salt)
                                break;
                        {
                                unsigned int j, k;
+#if !ARCH_ALLOWS_UNALIGNED
+                               if (!is_aligned(crypt_struct->cptr[k][idx], 4)) {
+                                       // byte by byte shit here (in both BE and LE code)
+                                       for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) {
+                                               unsigned char *o = crypt_struct->cptr[k][idx];
+                                               for (j = 0; j < 32; ++j)
+                                                       *o++ = ((unsigned char*)sse_outp)[GETPOS(j, k)];
+                                       }
+                               } else {
+
+#endif
                                for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) {
                                        uint32_t *o = (uint32_t *)crypt_struct->cptr[k][idx];
                                        for (j = 0; j < 8; ++j)
@@ -767,6 +778,9 @@ static int crypt_all(int *pcount, struct db_salt *salt)
 #else
                                                *o++ = sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/                                       SIMD_COEF_32*8*SIMD_COEF_32];
 #endif
+#if !ARCH_ALLOWS_UNALIGNED
+                               }
+#endif
                                }
                        }
                        if (++idx == 42)
<!-- gh-comment-id:345703478 --> @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) ```diff $ git diff cryptsha256_fmt_plug.c diff --git a/src/cryptsha256_fmt_plug.c b/src/cryptsha256_fmt_plug.c index dbb303ad9..341c8709f 100644 --- a/src/cryptsha256_fmt_plug.c +++ b/src/cryptsha256_fmt_plug.c @@ -759,6 +759,17 @@ static int crypt_all(int *pcount, struct db_salt *salt) break; { unsigned int j, k; +#if !ARCH_ALLOWS_UNALIGNED + if (!is_aligned(crypt_struct->cptr[k][idx], 4)) { + // byte by byte shit here (in both BE and LE code) + for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) { + unsigned char *o = crypt_struct->cptr[k][idx]; + for (j = 0; j < 32; ++j) + *o++ = ((unsigned char*)sse_outp)[GETPOS(j, k)]; + } + } else { + +#endif for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) { uint32_t *o = (uint32_t *)crypt_struct->cptr[k][idx]; for (j = 0; j < 8; ++j) @@ -767,6 +778,9 @@ static int crypt_all(int *pcount, struct db_salt *salt) #else *o++ = sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/ SIMD_COEF_32*8*SIMD_COEF_32]; #endif +#if !ARCH_ALLOWS_UNALIGNED + } +#endif } } if (++idx == 42) ```
Author
Owner

@kholia commented on GitHub (Nov 20, 2017):

The compiler is complaining that it does not know sse_outp and GETPOS. I did "s/sse_outp/sse_out" to solve the first problem but I don't know which version of GETPOS to use. If I use the one from dynamic_fmt.c, the format fails with FAILED (cmp_all(2)). I really don't understand this macro ;(

<!-- gh-comment-id:345708689 --> @kholia commented on GitHub (Nov 20, 2017): The compiler is complaining that it does not know `sse_outp` and `GETPOS`. I did "s/sse_outp/sse_out" to solve the first problem but I don't know which version of `GETPOS` to use. If I use the one from `dynamic_fmt.c`, the format fails with `FAILED (cmp_all(2))`. I really don't understand this macro ;(
Author
Owner

@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.

$ git diff cryptsha256_fmt_plug.c
diff --git a/src/cryptsha256_fmt_plug.c b/src/cryptsha256_fmt_plug.c
index dbb303ad9..7061d3dd2 100644
--- a/src/cryptsha256_fmt_plug.c
+++ b/src/cryptsha256_fmt_plug.c
@@ -155,6 +155,11 @@ john_register_one(&fmt_cryptsha256);
 #ifdef SIMD_COEF_32
 #define MIN_KEYS_PER_CRYPT             (SIMD_COEF_32*SIMD_PARA_SHA256)
 #define MAX_KEYS_PER_CRYPT             (SIMD_COEF_32*SIMD_PARA_SHA256)
+#if ARCH_LITTLE_ENDIAN==1
+#define GETPOS(i, index)               ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + (3-((i)&3)) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 ) //for endianity conversion
+#else
+#define GETPOS(i, index)               ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + ((i)&3) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 )
+#endif
 #else
 #define MIN_KEYS_PER_CRYPT             1
 #define MAX_KEYS_PER_CRYPT             1
@@ -759,6 +764,17 @@ static int crypt_all(int *pcount, struct db_salt *salt)
                                break;
                        {
                                unsigned int j, k;
+#if !ARCH_ALLOWS_UNALIGNED
+                               if (!is_aligned(crypt_struct->cptr[k][idx], 4)) {
+                                       // byte by byte shit here (in both BE and LE code)
+                                       for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) {
+                                               unsigned char *o = crypt_struct->cptr[k][idx];
+                                               for (j = 0; j < 32; ++j)
+                                                       *o++ = ((unsigned char*)sse_out)[GETPOS(j, k)];
+                                       }
+                               } else {
+
+#endif
                                for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) {
                                        uint32_t *o = (uint32_t *)crypt_struct->cptr[k][idx];
                                        for (j = 0; j < 8; ++j)
@@ -767,6 +783,9 @@ static int crypt_all(int *pcount, struct db_salt *salt)
 #else
                                                *o++ = sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32];
 #endif
+#if !ARCH_ALLOWS_UNALIGNED
+                               }
+#endif
                                }
                        }
                        if (++idx == 42)
<!-- gh-comment-id:345711984 --> @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. ```diff $ git diff cryptsha256_fmt_plug.c diff --git a/src/cryptsha256_fmt_plug.c b/src/cryptsha256_fmt_plug.c index dbb303ad9..7061d3dd2 100644 --- a/src/cryptsha256_fmt_plug.c +++ b/src/cryptsha256_fmt_plug.c @@ -155,6 +155,11 @@ john_register_one(&fmt_cryptsha256); #ifdef SIMD_COEF_32 #define MIN_KEYS_PER_CRYPT (SIMD_COEF_32*SIMD_PARA_SHA256) #define MAX_KEYS_PER_CRYPT (SIMD_COEF_32*SIMD_PARA_SHA256) +#if ARCH_LITTLE_ENDIAN==1 +#define GETPOS(i, index) ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + (3-((i)&3)) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 ) //for endianity conversion +#else +#define GETPOS(i, index) ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + ((i)&3) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 ) +#endif #else #define MIN_KEYS_PER_CRYPT 1 #define MAX_KEYS_PER_CRYPT 1 @@ -759,6 +764,17 @@ static int crypt_all(int *pcount, struct db_salt *salt) break; { unsigned int j, k; +#if !ARCH_ALLOWS_UNALIGNED + if (!is_aligned(crypt_struct->cptr[k][idx], 4)) { + // byte by byte shit here (in both BE and LE code) + for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) { + unsigned char *o = crypt_struct->cptr[k][idx]; + for (j = 0; j < 32; ++j) + *o++ = ((unsigned char*)sse_out)[GETPOS(j, k)]; + } + } else { + +#endif for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) { uint32_t *o = (uint32_t *)crypt_struct->cptr[k][idx]; for (j = 0; j < 8; ++j) @@ -767,6 +783,9 @@ static int crypt_all(int *pcount, struct db_salt *salt) #else *o++ = sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32]; #endif +#if !ARCH_ALLOWS_UNALIGNED + } +#endif } } if (++idx == 42) ```
Author
Owner

@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.

<!-- gh-comment-id:345716193 --> @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.
Author
Owner

@kholia commented on GitHub (Nov 20, 2017):

Alignment patch for ethereum format,

diff --git a/src/ethereum_common.h b/src/ethereum_common.h
index aedaa77..8a9fbc9 100644
--- a/src/ethereum_common.h
+++ b/src/ethereum_common.h
@@ -12,12 +12,12 @@
 #define BINARY_SIZE             16
 
 typedef struct {
+	uint8_t ct[256];
 	uint32_t type;
 	int N, r, p;
 	int iterations;
 	uint8_t salt[64];
 	int saltlen;
-	uint8_t ct[256];
 	int ctlen;
 	// following fields are only required for handling presale wallets
 	uint8_t encseed[2048];
diff --git a/src/ethereum_fmt_plug.c b/src/ethereum_fmt_plug.c
index afc8be0..2ab5924 100644
--- a/src/ethereum_fmt_plug.c
+++ b/src/ethereum_fmt_plug.c
@@ -50,7 +50,7 @@ john_register_one(&fmt_ethereum);
 #define PLAINTEXT_LENGTH        125
 #define SALT_SIZE               sizeof(*cur_salt)
 #define BINARY_ALIGN            sizeof(uint32_t)
-#define SALT_ALIGN              sizeof(int)
+#define SALT_ALIGN              sizeof(uint64_t)
 #ifdef SIMD_COEF_64
 #define MIN_KEYS_PER_CRYPT      SSE_GROUP_SZ_SHA256
 #define MAX_KEYS_PER_CRYPT      SSE_GROUP_SZ_SHA256
@@ -62,7 +62,12 @@ john_register_one(&fmt_ethereum);
 static char (*saved_key)[PLAINTEXT_LENGTH + 1];
 static uint32_t (*crypt_out)[BINARY_SIZE * 2 / sizeof(uint32_t)];
 
-custom_salt  *cur_salt;
+static custom_salt *cur_salt;
+
+static union {
+	uint64_t dummy;
+	unsigned char dpad[8];
+} pad;
 
 static void init(struct fmt_main *self)
 {
@@ -75,6 +80,8 @@ static void init(struct fmt_main *self)
 #endif
 	saved_key = mem_calloc(sizeof(*saved_key), self->params.max_keys_per_crypt);
 	crypt_out = mem_calloc(sizeof(*crypt_out), self->params.max_keys_per_crypt);
+
+	memcpy(pad.dpad, "\x02\x00\x00\x00\x00\x00\x00\x00", 8);
 }
 
 static void done(void)
@@ -98,8 +105,6 @@ static char *get_key(int index)
 	return saved_key[index];
 }
 
-static unsigned char *dpad = (unsigned char*)"\x02\x00\x00\x00\x00\x00\x00\x00";
-
 static int crypt_all(int *pcount, struct db_salt *salt)
 {
 	const int count = *pcount;
@@ -179,7 +184,7 @@ static int crypt_all(int *pcount, struct db_salt *salt)
 				}
 				Keccak_HashInitialize(&hash, 1088, 512, 256, 0x01);
 				Keccak_HashUpdate(&hash, seed, datalen * 8);
-				Keccak_HashUpdate(&hash, dpad, 1 * 8);
+				Keccak_HashUpdate(&hash, pad.dpad, 1 * 8);
 				Keccak_HashFinal(&hash, (unsigned char*)crypt_out[index+i]);
 			}
 		}

It is not pretty. Do you have a more cleaner looking patch @jfoug?

The cur_salt->ct is accessed via a uint64_t pointer by the Keccak code internally.

<!-- gh-comment-id:345718831 --> @kholia commented on GitHub (Nov 20, 2017): Alignment patch for `ethereum` format, ``` diff diff --git a/src/ethereum_common.h b/src/ethereum_common.h index aedaa77..8a9fbc9 100644 --- a/src/ethereum_common.h +++ b/src/ethereum_common.h @@ -12,12 +12,12 @@ #define BINARY_SIZE 16 typedef struct { + uint8_t ct[256]; uint32_t type; int N, r, p; int iterations; uint8_t salt[64]; int saltlen; - uint8_t ct[256]; int ctlen; // following fields are only required for handling presale wallets uint8_t encseed[2048]; diff --git a/src/ethereum_fmt_plug.c b/src/ethereum_fmt_plug.c index afc8be0..2ab5924 100644 --- a/src/ethereum_fmt_plug.c +++ b/src/ethereum_fmt_plug.c @@ -50,7 +50,7 @@ john_register_one(&fmt_ethereum); #define PLAINTEXT_LENGTH 125 #define SALT_SIZE sizeof(*cur_salt) #define BINARY_ALIGN sizeof(uint32_t) -#define SALT_ALIGN sizeof(int) +#define SALT_ALIGN sizeof(uint64_t) #ifdef SIMD_COEF_64 #define MIN_KEYS_PER_CRYPT SSE_GROUP_SZ_SHA256 #define MAX_KEYS_PER_CRYPT SSE_GROUP_SZ_SHA256 @@ -62,7 +62,12 @@ john_register_one(&fmt_ethereum); static char (*saved_key)[PLAINTEXT_LENGTH + 1]; static uint32_t (*crypt_out)[BINARY_SIZE * 2 / sizeof(uint32_t)]; -custom_salt *cur_salt; +static custom_salt *cur_salt; + +static union { + uint64_t dummy; + unsigned char dpad[8]; +} pad; static void init(struct fmt_main *self) { @@ -75,6 +80,8 @@ static void init(struct fmt_main *self) #endif saved_key = mem_calloc(sizeof(*saved_key), self->params.max_keys_per_crypt); crypt_out = mem_calloc(sizeof(*crypt_out), self->params.max_keys_per_crypt); + + memcpy(pad.dpad, "\x02\x00\x00\x00\x00\x00\x00\x00", 8); } static void done(void) @@ -98,8 +105,6 @@ static char *get_key(int index) return saved_key[index]; } -static unsigned char *dpad = (unsigned char*)"\x02\x00\x00\x00\x00\x00\x00\x00"; - static int crypt_all(int *pcount, struct db_salt *salt) { const int count = *pcount; @@ -179,7 +184,7 @@ static int crypt_all(int *pcount, struct db_salt *salt) } Keccak_HashInitialize(&hash, 1088, 512, 256, 0x01); Keccak_HashUpdate(&hash, seed, datalen * 8); - Keccak_HashUpdate(&hash, dpad, 1 * 8); + Keccak_HashUpdate(&hash, pad.dpad, 1 * 8); Keccak_HashFinal(&hash, (unsigned char*)crypt_out[index+i]); } } ``` It is not pretty. Do you have a more cleaner looking patch @jfoug? The `cur_salt->ct` is accessed via a uint64_t pointer by the Keccak code internally.
Author
Owner

@kholia commented on GitHub (Nov 20, 2017):

Regarding the sha256crypt patch. The code compiles, and the format works. However, the alignment error remains.

Benchmarking: sha256crypt, crypt(3) $5$ (rounds=5000) [SHA256 256/256 AVX2 8x]... (4xOMP) cryptsha256_fmt_plug.c:781:12: runtime error: store to misaligned address 0x7fffbec09a8e for type 'uint32_t', which requires 4 byte alignment
0x7fffbec09a8e: note: pointer points here
 1d d0 a3 45 2e e2  83 72 b0 e9 0a 4a b9 78  6d 3d 91 15 6e 0a ef 62  24 4d 48 07 74 1f 68 59  89 4e

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.

<!-- gh-comment-id:345722554 --> @kholia commented on GitHub (Nov 20, 2017): Regarding the `sha256crypt` patch. The code compiles, and the format works. However, the alignment error remains. ``` Benchmarking: sha256crypt, crypt(3) $5$ (rounds=5000) [SHA256 256/256 AVX2 8x]... (4xOMP) cryptsha256_fmt_plug.c:781:12: runtime error: store to misaligned address 0x7fffbec09a8e for type 'uint32_t', which requires 4 byte alignment 0x7fffbec09a8e: note: pointer points here 1d d0 a3 45 2e e2 83 72 b0 e9 0a 4a b9 78 6d 3d 91 15 6e 0a ef 62 24 4d 48 07 74 1f 68 59 89 4e ``` 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.
Author
Owner

@kholia commented on GitHub (Nov 20, 2017):

Quick note,

The dynamic_370 is exhibiting alignment problems on Raspberry Pi 2 with the Clang UBSan build. This format uses Keccak code which expects data be uint64_t aligned. The same format works fine (without any alignment problems) on standard AMD64 Linux builds.

<!-- gh-comment-id:345726104 --> @kholia commented on GitHub (Nov 20, 2017): Quick note, The `dynamic_370` is exhibiting alignment problems on Raspberry Pi 2 with the Clang UBSan build. This format uses Keccak code which expects data be `uint64_t` aligned. The same format works fine (without any alignment problems) on standard AMD64 Linux builds.
Author
Owner

@frank-dittrich commented on GitHub (Nov 20, 2017):

@jfoug

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).

What if you change the typedef struct cryptloopstruct_t definition so that unsigned char buf[8*2*64*BLKS] (currently the first component) becomes the last component?

<!-- gh-comment-id:345734864 --> @frank-dittrich commented on GitHub (Nov 20, 2017): @jfoug > 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). What if you change the `typedef struct cryptloopstruct_t` definition so that `unsigned char buf[8*2*64*BLKS]` (currently the first component) becomes the last component?
Author
Owner

@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)) {

<!-- gh-comment-id:345738190 --> @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)) {
Author
Owner

@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.

<!-- gh-comment-id:345739474 --> @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.
Author
Owner

@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.

  1. SIMD code will only be run under LE machines
  2. SIMD code will work find on REQUIRES_ALIGNMENT false.

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 .... #endif blocks. 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.

<!-- gh-comment-id:345741533 --> @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. 1. SIMD code will only be run under LE machines 2. SIMD code will work find on REQUIRES_ALIGNMENT false. 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 .... #endif``` blocks. 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.
Author
Owner

@kholia commented on GitHub (Nov 20, 2017):

No luck with that patch @jfoug :-(

diff --git a/src/cryptsha256_fmt_plug.c b/src/cryptsha256_fmt_plug.c
index dbb303a..e32075b 100644
--- a/src/cryptsha256_fmt_plug.c
+++ b/src/cryptsha256_fmt_plug.c
@@ -155,6 +155,11 @@ john_register_one(&fmt_cryptsha256);
 #ifdef SIMD_COEF_32
 #define MIN_KEYS_PER_CRYPT             (SIMD_COEF_32*SIMD_PARA_SHA256)
 #define MAX_KEYS_PER_CRYPT             (SIMD_COEF_32*SIMD_PARA_SHA256)
+#if ARCH_LITTLE_ENDIAN==1
+#define GETPOS(i, index)               ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + (3-((i)&3)) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 ) //for endianity conversion
+#else
+#define GETPOS(i, index)               ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + ((i)&3) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 )
+#endif
 #else
 #define MIN_KEYS_PER_CRYPT             1
 #define MAX_KEYS_PER_CRYPT             1
@@ -758,7 +763,17 @@ static int crypt_all(int *pcount, struct db_salt *salt)
                        if (cnt == cur_salt->rounds)
                                break;
                        {
-                               unsigned int j, k;
+                               unsigned int j, k = 0;
+#if !ARCH_ALLOWS_UNALIGNED
+                               if (!is_aligned(crypt_struct->cptr[0][idx], 4)) {
+                                       // byte by byte shit here (in both BE and LE code)
+                                       for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) {
+                                               unsigned char *o = crypt_struct->cptr[k][idx];
+                                               for (j = 0; j < 32; ++j)
+                                                       *o++ = ((unsigned char*)sse_out)[GETPOS(j, k)];
+                                       }
+                               } else {
+#endif
                                for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) {
                                        uint32_t *o = (uint32_t *)crypt_struct->cptr[k][idx];
                                        for (j = 0; j < 8; ++j)
@@ -767,6 +782,9 @@ static int crypt_all(int *pcount, struct db_salt *salt)
 #else
                                                *o++ = sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32];
 #endif
+#if !ARCH_ALLOWS_UNALIGNED
+                               }
+#endif
                                }
                        }
                        if (++idx == 42)

This is the complete patch I am testing.

Maybe we can move to other targets, and come back to this one later :-)

<!-- gh-comment-id:345742685 --> @kholia commented on GitHub (Nov 20, 2017): No luck with that patch @jfoug :-( ``` diff diff --git a/src/cryptsha256_fmt_plug.c b/src/cryptsha256_fmt_plug.c index dbb303a..e32075b 100644 --- a/src/cryptsha256_fmt_plug.c +++ b/src/cryptsha256_fmt_plug.c @@ -155,6 +155,11 @@ john_register_one(&fmt_cryptsha256); #ifdef SIMD_COEF_32 #define MIN_KEYS_PER_CRYPT (SIMD_COEF_32*SIMD_PARA_SHA256) #define MAX_KEYS_PER_CRYPT (SIMD_COEF_32*SIMD_PARA_SHA256) +#if ARCH_LITTLE_ENDIAN==1 +#define GETPOS(i, index) ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + (3-((i)&3)) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 ) //for endianity conversion +#else +#define GETPOS(i, index) ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + ((i)&3) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 ) +#endif #else #define MIN_KEYS_PER_CRYPT 1 #define MAX_KEYS_PER_CRYPT 1 @@ -758,7 +763,17 @@ static int crypt_all(int *pcount, struct db_salt *salt) if (cnt == cur_salt->rounds) break; { - unsigned int j, k; + unsigned int j, k = 0; +#if !ARCH_ALLOWS_UNALIGNED + if (!is_aligned(crypt_struct->cptr[0][idx], 4)) { + // byte by byte shit here (in both BE and LE code) + for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) { + unsigned char *o = crypt_struct->cptr[k][idx]; + for (j = 0; j < 32; ++j) + *o++ = ((unsigned char*)sse_out)[GETPOS(j, k)]; + } + } else { +#endif for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) { uint32_t *o = (uint32_t *)crypt_struct->cptr[k][idx]; for (j = 0; j < 8; ++j) @@ -767,6 +782,9 @@ static int crypt_all(int *pcount, struct db_salt *salt) #else *o++ = sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32]; #endif +#if !ARCH_ALLOWS_UNALIGNED + } +#endif } } if (++idx == 42) ``` This is the complete patch I am testing. Maybe we can move to other targets, and come back to this one later :-)
Author
Owner

@kholia commented on GitHub (Nov 20, 2017):

I will be going offline pretty soon. Happy bug hunting. See you guys tomorrow! :)

<!-- gh-comment-id:345749141 --> @kholia commented on GitHub (Nov 20, 2017): I will be going offline pretty soon. Happy bug hunting. See you guys tomorrow! :)
Author
Owner

@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....

<!-- gh-comment-id:345751299 --> @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....
Author
Owner

@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.

<!-- gh-comment-id:345751527 --> @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.
Author
Owner

@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.

<!-- gh-comment-id:345752305 --> @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.
Author
Owner

@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.

diff --git a/src/cryptsha256_fmt_plug.c b/src/cryptsha256_fmt_plug.c
index dbb303ad9..34c8cead9 100644
--- a/src/cryptsha256_fmt_plug.c
+++ b/src/cryptsha256_fmt_plug.c
@@ -155,6 +155,11 @@ john_register_one(&fmt_cryptsha256);
 #ifdef SIMD_COEF_32
 #define MIN_KEYS_PER_CRYPT             (SIMD_COEF_32*SIMD_PARA_SHA256)
 #define MAX_KEYS_PER_CRYPT             (SIMD_COEF_32*SIMD_PARA_SHA256)
+#if ARCH_LITTLE_ENDIAN==1
+#define GETPOS(i, index)               ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + (3-((i)&3)) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 ) //for endianity conversion
+#else
+#define GETPOS(i, index)               ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + ((i)&3) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 )
+#endif
 #else
 #define MIN_KEYS_PER_CRYPT             1
 #define MAX_KEYS_PER_CRYPT             1
@@ -759,14 +764,33 @@ static int crypt_all(int *pcount, struct db_salt *salt)
                                break;
                        {
                                unsigned int j, k;
+                               int aligned = is_aligned(crypt_struct->cptr[0][idx], 4);
+#if !ARCH_ALLOWS_UNALIGNED
+                               if (!is_aligned(crypt_struct->cptr[0][idx], 4)) {
+                                       // byte by byte shit here (in both BE and LE code)
+                                       for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) {
+                                               unsigned char *o = crypt_struct->cptr[k][idx];
+                                               for (j = 0; j < 32; ++j)
+                                                       *o++ = ((unsigned char*)sse_out)[GETPOS(j, k)];
+                                       }
+                               } else {
+
+#endif
                                for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) {
                                        uint32_t *o = (uint32_t *)crypt_struct->cptr[k][idx];
+                                       if (aligned && !is_aligned(o, 4)) {
+                                               printf("BOOM\n");
+                                               exit(0);
+                                   }
                                        for (j = 0; j < 8; ++j)
 #if ARCH_LITTLE_ENDIAN==1
                                                *o++ = JOHNSWAP(sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32]);
 #else
                                                *o++ = sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32];
 #endif
+#if !ARCH_ALLOWS_UNALIGNED
+                               }
+#endif
                                }
                        }
                        if (++idx == 42)
<!-- gh-comment-id:345753174 --> @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. ```diff diff --git a/src/cryptsha256_fmt_plug.c b/src/cryptsha256_fmt_plug.c index dbb303ad9..34c8cead9 100644 --- a/src/cryptsha256_fmt_plug.c +++ b/src/cryptsha256_fmt_plug.c @@ -155,6 +155,11 @@ john_register_one(&fmt_cryptsha256); #ifdef SIMD_COEF_32 #define MIN_KEYS_PER_CRYPT (SIMD_COEF_32*SIMD_PARA_SHA256) #define MAX_KEYS_PER_CRYPT (SIMD_COEF_32*SIMD_PARA_SHA256) +#if ARCH_LITTLE_ENDIAN==1 +#define GETPOS(i, index) ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + (3-((i)&3)) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 ) //for endianity conversion +#else +#define GETPOS(i, index) ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + ((i)&3) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 ) +#endif #else #define MIN_KEYS_PER_CRYPT 1 #define MAX_KEYS_PER_CRYPT 1 @@ -759,14 +764,33 @@ static int crypt_all(int *pcount, struct db_salt *salt) break; { unsigned int j, k; + int aligned = is_aligned(crypt_struct->cptr[0][idx], 4); +#if !ARCH_ALLOWS_UNALIGNED + if (!is_aligned(crypt_struct->cptr[0][idx], 4)) { + // byte by byte shit here (in both BE and LE code) + for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) { + unsigned char *o = crypt_struct->cptr[k][idx]; + for (j = 0; j < 32; ++j) + *o++ = ((unsigned char*)sse_out)[GETPOS(j, k)]; + } + } else { + +#endif for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) { uint32_t *o = (uint32_t *)crypt_struct->cptr[k][idx]; + if (aligned && !is_aligned(o, 4)) { + printf("BOOM\n"); + exit(0); + } for (j = 0; j < 8; ++j) #if ARCH_LITTLE_ENDIAN==1 *o++ = JOHNSWAP(sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32]); #else *o++ = sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32]; #endif +#if !ARCH_ALLOWS_UNALIGNED + } +#endif } } if (++idx == 42) ```
Author
Owner

@kholia commented on GitHub (Nov 20, 2017):

Yes, BOOM is hit.

$ ../run/john --format=sha256crypt --test
Will run 4 OpenMP threads
NOTE: This is a debug build, speed will be lower than normal
Benchmarking: sha256crypt, crypt(3) $5$ (rounds=5000) [SHA256 256/256 AVX2 8x]... (4xOMP) BOOM
<!-- gh-comment-id:345755059 --> @kholia commented on GitHub (Nov 20, 2017): Yes, `BOOM` is hit. ``` $ ../run/john --format=sha256crypt --test Will run 4 OpenMP threads NOTE: This is a debug build, speed will be lower than normal Benchmarking: sha256crypt, crypt(3) $5$ (rounds=5000) [SHA256 256/256 AVX2 8x]... (4xOMP) BOOM ```
Author
Owner

@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.

$ git diff cryptsha256_fmt_plug.c
diff --git a/src/cryptsha256_fmt_plug.c b/src/cryptsha256_fmt_plug.c
index dbb303ad9..898fe9151 100644
--- a/src/cryptsha256_fmt_plug.c
+++ b/src/cryptsha256_fmt_plug.c
@@ -155,6 +155,11 @@ john_register_one(&fmt_cryptsha256);
 #ifdef SIMD_COEF_32
 #define MIN_KEYS_PER_CRYPT             (SIMD_COEF_32*SIMD_PARA_SHA256)
 #define MAX_KEYS_PER_CRYPT             (SIMD_COEF_32*SIMD_PARA_SHA256)
+#if ARCH_LITTLE_ENDIAN==1
+#define GETPOS(i, index)               ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + (3-((i)&3)) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 ) //for endianity conversion
+#else
+#define GETPOS(i, index)               ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + ((i)&3) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 )
+#endif
 #else
 #define MIN_KEYS_PER_CRYPT             1
 #define MAX_KEYS_PER_CRYPT             1
@@ -761,6 +766,12 @@ static int crypt_all(int *pcount, struct db_salt *salt)
                                unsigned int j, k;
                                for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) {
                                        uint32_t *o = (uint32_t *)crypt_struct->cptr[k][idx];
+#if !ARCH_ALLOWS_UNALIGNED
+                                       if (!is_aligned(o, 4))
+                                               for (j = 0; j < 32; ++j)
+                                                       *o++ = ((unsigned char*)sse_out)[GETPOS(j, k)];
+                                       else
+#endif
                                        for (j = 0; j < 8; ++j)
 #if ARCH_LITTLE_ENDIAN==1
                                                *o++ = JOHNSWAP(sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32]);
<!-- gh-comment-id:345762221 --> @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. ```diff $ git diff cryptsha256_fmt_plug.c diff --git a/src/cryptsha256_fmt_plug.c b/src/cryptsha256_fmt_plug.c index dbb303ad9..898fe9151 100644 --- a/src/cryptsha256_fmt_plug.c +++ b/src/cryptsha256_fmt_plug.c @@ -155,6 +155,11 @@ john_register_one(&fmt_cryptsha256); #ifdef SIMD_COEF_32 #define MIN_KEYS_PER_CRYPT (SIMD_COEF_32*SIMD_PARA_SHA256) #define MAX_KEYS_PER_CRYPT (SIMD_COEF_32*SIMD_PARA_SHA256) +#if ARCH_LITTLE_ENDIAN==1 +#define GETPOS(i, index) ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + (3-((i)&3)) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 ) //for endianity conversion +#else +#define GETPOS(i, index) ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + ((i)&3) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 ) +#endif #else #define MIN_KEYS_PER_CRYPT 1 #define MAX_KEYS_PER_CRYPT 1 @@ -761,6 +766,12 @@ static int crypt_all(int *pcount, struct db_salt *salt) unsigned int j, k; for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) { uint32_t *o = (uint32_t *)crypt_struct->cptr[k][idx]; +#if !ARCH_ALLOWS_UNALIGNED + if (!is_aligned(o, 4)) + for (j = 0; j < 32; ++j) + *o++ = ((unsigned char*)sse_out)[GETPOS(j, k)]; + else +#endif for (j = 0; j < 8; ++j) #if ARCH_LITTLE_ENDIAN==1 *o++ = JOHNSWAP(sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32]); ```
Author
Owner

@jfoug commented on GitHub (Nov 20, 2017):

DO NOT TRY that one. I already see a bug!!

<!-- gh-comment-id:345762376 --> @jfoug commented on GitHub (Nov 20, 2017): DO NOT TRY that one. I already see a bug!!
Author
Owner

@jfoug commented on GitHub (Nov 20, 2017):

Ok, this should do it (I hope)

$ git diff cryptsha256_fmt_plug.c
diff --git a/src/cryptsha256_fmt_plug.c b/src/cryptsha256_fmt_plug.c
index dbb303ad9..1bb3a644d 100644
--- a/src/cryptsha256_fmt_plug.c
+++ b/src/cryptsha256_fmt_plug.c
@@ -155,6 +155,11 @@ john_register_one(&fmt_cryptsha256);
 #ifdef SIMD_COEF_32
 #define MIN_KEYS_PER_CRYPT             (SIMD_COEF_32*SIMD_PARA_SHA256)
 #define MAX_KEYS_PER_CRYPT             (SIMD_COEF_32*SIMD_PARA_SHA256)
+#if ARCH_LITTLE_ENDIAN==1
+#define GETPOS(i, index)               ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + (3-((i)&3)) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 ) //for endianity conversion
+#else
+#define GETPOS(i, index)               ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + ((i)&3) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 )
+#endif
 #else
 #define MIN_KEYS_PER_CRYPT             1
 #define MAX_KEYS_PER_CRYPT             1
@@ -761,6 +766,13 @@ static int crypt_all(int *pcount, struct db_salt *salt)
                                unsigned int j, k;
                                for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) {
                                        uint32_t *o = (uint32_t *)crypt_struct->cptr[k][idx];
+#if !ARCH_ALLOWS_UNALIGNED
+                                       if (!is_aligned(o, 4)) {
+                                               unsigned char *cp = (unsigned char*)o;
+                                               for (j = 0; j < 32; ++j)
+                                                       *cp++ = ((unsigned char*)sse_out)[GETPOS(j, k)];
+                                       } else
+#endif
                                        for (j = 0; j < 8; ++j)
 #if ARCH_LITTLE_ENDIAN==1
                                                *o++ = JOHNSWAP(sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32]);
<!-- gh-comment-id:345762767 --> @jfoug commented on GitHub (Nov 20, 2017): Ok, this should do it (I hope) ```diff $ git diff cryptsha256_fmt_plug.c diff --git a/src/cryptsha256_fmt_plug.c b/src/cryptsha256_fmt_plug.c index dbb303ad9..1bb3a644d 100644 --- a/src/cryptsha256_fmt_plug.c +++ b/src/cryptsha256_fmt_plug.c @@ -155,6 +155,11 @@ john_register_one(&fmt_cryptsha256); #ifdef SIMD_COEF_32 #define MIN_KEYS_PER_CRYPT (SIMD_COEF_32*SIMD_PARA_SHA256) #define MAX_KEYS_PER_CRYPT (SIMD_COEF_32*SIMD_PARA_SHA256) +#if ARCH_LITTLE_ENDIAN==1 +#define GETPOS(i, index) ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + (3-((i)&3)) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 ) //for endianity conversion +#else +#define GETPOS(i, index) ( (index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + ((i)&3) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*4*SIMD_COEF_32 ) +#endif #else #define MIN_KEYS_PER_CRYPT 1 #define MAX_KEYS_PER_CRYPT 1 @@ -761,6 +766,13 @@ static int crypt_all(int *pcount, struct db_salt *salt) unsigned int j, k; for (k = 0; k < MAX_KEYS_PER_CRYPT; ++k) { uint32_t *o = (uint32_t *)crypt_struct->cptr[k][idx]; +#if !ARCH_ALLOWS_UNALIGNED + if (!is_aligned(o, 4)) { + unsigned char *cp = (unsigned char*)o; + for (j = 0; j < 32; ++j) + *cp++ = ((unsigned char*)sse_out)[GETPOS(j, k)]; + } else +#endif for (j = 0; j < 8; ++j) #if ARCH_LITTLE_ENDIAN==1 *o++ = JOHNSWAP(sse_out[(j*SIMD_COEF_32)+(k&(SIMD_COEF_32-1))+k/SIMD_COEF_32*8*SIMD_COEF_32]); ```
Author
Owner

@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

<!-- gh-comment-id:345763687 --> @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
Author
Owner

@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. :)

<!-- gh-comment-id:345825934 --> @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. :)
Author
Owner

@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

sph_types.h:1625:9: runtime error: load of misaligned address 0x000002cbaa5a for type 'const sph_u32', which requires 4 byte alignment
0x000002cbaa5a: note: pointer points here
 35 36  37 38 39 30 31 32 33 34  35 36 37 38 39 30 31 32  33 34 35 36 37 38 39 30  31 32 33 34 35 36
              ^ 
<!-- gh-comment-id:345832209 --> @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 ``` sph_types.h:1625:9: runtime error: load of misaligned address 0x000002cbaa5a for type 'const sph_u32', which requires 4 byte alignment 0x000002cbaa5a: note: pointer points here 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 ^ ```
Author
Owner

@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.

<!-- gh-comment-id:345885343 --> @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.
Author
Owner

@kholia commented on GitHub (Nov 21, 2017):

Cool. Your latest sha256crypt patch works great. I have opened a PR in your name with that patch.

<!-- gh-comment-id:345918543 --> @kholia commented on GitHub (Nov 21, 2017): Cool. Your latest `sha256crypt` patch works great. I have opened a PR in your name with that patch.
Author
Owner

@kholia commented on GitHub (Nov 21, 2017):

@jfoug It seems that sha512crypt can be fixed very similarly to the sha256crypt format. I just need the proper GETPOS macros for sha512crypt format.

<!-- gh-comment-id:345935375 --> @kholia commented on GitHub (Nov 21, 2017): @jfoug It seems that `sha512crypt` can be fixed very similarly to the `sha256crypt` format. I just need the proper `GETPOS` macros for `sha512crypt` format.
Author
Owner

@kholia commented on GitHub (Nov 21, 2017):

Quick note,

I am also interested in testing the various hash extraction utilities for alignment correctness.

<!-- gh-comment-id:345938843 --> @kholia commented on GitHub (Nov 21, 2017): Quick note, I am also interested in testing the various hash extraction utilities for alignment correctness.
Author
Owner

@kholia commented on GitHub (Nov 21, 2017):

Here is a patch for the panama format,

diff --git a/src/panama_fmt_plug.c b/src/panama_fmt_plug.c
index 8533cd4..6e9f8ba 100644
--- a/src/panama_fmt_plug.c
+++ b/src/panama_fmt_plug.c
@@ -155,11 +155,24 @@ static int crypt_all(int *pcount, struct db_salt *salt)
 #endif
        {
                sph_panama_context ctx;
+               int plen = strlen(saved_key[index]);
+#if !ARCH_ALLOWS_UNALIGNED
+               union {
+                       uint32_t dummy;
+                       char password[PLAINTEXT_LENGTH + 1];
+               } data;
 
+               memcpy(data.password, saved_key[index], strlen(saved_key[index]));
+#endif
                sph_panama_init(&ctx);
-               sph_panama(&ctx, saved_key[index], strlen(saved_key[index]));
+#if !ARCH_ALLOWS_UNALIGNED
+               sph_panama(&ctx, data.password, plen);
+#else
+               sph_panama(&ctx, saved_key[index], plen);
+#endif
                sph_panama_close(&ctx, (unsigned char*)crypt_out[index]);
        }
+
        return count;
 }

It is not pretty but gets the job done.

<!-- gh-comment-id:345944626 --> @kholia commented on GitHub (Nov 21, 2017): Here is a patch for the `panama` format, ``` diff diff --git a/src/panama_fmt_plug.c b/src/panama_fmt_plug.c index 8533cd4..6e9f8ba 100644 --- a/src/panama_fmt_plug.c +++ b/src/panama_fmt_plug.c @@ -155,11 +155,24 @@ static int crypt_all(int *pcount, struct db_salt *salt) #endif { sph_panama_context ctx; + int plen = strlen(saved_key[index]); +#if !ARCH_ALLOWS_UNALIGNED + union { + uint32_t dummy; + char password[PLAINTEXT_LENGTH + 1]; + } data; + memcpy(data.password, saved_key[index], strlen(saved_key[index])); +#endif sph_panama_init(&ctx); - sph_panama(&ctx, saved_key[index], strlen(saved_key[index])); +#if !ARCH_ALLOWS_UNALIGNED + sph_panama(&ctx, data.password, plen); +#else + sph_panama(&ctx, saved_key[index], plen); +#endif sph_panama_close(&ctx, (unsigned char*)crypt_out[index]); } + return count; } ``` It is not pretty but gets the job done.
Author
Owner

@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.

<!-- gh-comment-id:345989695 --> @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.
Author
Owner

@jfoug commented on GitHub (Nov 21, 2017):

These are all that are left:

Oracle11
SAPB
SAPH

oracle11_fmt_plug.c:357:5: runtime error: load of misaligned address 0x0000019c6312 for type 'uint32_t', which requires 4 byte alignment
0x0000019c6312: note: pointer points here
 00 00  90 36 03 f2 c5 2e d1 b4  d6 42 00 00 00 00 00 00  00 00 00 00 00 00 00 00  c1 00 00 00 00 00
              ^ 
oracle11_fmt_plug.c:360:5: runtime error: load of misaligned address 0x0000019c6316 for type 'uint32_t', which requires 4 byte alignment
0x0000019c6316: note: pointer points here
 03 f2 c5 2e d1 b4  d6 42 00 00 00 00 00 00  00 00 00 00 00 00 00 00  c1 00 00 00 00 00 00 00  e8 4b
             ^ 
oracle11_fmt_plug.c:366:5: runtime error: load of misaligned address 0x0000019c6311 for type 'uint32_t', which requires 4 byte alignment
0x0000019c6311: note: pointer points here
 00 00 00  97 63 fc f0 d5 4d a6 67  d4 e6 00 00 00 00 00 00  00 00 00 00 00 00 00 00  c1 00 00 00 00
              ^ 
oracle11_fmt_plug.c:369:5: runtime error: load of misaligned address 0x0000019c6315 for type 'uint32_t', which requires 4 byte alignment
0x0000019c6315: note: pointer points here
 63 fc f0 d5 4d a6 67  d4 e6 00 00 00 00 00 00  00 00 00 00 00 00 00 00  c1 00 00 00 00 00 00 00  e8
             ^

  
Testing: sapb, SAP CODVN B (BCODE) [MD5 256/256 AVX2 8x3]... (4xOMP)
sapB_fmt_plug.c:481:36: runtime error: store to misaligned address 0x7fe2df5a9d05 for type 'unsigned int', which requires 4 byte alignment
0x7fe2df5a9d05: note: pointer points here
 00 32 00 19 00 00 00  ff 2f 00 00 00 00 00 00  bc 6a 61 03 00 00 00 00  04 00 00 00 08 00 00 00  00
             ^ 

			 
Testing: sapg, SAP CODVN F/G (PASSCODE) [SHA1 256/256 AVX2 8x]... (4xOMP)
sapG_fmt_plug.c:559:55: runtime error: load of misaligned address 0x000000a0ccea for type 'uint32_t', which requires 4 byte alignment
0x000000a0ccea: note: pointer points here
 ae dd  16 f2 4b 8d 2c e1 d4 dc  b0 cb df 9d d4 70 6d 17  f9 4d 42 3f 9b 1b 11 94  9f 5b c1 9b 06 05
              ^ 

			  
Testing: saph, SAP CODVN H (PWDSALTEDHASH) (SHA1x1024) [SHA-1/SHA-2 256/256 AVX2 8x]... (4xOMP) 
sapH_fmt_plug.c:318:15: runtime error: store to misaligned address 0x7ffcb1d6c5f7 for type 'uint32_t', which requires 4 byte alignment
0x7ffcb1d6c5f7: note: pointer points here
 30 31 32 33 8a  21 27 a4 ab 16 e8 e7 09  35 5d 20 48 37 6a eb b0  6a ed 06 80 00 00 00 00  00 00 00
             ^ 
sapH_fmt_plug.c:390:15: runtime error: store to misaligned address 0x7ffcb1d6c626 for type 'uint32_t', which requires 4 byte alignment
0x7ffcb1d6c626: note: pointer points here
 6f 62 6f 6f b2 6d  27 89 5b 9c bc e8 7b 13  2e 36 11 d7 f2 af 03 77  81 46 39 42 5b 2c 77 27  e0 bc
             ^ 
sapH_fmt_plug.c:463:15: runtime error: store to misaligned address 0x7ffcb1d6c6a6 for type 'uint64_t', which requires 8 byte alignment
0x7ffcb1d6c6a6: note: pointer points here
 6f 62 6f 6f 35 01  f7 03 40 88 d4 ef 9c 89  cb 2a 37 28 60 50 db ea  7a 98 27 e4 5a 3c 23 af  e7 65
             ^ 
sapH_fmt_plug.c:535:15: runtime error: store to misaligned address 0x7ffcb1d6c6a6 for type 'uint64_t', which requires 8 byte alignment
0x7ffcb1d6c6a6: note: pointer points here
 6f 62 6f 6f e6 b7  6a 34 b9 94 3d c5 17 33  da ce 35 54 23 6e d1 15  9a 7b 1b 2e e7 97 e4 91  69 06
<!-- gh-comment-id:345995473 --> @jfoug commented on GitHub (Nov 21, 2017): These are all that are left: Oracle11 SAPB SAPH ``` oracle11_fmt_plug.c:357:5: runtime error: load of misaligned address 0x0000019c6312 for type 'uint32_t', which requires 4 byte alignment 0x0000019c6312: note: pointer points here 00 00 90 36 03 f2 c5 2e d1 b4 d6 42 00 00 00 00 00 00 00 00 00 00 00 00 00 00 c1 00 00 00 00 00 ^ oracle11_fmt_plug.c:360:5: runtime error: load of misaligned address 0x0000019c6316 for type 'uint32_t', which requires 4 byte alignment 0x0000019c6316: note: pointer points here 03 f2 c5 2e d1 b4 d6 42 00 00 00 00 00 00 00 00 00 00 00 00 00 00 c1 00 00 00 00 00 00 00 e8 4b ^ oracle11_fmt_plug.c:366:5: runtime error: load of misaligned address 0x0000019c6311 for type 'uint32_t', which requires 4 byte alignment 0x0000019c6311: note: pointer points here 00 00 00 97 63 fc f0 d5 4d a6 67 d4 e6 00 00 00 00 00 00 00 00 00 00 00 00 00 00 c1 00 00 00 00 ^ oracle11_fmt_plug.c:369:5: runtime error: load of misaligned address 0x0000019c6315 for type 'uint32_t', which requires 4 byte alignment 0x0000019c6315: note: pointer points here 63 fc f0 d5 4d a6 67 d4 e6 00 00 00 00 00 00 00 00 00 00 00 00 00 00 c1 00 00 00 00 00 00 00 e8 ^ Testing: sapb, SAP CODVN B (BCODE) [MD5 256/256 AVX2 8x3]... (4xOMP) sapB_fmt_plug.c:481:36: runtime error: store to misaligned address 0x7fe2df5a9d05 for type 'unsigned int', which requires 4 byte alignment 0x7fe2df5a9d05: note: pointer points here 00 32 00 19 00 00 00 ff 2f 00 00 00 00 00 00 bc 6a 61 03 00 00 00 00 04 00 00 00 08 00 00 00 00 ^ Testing: sapg, SAP CODVN F/G (PASSCODE) [SHA1 256/256 AVX2 8x]... (4xOMP) sapG_fmt_plug.c:559:55: runtime error: load of misaligned address 0x000000a0ccea for type 'uint32_t', which requires 4 byte alignment 0x000000a0ccea: note: pointer points here ae dd 16 f2 4b 8d 2c e1 d4 dc b0 cb df 9d d4 70 6d 17 f9 4d 42 3f 9b 1b 11 94 9f 5b c1 9b 06 05 ^ Testing: saph, SAP CODVN H (PWDSALTEDHASH) (SHA1x1024) [SHA-1/SHA-2 256/256 AVX2 8x]... (4xOMP) sapH_fmt_plug.c:318:15: runtime error: store to misaligned address 0x7ffcb1d6c5f7 for type 'uint32_t', which requires 4 byte alignment 0x7ffcb1d6c5f7: note: pointer points here 30 31 32 33 8a 21 27 a4 ab 16 e8 e7 09 35 5d 20 48 37 6a eb b0 6a ed 06 80 00 00 00 00 00 00 00 ^ sapH_fmt_plug.c:390:15: runtime error: store to misaligned address 0x7ffcb1d6c626 for type 'uint32_t', which requires 4 byte alignment 0x7ffcb1d6c626: note: pointer points here 6f 62 6f 6f b2 6d 27 89 5b 9c bc e8 7b 13 2e 36 11 d7 f2 af 03 77 81 46 39 42 5b 2c 77 27 e0 bc ^ sapH_fmt_plug.c:463:15: runtime error: store to misaligned address 0x7ffcb1d6c6a6 for type 'uint64_t', which requires 8 byte alignment 0x7ffcb1d6c6a6: note: pointer points here 6f 62 6f 6f 35 01 f7 03 40 88 d4 ef 9c 89 cb 2a 37 28 60 50 db ea 7a 98 27 e4 5a 3c 23 af e7 65 ^ sapH_fmt_plug.c:535:15: runtime error: store to misaligned address 0x7ffcb1d6c6a6 for type 'uint64_t', which requires 8 byte alignment 0x7ffcb1d6c6a6: note: pointer points here 6f 62 6f 6f e6 b7 6a 34 b9 94 3d c5 17 33 da ce 35 54 23 6e d1 15 9a 7b 1b 2e e7 97 e4 91 69 06 ```
Author
Owner

@jfoug commented on GitHub (Nov 21, 2017):

Quick note,
I am also interested in testing the various hash extraction utilities for alignment correctness.

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.

<!-- gh-comment-id:345995896 --> @jfoug commented on GitHub (Nov 21, 2017): > Quick note, I am also interested in testing the various hash extraction utilities for alignment correctness. 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.
Author
Owner

@kholia commented on GitHub (Nov 21, 2017):

Cool! :-)

Also sha512crypt has an alignment problem,

Testing: sha512crypt, crypt(3) $6$ (rounds=5000) [SHA512 256/256 AVX2 4x]... (4xOMP) cryptsha512_fmt_plug.c:754:12: runtime error: store to misaligned address 0x7f84d6c1b3ee for type 'uint64_t', which requires 8 byte alignment
0x7f84d6c1b3ee: note: pointer points here
 fe c3 d0 56 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00

The problem seems to be very similar to the one in sha256crypt. I just need to know which GETPOS macros to use here.

<!-- gh-comment-id:345996419 --> @kholia commented on GitHub (Nov 21, 2017): Cool! :-) Also `sha512crypt` has an alignment problem, ``` Testing: sha512crypt, crypt(3) $6$ (rounds=5000) [SHA512 256/256 AVX2 4x]... (4xOMP) cryptsha512_fmt_plug.c:754:12: runtime error: store to misaligned address 0x7f84d6c1b3ee for type 'uint64_t', which requires 8 byte alignment 0x7f84d6c1b3ee: note: pointer points here fe c3 d0 56 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ``` The problem seems to be very similar to the one in `sha256crypt`. I just need to know which `GETPOS` macros to use here.
Author
Owner

@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.

<!-- gh-comment-id:345998969 --> @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.
Author
Owner

@solardiz commented on GitHub (Nov 21, 2017):

On Tue, Nov 21, 2017 at 11:29:51AM +0000, jfoug wrote:

That sha1crypt did not have problems (or md5crypt) surprises me some. Possibly they do NOT get data unaligned like the bigger crypts do.

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.

<!-- gh-comment-id:346001098 --> @solardiz commented on GitHub (Nov 21, 2017): On Tue, Nov 21, 2017 at 11:29:51AM +0000, jfoug wrote: > That sha1crypt did not have problems (or md5crypt) surprises me some. Possibly they do NOT get data unaligned like the bigger crypts do. 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.
Author
Owner

@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.

<!-- gh-comment-id:346016753 --> @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.
Author
Owner

@jfoug commented on GitHub (Nov 21, 2017):

Oracle11 fixed (both here, and BE porting)

<!-- gh-comment-id:346031449 --> @jfoug commented on GitHub (Nov 21, 2017): Oracle11 fixed (both here, and BE porting)
Author
Owner

@kholia commented on GitHub (Nov 21, 2017):

Some new alignments issues in OpenCL formats,

Testing: RAR5-opencl [PBKDF2-SHA256 OpenCL]... opencl_rar5_fmt_plug.c:225:30: runtime error: member access within misaligned address 0x000002e188c1 for type 'struct custom_salt', which requires 4 byte alignment
0x000002e188c1: note: pointer points here
 00 00 00  78 10 00 00 00 00 80 00  00 37 52 6a 09 22 b4 ad  cc 32 f8 fe d5 d5 1b b6  c8 00 00 00 00
              ^ 
opencl_rar5_fmt_plug.c:226:30: runtime error: member access within misaligned address 0x000002e188c1 for type 'struct custom_salt', which requires 4 byte alignment
0x000002e188c1: note: pointer points here
 00 00 00  78 10 00 00 00 00 80 00  00 37 52 6a 09 22 b4 ad  cc 32 f8 fe d5 d5 1b b6  c8 00 00 00 00
              ^ 
opencl_rar5_fmt_plug.c:227:50: runtime error: member access within misaligned address 0x000002e188c1 for type 'struct custom_salt', which requires 4 byte alignment
0x000002e188c1: note: pointer points here
 00 00 00  78 10 00 00 00 00 80 00  00 37 52 6a 09 22 b4 ad  cc 32 f8 fe d5 d5 1b b6  c8 00 00 00 00
              ^

Testing: sha512crypt-opencl, crypt(3) $6$ (rounds=5000) [SHA512 OpenCL]... opencl_cryptsha512_fmt_plug.c:624:48: runtime error: member access within misaligned address 0x000004930594 for type 'struct sha512_salt', which requires 8 byte alignment
0x000004930594: note: pointer points here
  00 00 00 00 88 13 00 00  10 00 00 00 02 00 00 00  00 00 00 00 4c 4b 4f 2f  55 74 65 34 30 54 33 46
              ^ 
opencl_cryptsha512_fmt_plug.c:557:11: runtime error: load of misaligned address 0x000002e187c4 for type 'uint64_t', which requires 8 byte alignment
0x000002e187c4: note: pointer points here
  78 4c 12 60 20 1f 35 8c  f5 55 8e cf 1e 3e 6f 1a  2e 0f 83 e1 93 e3 f9 f5  81 17 ea 1a 56 31 4d 89
              ^ 

Testing: FVDE-opencl, FileVault 2 [PBKDF2-SHA256 AES OpenCL]... opencl_fvde_fmt_plug.c:222:50: runtime error: member access within misaligned address 0x5589904c7821 for type 'struct fvde_custom_salt', which requires 8 byte alignment
0x5589904c7821: note: pointer points here
 00 00 00  98 10 00 00 00 e7 ee ba  ab ac af fe 04 dd 33 d2  2f d0 9e 30 e5 28 a0 00  00 74 fb da c6
              ^ 
opencl_fvde_fmt_plug.c:224:30: runtime error: member access within misaligned address 0x5589904c7821 for type 'struct fvde_custom_salt', which requires 8 byte alignment
0x5589904c7821: note: pointer points here
 00 00 00  98 10 00 00 00 e7 ee ba  ab ac af fe 04 dd 33 d2  2f d0 9e 30 e5 28 a0 00  00 74 fb da c6
              ^ 
opencl_fvde_fmt_plug.c:225:30: runtime error: member access within misaligned address 0x5589904c7821 for type 'struct fvde_custom_salt', which requires 8 byte alignment
0x5589904c7821: note: pointer points here
 00 00 00  98 10 00 00 00 e7 ee ba  ab ac af fe 04 dd 33 d2  2f d0 9e 30 e5 28 a0 00  00 74 fb da c6

Testing: krb5pa-sha1-opencl, Kerberos 5 AS-REQ Pre-Auth etype 17/18 [PBKDF2-SHA1 OpenCL]... (4xOMP) opencl_krb5pa-sha1_fmt_plug.c:504:14: runtime error: member access within misaligned address 0x558993c2dcd1 for type 'struct custom_salt', which requires 4 byte alignment
0x558993c2dcd1: note: pointer points here
 00 00 00  68 00 00 00 00 12 00 00  00 45 58 41 4d 50 4c 45  2e 43 4f 4d 00 00 00 00  00 00 00 00 00

office_custom_salt', which requires 4 byte alignment
0x5589958aad71: note: pointer points here
 00 00 00  c8 8b 2c 9e 8c 87 88 44  fc 84 20 12 27 3b e4 be  a8 aa 86 21 68 b8 0d 8c  45 c8 52 69 6a
              ^ 
opencl_office_fmt_plug.c:374:63: runtime error: member access within misaligned address 0x5589958aad71 for type 'struct ms_office_custom_salt', which requires 4 byte alignment
0x5589958aad71: note: pointer points here
 00 00 00  c8 8b 2c 9e 8c 87 88 44  fc 84 20 12 27 3b e4 be  a8 aa 86 21 68 b8 0d 8c  45 c8 52 69 6a
              ^ 
opencl_office_fmt_plug.c:380:15: runtime error: member access within misaligned address 0x5589958aad71 for type 'struct ms_office_custom_salt', which requires 4 byte alignment
0x5589958aad71: note: pointer points here
 00 00 00  c8 8b 2c 9e 8c 87 88 44  fc 84 20 12 27 3b e4 be  a8 aa 86 21 68 b8 0d 8c  45 c8 52 69 6a
              ^ 
opencl_office_fmt_plug.c:362:63: runtime error: member access within misaligned address 0x5589958aad71 for type 'struct ms_office_custom_salt', which requires 4 byte alignment
0x5589958aad71: note: pointer points here
 00 00 00  c8 9b 12 80 5d d6 d5 6f  46 d0 73 15 15 3f 3e cb  9c c5 a4 a1 67 b5 1f aa  66 29 f6 a4 ca
              ^ 

Testing: RAKP-opencl, IPMI 2.0 RAKP (RMCP+) [HMAC-SHA1 OpenCL]... opencl_rakp_fmt_plug.c:348:47: runtime error: load of misaligned address 0x5589968b7f51 for type 'unsigned int', which requires 4 byte alignment
0x5589968b7f51: note: pointer points here
 00 00 00  68 6d 7d a2 0e 99 aa ff  5e 85 dc 5e 6e 17 4e 94  5b 34 24 2f 9a 00 00 00  81 02 00 00 00
              ^ 
opencl_rakp_fmt_plug.c:355:50: runtime error: load of misaligned address 0x5589968b7f51 for type 'unsigned int', which requires 4 byte alignment
0x5589968b7f51: note: pointer points here
 00 00 00  68 6d 7d a2 0e 99 aa ff  5e 85 dc 5e 6e 17 4e 94  5b 34 24 2f 9a 00 00 00  81 02 00 00 00
              ^ 

Testing: Raw-MD4-opencl [MD4 OpenCL]... opencl_hash_check_128_plug.c:491:33: runtime error: load of misaligned address 0x558995caf341 for type 'unsigned int', which requires 4 byte alignment
0x558995caf341: note: pointer points here
 00 00 00  68 8a 9d 09 3f 14 f8 70  1d f1 77 32 b2 bb 18 2c  74 00 00 00 00 00 00 00  81 02 00 00 00
              ^ 
opencl_hash_check_128_plug.c:493:26: runtime error: load of misaligned address 0x558995caf345 for type 'unsigned int', which requires 4 byte alignment
0x558995caf345: note: pointer points here
 8a 9d 09 3f 14 f8 70  1d f1 77 32 b2 bb 18 2c  74 00 00 00 00 00 00 00  81 02 00 00 00 00 00 00  04
             ^ 
formats.c:1729:9: runtime error: load of misaligned address 0x558995caf341 for type 'uint32_t', which requires 4 byte alignment
0x558995caf341: note: pointer points here
 00 00 00  68 8a 9d 09 3f 14 f8 70  1d f1 77 32 b2 bb 18 2c  74 00 00 00 00 00 00 00  81 02 00 00 00
              ^ 
formats.c:1734:9: runtime error: load of misaligned address 0x558995caf341 for type 'uint32_t', which requires 4 byte alignment
0x558995caf341: note: pointer points here
 00 00 00  68 8a 9d 09 3f 14 f8 70  1d f1 77 32 b2 bb 18 2c  74 00 00 00 00 00 00 00  81 02 00 00 00
              ^ 
formats.c:1739:9: runtime error: load of misaligned address 0x558995caf341 for type 'uint32_t', which requires 4 byte alignment
0x558995caf341: note: pointer points here
 00 00 00  68 8a 9d 09 3f 14 f8 70  1d f1 77 32 b2 bb 18 2c  74 00 00 00 00 00 00 00  81 02 00 00 00
              ^ 
formats.c:1744:9: runtime error: load of misaligned address 0x558995caf341 for type 'uint32_t', which requires 4 byte alignment
0x558995caf341: note: pointer points here
 00 00 00  68 8a 9d 09 3f 14 f8 70  1d f1 77 32 b2 bb 18 2c  74 00 00 00 00 00 00 00  81 02 00 00 00
              ^ 
formats.c:1749:9: runtime error: load of misaligned address 0x558995caf341 for type 'uint32_t', which requires 4 byte alignment
0x558995caf341: note: pointer points here
 00 00 00  68 8a 9d 09 3f 14 f8 70  1d f1 77 32 b2 bb 18 2c  74 00 00 00 00 00 00 00  81 02 00 00 00
              ^ 
formats.c:1754:9: runtime error: load of misaligned address 0x558995caf341 for type 'uint32_t', which requires 4 byte alignment
0x558995caf341: note: pointer points here
 00 00 00  68 8a 9d 09 3f 14 f8 70  1d f1 77 32 b2 bb 18 2c  74 00 00 00 00 00 00 00  81 02 00 00 00
              ^ 
formats.c:1759:9: runtime error: load of misaligned address 0x558995caf341 for type 'uint32_t', which requires 4 byte alignment
0x558995caf341: note: pointer points here
 00 00 00  68 8a 9d 09 3f 14 f8 70  1d f1 77 32 b2 bb 18 2c  74 00 00 00 00 00 00 00  81 02 00 00 00

Testing: zip-opencl, ZIP [PBKDF2-SHA1 OpenCL]... (4xOMP) formats.c:1770:23: runtime error: load of misaligned address 0x5589995fe3d4 for type 'struct dyna_salt_john_core *', which requires 8 byte alignment
0x5589995fe3d4: note: pointer points here
  68 2b 3c b8 80 34 45 99  89 55 00 00 89 55 00 00  20 00 00 00 00 00 00 00  21 00 00 00 00 00 00 00
              ^ 
opencl_zip_fmt_plug.c:300:15: runtime error: load of misaligned address 0x5589995fe3d4 for type 'struct my_salt *', which requires 8 byte alignment
0x5589995fe3d4: note: pointer points here
  68 2b 3c b8 80 34 45 99  89 55 00 00 89 55 00 00  20 00 00 00 00 00 00 00  21 00 00 00 00 00 00 00
              ^ 
dyna_salt.c:90:24: runtime error: load of misaligned address 0x5589995fe3d4 for type 'struct dyna_salt_john_core *', which requires 8 byte alignment
0x5589995fe3d4: note: pointer points here
  68 2b 3c b8 80 34 45 99  89 55 00 00 89 55 00 00  20 00 00 00 00 00 00 00  21 00 00 00 00 00 00 00
              ^ 
opencl_zip_fmt_plug.c:397:61: runtime error: load of misaligned address 0x558998efe0b1 for type 'uint32_t', which requires 4 byte alignment
0x558998efe0b1: note: pointer points here
 00 00 00  00 bd 2e 94 68 11 c4 c5  b0 96 94 98 89 55 00 00  20 00 00 00 00 00 00 00  81 02 00 00 00
              ^ 
opencl_zip_fmt_plug.c:404:68: runtime error: load of misaligned address 0x558998efe0b1 for type 'uint32_t', which requires 4 byte alignment
0x558998efe0b1: note: pointer points here
 00 00 00  00 bd 2e 94 68 11 c4 c5  b0 96 94 98 89 55 00 00  20 00 00 00 00 00 00 00  81 02 00 00 00
              ^ 
opencl_zip_fmt_plug.c:397:35: runtime error: load of misaligned address 0x558999405c6a for type 'uint32_t', which requires 4 byte alignment
0x558999405c6a: note: pointer points here
 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00
              ^ 
dyna_salt.c:56:24: runtime error: load of misaligned address 0x5589995fe3d4 for type 'struct dyna_salt_john_core *', which requires 8 byte alignment
0x5589995fe3d4: note: pointer points here
  68 2b 3c b8 80 34 45 99  89 55 00 00 89 55 00 00  20 00 00 00 00 00 00 00  21 00 00 00 00 00 00 00
              ^ 

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.

<!-- gh-comment-id:346059889 --> @kholia commented on GitHub (Nov 21, 2017): Some new alignments issues in OpenCL formats, ``` Testing: RAR5-opencl [PBKDF2-SHA256 OpenCL]... opencl_rar5_fmt_plug.c:225:30: runtime error: member access within misaligned address 0x000002e188c1 for type 'struct custom_salt', which requires 4 byte alignment 0x000002e188c1: note: pointer points here 00 00 00 78 10 00 00 00 00 80 00 00 37 52 6a 09 22 b4 ad cc 32 f8 fe d5 d5 1b b6 c8 00 00 00 00 ^ opencl_rar5_fmt_plug.c:226:30: runtime error: member access within misaligned address 0x000002e188c1 for type 'struct custom_salt', which requires 4 byte alignment 0x000002e188c1: note: pointer points here 00 00 00 78 10 00 00 00 00 80 00 00 37 52 6a 09 22 b4 ad cc 32 f8 fe d5 d5 1b b6 c8 00 00 00 00 ^ opencl_rar5_fmt_plug.c:227:50: runtime error: member access within misaligned address 0x000002e188c1 for type 'struct custom_salt', which requires 4 byte alignment 0x000002e188c1: note: pointer points here 00 00 00 78 10 00 00 00 00 80 00 00 37 52 6a 09 22 b4 ad cc 32 f8 fe d5 d5 1b b6 c8 00 00 00 00 ^ Testing: sha512crypt-opencl, crypt(3) $6$ (rounds=5000) [SHA512 OpenCL]... opencl_cryptsha512_fmt_plug.c:624:48: runtime error: member access within misaligned address 0x000004930594 for type 'struct sha512_salt', which requires 8 byte alignment 0x000004930594: note: pointer points here 00 00 00 00 88 13 00 00 10 00 00 00 02 00 00 00 00 00 00 00 4c 4b 4f 2f 55 74 65 34 30 54 33 46 ^ opencl_cryptsha512_fmt_plug.c:557:11: runtime error: load of misaligned address 0x000002e187c4 for type 'uint64_t', which requires 8 byte alignment 0x000002e187c4: note: pointer points here 78 4c 12 60 20 1f 35 8c f5 55 8e cf 1e 3e 6f 1a 2e 0f 83 e1 93 e3 f9 f5 81 17 ea 1a 56 31 4d 89 ^ Testing: FVDE-opencl, FileVault 2 [PBKDF2-SHA256 AES OpenCL]... opencl_fvde_fmt_plug.c:222:50: runtime error: member access within misaligned address 0x5589904c7821 for type 'struct fvde_custom_salt', which requires 8 byte alignment 0x5589904c7821: note: pointer points here 00 00 00 98 10 00 00 00 e7 ee ba ab ac af fe 04 dd 33 d2 2f d0 9e 30 e5 28 a0 00 00 74 fb da c6 ^ opencl_fvde_fmt_plug.c:224:30: runtime error: member access within misaligned address 0x5589904c7821 for type 'struct fvde_custom_salt', which requires 8 byte alignment 0x5589904c7821: note: pointer points here 00 00 00 98 10 00 00 00 e7 ee ba ab ac af fe 04 dd 33 d2 2f d0 9e 30 e5 28 a0 00 00 74 fb da c6 ^ opencl_fvde_fmt_plug.c:225:30: runtime error: member access within misaligned address 0x5589904c7821 for type 'struct fvde_custom_salt', which requires 8 byte alignment 0x5589904c7821: note: pointer points here 00 00 00 98 10 00 00 00 e7 ee ba ab ac af fe 04 dd 33 d2 2f d0 9e 30 e5 28 a0 00 00 74 fb da c6 Testing: krb5pa-sha1-opencl, Kerberos 5 AS-REQ Pre-Auth etype 17/18 [PBKDF2-SHA1 OpenCL]... (4xOMP) opencl_krb5pa-sha1_fmt_plug.c:504:14: runtime error: member access within misaligned address 0x558993c2dcd1 for type 'struct custom_salt', which requires 4 byte alignment 0x558993c2dcd1: note: pointer points here 00 00 00 68 00 00 00 00 12 00 00 00 45 58 41 4d 50 4c 45 2e 43 4f 4d 00 00 00 00 00 00 00 00 00 office_custom_salt', which requires 4 byte alignment 0x5589958aad71: note: pointer points here 00 00 00 c8 8b 2c 9e 8c 87 88 44 fc 84 20 12 27 3b e4 be a8 aa 86 21 68 b8 0d 8c 45 c8 52 69 6a ^ opencl_office_fmt_plug.c:374:63: runtime error: member access within misaligned address 0x5589958aad71 for type 'struct ms_office_custom_salt', which requires 4 byte alignment 0x5589958aad71: note: pointer points here 00 00 00 c8 8b 2c 9e 8c 87 88 44 fc 84 20 12 27 3b e4 be a8 aa 86 21 68 b8 0d 8c 45 c8 52 69 6a ^ opencl_office_fmt_plug.c:380:15: runtime error: member access within misaligned address 0x5589958aad71 for type 'struct ms_office_custom_salt', which requires 4 byte alignment 0x5589958aad71: note: pointer points here 00 00 00 c8 8b 2c 9e 8c 87 88 44 fc 84 20 12 27 3b e4 be a8 aa 86 21 68 b8 0d 8c 45 c8 52 69 6a ^ opencl_office_fmt_plug.c:362:63: runtime error: member access within misaligned address 0x5589958aad71 for type 'struct ms_office_custom_salt', which requires 4 byte alignment 0x5589958aad71: note: pointer points here 00 00 00 c8 9b 12 80 5d d6 d5 6f 46 d0 73 15 15 3f 3e cb 9c c5 a4 a1 67 b5 1f aa 66 29 f6 a4 ca ^ Testing: RAKP-opencl, IPMI 2.0 RAKP (RMCP+) [HMAC-SHA1 OpenCL]... opencl_rakp_fmt_plug.c:348:47: runtime error: load of misaligned address 0x5589968b7f51 for type 'unsigned int', which requires 4 byte alignment 0x5589968b7f51: note: pointer points here 00 00 00 68 6d 7d a2 0e 99 aa ff 5e 85 dc 5e 6e 17 4e 94 5b 34 24 2f 9a 00 00 00 81 02 00 00 00 ^ opencl_rakp_fmt_plug.c:355:50: runtime error: load of misaligned address 0x5589968b7f51 for type 'unsigned int', which requires 4 byte alignment 0x5589968b7f51: note: pointer points here 00 00 00 68 6d 7d a2 0e 99 aa ff 5e 85 dc 5e 6e 17 4e 94 5b 34 24 2f 9a 00 00 00 81 02 00 00 00 ^ Testing: Raw-MD4-opencl [MD4 OpenCL]... opencl_hash_check_128_plug.c:491:33: runtime error: load of misaligned address 0x558995caf341 for type 'unsigned int', which requires 4 byte alignment 0x558995caf341: note: pointer points here 00 00 00 68 8a 9d 09 3f 14 f8 70 1d f1 77 32 b2 bb 18 2c 74 00 00 00 00 00 00 00 81 02 00 00 00 ^ opencl_hash_check_128_plug.c:493:26: runtime error: load of misaligned address 0x558995caf345 for type 'unsigned int', which requires 4 byte alignment 0x558995caf345: note: pointer points here 8a 9d 09 3f 14 f8 70 1d f1 77 32 b2 bb 18 2c 74 00 00 00 00 00 00 00 81 02 00 00 00 00 00 00 04 ^ formats.c:1729:9: runtime error: load of misaligned address 0x558995caf341 for type 'uint32_t', which requires 4 byte alignment 0x558995caf341: note: pointer points here 00 00 00 68 8a 9d 09 3f 14 f8 70 1d f1 77 32 b2 bb 18 2c 74 00 00 00 00 00 00 00 81 02 00 00 00 ^ formats.c:1734:9: runtime error: load of misaligned address 0x558995caf341 for type 'uint32_t', which requires 4 byte alignment 0x558995caf341: note: pointer points here 00 00 00 68 8a 9d 09 3f 14 f8 70 1d f1 77 32 b2 bb 18 2c 74 00 00 00 00 00 00 00 81 02 00 00 00 ^ formats.c:1739:9: runtime error: load of misaligned address 0x558995caf341 for type 'uint32_t', which requires 4 byte alignment 0x558995caf341: note: pointer points here 00 00 00 68 8a 9d 09 3f 14 f8 70 1d f1 77 32 b2 bb 18 2c 74 00 00 00 00 00 00 00 81 02 00 00 00 ^ formats.c:1744:9: runtime error: load of misaligned address 0x558995caf341 for type 'uint32_t', which requires 4 byte alignment 0x558995caf341: note: pointer points here 00 00 00 68 8a 9d 09 3f 14 f8 70 1d f1 77 32 b2 bb 18 2c 74 00 00 00 00 00 00 00 81 02 00 00 00 ^ formats.c:1749:9: runtime error: load of misaligned address 0x558995caf341 for type 'uint32_t', which requires 4 byte alignment 0x558995caf341: note: pointer points here 00 00 00 68 8a 9d 09 3f 14 f8 70 1d f1 77 32 b2 bb 18 2c 74 00 00 00 00 00 00 00 81 02 00 00 00 ^ formats.c:1754:9: runtime error: load of misaligned address 0x558995caf341 for type 'uint32_t', which requires 4 byte alignment 0x558995caf341: note: pointer points here 00 00 00 68 8a 9d 09 3f 14 f8 70 1d f1 77 32 b2 bb 18 2c 74 00 00 00 00 00 00 00 81 02 00 00 00 ^ formats.c:1759:9: runtime error: load of misaligned address 0x558995caf341 for type 'uint32_t', which requires 4 byte alignment 0x558995caf341: note: pointer points here 00 00 00 68 8a 9d 09 3f 14 f8 70 1d f1 77 32 b2 bb 18 2c 74 00 00 00 00 00 00 00 81 02 00 00 00 Testing: zip-opencl, ZIP [PBKDF2-SHA1 OpenCL]... (4xOMP) formats.c:1770:23: runtime error: load of misaligned address 0x5589995fe3d4 for type 'struct dyna_salt_john_core *', which requires 8 byte alignment 0x5589995fe3d4: note: pointer points here 68 2b 3c b8 80 34 45 99 89 55 00 00 89 55 00 00 20 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 ^ opencl_zip_fmt_plug.c:300:15: runtime error: load of misaligned address 0x5589995fe3d4 for type 'struct my_salt *', which requires 8 byte alignment 0x5589995fe3d4: note: pointer points here 68 2b 3c b8 80 34 45 99 89 55 00 00 89 55 00 00 20 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 ^ dyna_salt.c:90:24: runtime error: load of misaligned address 0x5589995fe3d4 for type 'struct dyna_salt_john_core *', which requires 8 byte alignment 0x5589995fe3d4: note: pointer points here 68 2b 3c b8 80 34 45 99 89 55 00 00 89 55 00 00 20 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 ^ opencl_zip_fmt_plug.c:397:61: runtime error: load of misaligned address 0x558998efe0b1 for type 'uint32_t', which requires 4 byte alignment 0x558998efe0b1: note: pointer points here 00 00 00 00 bd 2e 94 68 11 c4 c5 b0 96 94 98 89 55 00 00 20 00 00 00 00 00 00 00 81 02 00 00 00 ^ opencl_zip_fmt_plug.c:404:68: runtime error: load of misaligned address 0x558998efe0b1 for type 'uint32_t', which requires 4 byte alignment 0x558998efe0b1: note: pointer points here 00 00 00 00 bd 2e 94 68 11 c4 c5 b0 96 94 98 89 55 00 00 20 00 00 00 00 00 00 00 81 02 00 00 00 ^ opencl_zip_fmt_plug.c:397:35: runtime error: load of misaligned address 0x558999405c6a for type 'uint32_t', which requires 4 byte alignment 0x558999405c6a: note: pointer points here 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ dyna_salt.c:56:24: runtime error: load of misaligned address 0x5589995fe3d4 for type 'struct dyna_salt_john_core *', which requires 8 byte alignment 0x5589995fe3d4: note: pointer points here 68 2b 3c b8 80 34 45 99 89 55 00 00 89 55 00 00 20 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 ^ ``` 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.
Author
Owner

@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

<!-- gh-comment-id:346109506 --> @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
Author
Owner

@jfoug commented on GitHub (Nov 21, 2017):

I think these are new (using -enc=utf8)

testing: rar, RAR3 (4 characters) [SHA1 256/256 AVX2 8x AES] in UTF-8 mode... (2xOMP) unrarppm.c:55:32: runtime error: member access within misaligned address 0x7f63faf7fc94 for type 'struct rar_node', which requires 8 byte alignment
0x7f63faf7fc94: note: pointer points here
  00 00 00 00 16 f0 3f fa  63 7f 00 00 c9 02 21 f0  3f fa 63 7f 00 00 a5 02  00 00 00 00 16 f0 3f fa
              ^ 
unrarppm.c:64:43: runtime error: member access within misaligned address 0x7f6409facc94 for type 'struct rar_node', which requires 8 byte alignment
0x7f6409facc94: note: pointer points here
  00 00 00 00 00 00 00 00  00 00 00 00 c9 02 21 c0  42 09 64 7f 00 00 a5 02  00 00 00 00 16 c0 42 09
              ^ 
<!-- gh-comment-id:346111533 --> @jfoug commented on GitHub (Nov 21, 2017): I think these are new (using -enc=utf8) ``` testing: rar, RAR3 (4 characters) [SHA1 256/256 AVX2 8x AES] in UTF-8 mode... (2xOMP) unrarppm.c:55:32: runtime error: member access within misaligned address 0x7f63faf7fc94 for type 'struct rar_node', which requires 8 byte alignment 0x7f63faf7fc94: note: pointer points here 00 00 00 00 16 f0 3f fa 63 7f 00 00 c9 02 21 f0 3f fa 63 7f 00 00 a5 02 00 00 00 00 16 f0 3f fa ^ unrarppm.c:64:43: runtime error: member access within misaligned address 0x7f6409facc94 for type 'struct rar_node', which requires 8 byte alignment 0x7f6409facc94: note: pointer points here 00 00 00 00 00 00 00 00 00 00 00 00 c9 02 21 c0 42 09 64 7f 00 00 a5 02 00 00 00 00 16 c0 42 09 ^ ```
Author
Owner

@solardiz commented on GitHub (Nov 21, 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_UNALIGNED wrapper, keeping the original code

Not a big deal, but FWIW I disagree about #if'ing that one. We already have that #if inside mem_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_WORD alignment) 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_WORD for both integers and pointers, so let's continue with that for now, except that when we know we only have e.g. an int or an uint32_t, we can better use sizeof that.

<!-- gh-comment-id:346198503 --> @solardiz commented on GitHub (Nov 21, 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_UNALIGNED wrapper, keeping the original code Not a big deal, but FWIW I disagree about `#if`'ing that one. We already have that `#if` inside `mem_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_WORD` alignment) 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_WORD` for both integers and pointers, so let's continue with that for now, except that when we know we only have e.g. an `int` or an `uint32_t`, we can better use `sizeof` that.
Author
Owner

@solardiz commented on GitHub (Nov 22, 2017):

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.

I agree, but IIRC this happened because as initially contributed by Simon this file (called sse-intrinsics.c then) provided only md5crypt.

<!-- gh-comment-id:346200482 --> @solardiz commented on GitHub (Nov 22, 2017): > 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. I agree, but IIRC this happened because as initially contributed by Simon this file (called `sse-intrinsics.c` then) provided _only_ md5crypt.
Author
Owner

@kholia commented on GitHub (Nov 22, 2017):

Quick note so that I don't forget,

$ ../run/john --test-full=0

Testing: lotus5-opencl, Lotus Notes/Domino 5 [OpenCL]... OpenCL CL_INVALID_COMMAND_QUEUE (-36) error in opencl_lotus5_fmt_plug.c:253 - Shit hit fan
OpenCL CL_INVALID_COMMAND_QUEUE (-36) error in opencl_lotus5_fmt_plug.c:253 - Shit hit fan
OpenCL CL_INVALID_COMMAND_QUEUE (-36) error in opencl_lotus5_fmt_plug.c:253 - Shit hit fan
OpenCL CL_INVALID_COMMAND_QUEUE (-36) error in opencl_lotus5_fmt_plug.c:253 - Shit hit fan
FAILED (cmp_all(-1)

This output is associated with,

[  676.118271] NVRM: Xid (PCI:0000:01:00): 13, Graphics SM Warp Exception on (GPC 0, TPC 0): Out Of Range Address
[  676.118276] NVRM: Xid (PCI:0000:01:00): 13, Graphics Exception: ESR 0x504648=0x100000e 0x504650=0x20 0x504644=0xd3eff2 0x50464c=0x17f
[  676.118406] NVRM: Xid (PCI:0000:01:00): 43, Ch 00000038, engmask 00000101

This machine has a NVIDIA 1050 Ti GPU and it is running NVIDIA binary driver - version 375.66.

<!-- gh-comment-id:346244872 --> @kholia commented on GitHub (Nov 22, 2017): Quick note so that I don't forget, ``` $ ../run/john --test-full=0 Testing: lotus5-opencl, Lotus Notes/Domino 5 [OpenCL]... OpenCL CL_INVALID_COMMAND_QUEUE (-36) error in opencl_lotus5_fmt_plug.c:253 - Shit hit fan OpenCL CL_INVALID_COMMAND_QUEUE (-36) error in opencl_lotus5_fmt_plug.c:253 - Shit hit fan OpenCL CL_INVALID_COMMAND_QUEUE (-36) error in opencl_lotus5_fmt_plug.c:253 - Shit hit fan OpenCL CL_INVALID_COMMAND_QUEUE (-36) error in opencl_lotus5_fmt_plug.c:253 - Shit hit fan FAILED (cmp_all(-1) ``` This output is associated with, ``` [ 676.118271] NVRM: Xid (PCI:0000:01:00): 13, Graphics SM Warp Exception on (GPC 0, TPC 0): Out Of Range Address [ 676.118276] NVRM: Xid (PCI:0000:01:00): 13, Graphics Exception: ESR 0x504648=0x100000e 0x504650=0x20 0x504644=0xd3eff2 0x50464c=0x17f [ 676.118406] NVRM: Xid (PCI:0000:01:00): 43, Ch 00000038, engmask 00000101 ``` This machine has a NVIDIA 1050 Ti GPU and it is running `NVIDIA binary driver - version 375.66`.
Author
Owner

@magnumripper commented on GitHub (Nov 22, 2017):

BUT he then placed that code all over the place. On many formats, he got a gain, but only a percent or 2,

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.

since the format was not so bound up on the key_load code (i.e. salted, had more hashing functions, etc)

"Salted" is not a disqualifier at all, we may attack a single salt.

<!-- gh-comment-id:346401814 --> @magnumripper commented on GitHub (Nov 22, 2017): > BUT he then placed that code all over the place. On many formats, he got a gain, but only a percent or 2, 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. > since the format was not so bound up on the key_load code (i.e. salted, had more hashing functions, etc) "Salted" is not a disqualifier at all, we may attack a single salt.
Author
Owner

@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.

<!-- gh-comment-id:346435561 --> @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.
Author
Owner

@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.

<!-- gh-comment-id:346444782 --> @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.
Author
Owner

@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'.....

<!-- gh-comment-id:346449841 --> @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'.....
Author
Owner

@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.

<!-- gh-comment-id:346853795 --> @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.
Author
Owner

@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.

<!-- gh-comment-id:346919115 --> @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.
Author
Owner

@kholia commented on GitHub (Nov 25, 2017):

This was found by you earlier.

$ ../run/john -test-full=0 --format=cpu --encoding=utf8
...
Testing: rar, RAR3 (4 characters) [SHA1 256/256 AVX2 8x AES] in UTF-8 mode... (4xOMP) unrarppm.c:55:32: runtime error: member access within misaligned address 0x7fe9fe8d1c94 for type 'struct rar_node', which requires 8 byte alignment
0x7fe9fe8d1c94: note: pointer points here
  00 00 00 00 16 10 d5 fd  e9 7f 00 00 c9 02 21 10  d5 fd e9 7f 00 00 a5 02  00 00 00 00 16 10 d5 fd
              ^ 
unrarppm.c:64:43: runtime error: member access within misaligned address 0x7fe9f8cd0c94 for type 'struct rar_node', which requires 8 byte alignment
0x7fe9f8cd0c94: note: pointer points here
  00 00 00 00 00 00 00 00  00 00 00 00 c9 02 21 00  15 f8 e9 7f 00 00 a5 02  00 00 00 00 16 00 15 f8

Remaining OpenCL findings,

$ ../run/john -test-full=0 --format=opencl
Testing: ethereum-opencl, Ethereum Wallet [PBKDF2-SHA256 OpenCL AES]... KeccakF-1600-opt64.c:79:12: runtime error: load of misaligned address 0x55db72bbbad4 for type 'UINT64', which requires 8 byte alignment
0x55db72bbbad4: note: pointer points here
  b8 41 f9 1e 53 18 b4 d5  bc d2 8d e6 4e e5 55 9e  67 13 53 e1 6f 07 5e ca  e9 f9 9c 7a 79 a3 8a f5
              ^ 

Testing: Raw-MD5-opencl [MD5 OpenCL]... opencl_hash_check_128_plug.c:491:33: runtime error: load of misaligned address 0x55db75a148f1 for type 'unsigned int', which requires 4 byte alignment
0x55db75a148f1: note: pointer points here
 00 00 00  68 5a 10 5e 8b 9d 40 e1  32 97 80 d6 2e a2 26 5d  8a 00 00 00 00 00 00 00  81 02 00 00 00
              ^ 
opencl_hash_check_128_plug.c:493:26: runtime error: load of misaligned address 0x55db75a148f5 for type 'unsigned int', which requires 4 byte alignment
0x55db75a148f5: note: pointer points here
 5a 10 5e 8b 9d 40 e1  32 97 80 d6 2e a2 26 5d  8a 00 00 00 00 00 00 00  81 02 00 00 00 00 00 00  04
             ^ 
formats.c:1730:9: runtime error: load of misaligned address 0x55db75a148f1 for type 'uint32_t', which requires 4 byte alignment
0x55db75a148f1: note: pointer points here
 00 00 00  68 5a 10 5e 8b 9d 40 e1  32 97 80 d6 2e a2 26 5d  8a 00 00 00 00 00 00 00  81 02 00 00 00
              ^ 
formats.c:1735:9: runtime error: load of misaligned address 0x55db75a148f1 for type 'uint32_t', which requires 4 byte alignment
0x55db75a148f1: note: pointer points here
 00 00 00  68 5a 10 5e 8b 9d 40 e1  32 97 80 d6 2e a2 26 5d  8a 00 00 00 00 00 00 00  81 02 00 00 00
              ^ 
formats.c:1740:9: runtime error: load of misaligned address 0x55db75a148f1 for type 'uint32_t', which requires 4 byte alignment
0x55db75a148f1: note: pointer points here
 00 00 00  68 5a 10 5e 8b 9d 40 e1  32 97 80 d6 2e a2 26 5d  8a 00 00 00 00 00 00 00  81 02 00 00 00
              ^ 
formats.c:1745:9: runtime error: load of misaligned address 0x55db75a148f1 for type 'uint32_t', which requires 4 byte alignment
0x55db75a148f1: note: pointer points here
 00 00 00  68 5a 10 5e 8b 9d 40 e1  32 97 80 d6 2e a2 26 5d  8a 00 00 00 00 00 00 00  81 02 00 00 00
              ^ 
formats.c:1750:9: runtime error: load of misaligned address 0x55db75a148f1 for type 'uint32_t', which requires 4 byte alignment
0x55db75a148f1: note: pointer points here
 00 00 00  68 5a 10 5e 8b 9d 40 e1  32 97 80 d6 2e a2 26 5d  8a 00 00 00 00 00 00 00  81 02 00 00 00
              ^ 
formats.c:1755:9: runtime error: load of misaligned address 0x55db75a148f1 for type 'uint32_t', which requires 4 byte alignment
0x55db75a148f1: note: pointer points here
 00 00 00  68 5a 10 5e 8b 9d 40 e1  32 97 80 d6 2e a2 26 5d  8a 00 00 00 00 00 00 00  81 02 00 00 00
              ^ 
formats.c:1760:9: runtime error: load of misaligned address 0x55db75a148f1 for type 'uint32_t', which requires 4 byte alignment
0x55db75a148f1: note: pointer points here
 00 00 00  68 5a 10 5e 8b 9d 40 e1  32 97 80 d6 2e a2 26 5d  8a 00 00 00 00 00 00 00  81 02 00 00 00
              ^ 

Testing: zip-opencl, ZIP [PBKDF2-SHA1 OpenCL]... (4xOMP) opencl_zip_fmt_plug.c:397:35: runtime error: load of misaligned address 0x55db76f5b90a for type 'uint32_t', which requires 4 byte alignment
0x55db76f5b90a: note: pointer points here
 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00
              ^ 
<!-- gh-comment-id:346922093 --> @kholia commented on GitHub (Nov 25, 2017): This was found by you earlier. ``` $ ../run/john -test-full=0 --format=cpu --encoding=utf8 ... Testing: rar, RAR3 (4 characters) [SHA1 256/256 AVX2 8x AES] in UTF-8 mode... (4xOMP) unrarppm.c:55:32: runtime error: member access within misaligned address 0x7fe9fe8d1c94 for type 'struct rar_node', which requires 8 byte alignment 0x7fe9fe8d1c94: note: pointer points here 00 00 00 00 16 10 d5 fd e9 7f 00 00 c9 02 21 10 d5 fd e9 7f 00 00 a5 02 00 00 00 00 16 10 d5 fd ^ unrarppm.c:64:43: runtime error: member access within misaligned address 0x7fe9f8cd0c94 for type 'struct rar_node', which requires 8 byte alignment 0x7fe9f8cd0c94: note: pointer points here 00 00 00 00 00 00 00 00 00 00 00 00 c9 02 21 00 15 f8 e9 7f 00 00 a5 02 00 00 00 00 16 00 15 f8 ``` Remaining OpenCL findings, ``` $ ../run/john -test-full=0 --format=opencl Testing: ethereum-opencl, Ethereum Wallet [PBKDF2-SHA256 OpenCL AES]... KeccakF-1600-opt64.c:79:12: runtime error: load of misaligned address 0x55db72bbbad4 for type 'UINT64', which requires 8 byte alignment 0x55db72bbbad4: note: pointer points here b8 41 f9 1e 53 18 b4 d5 bc d2 8d e6 4e e5 55 9e 67 13 53 e1 6f 07 5e ca e9 f9 9c 7a 79 a3 8a f5 ^ Testing: Raw-MD5-opencl [MD5 OpenCL]... opencl_hash_check_128_plug.c:491:33: runtime error: load of misaligned address 0x55db75a148f1 for type 'unsigned int', which requires 4 byte alignment 0x55db75a148f1: note: pointer points here 00 00 00 68 5a 10 5e 8b 9d 40 e1 32 97 80 d6 2e a2 26 5d 8a 00 00 00 00 00 00 00 81 02 00 00 00 ^ opencl_hash_check_128_plug.c:493:26: runtime error: load of misaligned address 0x55db75a148f5 for type 'unsigned int', which requires 4 byte alignment 0x55db75a148f5: note: pointer points here 5a 10 5e 8b 9d 40 e1 32 97 80 d6 2e a2 26 5d 8a 00 00 00 00 00 00 00 81 02 00 00 00 00 00 00 04 ^ formats.c:1730:9: runtime error: load of misaligned address 0x55db75a148f1 for type 'uint32_t', which requires 4 byte alignment 0x55db75a148f1: note: pointer points here 00 00 00 68 5a 10 5e 8b 9d 40 e1 32 97 80 d6 2e a2 26 5d 8a 00 00 00 00 00 00 00 81 02 00 00 00 ^ formats.c:1735:9: runtime error: load of misaligned address 0x55db75a148f1 for type 'uint32_t', which requires 4 byte alignment 0x55db75a148f1: note: pointer points here 00 00 00 68 5a 10 5e 8b 9d 40 e1 32 97 80 d6 2e a2 26 5d 8a 00 00 00 00 00 00 00 81 02 00 00 00 ^ formats.c:1740:9: runtime error: load of misaligned address 0x55db75a148f1 for type 'uint32_t', which requires 4 byte alignment 0x55db75a148f1: note: pointer points here 00 00 00 68 5a 10 5e 8b 9d 40 e1 32 97 80 d6 2e a2 26 5d 8a 00 00 00 00 00 00 00 81 02 00 00 00 ^ formats.c:1745:9: runtime error: load of misaligned address 0x55db75a148f1 for type 'uint32_t', which requires 4 byte alignment 0x55db75a148f1: note: pointer points here 00 00 00 68 5a 10 5e 8b 9d 40 e1 32 97 80 d6 2e a2 26 5d 8a 00 00 00 00 00 00 00 81 02 00 00 00 ^ formats.c:1750:9: runtime error: load of misaligned address 0x55db75a148f1 for type 'uint32_t', which requires 4 byte alignment 0x55db75a148f1: note: pointer points here 00 00 00 68 5a 10 5e 8b 9d 40 e1 32 97 80 d6 2e a2 26 5d 8a 00 00 00 00 00 00 00 81 02 00 00 00 ^ formats.c:1755:9: runtime error: load of misaligned address 0x55db75a148f1 for type 'uint32_t', which requires 4 byte alignment 0x55db75a148f1: note: pointer points here 00 00 00 68 5a 10 5e 8b 9d 40 e1 32 97 80 d6 2e a2 26 5d 8a 00 00 00 00 00 00 00 81 02 00 00 00 ^ formats.c:1760:9: runtime error: load of misaligned address 0x55db75a148f1 for type 'uint32_t', which requires 4 byte alignment 0x55db75a148f1: note: pointer points here 00 00 00 68 5a 10 5e 8b 9d 40 e1 32 97 80 d6 2e a2 26 5d 8a 00 00 00 00 00 00 00 81 02 00 00 00 ^ Testing: zip-opencl, ZIP [PBKDF2-SHA1 OpenCL]... (4xOMP) opencl_zip_fmt_plug.c:397:35: runtime error: load of misaligned address 0x55db76f5b90a for type 'uint32_t', which requires 4 byte alignment 0x55db76f5b90a: note: pointer points here 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ ```
Author
Owner

@kholia commented on GitHub (Nov 25, 2017):

Patch for raw-md5-opencl format,

diff --git a/src/opencl_rawmd5_fmt_plug.c b/src/opencl_rawmd5_fmt_plug.c
index cac75d69c..179ab009f 100644
--- a/src/opencl_rawmd5_fmt_plug.c
+++ b/src/opencl_rawmd5_fmt_plug.c
@@ -43,7 +43,7 @@ john_register_one(&FMT_STRUCT);
 #define CIPHERTEXT_LENGTH   32
 #define DIGEST_SIZE         16
 #define BINARY_SIZE         16
-#define BINARY_ALIGN        1
+#define BINARY_ALIGN        sizeof(uint32_t)
 #define SALT_SIZE           0
 #define SALT_ALIGN          1

Patch for ethereum-opencl format,

diff --git a/src/opencl_ethereum_fmt_plug.c b/src/opencl_ethereum_fmt_plug.c
index b2e1b3e57..cc925fc91 100644
--- a/src/opencl_ethereum_fmt_plug.c
+++ b/src/opencl_ethereum_fmt_plug.c
@@ -34,7 +34,7 @@ john_register_one(&fmt_opencl_ethereum);
 #define MAX_KEYS_PER_CRYPT      1
 #define BINARY_ALIGN            sizeof(uint32_t)
 #define SALT_SIZE               sizeof(*cur_salt)
-#define SALT_ALIGN              sizeof(int)
+#define SALT_ALIGN              sizeof(uint64_t)
 #define PLAINTEXT_LENGTH        55
 #define KERNEL_NAME             "pbkdf2_sha256_kernel"
 #define SPLIT_KERNEL_NAME       "pbkdf2_sha256_loop"

Patch for zip-opencl format,

diff --git a/src/opencl_zip_fmt_plug.c b/src/opencl_zip_fmt_plug.c
index b554bf294..75ab4776f 100644
--- a/src/opencl_zip_fmt_plug.c
+++ b/src/opencl_zip_fmt_plug.c
@@ -81,7 +81,7 @@ typedef struct my_salt_t {
 
 static my_salt *saved_salt;
 
-static unsigned char (*crypt_key)[WINZIP_BINARY_SIZE];
+static unsigned char (*crypt_key)[((WINZIP_BINARY_SIZE + 4)/4)*4]; // ensure 32-bit alignment
 
 static cl_int cl_error;
 static zip_password *inbuffer;

After these patches only the -enc alignment problem remains.

<!-- gh-comment-id:346922180 --> @kholia commented on GitHub (Nov 25, 2017): Patch for `raw-md5-opencl` format, ``` diff diff --git a/src/opencl_rawmd5_fmt_plug.c b/src/opencl_rawmd5_fmt_plug.c index cac75d69c..179ab009f 100644 --- a/src/opencl_rawmd5_fmt_plug.c +++ b/src/opencl_rawmd5_fmt_plug.c @@ -43,7 +43,7 @@ john_register_one(&FMT_STRUCT); #define CIPHERTEXT_LENGTH 32 #define DIGEST_SIZE 16 #define BINARY_SIZE 16 -#define BINARY_ALIGN 1 +#define BINARY_ALIGN sizeof(uint32_t) #define SALT_SIZE 0 #define SALT_ALIGN 1 ``` Patch for `ethereum-opencl` format, ``` diff diff --git a/src/opencl_ethereum_fmt_plug.c b/src/opencl_ethereum_fmt_plug.c index b2e1b3e57..cc925fc91 100644 --- a/src/opencl_ethereum_fmt_plug.c +++ b/src/opencl_ethereum_fmt_plug.c @@ -34,7 +34,7 @@ john_register_one(&fmt_opencl_ethereum); #define MAX_KEYS_PER_CRYPT 1 #define BINARY_ALIGN sizeof(uint32_t) #define SALT_SIZE sizeof(*cur_salt) -#define SALT_ALIGN sizeof(int) +#define SALT_ALIGN sizeof(uint64_t) #define PLAINTEXT_LENGTH 55 #define KERNEL_NAME "pbkdf2_sha256_kernel" #define SPLIT_KERNEL_NAME "pbkdf2_sha256_loop" ``` Patch for `zip-opencl` format, ``` diff diff --git a/src/opencl_zip_fmt_plug.c b/src/opencl_zip_fmt_plug.c index b554bf294..75ab4776f 100644 --- a/src/opencl_zip_fmt_plug.c +++ b/src/opencl_zip_fmt_plug.c @@ -81,7 +81,7 @@ typedef struct my_salt_t { static my_salt *saved_salt; -static unsigned char (*crypt_key)[WINZIP_BINARY_SIZE]; +static unsigned char (*crypt_key)[((WINZIP_BINARY_SIZE + 4)/4)*4]; // ensure 32-bit alignment static cl_int cl_error; static zip_password *inbuffer; ``` After these patches only the `-enc` alignment problem remains.
Author
Owner

@jfoug commented on GitHub (Nov 25, 2017):

I think we still need to fix alignment problems for -enc= options, and one or two OpenCL formats.

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.

<!-- gh-comment-id:346938255 --> @jfoug commented on GitHub (Nov 25, 2017): > I think we still need to fix alignment problems for -enc= options, and one or two OpenCL formats. 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.
Author
Owner

@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.

<!-- gh-comment-id:346940846 --> @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.
Author
Owner

@jfoug commented on GitHub (Nov 29, 2017):

ghost@localhost src]$ ../run/john -test-full=0 | grep -v PASS
Will run 2 OpenMP threads
tacacs_plus_fmt_plug.c:220:36: runtime error: member access within misaligned address 0x0000031902f4 for type 'struct custom_salt', which requires 8 byte alignment
0x0000031902f4: note: pointer points here
  78 df 36 ee 06 00 00 00  01 23 45 67 89 ab cd ef  fe dc ba 98 76 54 32 10  20 00 00 00 00 00 00 00
              ^ 
tacacs_plus_fmt_plug.c:224:33: runtime error: member access within misaligned address 0x0000031902f4 for type 'struct custom_salt', which requires 8 byte alignment
0x0000031902f4: note: pointer points here
  78 df 36 ee 06 00 00 00  01 23 45 67 89 ab cd ef  fe dc ba 98 76 54 32 10  20 00 00 00 00 00 00 00
              ^ 
tacacs_plus_fmt_plug.c:231:40: runtime error: member access within misaligned address 0x0000031902f4 for type 'struct custom_salt', which requires 8 byte alignment
0x0000031902f4: note: pointer points here
  78 df 36 ee 06 00 00 00  01 23 45 67 89 ab cd ef  fe dc ba 98 76 54 32 10  20 00 00 00 00 00 00 00
              ^ 
<!-- gh-comment-id:347924899 --> @jfoug commented on GitHub (Nov 29, 2017): ``` ghost@localhost src]$ ../run/john -test-full=0 | grep -v PASS Will run 2 OpenMP threads tacacs_plus_fmt_plug.c:220:36: runtime error: member access within misaligned address 0x0000031902f4 for type 'struct custom_salt', which requires 8 byte alignment 0x0000031902f4: note: pointer points here 78 df 36 ee 06 00 00 00 01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10 20 00 00 00 00 00 00 00 ^ tacacs_plus_fmt_plug.c:224:33: runtime error: member access within misaligned address 0x0000031902f4 for type 'struct custom_salt', which requires 8 byte alignment 0x0000031902f4: note: pointer points here 78 df 36 ee 06 00 00 00 01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10 20 00 00 00 00 00 00 00 ^ tacacs_plus_fmt_plug.c:231:40: runtime error: member access within misaligned address 0x0000031902f4 for type 'struct custom_salt', which requires 8 byte alignment 0x0000031902f4: note: pointer points here 78 df 36 ee 06 00 00 00 01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10 20 00 00 00 00 00 00 00 ^ ```
Author
Owner

@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!

<!-- gh-comment-id:347925403 --> @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!
Author
Owner

@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.

<!-- gh-comment-id:347926292 --> @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.
Author
Owner

@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.

<!-- gh-comment-id:347927048 --> @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.
Author
Owner

@kholia commented on GitHub (Nov 29, 2017):

BUT I was not able to get the unaligned checks added along with the existing UBSan testing.

Same experience here. That is why I disabled the existing UBSan checks and only enabled alignment checks in my hacky alignment branch.

I agree that we need two configure options (--enable-ubsan and --enable-ubsanalign). Can we come up with a better name than --enable-ubsanalign though? Naming is really hard ;)

<!-- gh-comment-id:347928129 --> @kholia commented on GitHub (Nov 29, 2017): > BUT I was not able to get the unaligned checks added along with the existing UBSan testing. Same experience here. That is why I disabled the existing UBSan checks and only enabled alignment checks in my hacky `alignment` branch. I agree that we need two configure options (--enable-ubsan and --enable-ubsanalign). Can we come up with a better name than `--enable-ubsanalign` though? Naming is really hard ;)
Author
Owner

@jfoug commented on GitHub (Nov 29, 2017):

Already checked in with --enable-ubsanalign NOTE, I am not sure that --enable-ubsan is 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.

<!-- gh-comment-id:347933018 --> @jfoug commented on GitHub (Nov 29, 2017): Already checked in with ```--enable-ubsanalign``` NOTE, I am not sure that ```--enable-ubsan``` is 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.
Author
Owner

@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.

<!-- gh-comment-id:347933511 --> @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.
Author
Owner

@kholia commented on GitHub (Dec 6, 2017):

Update: Only the -enc alignment problem remains now.

<!-- gh-comment-id:349606292 --> @kholia commented on GitHub (Dec 6, 2017): Update: Only the `-enc` alignment problem remains now.
Author
Owner

@jfoug commented on GitHub (Dec 6, 2017):

is that the rar format?

<!-- gh-comment-id:349614782 --> @jfoug commented on GitHub (Dec 6, 2017): is that the rar format?
Author
Owner

@jfoug commented on GitHub (Dec 6, 2017):

finally figured out stack dumping for ubsan. Here is where we are at with rar:

$ ../run/john -test-full=0 -form=rar -enc=utf8
Will run 2 OpenMP threads
Testing: rar, RAR3 (4 characters) [SHA1 256/256 AVX2 8x AES] in UTF-8 mode... (2xOMP) unrarppm.c:55:32: runtime error: member access within misaligned address 0x7f5d70822484 for type 'struct rar_node', which requires 8 byte alignment
0x7f5d70822484: note: pointer points here
  00 00 00 00 06 18 ca 6f  5d 7f 00 00 c9 02 11 18  ca 6f 5d 7f 00 00 a5 02  00 00 00 00 06 18 ca 6f
              ^ 
    #0 0x6d8e0c in sub_allocator_insert_node /home/ghost/JtR/b64/src/unrarppm.c:55
    #1 0x6e291e in sub_allocator_expand_units /home/ghost/JtR/b64/src/unrarppm.c:298
    #2 0x6e3ddb in update_model /home/ghost/JtR/b64/src/unrarppm.c:698
    #3 0x6e48b6 in ppm_decode_char /home/ghost/JtR/b64/src/unrarppm.c:1038
    #4 0x6d7551 in rar_unpack29 /home/ghost/JtR/b64/src/unrar.c:988
    #5 0x94797e in check_rar._omp_fn.1 /home/ghost/JtR/b64/src/rar_common.c:614
    #6 0x7f5d832b918e in GOMP_parallel (/lib64/libgomp.so.1+0xe18e)
    #7 0x946ce5 in check_rar /home/ghost/JtR/b64/src/rar_common.c:529
    #8 0x946ce5 in crypt_all /home/ghost/JtR/b64/src/rar_fmt_plug.c:383
    #9 0xa2bbf6 in is_key_right /home/ghost/JtR/b64/src/formats.c:211
    #10 0xa3303c in fmt_self_test_body /home/ghost/JtR/b64/src/formats.c:915
    #11 0xa34a8d in fmt_self_test /home/ghost/JtR/b64/src/formats.c:1675
    #12 0xa02f92 in benchmark_format /home/ghost/JtR/b64/src/bench.c:367
    #13 0xa05c44 in benchmark_all /home/ghost/JtR/b64/src/bench.c:816
    #14 0xa464e8 in john_run /home/ghost/JtR/b64/src/john.c:1613
    #15 0xa48019 in main /home/ghost/JtR/b64/src/john.c:1996
    #16 0x7f5d81fd5730 in __libc_start_main (/lib64/libc.so.6+0x20730)
    #17 0x405ea8 in _start (/home/ghost/JtR/b64/run/john+0x405ea8)

unrarppm.c:64:43: runtime error: member access within misaligned address 0x7f5d6ac1f484 for type 'struct rar_node', which requires 8 byte alignment
0x7f5d6ac1f484: note: pointer points here
  00 00 00 00 00 00 00 00  00 00 00 00 c9 02 11 e8  09 6a 5d 7f 00 00 a5 02  00 00 00 00 06 e8 09 6a
              ^ 
    #0 0x6d8ef1 in sub_allocator_remove_node /home/ghost/JtR/b64/src/unrarppm.c:64
    #1 0x6da67b in sub_allocator_alloc_units /home/ghost/JtR/b64/src/unrarppm.c:263
    #2 0x6e383b in update_model /home/ghost/JtR/b64/src/unrarppm.c:706
    #3 0x6e48b6 in ppm_decode_char /home/ghost/JtR/b64/src/unrarppm.c:1038
    #4 0x6d7551 in rar_unpack29 /home/ghost/JtR/b64/src/unrar.c:988
    #5 0x94797e in check_rar._omp_fn.1 /home/ghost/JtR/b64/src/rar_common.c:614
    #6 0x7f5d832c1dd5  (/lib64/libgomp.so.1+0x16dd5)
    #7 0x7f5d8237e5c9 in start_thread (/lib64/libpthread.so.0+0x75c9)
    #8 0x7f5d820b7f6c in __clone (/lib64/libc.so.6+0x102f6c)

PASS
<!-- gh-comment-id:349630750 --> @jfoug commented on GitHub (Dec 6, 2017): finally figured out stack dumping for ubsan. Here is where we are at with rar: ``` $ ../run/john -test-full=0 -form=rar -enc=utf8 Will run 2 OpenMP threads Testing: rar, RAR3 (4 characters) [SHA1 256/256 AVX2 8x AES] in UTF-8 mode... (2xOMP) unrarppm.c:55:32: runtime error: member access within misaligned address 0x7f5d70822484 for type 'struct rar_node', which requires 8 byte alignment 0x7f5d70822484: note: pointer points here 00 00 00 00 06 18 ca 6f 5d 7f 00 00 c9 02 11 18 ca 6f 5d 7f 00 00 a5 02 00 00 00 00 06 18 ca 6f ^ #0 0x6d8e0c in sub_allocator_insert_node /home/ghost/JtR/b64/src/unrarppm.c:55 #1 0x6e291e in sub_allocator_expand_units /home/ghost/JtR/b64/src/unrarppm.c:298 #2 0x6e3ddb in update_model /home/ghost/JtR/b64/src/unrarppm.c:698 #3 0x6e48b6 in ppm_decode_char /home/ghost/JtR/b64/src/unrarppm.c:1038 #4 0x6d7551 in rar_unpack29 /home/ghost/JtR/b64/src/unrar.c:988 #5 0x94797e in check_rar._omp_fn.1 /home/ghost/JtR/b64/src/rar_common.c:614 #6 0x7f5d832b918e in GOMP_parallel (/lib64/libgomp.so.1+0xe18e) #7 0x946ce5 in check_rar /home/ghost/JtR/b64/src/rar_common.c:529 #8 0x946ce5 in crypt_all /home/ghost/JtR/b64/src/rar_fmt_plug.c:383 #9 0xa2bbf6 in is_key_right /home/ghost/JtR/b64/src/formats.c:211 #10 0xa3303c in fmt_self_test_body /home/ghost/JtR/b64/src/formats.c:915 #11 0xa34a8d in fmt_self_test /home/ghost/JtR/b64/src/formats.c:1675 #12 0xa02f92 in benchmark_format /home/ghost/JtR/b64/src/bench.c:367 #13 0xa05c44 in benchmark_all /home/ghost/JtR/b64/src/bench.c:816 #14 0xa464e8 in john_run /home/ghost/JtR/b64/src/john.c:1613 #15 0xa48019 in main /home/ghost/JtR/b64/src/john.c:1996 #16 0x7f5d81fd5730 in __libc_start_main (/lib64/libc.so.6+0x20730) #17 0x405ea8 in _start (/home/ghost/JtR/b64/run/john+0x405ea8) unrarppm.c:64:43: runtime error: member access within misaligned address 0x7f5d6ac1f484 for type 'struct rar_node', which requires 8 byte alignment 0x7f5d6ac1f484: note: pointer points here 00 00 00 00 00 00 00 00 00 00 00 00 c9 02 11 e8 09 6a 5d 7f 00 00 a5 02 00 00 00 00 06 e8 09 6a ^ #0 0x6d8ef1 in sub_allocator_remove_node /home/ghost/JtR/b64/src/unrarppm.c:64 #1 0x6da67b in sub_allocator_alloc_units /home/ghost/JtR/b64/src/unrarppm.c:263 #2 0x6e383b in update_model /home/ghost/JtR/b64/src/unrarppm.c:706 #3 0x6e48b6 in ppm_decode_char /home/ghost/JtR/b64/src/unrarppm.c:1038 #4 0x6d7551 in rar_unpack29 /home/ghost/JtR/b64/src/unrar.c:988 #5 0x94797e in check_rar._omp_fn.1 /home/ghost/JtR/b64/src/rar_common.c:614 #6 0x7f5d832c1dd5 (/lib64/libgomp.so.1+0x16dd5) #7 0x7f5d8237e5c9 in start_thread (/lib64/libpthread.so.0+0x75c9) #8 0x7f5d820b7f6c in __clone (/lib64/libc.so.6+0x102f6c) PASS ```
Author
Owner

@jfoug commented on GitHub (Dec 6, 2017):

Btw, if you do not have stack dumping on UBSan, to do it:

apt-get install -y llvm-symbolizer
export UBSAN_OPTIONS=print_stacktrace=1
<!-- gh-comment-id:349631211 --> @jfoug commented on GitHub (Dec 6, 2017): Btw, if you do not have stack dumping on UBSan, to do it: ```sh apt-get install -y llvm-symbolizer export UBSAN_OPTIONS=print_stacktrace=1 ```
Author
Owner

@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.

diff --git a/src/unrarppm.c b/src/unrarppm.c
index ad71050..f4c4fd6 100644
--- a/src/unrarppm.c
+++ b/src/unrarppm.c
@@ -52,7 +52,11 @@ static void sub_allocator_init(sub_allocator_t *sub_alloc)
 
 static void sub_allocator_insert_node(sub_allocator_t *sub_alloc, void *p, int indx)
 {
+#if ARCH_ALLOWS_UNALIGNED
        ((struct rar_node *) p)->next = sub_alloc->free_list[indx].next;
+#else
+       memcpy(&(((struct rar_node *) p)->next), &(sub_alloc->free_list[indx].next), sizeof(sub_alloc->free_list[indx].next));
+#endif
        sub_alloc->free_list[indx].next = (struct rar_node *) p;
 }
 
@@ -61,7 +65,11 @@ static void *sub_allocator_remove_node(sub_allocator_t *sub_alloc, int indx)
        struct rar_node *ret_val;
 
        ret_val = sub_alloc->free_list[indx].next;
+#if ARCH_ALLOWS_UNALIGNED
        sub_alloc->free_list[indx].next = ret_val->next;
+#else
+       memcpy(&(sub_alloc->free_list[indx].next), &(ret_val->next), sizeof(ret_val->next));
+#endif
        return ret_val;
 }

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.

<!-- gh-comment-id:349657708 --> @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. ```diff diff --git a/src/unrarppm.c b/src/unrarppm.c index ad71050..f4c4fd6 100644 --- a/src/unrarppm.c +++ b/src/unrarppm.c @@ -52,7 +52,11 @@ static void sub_allocator_init(sub_allocator_t *sub_alloc) static void sub_allocator_insert_node(sub_allocator_t *sub_alloc, void *p, int indx) { +#if ARCH_ALLOWS_UNALIGNED ((struct rar_node *) p)->next = sub_alloc->free_list[indx].next; +#else + memcpy(&(((struct rar_node *) p)->next), &(sub_alloc->free_list[indx].next), sizeof(sub_alloc->free_list[indx].next)); +#endif sub_alloc->free_list[indx].next = (struct rar_node *) p; } @@ -61,7 +65,11 @@ static void *sub_allocator_remove_node(sub_allocator_t *sub_alloc, int indx) struct rar_node *ret_val; ret_val = sub_alloc->free_list[indx].next; +#if ARCH_ALLOWS_UNALIGNED sub_alloc->free_list[indx].next = ret_val->next; +#else + memcpy(&(sub_alloc->free_list[indx].next), &(ret_val->next), sizeof(ret_val->next)); +#endif return ret_val; } ``` 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.
Author
Owner

@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.

<!-- gh-comment-id:349697888 --> @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.
Author
Owner

@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.

[ghost@localhost src]$ git diff
diff --git a/src/rar_fmt_plug.c b/src/rar_fmt_plug.c
index b786f63..7dfe592 100644
--- a/src/rar_fmt_plug.c
+++ b/src/rar_fmt_plug.c
@@ -42,9 +42,13 @@
  */
 
 #if FMT_EXTERNS_H
+#if ARCH_ALLOWS_UNALIGNED
 extern struct fmt_main fmt_rar;
+#endif
 #elif FMT_REGISTERS_H
+#if ARCH_ALLOWS_UNALIGNED
 john_register_one(&fmt_rar);
+#endif
 #else
 
 #include <string.h>
<!-- gh-comment-id:349712940 --> @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. ```diff [ghost@localhost src]$ git diff diff --git a/src/rar_fmt_plug.c b/src/rar_fmt_plug.c index b786f63..7dfe592 100644 --- a/src/rar_fmt_plug.c +++ b/src/rar_fmt_plug.c @@ -42,9 +42,13 @@ */ #if FMT_EXTERNS_H +#if ARCH_ALLOWS_UNALIGNED extern struct fmt_main fmt_rar; +#endif #elif FMT_REGISTERS_H +#if ARCH_ALLOWS_UNALIGNED john_register_one(&fmt_rar); +#endif #else #include <string.h> ```
Author
Owner

@frank-dittrich commented on GitHub (Dec 6, 2017):

Can you add a preprocessor warning for the disabled format?

<!-- gh-comment-id:349725259 --> @frank-dittrich commented on GitHub (Dec 6, 2017): Can you add a preprocessor warning for the disabled format?
Author
Owner

@frank-dittrich commented on GitHub (Dec 6, 2017):

E.g., something similar to this:

$ git diff rar_fmt_plug.c
diff --git a/src/rar_fmt_plug.c b/src/rar_fmt_plug.c
index b786f63..81d08e2 100644
--- a/src/rar_fmt_plug.c
+++ b/src/rar_fmt_plug.c
@@ -41,6 +41,7 @@
  *
  */
 
+#if ARCH_ALLOWS_UNALIGNED
 #if FMT_EXTERNS_H
 extern struct fmt_main fmt_rar;
 #elif FMT_REGISTERS_H
@@ -434,3 +435,6 @@ struct fmt_main fmt_rar = {
 };
 
 #endif /* plugin stanza */
+#else
+#pragma message(": target system requires aligned memory access, rar format disabled:")
+#endif

Update:

To avoid two warnings, the last change needs to be before the

#endif /* plugin stanza */
<!-- gh-comment-id:349727495 --> @frank-dittrich commented on GitHub (Dec 6, 2017): E.g., something similar to this: ```diff $ git diff rar_fmt_plug.c diff --git a/src/rar_fmt_plug.c b/src/rar_fmt_plug.c index b786f63..81d08e2 100644 --- a/src/rar_fmt_plug.c +++ b/src/rar_fmt_plug.c @@ -41,6 +41,7 @@ * */ +#if ARCH_ALLOWS_UNALIGNED #if FMT_EXTERNS_H extern struct fmt_main fmt_rar; #elif FMT_REGISTERS_H @@ -434,3 +435,6 @@ struct fmt_main fmt_rar = { }; #endif /* plugin stanza */ +#else +#pragma message(": target system requires aligned memory access, rar format disabled:") +#endif ``` Update: To avoid two warnings, the last change needs to be before the ``` #endif /* plugin stanza */ ```
Author
Owner

@jfoug commented on GitHub (Dec 6, 2017):

Can you add a preprocessor warning for the disabled format?

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:

#else
#include "some_helper.h"
PRAGMA_WARN("msg")
#endif

and the macro PRAGMA_WARN would take care of any nuanced differences.
<!-- gh-comment-id:349730164 --> @jfoug commented on GitHub (Dec 6, 2017): > Can you add a preprocessor warning for the disabled format? 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: ```c #else #include "some_helper.h" PRAGMA_WARN("msg") #endif and the macro PRAGMA_WARN would take care of any nuanced differences.
Author
Owner

@frank-dittrich commented on GitHub (Dec 6, 2017):

And then there is also -fsanitize=undefined -fsanitize-undefined-trap-on-error instead of just -fsanitize=undefined:

$ export LC_ALL=C; ../run/john --test=0 --format=r*
Testing: RACF [DES 32/64]... PASS
Testing: RAdmin, v2.x [MD5 32/64]... PASS
Testing: RAKP, IPMI 2.0 RAKP (RMCP+) [HMAC-SHA1 128/128 AVX 4x2]... PASS
Testing: rar, RAR3 (4 characters) [SHA1 128/128 AVX 4x2 AES]... Illegal instruction (core dumped)
<!-- gh-comment-id:349734755 --> @frank-dittrich commented on GitHub (Dec 6, 2017): And then there is also `-fsanitize=undefined -fsanitize-undefined-trap-on-error` instead of just `-fsanitize=undefined`: ``` $ export LC_ALL=C; ../run/john --test=0 --format=r* Testing: RACF [DES 32/64]... PASS Testing: RAdmin, v2.x [MD5 32/64]... PASS Testing: RAKP, IPMI 2.0 RAKP (RMCP+) [HMAC-SHA1 128/128 AVX 4x2]... PASS Testing: rar, RAR3 (4 characters) [SHA1 128/128 AVX 4x2 AES]... Illegal instruction (core dumped) ```
Author
Owner

@jfoug commented on GitHub (Dec 6, 2017):

Did that make it back into configure, grrr.

<!-- gh-comment-id:349741125 --> @jfoug commented on GitHub (Dec 6, 2017): Did that make it back into configure, grrr.
Author
Owner

@jfoug commented on GitHub (Dec 6, 2017):

@frank-dittrich if you are saying that -fsanitize-undefined-trap-on-error has 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.

<!-- gh-comment-id:349747112 --> @jfoug commented on GitHub (Dec 6, 2017): @frank-dittrich if you are saying that ```-fsanitize-undefined-trap-on-error``` has 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.
Author
Owner

@kholia commented on GitHub (Dec 6, 2017):

Yes, -fsanitize-undefined-trap-on-error produces undesirable results. Let's not introduce it back.

<!-- gh-comment-id:349748332 --> @kholia commented on GitHub (Dec 6, 2017): Yes, `-fsanitize-undefined-trap-on-error` produces undesirable results. Let's not introduce it back.
Author
Owner

@magnumripper commented on GitHub (Dec 6, 2017):

What are others opinions about simply disabling rar for now on a alignment-required build?

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.

<!-- gh-comment-id:349761105 --> @magnumripper commented on GitHub (Dec 6, 2017): > What are others opinions about simply disabling rar for now on a alignment-required build? 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.
Author
Owner

@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,

$ export LC_ALL=C; ./john --test=0 --format=ra*
Testing: RACF [DES 32/64]... PASS
Testing: RAdmin, v2.x [MD5 32/64]... PASS
Testing: RAKP, IPMI 2.0 RAKP (RMCP+) [HMAC-SHA1 128/128 AVX 4x2]... PASS
Testing: rar, RAR3 (4 characters) [SHA1 128/128 AVX 4x2 AES]... Illegal instruction (core dumped)
$ echo $?
132

is easier than

$ export LC_ALL=C; ./john --test=0 --format=ra*
Testing: RACF [DES 32/64]... PASS
Testing: RAdmin, v2.x [MD5 32/64]... PASS
Testing: RAKP, IPMI 2.0 RAKP (RMCP+) [HMAC-SHA1 128/128 AVX 4x2]... PASS
Testing: rar, RAR3 (4 characters) [SHA1 128/128 AVX 4x2 AES]... unrar.c:361:4: runtime error: index 6 out of bounds for type 'unsigned int [2]'
unrar.c:442:9: runtime error: index 3 out of bounds for type 'unsigned int [2]'
PASS
Testing: RAR5 [PBKDF2-SHA256 128/128 AVX 4x]... PASS
Testing: Raw-SHA512 [SHA512 128/128 AVX 2x]... PASS
Testing: Raw-Blake2 [BLAKE2b 512 128/128 AVX]... PASS
Testing: Raw-Keccak [Keccak 512 32/64]... PASS
Testing: Raw-Keccak-256 [Keccak 256 32/64]... PASS
Testing: Raw-MD4 [MD4 128/128 AVX 4x4]... PASS
Testing: Raw-MD5 [MD5 128/128 AVX 4x5]... PASS
Testing: Raw-MD5u [md5(utf16($p)) 128/128 AVX 4x5]... PASS
Testing: Raw-SHA1 [SHA1 128/128 AVX 4x2]... PASS
Testing: Raw-SHA1-AxCrypt [SHA1 128/128 AVX 4x2]... PASS
Testing: Raw-SHA1-Linkedin [SHA1 128/128 AVX 4x2]... PASS
Testing: Raw-SHA224 [SHA224 128/128 AVX 4x]... PASS
Testing: Raw-SHA256 [SHA256 128/128 AVX 4x]... PASS
Testing: Raw-SHA256-ng [SHA256 128/128 SSE4.1 4x]... PASS
Testing: Raw-SHA3 [SHA3 512 32/64]... PASS
Testing: Raw-SHA384 [SHA384 128/128 AVX 2x]... PASS
Testing: Raw-SHA512-ng [SHA512 128/128 SSSE3 2x]... PASS
Testing: Raw-SHA1-ng, (pwlen <= 15) [SHA1 128/128 AVX 4x]... PASS
All 22 formats passed self-tests!
$ echo $?
0

(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.)

<!-- gh-comment-id:349767857 --> @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, ``` $ export LC_ALL=C; ./john --test=0 --format=ra* Testing: RACF [DES 32/64]... PASS Testing: RAdmin, v2.x [MD5 32/64]... PASS Testing: RAKP, IPMI 2.0 RAKP (RMCP+) [HMAC-SHA1 128/128 AVX 4x2]... PASS Testing: rar, RAR3 (4 characters) [SHA1 128/128 AVX 4x2 AES]... Illegal instruction (core dumped) $ echo $? 132 ``` is easier than ``` $ export LC_ALL=C; ./john --test=0 --format=ra* Testing: RACF [DES 32/64]... PASS Testing: RAdmin, v2.x [MD5 32/64]... PASS Testing: RAKP, IPMI 2.0 RAKP (RMCP+) [HMAC-SHA1 128/128 AVX 4x2]... PASS Testing: rar, RAR3 (4 characters) [SHA1 128/128 AVX 4x2 AES]... unrar.c:361:4: runtime error: index 6 out of bounds for type 'unsigned int [2]' unrar.c:442:9: runtime error: index 3 out of bounds for type 'unsigned int [2]' PASS Testing: RAR5 [PBKDF2-SHA256 128/128 AVX 4x]... PASS Testing: Raw-SHA512 [SHA512 128/128 AVX 2x]... PASS Testing: Raw-Blake2 [BLAKE2b 512 128/128 AVX]... PASS Testing: Raw-Keccak [Keccak 512 32/64]... PASS Testing: Raw-Keccak-256 [Keccak 256 32/64]... PASS Testing: Raw-MD4 [MD4 128/128 AVX 4x4]... PASS Testing: Raw-MD5 [MD5 128/128 AVX 4x5]... PASS Testing: Raw-MD5u [md5(utf16($p)) 128/128 AVX 4x5]... PASS Testing: Raw-SHA1 [SHA1 128/128 AVX 4x2]... PASS Testing: Raw-SHA1-AxCrypt [SHA1 128/128 AVX 4x2]... PASS Testing: Raw-SHA1-Linkedin [SHA1 128/128 AVX 4x2]... PASS Testing: Raw-SHA224 [SHA224 128/128 AVX 4x]... PASS Testing: Raw-SHA256 [SHA256 128/128 AVX 4x]... PASS Testing: Raw-SHA256-ng [SHA256 128/128 SSE4.1 4x]... PASS Testing: Raw-SHA3 [SHA3 512 32/64]... PASS Testing: Raw-SHA384 [SHA384 128/128 AVX 2x]... PASS Testing: Raw-SHA512-ng [SHA512 128/128 SSSE3 2x]... PASS Testing: Raw-SHA1-ng, (pwlen <= 15) [SHA1 128/128 AVX 4x]... PASS All 22 formats passed self-tests! $ echo $? 0 ``` (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.)
Author
Owner

@jfoug commented on GitHub (Dec 6, 2017):

it's almost certainly written without the slightest care for non-x86.

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.

<!-- gh-comment-id:349776253 --> @jfoug commented on GitHub (Dec 6, 2017): > it's almost certainly written without the slightest care for non-x86. 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.
Author
Owner

@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

<!-- gh-comment-id:349777466 --> @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
Author
Owner

@frank-dittrich commented on GitHub (Dec 6, 2017):

@jfoug

Btw, if you do not have stack dumping on UBSan, to do it:

apt-get install -y llvm-symbolizer
export UBSAN_OPTIONS=print_stacktrace=1

Doesn't work on ubuntu 16.04:

# apt-get install -y llvm-symbolizer
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package llvm-symbolizer
# apt install llvm-symbolizer
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package llvm-symbolizer

What distribution do you have?

<!-- gh-comment-id:349813530 --> @frank-dittrich commented on GitHub (Dec 6, 2017): @jfoug > Btw, if you do not have stack dumping on UBSan, to do it: ```sh apt-get install -y llvm-symbolizer export UBSAN_OPTIONS=print_stacktrace=1 ``` Doesn't work on ubuntu 16.04: ``` # apt-get install -y llvm-symbolizer Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package llvm-symbolizer # apt install llvm-symbolizer Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package llvm-symbolizer ``` What distribution do you have?
Author
Owner

@ghost commented on GitHub (Dec 6, 2017):

Just taking note:

Testing: Citrix_NS10, Netscaler 10 [SHA1 256/256 AVX2 8x2]... (2xOMP) citrix_ns_fmt_plug.c:211:4: runtime error: index 1027 out of bounds for type 'unsigned char [1024]'
PASS
Testing: rar, RAR3 (4 characters) [SHA1 256/256 AVX2 8x2 AES]... (2xOMP) unrar.c:361:4: runtime error: index 6 out of bounds for type 'unsigned int [2]'
unrar.c:442:9: runtime error: index 3 out of bounds for type 'unsigned int [2]'
PASS
Testing: rar-opencl, RAR3 (length 4) [SHA1 OpenCL AES]... (2xOMP) unrar.c:361:4: runtime error: index 6 out of bounds for type 'unsigned int [2]'
unrar.c:442:9: runtime error: index 3 out of bounds for type 'unsigned int [2]'
PASS
Testing: LM-opencl [DES BS OpenCL]... opencl_lm_plug.c:227:30: runtime error: left shift of 193 by 24 places cannot be represented in type 'int'
opencl_lm_plug.c:210:23: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
opencl_lm_plug.c:209:25: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
PASS
<!-- gh-comment-id:349814897 --> @ghost commented on GitHub (Dec 6, 2017): Just taking note: ``` Testing: Citrix_NS10, Netscaler 10 [SHA1 256/256 AVX2 8x2]... (2xOMP) citrix_ns_fmt_plug.c:211:4: runtime error: index 1027 out of bounds for type 'unsigned char [1024]' PASS Testing: rar, RAR3 (4 characters) [SHA1 256/256 AVX2 8x2 AES]... (2xOMP) unrar.c:361:4: runtime error: index 6 out of bounds for type 'unsigned int [2]' unrar.c:442:9: runtime error: index 3 out of bounds for type 'unsigned int [2]' PASS Testing: rar-opencl, RAR3 (length 4) [SHA1 OpenCL AES]... (2xOMP) unrar.c:361:4: runtime error: index 6 out of bounds for type 'unsigned int [2]' unrar.c:442:9: runtime error: index 3 out of bounds for type 'unsigned int [2]' PASS Testing: LM-opencl [DES BS OpenCL]... opencl_lm_plug.c:227:30: runtime error: left shift of 193 by 24 places cannot be represented in type 'int' opencl_lm_plug.c:210:23: runtime error: left shift of 1 by 31 places cannot be represented in type 'int' opencl_lm_plug.c:209:25: runtime error: left shift of 1 by 31 places cannot be represented in type 'int' PASS ```
Author
Owner

@frank-dittrich commented on GitHub (Dec 7, 2017):

Looks like ubuntu 16.04 has llvm-symbolizer installed:

# ls -l /usr/bin/llvm-symbolizer-3.8 
lrwxrwxrwx 1 root root 35 Jul 12  2016 /usr/bin/llvm-symbolizer-3.8 -> ../lib/llvm-3.8/bin/llvm-symbolizer

But export UBSAN_OPTIONS=print_stacktrace=1 didn'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

<!-- gh-comment-id:349816255 --> @frank-dittrich commented on GitHub (Dec 7, 2017): Looks like ubuntu 16.04 has llvm-symbolizer installed: ``` # ls -l /usr/bin/llvm-symbolizer-3.8 lrwxrwxrwx 1 root root 35 Jul 12 2016 /usr/bin/llvm-symbolizer-3.8 -> ../lib/llvm-3.8/bin/llvm-symbolizer ``` But `export UBSAN_OPTIONS=print_stacktrace=1` didn'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
Author
Owner

@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 ;)

<!-- gh-comment-id:349819500 --> @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 ;)
Author
Owner

@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

<!-- gh-comment-id:349819993 --> @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
Author
Owner

@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).

<!-- gh-comment-id:349823903 --> @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).
Author
Owner

@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.

<!-- gh-comment-id:349824323 --> @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.
Author
Owner

@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.

<!-- gh-comment-id:349898566 --> @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.
Author
Owner

@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.

<!-- gh-comment-id:350009395 --> @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.
Author
Owner

@jfoug commented on GitHub (Dec 7, 2017):

New configure: 28bf52d2e

With trap, the configure status shows:

Development options (these may hurt performance when enabled):
Memdbg memory debugging settings ........... disabled
AddressSanitizer ("ASan") .................. enabled
UndefinedBehaviorSanitizer ("UbSan") ....... enabled (trap)
Fuzzing test ............................... no
Experimental code .......................... no
<!-- gh-comment-id:350130317 --> @jfoug commented on GitHub (Dec 7, 2017): New configure: 28bf52d2e With trap, the configure status shows: ``` Development options (these may hurt performance when enabled): Memdbg memory debugging settings ........... disabled AddressSanitizer ("ASan") .................. enabled UndefinedBehaviorSanitizer ("UbSan") ....... enabled (trap) Fuzzing test ............................... no Experimental code .......................... no ```
Author
Owner

@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 likerar-opencl on req-alignment and lm-opencl still have issues.

rar-opencl should probably just be disabled (like the CPU version, unless it also does rar5). I have no idea about the lm-opencl code.

<!-- gh-comment-id:350131287 --> @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-opencl` on req-alignment and `lm-opencl` still have issues. `rar-opencl` should probably just be disabled (like the CPU version, unless it also does rar5). I have no idea about the `lm-opencl` code.
Author
Owner

@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.

<!-- gh-comment-id:355941018 --> @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.
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#1822
No description provided.