[GH-ISSUE #328] illegal memory access in cracker.c when generating candidate passord on GPU. #69

Closed
opened 2026-10-14 02:51:16 +07:00 by bsakaguchi · 17 comments
Owner

Originally created by @sayan1an on GitHub (Jun 10, 2013).
Original GitHub issue: https://github.com/openwall/john/issues/328

crk_timestamp in cracker.c allocated memory based on max_keys_per_crypt. However when generating password on gpu we would like to keep max_keys_per_crypt as low as possible which is much much lower than actual crypt all return value. This causes segmentation fault in crk_process_guess(). The index values in the function are way beyond crk_timestamp allocated range.

Originally created by @sayan1an on GitHub (Jun 10, 2013). Original GitHub issue: https://github.com/openwall/john/issues/328 crk_timestamp in cracker.c allocated memory based on max_keys_per_crypt. However when generating password on gpu we would like to keep max_keys_per_crypt as low as possible which is much much lower than actual crypt all return value. This causes segmentation fault in crk_process_guess(). The index values in the function are way beyond crk_timestamp allocated range.
bsakaguchi 2026-10-14 02:51:16 +07:00
Author
Owner

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

Is this taken care of in bleeding-mask branch, or is there just a work-around in place for now?

<!-- gh-comment-id:23371789 --> @magnumripper commented on GitHub (Aug 27, 2013): Is this taken care of in bleeding-mask branch, or is there just a work-around in place for now?
Author
Owner

@sayan1an commented on GitHub (Aug 28, 2013):

No the problem still persist. However it will only occur if (inital kpc < num_loaded_hashes) && (something gets cracked)

<!-- gh-comment-id:23416235 --> @sayan1an commented on GitHub (Aug 28, 2013): No the problem still persist. However it will only occur if (inital kpc < num_loaded_hashes) && (something gets cracked)
Author
Owner

@magnumripper commented on GitHub (Sep 2, 2013):

Perhaps now you can do this:

@@ -121,6 +121,8 @@ void crk_init(struct db_main *db, void (*fix_state)(void),

        if (db->loaded) {
                size = crk_params.max_keys_per_crypt * sizeof(int64);
+               if (crk_params.num_internal_keys)
+                       size *= crk_params.num_internal_keys;
                memset(crk_timestamps = mem_alloc_tiny(size,sizeof(int64)), -1, size);
        } else
                crk_stdout_key[0] = 0;

That should fix it, no?

I could commit this to bleeding-jumbo and it'll be merged to bleeding-mask.

<!-- gh-comment-id:23668551 --> @magnumripper commented on GitHub (Sep 2, 2013): Perhaps now you can do this: ``` @@ -121,6 +121,8 @@ void crk_init(struct db_main *db, void (*fix_state)(void), if (db->loaded) { size = crk_params.max_keys_per_crypt * sizeof(int64); + if (crk_params.num_internal_keys) + size *= crk_params.num_internal_keys; memset(crk_timestamps = mem_alloc_tiny(size,sizeof(int64)), -1, size); } else crk_stdout_key[0] = 0; ``` That should fix it, no? I could commit this to bleeding-jumbo and it'll be merged to bleeding-mask.
Author
Owner

@sayan1an commented on GitHub (Sep 2, 2013):

Yes , this should fix the problem. However one minor modification is needed in mask.c. Commit it please.

<!-- gh-comment-id:23671434 --> @sayan1an commented on GitHub (Sep 2, 2013): Yes , this should fix the problem. However one minor modification is needed in mask.c. Commit it please.
Author
Owner

@magnumripper commented on GitHub (Sep 2, 2013):

Done in 9a6eb53

<!-- gh-comment-id:23671771 --> @magnumripper commented on GitHub (Sep 2, 2013): Done in 9a6eb53
Author
Owner

@sayan1an commented on GitHub (Sep 2, 2013):

We have a different problem now:

sayantan@Eden:~/JohnTheRipper/run$ ./john -format=nt-opencl nt -mask=?l?l?l?l -w:wrdlst
Device 0: Tahiti (AMD Radeon HD 7900 Series)
Local worksize (LWS) 64, Global worksize (GWS) 4194304
Loaded 4 password hashes with no different salts (nt-opencl, NT [MD4 OpenCL (inefficient, development use only)])
mem_alloc(): Cannot allocate memory trying to allocate 22682796039 bytes

4194304 * 676 * sizeof(uint64_t) == 22682796039

<!-- gh-comment-id:23672709 --> @sayan1an commented on GitHub (Sep 2, 2013): We have a different problem now: sayantan@Eden:~/JohnTheRipper/run$ ./john -format=nt-opencl nt -mask=?l?l?l?l -w:wrdlst Device 0: Tahiti (AMD Radeon HD 7900 Series) Local worksize (LWS) 64, Global worksize (GWS) 4194304 Loaded 4 password hashes with no different salts (nt-opencl, NT [MD4 OpenCL (inefficient, development use only)]) mem_alloc(): Cannot allocate memory trying to allocate 22682796039 bytes 4194304 \* 676 \* sizeof(uint64_t) == 22682796039
Author
Owner

@magnumripper commented on GitHub (Sep 2, 2013):

Oh my :) I think we should consult Solar on this. Maybe a totally different solution is needed.

<!-- gh-comment-id:23672773 --> @magnumripper commented on GitHub (Sep 2, 2013): Oh my :) I think we should consult Solar on this. Maybe a totally different solution is needed.
Author
Owner

@sayan1an commented on GitHub (Sep 2, 2013):

Possible solution:

if (num_loaded_hashes < (max_kpc * num_internal_keys))
size = num_loaded_hashes;

<!-- gh-comment-id:23672841 --> @sayan1an commented on GitHub (Sep 2, 2013): Possible solution: if (num_loaded_hashes < (max_kpc \* num_internal_keys)) size = num_loaded_hashes;
Author
Owner

@magnumripper commented on GitHub (Sep 2, 2013):

OK, so like this?

        if (db->loaded) {
                size = crk_params.max_keys_per_crypt * sizeof(int64);
                if (crk_params.num_internal_keys)
+               if (db->password_count > size * crk_params.num_internal_keys)
                        size *= crk_params.num_internal_keys;
                memset(crk_timestamps = mem_alloc_tiny(size,sizeof(int64)), -1, size);
        } else

I'll test it just a little before committing.

<!-- gh-comment-id:23675649 --> @magnumripper commented on GitHub (Sep 2, 2013): OK, so like this? ``` if (db->loaded) { size = crk_params.max_keys_per_crypt * sizeof(int64); if (crk_params.num_internal_keys) + if (db->password_count > size * crk_params.num_internal_keys) size *= crk_params.num_internal_keys; memset(crk_timestamps = mem_alloc_tiny(size,sizeof(int64)), -1, size); } else ``` I'll test it just a little before committing.
Author
Owner

@magnumripper commented on GitHub (Sep 2, 2013):

Committed in 5f75e60 though I'm not sure this is it. Will crk_process_key() never be called with an index larger than max_keys_per_crypt? Anyway this is still a no-op in bleeding so can't do any bad.

<!-- gh-comment-id:23675979 --> @magnumripper commented on GitHub (Sep 2, 2013): Committed in 5f75e60 though I'm not sure this is it. Will crk_process_key() never be called with an index larger than max_keys_per_crypt? Anyway this is still a no-op in bleeding so can't do any bad.
Author
Owner

@magnumripper commented on GitHub (Sep 2, 2013):

Not working. I get segfaults using a GWS of 32K and num_internal_keys of 1000 with some 10M hashes loaded. One problem was that I compared with size instead of max_kpc and size is already multipled with sizeof(int64) but there are problems after fixing that too.

<!-- gh-comment-id:23677095 --> @magnumripper commented on GitHub (Sep 2, 2013): Not working. I get segfaults using a GWS of 32K and num_internal_keys of 1000 with some 10M hashes loaded. One problem was that I compared with size instead of max_kpc and size is already multipled with sizeof(int64) but there are problems after fixing that too.
Author
Owner

@magnumripper commented on GitHub (Sep 2, 2013):

Hmm but the segfault happens in raw-md5-opencl crypt_all(). Maybe it's unrelated.

<!-- gh-comment-id:23677481 --> @magnumripper commented on GitHub (Sep 2, 2013): Hmm but the segfault happens in raw-md5-opencl crypt_all(). Maybe it's unrelated.
Author
Owner

@magnumripper commented on GitHub (Sep 2, 2013):

Tried testing with just 62K hashes and now I got the segfault in crk_process_key(). Obviously we can get an index up to (crk_params.max_keys_per_crypt * num_internal_keys) and the number of loaded hashes seems irrelevant to me.

I think we, you or Solar need to re-work this totally. We obviously can't allocate 32 GB of memory for timestamps which is what happens with a keys_per_crypt of 4M and a multiplier (num_internal_keys) of 1K.

<!-- gh-comment-id:23677945 --> @magnumripper commented on GitHub (Sep 2, 2013): Tried testing with just 62K hashes and now I got the segfault in crk_process_key(). Obviously we can get an index up to (crk_params.max_keys_per_crypt \* num_internal_keys) and the number of loaded hashes seems irrelevant to me. I think we, you or Solar need to re-work this totally. We obviously can't allocate 32 GB of memory for timestamps which is what happens with a keys_per_crypt of 4M and a multiplier (num_internal_keys) of 1K.
Author
Owner

@magnumripper commented on GitHub (Sep 2, 2013):

OK I reverted the last commits. We are now back to code that works fine (multiply size with num_int_keys) but it will not work with a GWS in the millions. Speaking of that, do you really need that high GWS? It seems excessive to me. At a speed of 2GH/s and a num_int_keys of 1000 you should have a GWS of just 400K in order to get under 200 ms. However that would still be 3.2 GB of crk_timestamp so we need to fix that anyway.

<!-- gh-comment-id:23678567 --> @magnumripper commented on GitHub (Sep 2, 2013): OK I reverted the last commits. We are now back to code that works fine (multiply size with num_int_keys) but it will not work with a GWS in the millions. Speaking of that, do you really need that high GWS? It seems excessive to me. At a speed of 2GH/s and a num_int_keys of 1000 you should have a GWS of just 400K in order to get under 200 ms. However that would still be 3.2 GB of crk_timestamp so we need to fix that anyway.
Author
Owner

@sayan1an commented on GitHub (Sep 3, 2013):

"Hmm but the segfault happens in raw-md5-opencl crypt_all(). Maybe it's unrelated."

Is it in Bleeding-mask or jumbo, because crypt all return is different in them.

<!-- gh-comment-id:23685492 --> @sayan1an commented on GitHub (Sep 3, 2013): "Hmm but the segfault happens in raw-md5-opencl crypt_all(). Maybe it's unrelated." Is it in Bleeding-mask or jumbo, because crypt all return is different in them.
Author
Owner

@magnumripper commented on GitHub (Sep 3, 2013):

Segfault was in bleeding-mask with 10M hashes loaded. It is unrelated to this issue.

<!-- gh-comment-id:23690911 --> @magnumripper commented on GitHub (Sep 3, 2013): Segfault was in bleeding-mask with 10M hashes loaded. It is unrelated to this issue.
Author
Owner

@magnumripper commented on GitHub (Sep 3, 2013):

Maybe we should do this too but that's another issue and need to be done throughout john:

-  if (index < crk_params.max_keys_per_crypt) {
+  if ((unsigned int)index < (unsigned int)crk_params.max_keys_per_crypt) {
<!-- gh-comment-id:23714421 --> @magnumripper commented on GitHub (Sep 3, 2013): Maybe we should do this too but that's another issue and need to be done throughout john: ``` - if (index < crk_params.max_keys_per_crypt) { + if ((unsigned int)index < (unsigned int)crk_params.max_keys_per_crypt) { ```
bsakaguchi changed title from [GH-ISSUE #328] illegal memory access in cracker.c when generating candidate passord on GPU. to [GH-ISSUE #328] illegal memory access in cracker.c when generating candidate passord on GPU. 2026-10-14 04:16:36 +07:00
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#69
No description provided.