[GH-ISSUE #2908] Enable alignment checking within UBSan #1838

Closed
opened 2026-10-15 04:26:19 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @jfoug on GitHub (Nov 20, 2017).
Original GitHub issue: https://github.com/openwall/john/issues/2908

Currently when UBSan is enabled, the alignment sanitizer is disabled. This can be re-enabled.

To do this, we need to change the configure.ac to NOT do -fno-address-sanatizer

Then we add -DARCH_ALLOWS_UNALIGNED=0 to the 'extra CFLAGS (similar to how we add -DWITH_UBSAN to the compile line)

Then change all arch.h file which have ARCH_ALLOWS_UNALIGNED 1 to be this:

#if !defined (ARCH_ALLOWS_UNALIGNED)
#define ARCH_ALLOWS_UNALIGNED 1
#endif

That way, the compiler call will set a forced alignment requirement, and the arch.h will not mess with it.

Bug #2868

Originally created by @jfoug on GitHub (Nov 20, 2017). Original GitHub issue: https://github.com/openwall/john/issues/2908 Currently when UBSan is enabled, the alignment sanitizer is disabled. This can be re-enabled. To do this, we need to change the configure.ac to NOT do -fno-address-sanatizer Then we add -DARCH_ALLOWS_UNALIGNED=0 to the 'extra CFLAGS (similar to how we add -DWITH_UBSAN to the compile line) Then change all arch.h file which have ARCH_ALLOWS_UNALIGNED 1 to be this: #if !defined (ARCH_ALLOWS_UNALIGNED) #define ARCH_ALLOWS_UNALIGNED 1 #endif That way, the compiler call will set a forced alignment requirement, and the arch.h will not mess with it. Bug #2868
bsakaguchi 2026-10-15 04:26:19 +07:00
Author
Owner

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

I tried to simply add the -faddress-sanatizer to the existing configure script. All sorts of runtime problems. But I can run the -faddress-sanitizer all by itself (removing the other UBSan items). I do not have enough knowledge of what was talked about getting the current UBSan params setup. So for now, we have a 'special' hacking way to setup an environment to work with address-sanitizer enabled (but no other UBSan stuff). It will certainly allow us to get john alignment fixed.

BUT we need some way to add this easily, so that once we get john alignment happy that it stays that way.

<!-- gh-comment-id:346438242 --> @jfoug commented on GitHub (Nov 22, 2017): I tried to simply add the -faddress-sanatizer to the existing configure script. All sorts of runtime problems. But I can run the -faddress-sanitizer all by itself (removing the other UBSan items). I do not have enough knowledge of what was talked about getting the current UBSan params setup. So for now, we have a 'special' hacking way to setup an environment to work with address-sanitizer enabled (but no other UBSan stuff). It will certainly allow us to get john alignment fixed. BUT we need some way to add this easily, so that once we get john alignment happy that it stays that way.
Author
Owner

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

NOTE, added a new --enable-ubsanalign The existing --enable-ubsan still does not include alignment tests. --enable-ubsanalign does NOT contain the other ubsan tests. When I tried to add things to the existing ubsan testing, I could not get it working right, so I simply added a new enable.

This --enable-ubsanalign is being used in bug #2868

<!-- gh-comment-id:347932155 --> @jfoug commented on GitHub (Nov 29, 2017): NOTE, added a new --enable-ubsanalign The existing --enable-ubsan still does not include alignment tests. --enable-ubsanalign does NOT contain the other ubsan tests. When I tried to add things to the existing ubsan testing, I could not get it working right, so I simply added a new enable. This --enable-ubsanalign is being used in bug #2868
Author
Owner

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

I believe I can get this all working under --with-ubsan, and get the entire -fsanitize=undefined logic working properly, on a single target.

I had to make a tweek to a few format files (the #pragma omp parallel for had to be reduced to the vanilla version (removing the extra params). This worked fine on 2 formats, but on the 3rd (only 3 had this problem), I was getting builds to work, but testing was failing. this format (mscash2) I will simply neuter GOMP when I see builds happening WITH_UBSAN set. Not ideal, if there was some undefined behavior happening only in the OMP code, but it is the best I have been able to do so far.

<!-- gh-comment-id:348779761 --> @jfoug commented on GitHub (Dec 3, 2017): I believe I can get this all working under --with-ubsan, and get the entire ```-fsanitize=undefined``` logic working properly, on a single target. I had to make a tweek to a few format files (the ```#pragma omp parallel for``` had to be reduced to the vanilla version (removing the extra params). This worked fine on 2 formats, but on the 3rd (only 3 had this problem), I was getting builds to work, but testing was failing. this format (mscash2) I will simply neuter GOMP when I see builds happening WITH_UBSAN set. Not ideal, if there was some undefined behavior happening only in the OMP code, but it is the best I have been able to do so far.
Author
Owner

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

790768289 This adds full UBSan to a single target.

NOTE, it already has found an undefined item (memcpy(a,b,c) where a was passed a null) just in the testing ;)

This task is now fully completed, and down to a clean single configure enable. NOTE, fully UBSan is pretty damn slow, but that is OK. The branch I had only testing alignment was pretty much same speed as a normal build, but full UBSAN is very noticeably slower.

I did test out that the ubsan stuff was working, by making a change to sapG format (for testing). I set ARCH_ALLOWS_UNALIGNED back to 1, rebuilt, and got several UBSan failures in that format. So things look very good.

Build is error/warning free (had to fix 3 formats to get this), and a --test-full=0 is also UBSan warning free (well, it will be when I get that bug from formats.c fixed).

Closing this issue, it is done!

<!-- gh-comment-id:348786704 --> @jfoug commented on GitHub (Dec 3, 2017): 790768289 This adds full UBSan to a single target. NOTE, it already has found an undefined item (memcpy(a,b,c) where a was passed a null) just in the testing ;) This task is now fully completed, and down to a clean single configure enable. NOTE, fully UBSan is pretty damn slow, but that is OK. The branch I had only testing alignment was pretty much same speed as a normal build, but full UBSAN is very noticeably slower. I did test out that the ubsan stuff was working, by making a change to sapG format (for testing). I set ARCH_ALLOWS_UNALIGNED back to 1, rebuilt, and got several UBSan failures in that format. So things look very good. Build is error/warning free (had to fix 3 formats to get this), and a --test-full=0 is also UBSan warning free (well, it will be when I get that bug from formats.c fixed). Closing this issue, it is done!
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#1838
No description provided.