[GH-ISSUE #726] rar5 and pbkdf2-hmac-sha256 OpenCL formats segfault #369

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

Originally created by @magnumripper on GitHub (Aug 27, 2014).
Original GitHub issue: https://github.com/openwall/john/issues/726

@ukasz mentions a bug in 4aa53ac (or http://www.openwall.com/lists/john-dev/2013/08/11/6) that seems to be worse now and just (re-) commenting out the clReleaseMemObject for mem_state does not help much anymore. We need to find the real bug. I spent the better parts of this day trying to track it down (using pbkdf2-hmac-sha256-opencl from 3774f329 because it's simpler than current code) but I just can't nail it.

There's got to be a buffer overwrite or something. It's not a driver bug: I see the bug in rar5-opencl and/or pbkdf2-hmac-sha256-opencl with several totally different drivers (AMD, nvidia, Intel) yet some drivers (or situations) don't trigger it.

In some cases, --skip-self-tests reliably hides the bug, in others it does not.

Originally created by @magnumripper on GitHub (Aug 27, 2014). Original GitHub issue: https://github.com/openwall/john/issues/726 @ukasz mentions a bug in 4aa53ac (or http://www.openwall.com/lists/john-dev/2013/08/11/6) that seems to be worse now and just (re-) commenting out the clReleaseMemObject for mem_state does not help much anymore. We need to find the real bug. I spent the better parts of this day trying to track it down (using pbkdf2-hmac-sha256-opencl from 3774f329 because it's simpler than current code) but I just can't nail it. There's got to be a buffer overwrite or something. It's not a driver bug: I see the bug in rar5-opencl and/or pbkdf2-hmac-sha256-opencl with several totally different drivers (AMD, nvidia, Intel) yet some drivers (or situations) don't trigger it. In some cases, --skip-self-tests reliably hides the bug, in others it does not.
bsakaguchi 2026-10-14 03:03:14 +07:00
Author
Owner

@magnumripper commented on GitHub (Aug 27, 2014):

Valgrind has a hard time keeping up with OpenCL stuff (missing debug info in libraries). Among lots of probably false positives, it outputs some cryptic stuff about overwrites but with an unusable backtrace.

Enabling MEMDBG_ON with MEMDBG_EXTRA_CHECKS in JtR (see memdbg_defines.h) does warn about buffers used (even written to iirc) after free but it only points out where they (I think) were allocated, not where they were molested. Both cases I've seen pointed to host_crack = mem_calloc(kpc * sizeof(crack_t)); which is kinda confusing.

Heavily over-allocating buffers, or shrinking max password length, does not help.

<!-- gh-comment-id:53619111 --> @magnumripper commented on GitHub (Aug 27, 2014): Valgrind has a hard time keeping up with OpenCL stuff (missing debug info in libraries). Among lots of probably false positives, it outputs some cryptic stuff about overwrites but with an unusable backtrace. Enabling MEMDBG_ON with MEMDBG_EXTRA_CHECKS in JtR (see memdbg_defines.h) does warn about buffers used (even written to iirc) after free but it only points out where they (I think) were allocated, not where they were molested. Both cases I've seen pointed to `host_crack = mem_calloc(kpc * sizeof(crack_t));` which is kinda confusing. Heavily over-allocating buffers, or shrinking max password length, does not help.
Author
Owner

@magnumripper commented on GitHub (Aug 27, 2014):

BTW I tried calling clGetMemObjectInfo() on mem_state instead of releasing it, but even THAT caused a segfault. So I reverted to just putting a breakpoint in release_clobj() and trying to look at things from there but gdb does not understand a cl_mem (incomplete type) so I lost faith in that track and gave it up.

<!-- gh-comment-id:53620047 --> @magnumripper commented on GitHub (Aug 27, 2014): BTW I tried calling clGetMemObjectInfo() on mem_state instead of releasing it, but even THAT caused a segfault. So I reverted to just putting a breakpoint in release_clobj() and trying to look at things from there but gdb does not understand a cl_mem (incomplete type) so I lost faith in that track and gave it up.
Author
Owner

@magnumripper commented on GitHub (Sep 13, 2014):

Someone PLEASE spot this bug, or I will die trying 😢

<!-- gh-comment-id:55486521 --> @magnumripper commented on GitHub (Sep 13, 2014): Someone PLEASE spot this bug, or I will die trying :cry:
Author
Owner

@ghost commented on GitHub (Sep 15, 2014):

My opinion is that something wrong (a buffer overflow) is happening inside passlib_binary/base64_decode.

Not sure how you guys see the error, I can only see it as reported in #739. To fix it, I correct the size of:

static char ret[X]

The size you guys selected is not good enough.

<!-- gh-comment-id:55550023 --> @ghost commented on GitHub (Sep 15, 2014): My opinion is that something wrong (a buffer overflow) is happening inside passlib_binary/base64_decode. Not sure how you guys see the error, I can only see it as reported in #739. To fix it, I correct the size of: ``` static char ret[X] ``` The size you guys selected is not good enough.
Author
Owner

@magnumripper commented on GitHub (Sep 15, 2014):

Wow, it's always so obvious in hindsight. Thanks!! I guess whatever I thought I saw in rar5 was unrelated.

<!-- gh-comment-id:55558793 --> @magnumripper commented on GitHub (Sep 15, 2014): Wow, it's always so obvious in hindsight. Thanks!! I guess whatever I thought I saw in rar5 was unrelated.
Author
Owner

@magnumripper commented on GitHub (Sep 15, 2014):

Committed in e771a85

<!-- gh-comment-id:55558810 --> @magnumripper commented on GitHub (Sep 15, 2014): Committed in e771a85
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#369
No description provided.