[GH-ISSUE #1111] Segfault in raw-sha1-ng on OpenBSD 5.6 (x86-64) #692

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

Originally created by @magnumripper on GitHub (Mar 17, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1111

Segfaults with --test but not when run alone. Likely some format prior to it that breaks something.
Seen on OpenBSD (x86-64)

Originally created by @magnumripper on GitHub (Mar 17, 2015). Original GitHub issue: https://github.com/openwall/john/issues/1111 Segfaults with --test ~~but not when run alone. Likely some format prior to it that breaks something.~~ Seen on OpenBSD (x86-64)
bsakaguchi 2026-10-14 03:20:07 +07:00
Author
Owner

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

Program received signal SIGSEGV, Segmentation fault.
0x0000003f6f7e7392 in sha1_fmt_get_key (index=Variable "index" is not available.
) at rawSHA1_ng_fmt_plug.c:448
448         memset(strrchr((char *)(key), 0x80), 0x00, 1);
(gdb) bt
#0  0x0000003f6f7e7392 in sha1_fmt_get_key (index=Variable "index" is not available.
) at rawSHA1_ng_fmt_plug.c:448
#1  0x0000003f6f8490f6 in fmt_self_test (format=0x3f6fbb6460) at formats.c:525
#2  0x0000003f6f83e034 in benchmark_format (format=0x3f6fbb6460, salts=1, results=0x7f7ffffdddc0)
    at bench.c:240
#3  0x0000003f6f83ec16 in benchmark_all () at bench.c:648
#4  0x0000003f6f850775 in john_run () at john.c:1309
#5  0x0000003f6f8514cb in main (argc=2, argv=0x7f7ffffde028) at john.c:1687
<!-- gh-comment-id:82489192 --> @magnumripper commented on GitHub (Mar 17, 2015): ``` Program received signal SIGSEGV, Segmentation fault. 0x0000003f6f7e7392 in sha1_fmt_get_key (index=Variable "index" is not available. ) at rawSHA1_ng_fmt_plug.c:448 448 memset(strrchr((char *)(key), 0x80), 0x00, 1); (gdb) bt #0 0x0000003f6f7e7392 in sha1_fmt_get_key (index=Variable "index" is not available. ) at rawSHA1_ng_fmt_plug.c:448 #1 0x0000003f6f8490f6 in fmt_self_test (format=0x3f6fbb6460) at formats.c:525 #2 0x0000003f6f83e034 in benchmark_format (format=0x3f6fbb6460, salts=1, results=0x7f7ffffdddc0) at bench.c:240 #3 0x0000003f6f83ec16 in benchmark_all () at bench.c:648 #4 0x0000003f6f850775 in john_run () at john.c:1309 #5 0x0000003f6f8514cb in main (argc=2, argv=0x7f7ffffde028) at john.c:1687 ```
Author
Owner

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

Testing: Raw-SHA1-ng, (pwlen <= 15) [SHA1 128/128 SSE2 4x]... 
Program received signal SIGSEGV, Segmentation fault.
memset (dst=0x0, c=0, n=1) at /usr/src/lib/libc/string/memset.c:43
43                              *d++ = (unsigned char)c;
(gdb) bt
#0  memset (dst=0x0, c=0, n=1) at /usr/src/lib/libc/string/memset.c:43
#1  0x00000339407e787a in sha1_fmt_get_key (index=0) at rawSHA1_ng_fmt_plug.c:449
#2  0x0000033940857216 in fmt_self_test (format=0x33940bc4d00) at formats.c:525
#3  0x000003394084c154 in benchmark_format (format=0x33940bc4d00, salts=1, results=0x7f7fffff5ba0)
    at bench.c:240
#4  0x000003394084cd36 in benchmark_all () at bench.c:648
#5  0x000003394085e895 in john_run () at john.c:1309
#6  0x000003394085f5eb in main (argc=3, argv=0x7f7fffff5e08) at john.c:1687
(gdb) fram 1
#1  0x00000339407e787a in sha1_fmt_get_key (index=0) at rawSHA1_ng_fmt_plug.c:449
449         memset(strrchr((char *)(key), 0x80), 0x00, 1);
(gdb) print key
$1 = {808998960, 1599293791, 1599360846, 2153205573, 0}
(gdb) x/5 key
0x339413cfa20 <key.8034>:       0x30385830      0x5f53495f      0x5f544f4e      0x80574f45
0x339413cfa30 <key.8034+16>:    0x00000000

This is just weird. Maybe its strrchr is totally fuked up? There is a 0x80 in the string, yet strrchr seems to have returned NULL.

<!-- gh-comment-id:82492855 --> @magnumripper commented on GitHub (Mar 17, 2015): ``` Testing: Raw-SHA1-ng, (pwlen <= 15) [SHA1 128/128 SSE2 4x]... Program received signal SIGSEGV, Segmentation fault. memset (dst=0x0, c=0, n=1) at /usr/src/lib/libc/string/memset.c:43 43 *d++ = (unsigned char)c; (gdb) bt #0 memset (dst=0x0, c=0, n=1) at /usr/src/lib/libc/string/memset.c:43 #1 0x00000339407e787a in sha1_fmt_get_key (index=0) at rawSHA1_ng_fmt_plug.c:449 #2 0x0000033940857216 in fmt_self_test (format=0x33940bc4d00) at formats.c:525 #3 0x000003394084c154 in benchmark_format (format=0x33940bc4d00, salts=1, results=0x7f7fffff5ba0) at bench.c:240 #4 0x000003394084cd36 in benchmark_all () at bench.c:648 #5 0x000003394085e895 in john_run () at john.c:1309 #6 0x000003394085f5eb in main (argc=3, argv=0x7f7fffff5e08) at john.c:1687 (gdb) fram 1 #1 0x00000339407e787a in sha1_fmt_get_key (index=0) at rawSHA1_ng_fmt_plug.c:449 449 memset(strrchr((char *)(key), 0x80), 0x00, 1); (gdb) print key $1 = {808998960, 1599293791, 1599360846, 2153205573, 0} (gdb) x/5 key 0x339413cfa20 <key.8034>: 0x30385830 0x5f53495f 0x5f544f4e 0x80574f45 0x339413cfa30 <key.8034+16>: 0x00000000 ``` This is just weird. Maybe its strrchr is totally fuked up? There **is** a 0x80 in the string, yet strrchr seems to have returned NULL.
Author
Owner

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

I am seeing this on linux-32 bit build also (since our memory changes)

Testing: Raw-SHA384 [SHA384 128/128 SSE4.1 2x]... (2xOMP) PASS
Testing: Raw-SHA512-ng [SHA512 128/128 SSSE3 2x]... (2xOMP) Segmentation fault (core dumped)

SHA1-ng does not run on this 32 bit VM (does not do SSSE4.1)

<!-- gh-comment-id:82517926 --> @jfoug commented on GitHub (Mar 17, 2015): I am seeing this on linux-32 bit build also (since our memory changes) Testing: Raw-SHA384 [SHA384 128/128 SSE4.1 2x]... (2xOMP) PASS Testing: Raw-SHA512-ng [SHA512 128/128 SSSE3 2x]... (2xOMP) Segmentation fault (core dumped) SHA1-ng does not run on this 32 bit VM (does not do SSSE4.1)
Author
Owner

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

SHA1-ng should work fine with just SSE2 as far as I can see. It emulates newer intrinsics if needed. BTW all other formats pass on that OpenBSD machine.

<!-- gh-comment-id:82539759 --> @magnumripper commented on GitHub (Mar 17, 2015): SHA1-ng should work fine with just SSE2 as far as I can see. It emulates newer intrinsics if needed. BTW all other formats pass on that OpenBSD machine.
Author
Owner

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

Found the problem in raw-sha512-ng. It required aligned allocation. It probably simply just did not show up before, since so much was done with alloc_tiny. But it certainly had issues on 32 bit.

I will look at SHA1-ng if I have time. I really hate working on the -ng stuff.

<!-- gh-comment-id:82639388 --> @jfoug commented on GitHub (Mar 17, 2015): Found the problem in raw-sha512-ng. It required aligned allocation. It probably simply just did not show up before, since so much was done with alloc_tiny. But it certainly had issues on 32 bit. I will look at SHA1-ng if I have time. I really hate working on the -ng stuff.
Author
Owner

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

I'd be surprised if you see the same bug I saw in raw-sha1-ng on that OpenBSD gear. I can break right before that strrchr() and verify the 'key' string ends with 0x80. Still, the strrchr(key, 0x80) returns NULL. That just doesn't make sense so I'm tempted to just ignore that crapyard machine and close this.

<!-- gh-comment-id:82653801 --> @magnumripper commented on GitHub (Mar 18, 2015): I'd be surprised if you see the same bug I saw in raw-sha1-ng on that OpenBSD gear. I can break right before that strrchr() and verify the 'key' string ends with 0x80. Still, the strrchr(key, 0x80) returns NULL. That just doesn't make sense so I'm tempted to just ignore that crapyard machine and close this.
Author
Owner

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

BTW for a while I thought it was something to do with 0x80 being negative (if a signed char) and that parameter to strrchr being an int. But as written, that 0x80 never is a char. It is a constant of 0x80 given where an int is expected, should be no problem at all. Besides, it works on all other machines I know of.

<!-- gh-comment-id:82654300 --> @magnumripper commented on GitHub (Mar 18, 2015): BTW for a while I thought it was something to do with 0x80 being negative (if a signed char) and that parameter to strrchr being an int. But as written, that 0x80 never is a char. It is a constant of 0x80 given where an int is expected, should be no problem at all. Besides, it works on all other machines I know of.
Author
Owner

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

Dropped the bug label from this one. It simply can't be a bug in the format, I could see everything being fine and dandy in the debugger - except the return from strrchr. Not sure what that is about, but it's not us.

<!-- gh-comment-id:83754419 --> @magnumripper commented on GitHub (Mar 19, 2015): Dropped the bug label from this one. It simply can't be a bug in the format, I could see everything being fine and dandy in the debugger - except the return from strrchr. Not sure what that is about, but it's not us.
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#692
No description provided.