[GH-ISSUE #1577] Raw-SHA384 ASan error #1034

Closed
opened 2026-10-14 03:32:36 +07:00 by bsakaguchi · 14 comments
Owner

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

Originally assigned to: @magnumripper on GitHub.

(bleeding-jumbo)run $ ./john --list=build-info 
Version: 1.8.0.6-jumbo-1-535-g312adab
Build: linux-gnu 64-bit AVX-ac OMP debug ASan
SIMD: AVX, interleaving: MD4:3 MD5:3 SHA1:1 SHA256:1 SHA512:1
$JOHN is ./
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
gcc version: 5.1.1
GNU libc version: 2.21 (loaded: 2.21)
Crypto library: OpenSSL
OpenSSL library version: 0100010bf
OpenSSL 1.0.1k-fips 8 Jan 2015
GMP library version: 6.0.0
Regex library version: 1.2  (loaded: 1.2.6)
File locking: fcntl()
fseek(): fseek
ftell(): ftell
fopen(): fopen
memmem(): System's
Built with these debugging options
    '#define DEBUG' set
    ASan (Address Sanitizer debugging)

(bleeding-jumbo)run $ ./john --test --format=Raw-SHA384
Will run 8 OpenMP threads
NOTE: This is a debug build, speed will be lower than normal
Benchmarking: Raw-SHA384 [SHA384 128/128 AVX 2x]... (8xOMP) =================================================================
==17314==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60600019eef8 at pc 0x0000006cd71e bp 0x7ffdebe80d80 sp 0x7ffdebe80d70
READ of size 8 at 0x60600019eef8 thread T0
    #0 0x6cd71d in get_binary /home/fd/git/JtR/src/rawSHA384_fmt_plug.c:204
    #1 0x73c51b in fmt_self_test_body /home/fd/git/JtR/src/formats.c:383
    #2 0x73ebf4 in fmt_self_test /home/fd/git/JtR/src/formats.c:719
    #3 0x72598f in benchmark_format /home/fd/git/JtR/src/bench.c:235
    #4 0x7273ba in benchmark_all /home/fd/git/JtR/src/bench.c:652
    #5 0x74bb98 in john_run /home/fd/git/JtR/src/john.c:1365
    #6 0x74cfea in main /home/fd/git/JtR/src/john.c:1731
    #7 0x7f7868c036ff in __libc_start_main (/lib64/libc.so.6+0x206ff)
    #8 0x406e38 in _start (/home/fd/git/JtR/run/john+0x406e38)

0x60600019eeff is located 0 bytes to the right of 63-byte region [0x60600019eec0,0x60600019eeff)
allocated by thread T0 here:
    #0 0x7f786a8bfa0a in malloc (/lib64/libasan.so.2+0x98a0a)
    #1 0x76772c in mem_alloc_func /home/fd/git/JtR/src/memory.c:89
    #2 0x7678f7 in mem_alloc_tiny_func /home/fd/git/JtR/src/memory.c:196
    #3 0x76793e in mem_calloc_tiny_func /home/fd/git/JtR/src/memory.c:217
    #4 0x6cd494 in get_binary /home/fd/git/JtR/src/rawSHA384_fmt_plug.c:183
    #5 0x73c51b in fmt_self_test_body /home/fd/git/JtR/src/formats.c:383
    #6 0x73ebf4 in fmt_self_test /home/fd/git/JtR/src/formats.c:719
    #7 0x72598f in benchmark_format /home/fd/git/JtR/src/bench.c:235
    #8 0x7273ba in benchmark_all /home/fd/git/JtR/src/bench.c:652
    #9 0x74bb98 in john_run /home/fd/git/JtR/src/john.c:1365
    #10 0x74cfea in main /home/fd/git/JtR/src/john.c:1731
    #11 0x7f7868c036ff in __libc_start_main (/lib64/libc.so.6+0x206ff)
Originally created by @frank-dittrich on GitHub (Jul 26, 2015). Original GitHub issue: https://github.com/openwall/john/issues/1577 Originally assigned to: @magnumripper on GitHub. ``` (bleeding-jumbo)run $ ./john --list=build-info Version: 1.8.0.6-jumbo-1-535-g312adab Build: linux-gnu 64-bit AVX-ac OMP debug ASan SIMD: AVX, interleaving: MD4:3 MD5:3 SHA1:1 SHA256:1 SHA512:1 $JOHN is ./ 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 gcc version: 5.1.1 GNU libc version: 2.21 (loaded: 2.21) Crypto library: OpenSSL OpenSSL library version: 0100010bf OpenSSL 1.0.1k-fips 8 Jan 2015 GMP library version: 6.0.0 Regex library version: 1.2 (loaded: 1.2.6) File locking: fcntl() fseek(): fseek ftell(): ftell fopen(): fopen memmem(): System's Built with these debugging options '#define DEBUG' set ASan (Address Sanitizer debugging) (bleeding-jumbo)run $ ./john --test --format=Raw-SHA384 Will run 8 OpenMP threads NOTE: This is a debug build, speed will be lower than normal Benchmarking: Raw-SHA384 [SHA384 128/128 AVX 2x]... (8xOMP) ================================================================= ==17314==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60600019eef8 at pc 0x0000006cd71e bp 0x7ffdebe80d80 sp 0x7ffdebe80d70 READ of size 8 at 0x60600019eef8 thread T0 #0 0x6cd71d in get_binary /home/fd/git/JtR/src/rawSHA384_fmt_plug.c:204 #1 0x73c51b in fmt_self_test_body /home/fd/git/JtR/src/formats.c:383 #2 0x73ebf4 in fmt_self_test /home/fd/git/JtR/src/formats.c:719 #3 0x72598f in benchmark_format /home/fd/git/JtR/src/bench.c:235 #4 0x7273ba in benchmark_all /home/fd/git/JtR/src/bench.c:652 #5 0x74bb98 in john_run /home/fd/git/JtR/src/john.c:1365 #6 0x74cfea in main /home/fd/git/JtR/src/john.c:1731 #7 0x7f7868c036ff in __libc_start_main (/lib64/libc.so.6+0x206ff) #8 0x406e38 in _start (/home/fd/git/JtR/run/john+0x406e38) 0x60600019eeff is located 0 bytes to the right of 63-byte region [0x60600019eec0,0x60600019eeff) allocated by thread T0 here: #0 0x7f786a8bfa0a in malloc (/lib64/libasan.so.2+0x98a0a) #1 0x76772c in mem_alloc_func /home/fd/git/JtR/src/memory.c:89 #2 0x7678f7 in mem_alloc_tiny_func /home/fd/git/JtR/src/memory.c:196 #3 0x76793e in mem_calloc_tiny_func /home/fd/git/JtR/src/memory.c:217 #4 0x6cd494 in get_binary /home/fd/git/JtR/src/rawSHA384_fmt_plug.c:183 #5 0x73c51b in fmt_self_test_body /home/fd/git/JtR/src/formats.c:383 #6 0x73ebf4 in fmt_self_test /home/fd/git/JtR/src/formats.c:719 #7 0x72598f in benchmark_format /home/fd/git/JtR/src/bench.c:235 #8 0x7273ba in benchmark_all /home/fd/git/JtR/src/bench.c:652 #9 0x74bb98 in john_run /home/fd/git/JtR/src/john.c:1365 #10 0x74cfea in main /home/fd/git/JtR/src/john.c:1731 #11 0x7f7868c036ff in __libc_start_main (/lib64/libc.so.6+0x206ff) ```
bsakaguchi 2026-10-14 03:32:36 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@jfoug commented on GitHub (Jul 26, 2015):

This brings up the question: (for @magnumripper )

since we do not use this hash for anything later in these raw formats, why are we reversing the entire 64 bytes? Could we just get by with simply reversing the first 16, and know that there will be no 128 bit collisions That should speed things up, along with require a smaller memory footprint to be kept for the binary() ?

<!-- gh-comment-id:124995881 --> @jfoug commented on GitHub (Jul 26, 2015): This brings up the question: (for @magnumripper ) since we do not use this hash for anything later in these raw formats, why are we reversing the entire 64 bytes? Could we just get by with simply reversing the first 16, and know that there will be no 128 bit collisions That should speed things up, along with require a smaller memory footprint to be kept for the binary() ?
Author
Owner

@jfoug commented on GitHub (Jul 26, 2015):

So we would see this:

#define CIPHERTEXT_LENGTH       96

//#define BINARY_SIZE               48
#define BINARY_SIZE             16
#define BINARY_ALIGN            8
#define SALT_SIZE               0

......

void *get_binary(char *ciphertext)
{
    static ARCH_WORD_64 *outw;
    unsigned char *out;
    char *p;
    int i;

    if (!outw)
        outw = mem_calloc_tiny(BINARY_SIZE, BINARY_ALIGN);

    out = (unsigned char*)outw;

    p = ciphertext + TAG_LENGTH;
    for (i = 0; i < BINARY_SIZE; i++) {
        out[i] =
                (atoi16[ARCH_INDEX(*p)] << 4) |
                 atoi16[ARCH_INDEX(p[1])];
        p += 2;
    }

#ifdef SIMD_COEF_64
    alter_endianity_to_BE64(out, BINARY_SIZE/8);
#ifdef REVERSE_STEPS
    outw[0] -= INIT_A;
    outw[1] -= INIT_B;
//  outw[2] -= INIT_C;
//  outw[3] -= INIT_D;
//  outw[4] -= INIT_E;
//  outw[5] -= INIT_F;
//  outw[6] -= INIT_G;
//  outw[7] -= INIT_H;
#endif
#endif
    return out;
}

First off, I think this was already wrong to start with:

    outw[6] -= INIT_G;
    outw[7] -= INIT_H;

Since it is longer than the BINARY_SIZE of the format.

<!-- gh-comment-id:124996403 --> @jfoug commented on GitHub (Jul 26, 2015): So we would see this: ``` C #define CIPHERTEXT_LENGTH 96 //#define BINARY_SIZE 48 #define BINARY_SIZE 16 #define BINARY_ALIGN 8 #define SALT_SIZE 0 ...... void *get_binary(char *ciphertext) { static ARCH_WORD_64 *outw; unsigned char *out; char *p; int i; if (!outw) outw = mem_calloc_tiny(BINARY_SIZE, BINARY_ALIGN); out = (unsigned char*)outw; p = ciphertext + TAG_LENGTH; for (i = 0; i < BINARY_SIZE; i++) { out[i] = (atoi16[ARCH_INDEX(*p)] << 4) | atoi16[ARCH_INDEX(p[1])]; p += 2; } #ifdef SIMD_COEF_64 alter_endianity_to_BE64(out, BINARY_SIZE/8); #ifdef REVERSE_STEPS outw[0] -= INIT_A; outw[1] -= INIT_B; // outw[2] -= INIT_C; // outw[3] -= INIT_D; // outw[4] -= INIT_E; // outw[5] -= INIT_F; // outw[6] -= INIT_G; // outw[7] -= INIT_H; #endif #endif return out; } ``` First off, I think this was already wrong to start with: ``` C outw[6] -= INIT_G; outw[7] -= INIT_H; ``` Since it is longer than the BINARY_SIZE of the format.
Author
Owner

@jfoug commented on GitHub (Jul 26, 2015):

NOTE, rawsha224 has the same bug. BINARY_SIZE is only 28, but in the REVERSE_STEPS, 32 bytes are reversed. It does not 'trip' an ASAN error, but that is probably due to the MEM_ALIGN_WORD giving it an extra 4 bytes (often) at the end of the buffer (buffer is allocated large, so that we can align if needed).

<!-- gh-comment-id:124997018 --> @jfoug commented on GitHub (Jul 26, 2015): NOTE, rawsha224 has the same bug. BINARY_SIZE is only 28, but in the REVERSE_STEPS, 32 bytes are reversed. It does not 'trip' an ASAN error, but that is probably due to the MEM_ALIGN_WORD giving it an extra 4 bytes (often) at the end of the buffer (buffer is allocated large, so that we can align if needed).
Author
Owner

@jfoug commented on GitHub (Jul 26, 2015):

I am waiting on 'fixing' raw-sha224 to hear from @magnumripper on this, since he was the reverser and knows what he intended to do.

<!-- gh-comment-id:124997276 --> @jfoug commented on GitHub (Jul 26, 2015): I am waiting on 'fixing' raw-sha224 to hear from @magnumripper on this, since he was the reverser and knows what he intended to do.
Author
Owner

@magnumripper commented on GitHub (Jul 26, 2015):

It's still on my (or our) to-do list to find ways to improve SHA2 reversing similar to what I just did to SHA-1 in 48c80a44 (not my idea, I saw it in Tavis' raw-sha1-ng).

I might have introduced these (and possibly other) bugs in this first step towards more reversing (sorry!). We should always check the full binary size (or DIGEST_SIZE). We can (and perhaps should) use a BINARY_SIZE as small as 4 (32 bits) but then we must implement a proper cmp_exact such as in latest raw md4/md5/sha1 formats.

<!-- gh-comment-id:125036973 --> @magnumripper commented on GitHub (Jul 26, 2015): It's still on my (or our) to-do list to find ways to improve SHA2 reversing similar to what I just did to SHA-1 in 48c80a44 (not my idea, I saw it in Tavis' raw-sha1-ng). I might have introduced these (and possibly other) bugs in this first step towards more reversing (sorry!). We should always check the full binary size (or DIGEST_SIZE). We can (and perhaps should) use a BINARY_SIZE as small as 4 (32 bits) but then we must implement a proper cmp_exact such as in latest raw md4/md5/sha1 formats.
Author
Owner

@jfoug commented on GitHub (Jul 26, 2015):

So, in the 'current' sha384-raw, I have switched the binary to have a 64 byte buffer. That is probably wrong, correct? The correct fix would be to only reverse 48 bytes with the first 6 constants, correct?

Same for sha224 (first 7 constants into 28 bytes.

<!-- gh-comment-id:125040327 --> @jfoug commented on GitHub (Jul 26, 2015): So, in the 'current' sha384-raw, I have switched the binary to have a 64 byte buffer. That is probably wrong, correct? The correct fix would be to only reverse 48 bytes with the first 6 constants, correct? Same for sha224 (first 7 constants into 28 bytes.
Author
Owner

@magnumripper commented on GitHub (Jul 26, 2015):

We obviously need the SIMD buffers to be full sized. Only core's buffer (list) of loaded binaries should be using the smaller figure, nothing else.

Note also that it's perfectly sane and sometimes very useful to have a binary() that returns a buffer of DIGEST_SIZE, with all of it byte-swapped and sums reversed. The smaller BINARY_SIZE is what will be copied from that returned buffer by loader.c but we can use binary() in other places if needed, eg. in cmp_exact().

<!-- gh-comment-id:125040680 --> @magnumripper commented on GitHub (Jul 26, 2015): We obviously need the SIMD buffers to be full sized. Only core's buffer (list) of loaded binaries should be using the smaller figure, nothing else. Note also that it's perfectly sane and sometimes very useful to have a binary() that returns a buffer of DIGEST_SIZE, with all of it byte-swapped and sums reversed. The smaller BINARY_SIZE is what will be **copied** from that returned buffer by loader.c but we can use binary() in other places if needed, eg. in cmp_exact().
Author
Owner

@magnumripper commented on GitHub (Jul 26, 2015):

I can clean up this mess of mine if you want, but I'm not touching it until you back off since you are on it (by all means feel free to continue). To sum up, I think (taking SHA384 as example):

  1. BINARY_SIZE should be 4 EDIT it should be 8 for SHA384/512 and 4 for SHA224/256.
  2. DIGEST_SIZE should be 48.
  3. SIMD buffers need to be 64, this is somewhat confusingly named FULL_BINARY_SIZE (maybe we should refactor to BINARY_SIZE_512 as in PBKDF2).
  4. get_binary() should return a buffer of DIGEST_SIZE, fully swapped and sums reversed (up to INIT_F).
  5. cmp_all() and cmp_one() should use BINARY_SIZE.
  6. cmp_exact() should call binary to get a full buffer of DIGEST_SIZE, and compare all of it.
<!-- gh-comment-id:125041636 --> @magnumripper commented on GitHub (Jul 26, 2015): I can clean up this mess of mine if you want, but I'm not touching it until you back off since you are on it (by all means feel free to continue). To sum up, I think (taking SHA384 as example): 1. BINARY_SIZE should be ~~4~~ **EDIT** it should be 8 for SHA384/512 and 4 for SHA224/256. 2. DIGEST_SIZE should be 48. 3. SIMD buffers need to be 64, this is somewhat confusingly named FULL_BINARY_SIZE (maybe we should refactor to BINARY_SIZE_512 as in PBKDF2). 4. get_binary() should return a buffer of DIGEST_SIZE, fully swapped and sums reversed (up to INIT_F). 5. cmp_all() and cmp_one() should use BINARY_SIZE. 6. cmp_exact() should call binary to get a full buffer of DIGEST_SIZE, and compare all of it.
Author
Owner

@magnumripper commented on GitHub (Jul 26, 2015):

We have this in simd-intrinsics.c, that's what made me introduce the original bug

        if (SSEi_flags & SSEi_CRYPT_SHA384) {
            SHA512_PARA_DO(i)
            {
                /* SHA-384 IV */
                a[i] = vset1_epi64(0xcbbb9d5dc1059ed8ULL);
                b[i] = vset1_epi64(0x629a292a367cd507ULL);
                c[i] = vset1_epi64(0x9159015a3070dd17ULL);
                d[i] = vset1_epi64(0x152fecd8f70e5939ULL);
                e[i] = vset1_epi64(0x67332667ffc00b31ULL);
                f[i] = vset1_epi64(0x8eb44a8768581511ULL);
                g[i] = vset1_epi64(0xdb0c2e0d64f98fa7ULL);
                h[i] = vset1_epi64(0x47b5481dbefa4fa4ULL);
            }
        } else {

I believe this is totally correct BUT in the format's binary, we can obviously only reverse up to INIT_F.

<!-- gh-comment-id:125041730 --> @magnumripper commented on GitHub (Jul 26, 2015): We have this in simd-intrinsics.c, that's what made me introduce the original bug ``` if (SSEi_flags & SSEi_CRYPT_SHA384) { SHA512_PARA_DO(i) { /* SHA-384 IV */ a[i] = vset1_epi64(0xcbbb9d5dc1059ed8ULL); b[i] = vset1_epi64(0x629a292a367cd507ULL); c[i] = vset1_epi64(0x9159015a3070dd17ULL); d[i] = vset1_epi64(0x152fecd8f70e5939ULL); e[i] = vset1_epi64(0x67332667ffc00b31ULL); f[i] = vset1_epi64(0x8eb44a8768581511ULL); g[i] = vset1_epi64(0xdb0c2e0d64f98fa7ULL); h[i] = vset1_epi64(0x47b5481dbefa4fa4ULL); } } else { ``` I believe this is totally correct BUT in the format's binary, we can obviously only reverse up to INIT_F.
Author
Owner

@jfoug commented on GitHub (Jul 26, 2015):

I am not working on this, I was simply asking. I did an initial stab at it when seeing that a 48 byte buffer was being smashed with 64 bytes, but that simply brought up 'what IS the right way'

Yes, WITHIN the SIMD code, the full 64 bytes is required, because you do not know if the users is going to use that as input to the next limb. But outside (in this raw format), we know that we only care about 48 bytes.

I do agree with your assessment about binary(). It should do the FULL proper 48 byte item, then we can simply use it in cmp_exact to do a full compare, while making BINARY_SIZE only 1 uint64_t sized.

<!-- gh-comment-id:125044566 --> @jfoug commented on GitHub (Jul 26, 2015): I am not working on this, I was simply asking. I did an initial stab at it when seeing that a 48 byte buffer was being smashed with 64 bytes, but that simply brought up 'what IS the right way' Yes, WITHIN the SIMD code, the full 64 bytes is required, because you do not know if the users is going to use that as input to the next limb. But outside (in this raw format), we know that we only care about 48 bytes. I do agree with your assessment about binary(). It should do the FULL proper 48 byte item, then we can simply use it in cmp_exact to do a full compare, while making BINARY_SIZE only 1 uint64_t sized.
Author
Owner

@magnumripper commented on GitHub (Jul 26, 2015):

OK, I will review and fix all raw SHA-2.

<!-- gh-comment-id:125044740 --> @magnumripper commented on GitHub (Jul 26, 2015): OK, I will review and fix all raw SHA-2.
Author
Owner

@magnumripper commented on GitHub (Jul 26, 2015):

This will save PLENTY of memory when loading 100 million hashes... For raw MD5 and things like that, we save 12 bytes per hash. In SHA512 we save 60 bytes per hash...

<!-- gh-comment-id:125049021 --> @magnumripper commented on GitHub (Jul 26, 2015): This will save PLENTY of memory when loading 100 million hashes... For raw MD5 and things like that, we save 12 bytes per hash. In SHA512 we save 60 bytes per hash...
Author
Owner

@jfoug commented on GitHub (Jul 27, 2015):

The problem is, john still stores the full TEXT string in memory. It is a trade off. We put in the source() function to allow john to only store the full binary hash. BUT there is a trade off, in that we may have the 'hot' memory be much larger.

I know Solar talked about splitting the binary into hot/warm parts. Has there been any progress on that?

<!-- gh-comment-id:125050881 --> @jfoug commented on GitHub (Jul 27, 2015): The problem is, john still stores the full TEXT string in memory. It is a trade off. We put in the source() function to allow john to only store the full binary hash. BUT there is a trade off, in that we may have the 'hot' memory be much larger. I know Solar talked about splitting the binary into hot/warm parts. Has there been any progress on that?
Author
Owner

@magnumripper commented on GitHub (Jul 27, 2015):

Yes. SHA1 had source() but that is not compatible with reduced binary. The reversing (beyond constant adds) implies reduced binary so its source() was dropped. I picture the SHA-2 formats will go that way too so there's no point in adding source() now.

<!-- gh-comment-id:125052545 --> @magnumripper commented on GitHub (Jul 27, 2015): Yes. SHA1 had source() but that is not compatible with reduced binary. The reversing (beyond constant adds) _implies_ reduced binary so its source() was dropped. I picture the SHA-2 formats will go that way too so there's no point in adding source() now.
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#1034
No description provided.