[GH-ISSUE #1159] aix_smd5_fmt: asan error #725

Closed
opened 2026-10-14 03:21:26 +07:00 by bsakaguchi · 28 comments
Owner

Originally created by @loverszhaokai on GitHub (Mar 26, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1159

This bug is found by fuzzzing John using AFL.
#1. Prepare

1.1 content of aix_smd5_fmt

{smd5}s8/xSJ/v$uGam4GB8hOjTLQqvBfxJ2/
{smd5}alRJaSLb$aKM3H1.h1ycXl5GEVDH1e1
{smd5}eLB0QWeS$Eg.YfWY8clZuCxF0xNrKg.
$1$JVDbGx8K$T9h8HK4LZxeLPMTAxCfpc1
$1$1Cu6fEvv$42kuaJ5fMEqyVStPuFG040
$1$ql5x.xXL$vYVDhExol2xUBBpERRWcn1

1.2 compile with asan

$ export ASAN_OPTIONS='abort_on_error=1'
$ AFL_USE_ASAN=1 AFL_HARDEN=1 ./configure CC=gcc-4.9 --enable-asan && make -sj8
#2. Reproduce

Note: you should press Ctrl-C to abort john, and after cancel you will see the asan error

$ ./john aix_smd5_fmt
Warning: detected hash type "md5crypt", but the string is also recognized as "aix-smd5"
Use the "--format=aix-smd5" option to force loading these as that type instead
Loaded 6 password hashes with 6 different salts (md5crypt, crypt(3) 1 [MD5 128/128 AVX 12x])
Remaining 4 password hashes with 4 different salts
Will run 8 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
0g 0:00:00:01 2/3 0g/s 5907p/s 24287c/s 24287C/s Sss..rogers

==21362==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x000002d3e040 in thread T0
#0 0x7f0bb6f805c7 in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x545c7)
#1 0x7a6c62 in MEMDBG_off_free /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/memdbg.c:1099
#2 0x426ce1 in done /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/MD5_fmt.c:119
#3 0x732358 in fmt_done /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/formats.c:112
#4 0x73fecb in john_done /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/john.c:1478
#5 0x740633 in main /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/john.c:1688
#6 0x7f0bb57bfec4 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21ec4)
#7 0x406cb2 (/home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/run/john+0x406cb2)

AddressSanitizer can not describe address in more detail (wild memory access suspected).
SUMMARY: AddressSanitizer: bad-free ??:0 __interceptor_free
==21362==ABORTING
Aborted (core dumped)

Originally created by @loverszhaokai on GitHub (Mar 26, 2015). Original GitHub issue: https://github.com/openwall/john/issues/1159 This bug is found by fuzzzing John using AFL. #1. Prepare ## 1.1 content of aix_smd5_fmt {smd5}s8/xSJ/v$uGam4GB8hOjTLQqvBfxJ2/ {smd5}alRJaSLb$aKM3H1.h1ycXl5GEVDH1e1 {smd5}eLB0QWeS$Eg.YfWY8clZuCxF0xNrKg. $1$JVDbGx8K$T9h8HK4LZxeLPMTAxCfpc1 $1$1Cu6fEvv$42kuaJ5fMEqyVStPuFG040 $1$ql5x.xXL$vYVDhExol2xUBBpERRWcn1 ## 1.2 compile with asan $ export ASAN_OPTIONS='abort_on_error=1' $ AFL_USE_ASAN=1 AFL_HARDEN=1 ./configure CC=gcc-4.9 --enable-asan && make -sj8 #2. Reproduce Note: you should press **Ctrl-C** to abort john, and after cancel you will see the asan error $ ./john aix_smd5_fmt Warning: detected hash type "md5crypt", but the string is also recognized as "aix-smd5" Use the "--format=aix-smd5" option to force loading these as that type instead Loaded 6 password hashes with 6 different salts (md5crypt, crypt(3) $1$ [MD5 128/128 AVX 12x]) Remaining 4 password hashes with 4 different salts Will run 8 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status 0g 0:00:00:01 2/3 0g/s 5907p/s 24287c/s 24287C/s Sss..rogers ==21362==**ERROR**: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x000002d3e040 in thread T0 #0 0x7f0bb6f805c7 in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x545c7) #1 0x7a6c62 in MEMDBG_off_free /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/memdbg.c:1099 #2 0x426ce1 in done /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/MD5_fmt.c:119 #3 0x732358 in fmt_done /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/formats.c:112 #4 0x73fecb in john_done /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/john.c:1478 #5 0x740633 in main /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/john.c:1688 #6 0x7f0bb57bfec4 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21ec4) #7 0x406cb2 (/home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/run/john+0x406cb2) AddressSanitizer can not describe address in more detail (wild memory access suspected). SUMMARY: AddressSanitizer: bad-free ??:0 __interceptor_free ==21362==ABORTING Aborted (core dumped)
bsakaguchi 2026-10-14 03:21:26 +07:00
Author
Owner

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

I can not reproduce. Are you still using gcc 4.8? Like I said, it seems you can't reliably use ASan with gcc older than 4.9 since we introduced posix_memalign in f22ab24c7

<!-- gh-comment-id:86493317 --> @magnumripper commented on GitHub (Mar 26, 2015): I can not reproduce. Are you still using gcc 4.8? Like I said, it seems you can't reliably use ASan with gcc older than 4.9 since we introduced posix_memalign in f22ab24c7
Author
Owner

@loverszhaokai commented on GitHub (Mar 26, 2015):

@magnumripper I will reproduce again with gcc 4.8 to ensure. If I can reproduce, I will update my gcc.

<!-- gh-comment-id:86495682 --> @loverszhaokai commented on GitHub (Mar 26, 2015): @magnumripper I will reproduce again with gcc 4.8 to ensure. If I can reproduce, I will update my gcc.
Author
Owner

@loverszhaokai commented on GitHub (Mar 26, 2015):

@magnumripper

I tested again with gcc-4.8 and gcc-4.9, both can reproduce. I have updated the issue. The gcc-4.9 is good than gcc-4.8 for it does not need asan_symbolize.py.

Have you pay attention to the note: "you should press Ctrl-C to abort john, and after cancel you will see the asan error"

  • Firstly

$ ./john aix_smd5_fmt

  • Secondly

$ Ctrl-C

<!-- gh-comment-id:86512781 --> @loverszhaokai commented on GitHub (Mar 26, 2015): @magnumripper I tested again with gcc-4.8 and gcc-4.9, **both can reproduce**. I have updated the issue. The gcc-4.9 is good than gcc-4.8 for it does not need asan_symbolize.py. Have you pay attention to the note: "you should press **Ctrl-C** to abort john, and after cancel you will see the asan error" - Firstly $ ./john aix_smd5_fmt - Secondly $ **Ctrl-C**
Author
Owner

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

Have you pay attention to the note:

Yes, and I tried several times. Does it happen every time for you?

<!-- gh-comment-id:86517623 --> @magnumripper commented on GitHub (Mar 26, 2015): > Have you pay attention to the note: Yes, and I tried several times. Does it happen every time for you?
Author
Owner

@loverszhaokai commented on GitHub (Mar 26, 2015):

@magnumripper

Does it happen every time for you?

Yes. And I used test latest commit.

<!-- gh-comment-id:86518070 --> @loverszhaokai commented on GitHub (Mar 26, 2015): @magnumripper > Does it happen every time for you? Yes. And I used test latest commit.
Author
Owner

@loverszhaokai commented on GitHub (Mar 26, 2015):

@magnumripper

Same as the asaMD5_fmt. Both github.com/magnumripper/JohnTheRipper@2804be3762 and github.com/magnumripper/JohnTheRipper@dc6159870e can not reproduce. The bug seems to be introduced days ago.

<!-- gh-comment-id:86522056 --> @loverszhaokai commented on GitHub (Mar 26, 2015): @magnumripper Same as the asaMD5_fmt. Both https://github.com/magnumripper/JohnTheRipper/commit/2804be3762a818b833ee7b7155b3165c1c9c93d7 and https://github.com/magnumripper/JohnTheRipper/commit/dc6159870e53467fb90acb54105497dd4acc87fa **can not reproduce**. The bug seems to be introduced days ago.
Author
Owner

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

This is probably same ASan problem as seen in #1160. ASan mentions MD5_fmt.c:119

    91  static void init(struct fmt_main *self)
    92  {
    93          MD5_std_init(self);
    94  #if defined(_OPENMP) && defined(MD5_SSE_PARA)
    95          omp_para = omp_get_max_threads();
    96          if (omp_para < 1)
    97                  omp_para = 1;
    98          self->params.min_keys_per_crypt = MD5_N * omp_para;
    99          omp_para *= OMP_SCALE;
   100          self->params.max_keys_per_crypt = MD5_N * omp_para;
   101  #elif MD5_std_mt
   102          self->params.min_keys_per_crypt = MD5_std_min_kpc;
   103          self->params.max_keys_per_crypt = MD5_std_max_kpc;
   104  #endif
   105  
   106          saved_key = mem_calloc_align(self->params.max_keys_per_crypt,
   107                                       sizeof(*saved_key), MEM_ALIGN_CACHE);
   108  #ifdef MD5_SSE_PARA
   109          sout = mem_calloc(self->params.max_keys_per_crypt,
   110                            sizeof(*sout) * BINARY_SIZE);
   111  #endif
   112  }
   113  
   114  static void done(void)
   115  {
   116  #ifdef MD5_SSE_PARA
   117          MEM_FREE(sout);
   118  #endif
   119          MEM_FREE(saved_key);
   120  }

...so just put debug prints after line 107 and before line 119. If they show the same (I bet they do) you merely have the ASan bug showing up.

<!-- gh-comment-id:86532571 --> @magnumripper commented on GitHub (Mar 26, 2015): This is probably same ASan problem as seen in #1160. ASan mentions MD5_fmt.c:119 ``` C 91 static void init(struct fmt_main *self) 92 { 93 MD5_std_init(self); 94 #if defined(_OPENMP) && defined(MD5_SSE_PARA) 95 omp_para = omp_get_max_threads(); 96 if (omp_para < 1) 97 omp_para = 1; 98 self->params.min_keys_per_crypt = MD5_N * omp_para; 99 omp_para *= OMP_SCALE; 100 self->params.max_keys_per_crypt = MD5_N * omp_para; 101 #elif MD5_std_mt 102 self->params.min_keys_per_crypt = MD5_std_min_kpc; 103 self->params.max_keys_per_crypt = MD5_std_max_kpc; 104 #endif 105 106 saved_key = mem_calloc_align(self->params.max_keys_per_crypt, 107 sizeof(*saved_key), MEM_ALIGN_CACHE); 108 #ifdef MD5_SSE_PARA 109 sout = mem_calloc(self->params.max_keys_per_crypt, 110 sizeof(*sout) * BINARY_SIZE); 111 #endif 112 } 113 114 static void done(void) 115 { 116 #ifdef MD5_SSE_PARA 117 MEM_FREE(sout); 118 #endif 119 MEM_FREE(saved_key); 120 } ``` ...so just put debug prints after line 107 and before line 119. If they show the same (I bet they do) you merely have the ASan bug showing up.
Author
Owner

@loverszhaokai commented on GitHub (Mar 26, 2015):

@magnumripper

diff --git a/src/MD5_fmt.c b/src/MD5_fmt.c
index a09360f..9593ade 100644
--- a/src/MD5_fmt.c
+++ b/src/MD5_fmt.c
@@ -105,6 +105,7 @@ static void init(struct fmt_main *self)

        saved_key = mem_calloc_align(self->params.max_keys_per_crypt,
                                     sizeof(*saved_key), MEM_ALIGN_CACHE);
+       fprintf(stderr, "%s(): saved_key is at %p\n", __FUNCTION__, saved_key);
 #ifdef MD5_SSE_PARA
        sout = mem_calloc(self->params.max_keys_per_crypt,
                          sizeof(*sout) * BINARY_SIZE);
@@ -116,6 +117,7 @@ static void done(void)
 #ifdef MD5_SSE_PARA
        MEM_FREE(sout);
 #endif
+       fprintf(stderr, "%s(): saved_key is at %p\n", __FUNCTION__, saved_key);
        MEM_FREE(saved_key);
 }

And the output is below, they are the same address.

init(): saved_key is at 0x2521040
Warning: detected hash type "md5crypt", but the string is also recognized as "aix-smd5"
Use the "--format=aix-smd5" option to force loading these as that type instead
Loaded 6 password hashes with 6 different salts (md5crypt, crypt(3) 1 [MD5 128/128 AVX 12x])
Remaining 4 password hashes with 4 different salts
Will run 8 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
0g 0:00:00:02 2/3 0g/s 6087p/s 24819c/s 24819C/s Inuyasha1..Supra1
done(): saved_key is at 0x2521040

==61195==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x000002521040 in thread T0
#0 0x7fb5814cd5c7 in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x545c7)
#1 0x7a6e09 in MEMDBG_off_free /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/memdbg.c:1099
#2 0x426d24 in done /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/MD5_fmt.c:121
#3 0x7323dc in fmt_done /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/formats.c:112
#4 0x73ff4f in john_done /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/john.c:1478
#5 0x7406b7 in main /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/john.c:1688
#6 0x7fb57fd0cec4 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21ec4)
#7 0x406cb2 (/home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/run/john+0x406cb2)

AddressSanitizer can not describe address in more detail (wild memory access suspected).
SUMMARY: AddressSanitizer: bad-free ??:0 __interceptor_free
==61195==ABORTING
Aborted

<!-- gh-comment-id:86537217 --> @loverszhaokai commented on GitHub (Mar 26, 2015): @magnumripper ``` C diff --git a/src/MD5_fmt.c b/src/MD5_fmt.c index a09360f..9593ade 100644 --- a/src/MD5_fmt.c +++ b/src/MD5_fmt.c @@ -105,6 +105,7 @@ static void init(struct fmt_main *self) saved_key = mem_calloc_align(self->params.max_keys_per_crypt, sizeof(*saved_key), MEM_ALIGN_CACHE); + fprintf(stderr, "%s(): saved_key is at %p\n", __FUNCTION__, saved_key); #ifdef MD5_SSE_PARA sout = mem_calloc(self->params.max_keys_per_crypt, sizeof(*sout) * BINARY_SIZE); @@ -116,6 +117,7 @@ static void done(void) #ifdef MD5_SSE_PARA MEM_FREE(sout); #endif + fprintf(stderr, "%s(): saved_key is at %p\n", __FUNCTION__, saved_key); MEM_FREE(saved_key); } ``` And the output is below, they are the same address. **init(): saved_key is at 0x2521040** Warning: detected hash type "md5crypt", but the string is also recognized as "aix-smd5" Use the "--format=aix-smd5" option to force loading these as that type instead Loaded 6 password hashes with 6 different salts (md5crypt, crypt(3) $1$ [MD5 128/128 AVX 12x]) Remaining 4 password hashes with 4 different salts Will run 8 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status 0g 0:00:00:02 2/3 0g/s 6087p/s 24819c/s 24819C/s Inuyasha1..Supra1 **done(): saved_key is at 0x2521040** ==61195==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: **0x000002521040** in thread T0 #0 0x7fb5814cd5c7 in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x545c7) #1 0x7a6e09 in MEMDBG_off_free /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/memdbg.c:1099 #2 0x426d24 in done /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/MD5_fmt.c:121 #3 0x7323dc in fmt_done /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/formats.c:112 #4 0x73ff4f in john_done /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/john.c:1478 #5 0x7406b7 in main /home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/src/john.c:1688 #6 0x7fb57fd0cec4 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21ec4) #7 0x406cb2 (/home/zhaokai/WorkSpace/open_wall/JohnTheRipper_test_valid/run/john+0x406cb2) AddressSanitizer can not describe address in more detail (wild memory access suspected). SUMMARY: AddressSanitizer: bad-free ??:0 __interceptor_free ==61195==ABORTING Aborted
Author
Owner

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

Assuming you run 64-bit Linux, here's a patch that will mitigate this ASan bug from showing up:

diff --git a/src/memory.c b/src/memory.c
index e0f60a0..9c8ae1d 100644
--- a/src/memory.c
+++ b/src/memory.c
@@ -224,6 +224,10 @@ void *mem_alloc_align_func(size_t size, size_t align
        )
 {
        void *ptr = NULL;
+#if WITH_ASAN && defined(__APPLE__) || (defined(__linux__) && ARCH_BITS >= 64)
+       if (align <= 16)
+               return mem_alloc(size);
+#endif
 #if defined (MEMDBG_ON)
        ptr = (char*) MEMDBG_alloc_align(size, align, file, line);
 #elif HAVE_ALIGNED_ALLOC

(edit: the second part of the patch was not needed so I deleted it)

This relies on the fact that 64-bit Linux (and any OSX) will always align to 16. Please try this. If your problems with ASan go away, we can commit this.

<!-- gh-comment-id:86538627 --> @magnumripper commented on GitHub (Mar 26, 2015): Assuming you run 64-bit Linux, here's a patch that will mitigate this ASan bug from showing up: ``` diff diff --git a/src/memory.c b/src/memory.c index e0f60a0..9c8ae1d 100644 --- a/src/memory.c +++ b/src/memory.c @@ -224,6 +224,10 @@ void *mem_alloc_align_func(size_t size, size_t align ) { void *ptr = NULL; +#if WITH_ASAN && defined(__APPLE__) || (defined(__linux__) && ARCH_BITS >= 64) + if (align <= 16) + return mem_alloc(size); +#endif #if defined (MEMDBG_ON) ptr = (char*) MEMDBG_alloc_align(size, align, file, line); #elif HAVE_ALIGNED_ALLOC ``` (**edit**: the second part of the patch was not needed so I deleted it) This relies on the fact that 64-bit Linux (and any OSX) will always align to 16. Please try this. If your problems with ASan go away, we can commit this.
Author
Owner

@loverszhaokai commented on GitHub (Mar 26, 2015):

@magnumripper

Yes, my ubuntu is 64 bit.
$ uname -a
Linux ubuntu 4.0.0-rc1+ #2 SMP Sun Mar 1 10:08:08 CST 2015 x86_64 x86_64 x86_64 GNU/Linux

<!-- gh-comment-id:86540104 --> @loverszhaokai commented on GitHub (Mar 26, 2015): @magnumripper Yes, my ubuntu is **64** bit. $ uname -a Linux ubuntu 4.0.0-rc1+ #2 SMP Sun Mar 1 10:08:08 CST 2015 x86_64 x86_64 x86_64 GNU/Linux
Author
Owner

@loverszhaokai commented on GitHub (Mar 26, 2015):

@magnumripper

I tested, but there is still ASan error.

diff --git a/src/memory.c b/src/memory.c
index e0f60a0..95230f2 100644
--- a/src/memory.c
+++ b/src/memory.c
@@ -224,6 +224,12 @@ void *mem_alloc_align_func(size_t size, size_t align
        )
 {
        void *ptr = NULL;
+
+#if defined(__APPLE__) || (defined(__linux__) && ARCH_BITS >= 64)
+      if (align <= 16)
+               return mem_alloc(size);
+#endif
+
 #if defined (MEMDBG_ON)
        ptr = (char*) MEMDBG_alloc_align(size, align, file, line);
 #elif HAVE_ALIGNED_ALLOC
@@ -254,10 +260,18 @@ void *mem_calloc_align_func(size_t count, size_t size, size_t align
 #endif
        )
 {
+
+       void *ptr = NULL;
+#if defined(__APPLE__) || (defined(__linux__) && ARCH_BITS >= 64)
+       if (align <= 16)
+               return mem_calloc(count, size);
+#endif
+
+
 #if defined (MEMDBG_ON)
-       void *ptr = mem_alloc_align_func(size * count, align, file, line);
+       ptr = mem_alloc_align_func(size * count, align, file, line);
 #else
-       void *ptr = mem_alloc_align_func(size * count, align);
+       ptr = mem_alloc_align_func(size * count, align);
 #endif

        memset(ptr, 0, size * count);
<!-- gh-comment-id:86541345 --> @loverszhaokai commented on GitHub (Mar 26, 2015): @magnumripper I tested, but there is still ASan error. ``` diff diff --git a/src/memory.c b/src/memory.c index e0f60a0..95230f2 100644 --- a/src/memory.c +++ b/src/memory.c @@ -224,6 +224,12 @@ void *mem_alloc_align_func(size_t size, size_t align ) { void *ptr = NULL; + +#if defined(__APPLE__) || (defined(__linux__) && ARCH_BITS >= 64) + if (align <= 16) + return mem_alloc(size); +#endif + #if defined (MEMDBG_ON) ptr = (char*) MEMDBG_alloc_align(size, align, file, line); #elif HAVE_ALIGNED_ALLOC @@ -254,10 +260,18 @@ void *mem_calloc_align_func(size_t count, size_t size, size_t align #endif ) { + + void *ptr = NULL; +#if defined(__APPLE__) || (defined(__linux__) && ARCH_BITS >= 64) + if (align <= 16) + return mem_calloc(count, size); +#endif + + #if defined (MEMDBG_ON) - void *ptr = mem_alloc_align_func(size * count, align, file, line); + ptr = mem_alloc_align_func(size * count, align, file, line); #else - void *ptr = mem_alloc_align_func(size * count, align); + ptr = mem_alloc_align_func(size * count, align); #endif memset(ptr, 0, size * count); ```
Author
Owner

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

OK That is really strange. Why would ASan not recognize a simple malloc/free?

Maybe this isn't an ASan bug after all but Jim's memdbg macros are interfering in some way. I never liked the fact they "show up" at all in a non-memdbg build. @jfoug what do you think?

<!-- gh-comment-id:86543269 --> @magnumripper commented on GitHub (Mar 26, 2015): OK That is **really** strange. Why would ASan not recognize a simple malloc/free? Maybe this isn't an ASan bug after all but Jim's memdbg macros are interfering in some way. I never liked the fact they "show up" at all in a non-memdbg build. @jfoug what do you think?
Author
Owner

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

@loverszhaokai try a memdbg AND ASan build:

make -s distclean && ./configure --enable-memdbg --enable-asan && make -sj8

...and see how that one behaves.

<!-- gh-comment-id:86544444 --> @magnumripper commented on GitHub (Mar 26, 2015): @loverszhaokai try a memdbg AND ASan build: ``` make -s distclean && ./configure --enable-memdbg --enable-asan && make -sj8 ``` ...and see how that one behaves.
Author
Owner

@loverszhaokai commented on GitHub (Mar 26, 2015):

@magnumripper Should I use gcc-4.9 ?

make -s distclean && ./configure CC=gcc-4.9 --enable-memdbg --enable-asan && make -sj8
<!-- gh-comment-id:86545397 --> @loverszhaokai commented on GitHub (Mar 26, 2015): @magnumripper Should I use gcc-4.9 ? ``` make -s distclean && ./configure CC=gcc-4.9 --enable-memdbg --enable-asan && make -sj8 ```
Author
Owner

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

Yes, or 4.8 - doesn't matter

<!-- gh-comment-id:86545561 --> @magnumripper commented on GitHub (Mar 26, 2015): Yes, or 4.8 - doesn't matter
Author
Owner

@loverszhaokai commented on GitHub (Mar 26, 2015):

@magnumripper There is still ASan error with both gcc-4.8 and gcc-4.9

<!-- gh-comment-id:86547171 --> @loverszhaokai commented on GitHub (Mar 26, 2015): @magnumripper There is still ASan error with both gcc-4.8 and gcc-4.9
Author
Owner

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

I have absolutely no idea what is happening here. Please try to debug it and see what is really happening. At some point we get a pointer from an actual libc function and not a wrapper. What is that pointer? Are we not freeing the very same address?

<!-- gh-comment-id:86555284 --> @magnumripper commented on GitHub (Mar 26, 2015): I have absolutely no idea what is happening here. Please try to debug it and see what is really happening. At some point we get a pointer from an actual libc function and not a wrapper. What is that pointer? Are we not freeing the very same address?
Author
Owner

@loverszhaokai commented on GitHub (Mar 26, 2015):

@magnumripper I just get many ASan errors like aix_smd5_fmt which seems alike.

<!-- gh-comment-id:86557630 --> @loverszhaokai commented on GitHub (Mar 26, 2015): @magnumripper I just get many ASan errors like aix_smd5_fmt which seems alike.
Author
Owner

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

Yes. I'd just like to be really sure it's an ASan bug and not some memdbg header bug. So you should concentrate on one (perhaps this one) and try to explain it too 100%.

<!-- gh-comment-id:86559491 --> @magnumripper commented on GitHub (Mar 26, 2015): Yes. I'd just like to be **really** sure it's an ASan bug and not some memdbg header bug. So you should concentrate on one (perhaps this one) and try to explain it too 100%.
Author
Owner

@loverszhaokai commented on GitHub (Mar 26, 2015):

@magnumripper Thanks. I will try to make it sure in recent days.

<!-- gh-comment-id:86559988 --> @loverszhaokai commented on GitHub (Mar 26, 2015): @magnumripper Thanks. I will try to make it sure in recent days.
Author
Owner

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

@loverszhaokai did you get accounts on Openwall's hosts yet? I just tried to reproduce this bug on "well" (64-bit Linux) but I still see no problem. I used gcc version 4.9.2.

<!-- gh-comment-id:86567455 --> @magnumripper commented on GitHub (Mar 26, 2015): @loverszhaokai did you get accounts on Openwall's hosts yet? I just tried to reproduce this bug on "well" (64-bit Linux) but I still see no problem. I used gcc version 4.9.2.
Author
Owner

@loverszhaokai commented on GitHub (Mar 26, 2015):

@magnumripper I have not got an account on Openwall's hosts.

but I still see no problem

Do you mean you can not see ASan error ?

<!-- gh-comment-id:86567930 --> @loverszhaokai commented on GitHub (Mar 26, 2015): @magnumripper I have not got an account on Openwall's hosts. > but I still see no problem Do you mean you can not see ASan error ?
Author
Owner

@loverszhaokai commented on GitHub (Mar 28, 2015):

@magnumripper

Thanks for your help. It's really a asan bug, 👍
[asan] is not intercepting aligned_alloc, here is the link for asan bug of gcc: https://gcc.gnu.org/ml/gcc-bugs/2014-07/msg00198.html

The mem_calloc_align() in MD5_fmt.c line 106 invokes aligned_alloc()

 91static void init(struct fmt_main *self)
 92{
 93        MD5_std_init(self);
 94#if defined(_OPENMP) && defined(MD5_SSE_PARA)
 95        omp_para = omp_get_max_threads();
 96        if (omp_para < 1)
 97                omp_para = 1;
 98        self->params.min_keys_per_crypt = MD5_N * omp_para;
 99        omp_para *= OMP_SCALE;
100        self->params.max_keys_per_crypt = MD5_N * omp_para;
101#elif MD5_std_mt
102        self->params.min_keys_per_crypt = MD5_std_min_kpc;
103        self->params.max_keys_per_crypt = MD5_std_max_kpc;
104#endif
105
106        saved_key = mem_calloc_align(self->params.max_keys_per_crypt,
107                                     sizeof(*saved_key), MEM_ALIGN_CACHE);
108#ifdef MD5_SSE_PARA
109        sout = mem_calloc(self->params.max_keys_per_crypt,
110                          sizeof(*sout) * BINARY_SIZE);
<!-- gh-comment-id:87226192 --> @loverszhaokai commented on GitHub (Mar 28, 2015): @magnumripper Thanks for your help. It's really a asan bug, :+1: [asan] is not intercepting **aligned_alloc**, here is the link for **asan bug of gcc**: https://gcc.gnu.org/ml/gcc-bugs/2014-07/msg00198.html The mem_calloc_align() in MD5_fmt.c line 106 invokes **aligned_alloc()** ``` C 91static void init(struct fmt_main *self) 92{ 93 MD5_std_init(self); 94#if defined(_OPENMP) && defined(MD5_SSE_PARA) 95 omp_para = omp_get_max_threads(); 96 if (omp_para < 1) 97 omp_para = 1; 98 self->params.min_keys_per_crypt = MD5_N * omp_para; 99 omp_para *= OMP_SCALE; 100 self->params.max_keys_per_crypt = MD5_N * omp_para; 101#elif MD5_std_mt 102 self->params.min_keys_per_crypt = MD5_std_min_kpc; 103 self->params.max_keys_per_crypt = MD5_std_max_kpc; 104#endif 105 106 saved_key = mem_calloc_align(self->params.max_keys_per_crypt, 107 sizeof(*saved_key), MEM_ALIGN_CACHE); 108#ifdef MD5_SSE_PARA 109 sout = mem_calloc(self->params.max_keys_per_crypt, 110 sizeof(*sout) * BINARY_SIZE); ```
Author
Owner

@magnumripper commented on GitHub (Mar 28, 2015):

Oh, I see now the bug is only when aligned_alloc() is used. So we can prefer posix_memalign() when both are available (we currently prefer aligned_alloc) and problem is practically 100% worked around! This also explains why I did not see the bug on OSX - on that platform we use posix_memalign since aligned_alloc is not yet available. Will commit a workaround ASAP. I searched gcc bug tracker but did not find the bug you mention.

This also explains why problem was not seen on "well". That machine has an older libc so ends up using posix_memalign.

<!-- gh-comment-id:87305692 --> @magnumripper commented on GitHub (Mar 28, 2015): Oh, I see now the bug is only when aligned_alloc() is used. So we can prefer posix_memalign() when both are available (we currently prefer aligned_alloc) and problem is practically 100% worked around! This also explains why I did not see the bug on OSX - on that platform we use posix_memalign since aligned_alloc is not yet available. Will commit a workaround ASAP. I searched gcc bug tracker but did not find the bug you mention. This also explains why problem was not seen on "well". That machine has an older libc so ends up using posix_memalign.
Author
Owner

@magnumripper commented on GitHub (Mar 28, 2015):

@loverszhaokai please verify that 8c56cb2 fc55245 gets rid of the false positives, and thanks for finding this out!

<!-- gh-comment-id:87309043 --> @magnumripper commented on GitHub (Mar 28, 2015): @loverszhaokai please verify that ~~8c56cb2~~ fc55245 gets rid of the false positives, and thanks for finding this out!
Author
Owner

@magnumripper commented on GitHub (Mar 28, 2015):

Stupid me, I googled for "asan posix_memalign"... I should have googled "asan aligned_alloc" and I would have got it in the very first hit o.O

<!-- gh-comment-id:87313125 --> @magnumripper commented on GitHub (Mar 28, 2015): Stupid me, I googled for "asan posix_memalign"... I should have googled "asan aligned_alloc" and I would have got it in the very first hit o.O
Author
Owner

@magnumripper commented on GitHub (Mar 28, 2015):

OK I had to modify configure too because it did not look for posix_memalign after seeing aligned_alloc. fc55245 should be the definitve solution (and you have to re-run configure).

<!-- gh-comment-id:87315798 --> @magnumripper commented on GitHub (Mar 28, 2015): OK I had to modify configure too because it did not look for posix_memalign after seeing aligned_alloc. fc55245 should be the definitve solution (and you have to re-run configure).
Author
Owner

@loverszhaokai commented on GitHub (Mar 29, 2015):

@magnumripper Great! 👍

I searched gcc bug tracker but did not find the bug you mention.

Google: gcc asan aligned_alloc, and here is the link: https://gcc.gnu.org/ml/gcc-bugs/2014-07/msg00198.html

please verify that fc55245 gets rid of the false positives

Good! github.com/magnumripper/JohnTheRipper@fc552453a3 has solved this problem.

<!-- gh-comment-id:87331935 --> @loverszhaokai commented on GitHub (Mar 29, 2015): @magnumripper Great! :+1: > I searched gcc bug tracker but did not find the bug you mention. Google: gcc asan aligned_alloc, and here is the link: https://gcc.gnu.org/ml/gcc-bugs/2014-07/msg00198.html > please verify that fc55245 gets rid of the false positives Good! https://github.com/magnumripper/JohnTheRipper/commit/fc552453a35550168c99215f87e3adf6f10915e2 has solved this problem.
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#725
No description provided.