[GH-ISSUE #1284] KeePass format, "Warning: salt() returned misaligned pointer" for 32bit Linux clang build #809

Closed
opened 2026-10-14 03:24:59 +07:00 by bsakaguchi · 8 comments
Owner

Originally created by @frank-dittrich on GitHub (May 9, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1284

$ ../run/john --test=0 --format=cpu-dynamic | grep -C 1 -v PASS
[...]
Testing: ipb2, Invision Power Board 2.x [MD5 256/256 AVX2 8x4]... PASS
Testing: KeePass [SHA256 AES 32/32 OpenSSL]... Warning: salt() returned misaligned pointer
PASS
[...]

In keepass_fmt_plug.c, SALT_ALIGN is defined as sizeof(long long).

But in get_salt(), we just have static struct custom_salt cs;, i.e., SALT_ALIGN is not used.

But I don't know whether just adding #include "aligned.h" and changing the definition to
JTR_ALIGN(SALT_ALIGN) static struct custom_salt cs; really is the right fix, because of the definiton of custom_salt:

static struct custom_salt {
    int version;
    long long offset;
    int isinline;
    int keyfilesize;
    int have_keyfile;
    int contentsize;
    unsigned char contents[LINE_BUFFER_SIZE];
    unsigned char final_randomseed[32];
    unsigned char enc_iv[16];
    unsigned char keyfile[32];
    unsigned char contents_hash[32];
    unsigned char transf_randomseed[32];
    unsigned char expected_bytes[32];
    uint32_t key_transf_rounds;
    int algorithm; // 1 for Twofish
} *cur_salt;

Wouldn't it make sense to switch version and offset?

Originally created by @frank-dittrich on GitHub (May 9, 2015). Original GitHub issue: https://github.com/openwall/john/issues/1284 ``` $ ../run/john --test=0 --format=cpu-dynamic | grep -C 1 -v PASS [...] Testing: ipb2, Invision Power Board 2.x [MD5 256/256 AVX2 8x4]... PASS Testing: KeePass [SHA256 AES 32/32 OpenSSL]... Warning: salt() returned misaligned pointer PASS [...] ``` In keepass_fmt_plug.c, `SALT_ALIGN` is defined as `sizeof(long long)`. But in `get_salt()`, we just have `static struct custom_salt cs;`, i.e., SALT_ALIGN is not used. But I don't know whether just adding `#include "aligned.h"` and changing the definition to `JTR_ALIGN(SALT_ALIGN) static struct custom_salt cs;` really is the right fix, because of the definiton of custom_salt: ``` static struct custom_salt { int version; long long offset; int isinline; int keyfilesize; int have_keyfile; int contentsize; unsigned char contents[LINE_BUFFER_SIZE]; unsigned char final_randomseed[32]; unsigned char enc_iv[16]; unsigned char keyfile[32]; unsigned char contents_hash[32]; unsigned char transf_randomseed[32]; unsigned char expected_bytes[32]; uint32_t key_transf_rounds; int algorithm; // 1 for Twofish } *cur_salt; ``` Wouldn't it make sense to switch `version` and `offset`?
bsakaguchi 2026-10-14 03:24:59 +07:00
Author
Owner

@magnumripper commented on GitHub (May 9, 2015):

Yes, it would. And I guess after that you won't need to add any JTR_ALIGN.

<!-- gh-comment-id:100529938 --> @magnumripper commented on GitHub (May 9, 2015): Yes, it would. And I guess after that you won't need to add any JTR_ALIGN.
Author
Owner

@frank-dittrich commented on GitHub (May 9, 2015):

OK, I'll try that.
But we really need to fix issue https://github.com/magnumripper/JohnTheRipper/issues/1195, because in repeated builds/runs without significant changes, I very rarely get this error.
So, testing that fix might not be very reliable.

<!-- gh-comment-id:100530134 --> @frank-dittrich commented on GitHub (May 9, 2015): OK, I'll try that. But we really need to fix issue https://github.com/magnumripper/JohnTheRipper/issues/1195, because in repeated builds/runs without significant changes, I very rarely get this error. So, testing that fix might not be very reliable.
Author
Owner

@frank-dittrich commented on GitHub (May 9, 2015):

Scratch that, issue #1195 is unrelated, because here it is a static buffer.

<!-- gh-comment-id:100530157 --> @frank-dittrich commented on GitHub (May 9, 2015): Scratch that, issue #1195 is unrelated, because here it is a static buffer.
Author
Owner

@frank-dittrich commented on GitHub (May 10, 2015):

Just want to mention that I saw

Testing: KeePass [SHA256 AES 32/32 OpenSSL]... Warning: salt() returned misaligned pointer
PASS

on a 32bit Fedora 21 (clang version 3.5.0) with commit bfc611d1e0.

$ ../run/john --list=build-info
Version: 1.8.0.4-jumbo-1-bleeding
Build: linux-gnu 32-bit AVX2-autoconf
Time stamp: Sat May  9 09:01:59 2015
Arch: 32-bit LE
$JOHN is ../run/
Format interface version: 13
Max. number of reported tunable costs: 3
Rec file version: REC4
Charset file version: CHR3
CHARSET_MIN: 1 (0x01)
CHARSET_MAX: 255 (0xff)
CHARSET_LENGTH: 24
Max. Markov mode level: 400
Max. Markov mode password length: 30
File locking: fcntl()
Compiler version: 4.2.1 Compatible Clang 3.5.0 (tags/RELEASE_350/final)
gcc version: 4.3.0
clang version: 3.5.0 (tags/RELEASE_350/final)
GNU libc version: 2.20 (loaded: 2.20)
OpenSSL library version: 0100010bf
OpenSSL 1.0.1k-fips 8 Jan 2015
fseek(): fseeko64
ftell(): ftello64
fopen(): fopen64
memmem(): System's

<!-- gh-comment-id:100605281 --> @frank-dittrich commented on GitHub (May 10, 2015): Just want to mention that I saw ``` Testing: KeePass [SHA256 AES 32/32 OpenSSL]... Warning: salt() returned misaligned pointer PASS ``` on a 32bit Fedora 21 (clang version 3.5.0) with commit bfc611d1e0d2d2f09799330b719f218d733f8c05. ``` $ ../run/john --list=build-info Version: 1.8.0.4-jumbo-1-bleeding Build: linux-gnu 32-bit AVX2-autoconf Time stamp: Sat May 9 09:01:59 2015 Arch: 32-bit LE $JOHN is ../run/ Format interface version: 13 Max. number of reported tunable costs: 3 Rec file version: REC4 Charset file version: CHR3 CHARSET_MIN: 1 (0x01) CHARSET_MAX: 255 (0xff) CHARSET_LENGTH: 24 Max. Markov mode level: 400 Max. Markov mode password length: 30 File locking: fcntl() Compiler version: 4.2.1 Compatible Clang 3.5.0 (tags/RELEASE_350/final) gcc version: 4.3.0 clang version: 3.5.0 (tags/RELEASE_350/final) GNU libc version: 2.20 (loaded: 2.20) OpenSSL library version: 0100010bf OpenSSL 1.0.1k-fips 8 Jan 2015 fseek(): fseeko64 ftell(): ftello64 fopen(): fopen64 memmem(): System's ```
Author
Owner

@frank-dittrich commented on GitHub (May 10, 2015):

Unfortunately, applying the suggested fix (switching the sequence of long long offset and int version) applied after commit bfc611d didn't help. I still get the same warning.
In commit 2ff23cf5, JimF adjusted SALT_ALIGN to sizeof (long long) because he saw crashes on sparc.
I would feel better if we could test any fix on sparc (real metal, not a VM).

<!-- gh-comment-id:100607973 --> @frank-dittrich commented on GitHub (May 10, 2015): Unfortunately, applying the suggested fix (switching the sequence of `long long offset` and `int version`) applied after commit bfc611d didn't help. I still get the same warning. In commit 2ff23cf5, JimF adjusted SALT_ALIGN to `sizeof (long long)` because he saw crashes on sparc. I would feel better if we could test any fix on sparc (real metal, not a VM).
Author
Owner

@magnumripper commented on GitHub (May 18, 2015):

If 9600110 did not fix it, I call compiler bug.

Workaround:

#if ARCH_ALLOWS_UNALIGNED
#define SALT_ALIGN              1
#else
#define SALT_ALIGN              sizeof(long long)
#endif
<!-- gh-comment-id:103251970 --> @magnumripper commented on GitHub (May 18, 2015): If 9600110 did not fix it, I call compiler bug. Workaround: ``` C #if ARCH_ALLOWS_UNALIGNED #define SALT_ALIGN 1 #else #define SALT_ALIGN sizeof(long long) #endif ```
Author
Owner

@jfoug commented on GitHub (Jun 1, 2015):

The issue 'should' have been addressed by moving the long long to being the first value. In that type build, there is nothing ambiguous for the compiler. Start of structure is 8 byte value needing 8 byte align for whole structure. I agree with @magnumripper, if this still throws the warning, it is a compiler bug.

It can also be fixed with a static null pointer, that is allocated upon first run of salt.

<!-- gh-comment-id:107696238 --> @jfoug commented on GitHub (Jun 1, 2015): The issue 'should' have been addressed by moving the long long to being the first value. In that type build, there is nothing ambiguous for the compiler. Start of structure is 8 byte value needing 8 byte align for whole structure. I agree with @magnumripper, if this still throws the warning, it is a compiler bug. It can also be fixed with a static null pointer, that is allocated upon first run of salt.
Author
Owner

@jfoug commented on GitHub (Jun 1, 2015):

Btw, this does NOT crash on a sparc system (32 bit compiler), so I do not see this as an issue there, with the salt align, and with the static struct.

<!-- gh-comment-id:107696428 --> @jfoug commented on GitHub (Jun 1, 2015): Btw, this does NOT crash on a sparc system (32 bit compiler), so I do not see this as an issue there, with the salt align, and with the static struct.
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#809
No description provided.