[GH-ISSUE #1437] some dynamic formats malfunction on MIC #922

Closed
opened 2026-10-14 03:27:49 +07:00 by bsakaguchi · 29 comments
Owner

Originally created by @lei-april on GitHub (Jun 14, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1437

Originally assigned to: @lei-april on GitHub.

dynamic_30 core dumps on MIC, resulting from the following code:

MEM_FREE(crypt_key2);
MEM_FREE(crypt_key);
MEM_FREE(input_buf2);
...

corresponding allocation code:

...
input_buf2 = mem_calloc_align(1, MMX_INP_BUF2_SZ, MEM_ALIGN_SIMD);
crypt_key  = mem_calloc_align(1, MMX_CRYPT_KEY_SZ, MEM_ALIGN_SIMD);
crypt_key2 = mem_calloc_align(1, MMX_CRYPT_KEY2_SZ, MEM_ALIGN_SIMD);

dynamic_31, dynamic_32 and so on fail self-test on MIC.

Originally created by @lei-april on GitHub (Jun 14, 2015). Original GitHub issue: https://github.com/openwall/john/issues/1437 Originally assigned to: @lei-april on GitHub. dynamic_30 core dumps on MIC, resulting from the following code: ``` c MEM_FREE(crypt_key2); MEM_FREE(crypt_key); MEM_FREE(input_buf2); ... ``` corresponding allocation code: ``` c ... input_buf2 = mem_calloc_align(1, MMX_INP_BUF2_SZ, MEM_ALIGN_SIMD); crypt_key = mem_calloc_align(1, MMX_CRYPT_KEY_SZ, MEM_ALIGN_SIMD); crypt_key2 = mem_calloc_align(1, MMX_CRYPT_KEY2_SZ, MEM_ALIGN_SIMD); ``` dynamic_31, dynamic_32 and so on fail self-test on MIC.
bsakaguchi 2026-10-14 03:27:49 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@lei-april commented on GitHub (Jun 15, 2015):

BTW, I tried replacing mem_calloc_align and MEM_FREE with icc's builtin _mm_malloc and _mm_free respectively. Yet it still segfaults on those freeing code. I think it's not something wrong with mem_calloc_align or MEM_FREE.

<!-- gh-comment-id:111897088 --> @lei-april commented on GitHub (Jun 15, 2015): BTW, I tried replacing `mem_calloc_align` and `MEM_FREE` with icc's builtin `_mm_malloc` and `_mm_free` respectively. Yet it still segfaults on those freeing code. I think it's not something wrong with `mem_calloc_align` or `MEM_FREE`.
Author
Owner

@magnumripper commented on GitHub (Jun 15, 2015):

Sounds like a buffer overrun. Perhaps the pointer is overwritten with garbage, that will definitely cause a segfault when freeing.

dynamic_31 through dynamic_33 are MD4 (see ../run/john --list=subformats). Does dynamic_34 work?

The cause is likely some multiplier/divisor that does not work well with your combination of SIMD_COEF_32 and SIMD_PARA_MD4.

<!-- gh-comment-id:112163382 --> @magnumripper commented on GitHub (Jun 15, 2015): Sounds like a buffer overrun. Perhaps the pointer is overwritten with garbage, that will definitely cause a segfault when freeing. dynamic_31 through dynamic_33 are MD4 (see `../run/john --list=subformats`). Does dynamic_34 work? The cause is likely some multiplier/divisor that does not work well with your combination of SIMD_COEF_32 and SIMD_PARA_MD4.
Author
Owner

@lei-april commented on GitHub (Jun 16, 2015):

Sounds like a buffer overrun. Perhaps the pointer is overwritten with garbage, that will definitely cause a segfault when freeing.

Perhaps not. I manually checked the value of crypt_key2 after allocation and that before freeing, which two are the same. And freeing crypt_key2 core-dumps immediately.

dynamic_31 through dynamic_33 are MD4 (see ../run/john --list=subformats). Does dynamic_34 work?

Yes, it works, but also core-dumps in the epilogue.

The cause is likely some multiplier/divisor that does not work well with your combination of SIMD_COEF_32 and SIMD_PARA_MD4.

It looks you're right. Setting SIMD_PARA_MD4 to 1 (which is originally 6) just erases all the problems. I tried some other values, while some make dynamic_30 work but make dynamic_31 fail, and some vice versa.

<!-- gh-comment-id:112249747 --> @lei-april commented on GitHub (Jun 16, 2015): > Sounds like a buffer overrun. Perhaps the pointer is overwritten with garbage, that will definitely cause a segfault when freeing. Perhaps not. I manually checked the value of `crypt_key2` after allocation and that before freeing, which two are the same. And freeing `crypt_key2` core-dumps immediately. > dynamic_31 through dynamic_33 are MD4 (see `../run/john --list=subformats`). Does dynamic_34 work? Yes, it works, but also core-dumps in the epilogue. > The cause is likely some multiplier/divisor that does not work well with your combination of SIMD_COEF_32 and SIMD_PARA_MD4. It looks you're right. Setting `SIMD_PARA_MD4` to 1 (which is originally 6) just erases all the problems. I tried some other values, while some make dynamic_30 work but make dynamic_31 fail, and some vice versa.
Author
Owner

@magnumripper commented on GitHub (Jun 16, 2015):

So perhaps 2da5ccba (or something similar) is not doing the trick fully. It "handles paras up to 7" but does it handle a coef of 16 at the same time as a para of 6?

<!-- gh-comment-id:112302623 --> @magnumripper commented on GitHub (Jun 16, 2015): So perhaps 2da5ccba (or something similar) is not doing the trick fully. It "handles paras up to 7" but does it handle a coef of 16 at the same time as a para of 6?
Author
Owner

@magnumripper commented on GitHub (Jun 16, 2015):

We also have this perhaps problematic code in dynamic_types.h

#  ifdef SIMD_PARA_MD5
// gives us 16 'loops' for para=2 and 10 loops for para==3 (or max of 128 for 2 and 120 for 3)
#   define MAX_KEYS_PER_CRYPT   (((SIMD_COEF_32*BLOCK_LOOPS)/(SIMD_PARA_MD5*4))*(SIMD_PARA_MD5*4))
#  else
#   define MAX_KEYS_PER_CRYPT   SIMD_COEF_32*BLOCK_LOOPS
#  endif

It ensures an even multiple for MD5, but not for any other hash type. @jfoug what do you think?

<!-- gh-comment-id:112303418 --> @magnumripper commented on GitHub (Jun 16, 2015): We also have this perhaps problematic code in dynamic_types.h ``` C # ifdef SIMD_PARA_MD5 // gives us 16 'loops' for para=2 and 10 loops for para==3 (or max of 128 for 2 and 120 for 3) # define MAX_KEYS_PER_CRYPT (((SIMD_COEF_32*BLOCK_LOOPS)/(SIMD_PARA_MD5*4))*(SIMD_PARA_MD5*4)) # else # define MAX_KEYS_PER_CRYPT SIMD_COEF_32*BLOCK_LOOPS # endif ``` It ensures an even multiple for MD5, but not for any other hash type. @jfoug what do you think?
Author
Owner

@lei-april commented on GitHub (Jun 16, 2015):

Doubling NON_OMP_MAX from 1680 to 3360 makes dynamic_30 work with paras up to 7. But dynamic_31 to dynamic_33 still fail, all with the same output: FAILED (cmp_all(64))

<!-- gh-comment-id:112326574 --> @lei-april commented on GitHub (Jun 16, 2015): Doubling `NON_OMP_MAX` from 1680 to 3360 makes dynamic_30 work with paras up to 7. But dynamic_31 to dynamic_33 still fail, all with the same output: `FAILED (cmp_all(64))`
Author
Owner

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

Can you try again multiplying by 4, not 2. You are switching from COEF==4 to COEF==16 (4x more candidates)

<!-- gh-comment-id:112520345 --> @jfoug commented on GitHub (Jun 16, 2015): Can you try again multiplying by 4, not 2. You are switching from COEF==4 to COEF==16 (4x more candidates)
Author
Owner

@lei-april commented on GitHub (Jun 17, 2015):

@jfoug No, it still doesn't work for dynamic_31 to dynamic_33, not even with NON_OMP_MAX assigned the same value as OMP_MAX.

<!-- gh-comment-id:112619736 --> @lei-april commented on GitHub (Jun 17, 2015): @jfoug No, it still doesn't work for dynamic_31 to dynamic_33, not even with `NON_OMP_MAX` assigned the same value as `OMP_MAX`.
Author
Owner

@magnumripper commented on GitHub (Jun 17, 2015):

I bet the problem is not the coef of 16 but the para of 6. The actual keys-per-batch from the intrinsics function is 96. What is the output of ../run/john --list=format-all-details --format=dynamic_31?

<!-- gh-comment-id:112717515 --> @magnumripper commented on GitHub (Jun 17, 2015): I bet the problem is not the coef of 16 but the para of 6. The actual keys-per-batch from the intrinsics function is 96. What is the output of `../run/john --list=format-all-details --format=dynamic_31`?
Author
Owner

@lei-april commented on GitHub (Jun 17, 2015):

I bet the problem is not the coef of 16 but the para of 6.

Not necessarily. dynamic_31 fails on lower paras too.

[zhanglei@mic0 zhanglei]$ run/john --list=format-all-details --format=dynamic_31
Format label                         dynamic_31
 Disabled in configuration file      no
Min. password length in bytes        0
Max. password length in bytes        31
Min. keys per crypt                  1
Max. keys per crypt                  1680
Flags
 Case sensitive                      yes
 Supports 8-bit characters           yes
 Converts 8859-1 to UTF-16/UCS-2     no
 Honours --encoding=NAME             no
 False positives possible            no
 Uses a bitslice implementation      no
 The split() method unifies case     yes
 A $dynamic$ format                  yes
 A dynamic sized salt                no
Number of test vectors               24
Algorithm name                       md4($s.$p) 512/512 MIC 16x5
Format name
Benchmark comment
Benchmark length                     0
Binary size                          16
Salt size                            24
Tunable cost parameters
Example ciphertext                   $dynamic_31$5f4de0716cc8e0c8ebbd20f5adbdc09f$fHyMBLzW
<!-- gh-comment-id:112828993 --> @lei-april commented on GitHub (Jun 17, 2015): > I bet the problem is not the coef of 16 but the para of 6. Not necessarily. dynamic_31 fails on lower paras too. ``` [zhanglei@mic0 zhanglei]$ run/john --list=format-all-details --format=dynamic_31 Format label dynamic_31 Disabled in configuration file no Min. password length in bytes 0 Max. password length in bytes 31 Min. keys per crypt 1 Max. keys per crypt 1680 Flags Case sensitive yes Supports 8-bit characters yes Converts 8859-1 to UTF-16/UCS-2 no Honours --encoding=NAME no False positives possible no Uses a bitslice implementation no The split() method unifies case yes A $dynamic$ format yes A dynamic sized salt no Number of test vectors 24 Algorithm name md4($s.$p) 512/512 MIC 16x5 Format name Benchmark comment Benchmark length 0 Binary size 16 Salt size 24 Tunable cost parameters Example ciphertext $dynamic_31$5f4de0716cc8e0c8ebbd20f5adbdc09f$fHyMBLzW ```
Author
Owner

@magnumripper commented on GitHub (Jun 17, 2015):

But it works with para 1, right?

<!-- gh-comment-id:112872492 --> @magnumripper commented on GitHub (Jun 17, 2015): But it works with para 1, right?
Author
Owner

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

What exactly are the md5-para, md4-para, sha1-para and simd_coef values for a build that fails?

I 'should' be able to replicate this problem and fix it.

<!-- gh-comment-id:112886003 --> @jfoug commented on GitHub (Jun 17, 2015): What exactly are the md5-para, md4-para, sha1-para and simd_coef values for a build that fails? I 'should' be able to replicate this problem and fix it.
Author
Owner

@lei-april commented on GitHub (Jun 18, 2015):

But it works with para 1, right?

Yes.

<!-- gh-comment-id:112995571 --> @lei-april commented on GitHub (Jun 18, 2015): > But it works with para 1, right? Yes.
Author
Owner

@lei-april commented on GitHub (Jun 18, 2015):

What exactly are the md5-para, md4-para, sha1-para and simd_coef values for a build that fails?

md4-para = any value higher than 1
md5-para = 1
sha1-para = 1
coef-32 = 16

<!-- gh-comment-id:112996709 --> @lei-april commented on GitHub (Jun 18, 2015): > What exactly are the md5-para, md4-para, sha1-para and simd_coef values for a build that fails? md4-para = any value higher than 1 md5-para = 1 sha1-para = 1 coef-32 = 16
Author
Owner

@lei-april commented on GitHub (Jun 18, 2015):

I find that dynamic_31 works when NON_OMP_MAX = 6720 and SIMD_PARA_MD5 = SIMD_PARA_MD4 = whatever value. But I don't know why.

<!-- gh-comment-id:113089131 --> @lei-april commented on GitHub (Jun 18, 2015): I find that dynamic_31 works when `NON_OMP_MAX = 6720` and SIMD_PARA_MD5 = SIMD_PARA_MD4 = whatever value. But I don't know why.
Author
Owner

@lei-april commented on GitHub (Jul 2, 2015):

I reverted to some older commits and tested them on MIC with SIMD_PARA_MD4 > 1 (or MD4_SSE_PARA > 1), and dynamic_31-33 all failed. I think those dynamic formats never worked properly on MIC with interleaving.

<!-- gh-comment-id:117878981 --> @lei-april commented on GitHub (Jul 2, 2015): I reverted to some older commits and tested them on MIC with SIMD_PARA_MD4 > 1 (or MD4_SSE_PARA > 1), and dynamic_31-33 all failed. I think those dynamic formats never worked properly on MIC with interleaving.
Author
Owner

@lei-april commented on GitHub (Jul 16, 2015):

I think I found the culprit:

dynamic_fmt.c

static void SSE_Intrinsics_LoadLens(int side, int i)
{
    ARCH_WORD_32 *p;
    unsigned int j, k;
    if (side == 0)
    {
        for (j = 0; j < SIMD_PARA_MD5; j++)
        {
            p = input_buf[i+j].w;
            for (k = 0; k < SIMD_COEF_32; k++)
                p[14*SIMD_COEF_32+k] = total_len[i+j][k] << 3;
        }
    }
    else
    {
        for (j = 0; j < SIMD_PARA_MD5; j++)
        {
            p = input_buf2[i+j].w;
            for (k = 0; k < SIMD_COEF_32; k++)
                p[14*SIMD_COEF_32+k] = total_len2[i+j][k] << 3;
        }
    }
}

Simply replacing SIMD_PARA_MD5 with SIMD_PARA_MD4 here would erase all issues encountered previously in this thread. But of course that renders other dynamic formats that rely on MD5 not working.

A strange thing is that this function gets invoked both by code for MD4 and code for MD5, but only SIMD_PARA_MD5 is used here. It's even stranger that never caused problem on other platforms (non-MIC).

A possible fix is to make two versions of this function, one for MD4 and one for MD5. But I think there may be a better fix.

<!-- gh-comment-id:121816869 --> @lei-april commented on GitHub (Jul 16, 2015): I think I found the culprit: dynamic_fmt.c ``` c static void SSE_Intrinsics_LoadLens(int side, int i) { ARCH_WORD_32 *p; unsigned int j, k; if (side == 0) { for (j = 0; j < SIMD_PARA_MD5; j++) { p = input_buf[i+j].w; for (k = 0; k < SIMD_COEF_32; k++) p[14*SIMD_COEF_32+k] = total_len[i+j][k] << 3; } } else { for (j = 0; j < SIMD_PARA_MD5; j++) { p = input_buf2[i+j].w; for (k = 0; k < SIMD_COEF_32; k++) p[14*SIMD_COEF_32+k] = total_len2[i+j][k] << 3; } } } ``` Simply replacing `SIMD_PARA_MD5` with `SIMD_PARA_MD4` here would erase all issues encountered previously in this thread. But of course that renders other dynamic formats that rely on MD5 not working. A strange thing is that this function gets invoked both by code for MD4 and code for MD5, but only `SIMD_PARA_MD5` is used here. It's even stranger that never caused problem on other platforms (non-MIC). A possible fix is to make two versions of this function, one for MD4 and one for MD5. But I think there may be a better fix.
Author
Owner

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

I will simply make 2 functions, easy enough. That code had not been touched for a LONG time. I think on most builds up to now, md5/md4 para was usually the same, so this never showed up.

<!-- gh-comment-id:121822502 --> @jfoug commented on GitHub (Jul 16, 2015): I will simply make 2 functions, easy enough. That code had not been touched for a LONG time. I think on most builds up to now, md5/md4 para was usually the same, so this never showed up.
Author
Owner

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

Please test. I have no way of knowing if this corrected things. It does work on my AVX2 build and on SSE4.1 build.

<!-- gh-comment-id:121823801 --> @jfoug commented on GitHub (Jul 16, 2015): Please test. I have no way of knowing if this corrected things. It does work on my AVX2 build and on SSE4.1 build.
Author
Owner

@lei-april commented on GitHub (Jul 16, 2015):

NON_OMP_MAX in dynamic_types.h should be at least 6720 (currently 1680) to work on MIC when para is 4.

And I just tested SIMD_PARA_MD5 = 4 on well (AVX2) with NON_OMP_MAX unaltered (1680), which also gave me a bunch of segfaults. I think this piece of code is never thoroughly tested. We're just lucky that the paras chosen so far happened to work.

<!-- gh-comment-id:121877602 --> @lei-april commented on GitHub (Jul 16, 2015): `NON_OMP_MAX` in dynamic_types.h should be at least 6720 (currently 1680) to work on MIC when para is 4. And I just tested SIMD_PARA_MD5 = 4 on well (AVX2) with `NON_OMP_MAX` unaltered (1680), which also gave me a bunch of segfaults. I think this piece of code is never thoroughly tested. We're just lucky that the paras chosen so far happened to work.
Author
Owner

@lei-april commented on GitHub (Jul 16, 2015):

Unfortunately, dynamic_1007 still segfaults on MIC with whatever paras I chose.

Benchmarking: dynamic_1007 [md5(md5($p).$s) (vBulletin) 512/512 MIC 16x1]... DONE
Many salts:     3261K c/s real, 3261K c/s virtual
Only one salt:  818376 c/s real, 818376 c/s virtual

Segmentation fault
<!-- gh-comment-id:121879294 --> @lei-april commented on GitHub (Jul 16, 2015): Unfortunately, dynamic_1007 still segfaults on MIC with whatever paras I chose. ``` Benchmarking: dynamic_1007 [md5(md5($p).$s) (vBulletin) 512/512 MIC 16x1]... DONE Many salts: 3261K c/s real, 3261K c/s virtual Only one salt: 818376 c/s real, 818376 c/s virtual Segmentation fault ```
Author
Owner

@frank-dittrich commented on GitHub (Jul 16, 2015):

@zzlei SInce Jim can't reproduce this, he might want to see the backtrace.

<!-- gh-comment-id:121928914 --> @frank-dittrich commented on GitHub (Jul 16, 2015): @zzlei SInce Jim can't reproduce this, he might want to see the backtrace.
Author
Owner

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

Please test again, after 7971927

<!-- gh-comment-id:121955373 --> @jfoug commented on GitHub (Jul 16, 2015): Please test again, after 7971927
Author
Owner

@lei-april commented on GitHub (Jul 16, 2015):

I think there's something else wrong with dynamic_1007. It still segfaults after github.com/magnumripper/JohnTheRipper@79719273ae.

<!-- gh-comment-id:121960876 --> @lei-april commented on GitHub (Jul 16, 2015): I think there's something else wrong with dynamic_1007. It still segfaults after https://github.com/magnumripper/JohnTheRipper/commit/79719273ae68a4990d6a163f8a05175b43494e49.
Author
Owner

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

I do not understand the problem. The script is the same for dynamic_6 and dynamic_1007. In your dynamic.conf, please comment this line out of the 1007

#SaltLenX86=-64

Other than that, these formats should be 100% the same, AND since this is MIC, then I would think the above flag would be ignored anyway. There really should be no differences.

On a 2nd item, can you comment out the test lines, and replace them with the test vectors from dyna_6 and see if that helps.

If either of these help, then it may show some underlying issue in the dyna-6/1007 code. But I just do not see how.

<!-- gh-comment-id:121978606 --> @jfoug commented on GitHub (Jul 16, 2015): I do not understand the problem. The script is the same for dynamic_6 and dynamic_1007. In your dynamic.conf, please comment this line out of the 1007 #SaltLenX86=-64 Other than that, these formats should be 100% the same, AND since this is MIC, then I would think the above flag would be ignored anyway. There really should be no differences. On a 2nd item, can you comment out the test lines, and replace them with the test vectors from dyna_6 and see if that helps. If either of these help, then it may show some underlying issue in the dyna-6/1007 code. But I just do not see how.
Author
Owner

@lei-april commented on GitHub (Jul 16, 2015):

According to the backtrace, the segfault happened in some OpenMP library function. I guess there's something wrong with the OpenMP library used. I rebuilt with a newer version of icc and libiomp, and the problem was gone. At least for SIMD_PARA_MD4 = 5 and SIMD_PARA_MD5 = 4, no dynamic format fails or segfaults anymore. I'll test against other combinations of paras.

<!-- gh-comment-id:121979239 --> @lei-april commented on GitHub (Jul 16, 2015): According to the backtrace, the segfault happened in some OpenMP library function. I guess there's something wrong with the OpenMP library used. I rebuilt with a newer version of icc and libiomp, and the problem was gone. At least for `SIMD_PARA_MD4 = 5` and `SIMD_PARA_MD5 = 4`, no dynamic format fails or segfaults anymore. I'll test against other combinations of paras.
Author
Owner

@lei-april commented on GitHub (Jul 16, 2015):

I think this issue is solved.

<!-- gh-comment-id:121985596 --> @lei-april commented on GitHub (Jul 16, 2015): I think this issue is solved.
Author
Owner

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

@zzlei for future reference please state versions of the failing icc/lib as well as the working ones.

<!-- gh-comment-id:122023089 --> @magnumripper commented on GitHub (Jul 16, 2015): @zzlei for future reference please state versions of the failing icc/lib as well as the working ones.
Author
Owner

@lei-april commented on GitHub (Jul 17, 2015):

Strangely, somehow I cannot reproduce dynamic_1007's error...

I previously tested this on super and got this error. Then I move to my lab's machine, where a newer version of icc is installed (bundled with libiomp), and found the error gone. So I thought there must be something wrong with the older libiomp used on super.

Just now I went back to super and re-transfered libiomp to MIC, and the error was also gone. libiomp here should be the same one as before (I don't have the permission to upgrade icc on super). I really don't know how re-transfering the lib solved the problem. Maybe I did something else wrong, but I couldn't remember...

<!-- gh-comment-id:122148636 --> @lei-april commented on GitHub (Jul 17, 2015): Strangely, somehow I cannot reproduce dynamic_1007's error... I previously tested this on super and got this error. Then I move to my lab's machine, where a newer version of icc is installed (bundled with libiomp), and found the error gone. So I thought there must be something wrong with the older libiomp used on super. Just now I went back to super and re-transfered libiomp to MIC, and the error was also gone. libiomp here should be the same one as before (I don't have the permission to upgrade icc on super). I really don't know how re-transfering the lib solved the problem. Maybe I did something else wrong, but I couldn't remember...
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#922
No description provided.