[GH-ISSUE #2022] Mask mode oddities #1360

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

Originally created by @ghost on GitHub (Feb 4, 2016).
Original GitHub issue: https://github.com/openwall/john/issues/2022

Originally assigned to: @magnumripper on GitHub.

This is a collection of things mask mode does that left me confused. No need to be errors and maybe a clarification will be good for everyone.

  • The way mask mode selects the task to be sent to GPU is not deterministic for the same --mask. From a printf in setkey() in 2 executions of JtR using the same mask: ####w0rd / ###5#0rd. Once p[3]. The other p[4].
  • When selecting a multiplier (e.g. ?a?a or ?A?A), mask mode has to divide the work: 95 x 95 and 223 x 223 will not fit in many devices. Suggestion: try 95 x (95 / N) (N could be {2, 4, 8, 16 and 32}
  • Rather than warning 'Format internal ranges cannot be truncated!', why not advice the poor performance, expand the mask the best way and go on.
  • One can safely ignore the mask_gpu_is_static hint, right? The regular candidates generation will happen and it will work (it worked for every test case I have tried).
Originally created by @ghost on GitHub (Feb 4, 2016). Original GitHub issue: https://github.com/openwall/john/issues/2022 Originally assigned to: @magnumripper on GitHub. This is a collection of things mask mode does that left me confused. No need to be errors and maybe a clarification will be good for everyone. - [ ] The way mask mode selects the task to be sent to GPU is not deterministic for the same --mask. From a printf in setkey() in 2 executions of JtR using the same mask: ####w0rd / ###5#0rd. Once p[3]. The other p[4]. - [ ] When selecting a multiplier (e.g. ?a?a or ?A?A), mask mode has to divide the work: 95 x 95 and 223 x 223 will not fit in many devices. Suggestion: try 95 x (95 / N) (N could be {2, 4, 8, 16 and 32} - [ ] Rather than warning 'Format internal ranges cannot be truncated!', why not advice the poor performance, expand the mask the best way and go on. - [ ] One can safely ignore the _mask_gpu_is_static_ hint, right? The regular candidates generation will happen and it will work (it worked for every test case I have tried).
bsakaguchi 2026-10-14 03:45:47 +07:00
Author
Owner

@magnumripper commented on GitHub (Oct 7, 2016):

The way mask mode selects the task to be sent to GPU is not deterministic for the same --mask. From a printf in setkey() in 2 executions of JtR using the same mask: ####w0rd / ###5#0rd. Once p[3]. The other p[4].

This sounds like it could be a huge problem when restoring a job.

<!-- gh-comment-id:252208317 --> @magnumripper commented on GitHub (Oct 7, 2016): > The way mask mode selects the task to be sent to GPU is not deterministic for the same --mask. From a printf in setkey() in 2 executions of JtR using the same mask: ####w0rd / ###5#0rd. Once p[3]. The other p[4]. This sounds like it could be a huge problem when restoring a job.
Author
Owner

@magnumripper commented on GitHub (Oct 10, 2016):

The way mask mode selects the task to be sent to GPU is not deterministic for the same --mask. From a printf in setkey() in 2 executions of JtR using the same mask: ####w0rd / ###5#0rd. Once p[3]. The other p[4].

This sounds like it could be a huge problem when restoring a job.

...and perhaps an even worse problem when running node/fork. If different nodes ends up dividing work differently, and then apply the node/fork "I'm node x out of y" stuff, I guess things could go wrong. Even worse if such a job was then stopped and resumed, and nodes end up with yet another different selection.

I'm not 100% sure any of these situations is a problem, I just don't feel very good about this. And I have seen some occasions of forked resuming ending up completely wrong and "finishing" prematurely. I never understood why but this might be the explanation.

I tried to reproduce this today but failed. @claudioandre do you know some way to trigger this behavior? We should try to make the selection deterministic.

<!-- gh-comment-id:252658077 --> @magnumripper commented on GitHub (Oct 10, 2016): > > The way mask mode selects the task to be sent to GPU is not deterministic for the same --mask. From a printf in setkey() in 2 executions of JtR using the same mask: ####w0rd / ###5#0rd. Once p[3]. The other p[4]. > > This sounds like it could be a huge problem when restoring a job. ...and perhaps an even worse problem when running node/fork. If different nodes ends up dividing work differently, and then apply the node/fork "I'm node x out of y" stuff, I guess things could go wrong. Even worse if such a job was then stopped and resumed, and nodes end up with yet another different selection. I'm not 100% sure any of these situations is a problem, I just don't feel very good about this. And I have seen some occasions of forked resuming ending up completely wrong and "finishing" prematurely. I never understood why but this _might_ be the explanation. I tried to reproduce this today but failed. @claudioandre do you know some way to trigger this behavior? We should try to make the selection deterministic.
Author
Owner

@ghost commented on GitHub (Oct 10, 2016):

I tried to reproduce this today but failed

Me too. I'm almost sure it was easy to see it happening.

My guess is that the selection improved since then.

<!-- gh-comment-id:252739086 --> @ghost commented on GitHub (Oct 10, 2016): > I tried to reproduce this today but failed Me too. I'm almost sure it was easy to see it happening. My guess is that the selection improved since then.
Author
Owner

@magnumripper commented on GitHub (Oct 10, 2016):

I'm pretty sure nothing of that has changed. It might be that it only happens in certain situations. I'll keep my eyes open.

<!-- gh-comment-id:252739727 --> @magnumripper commented on GitHub (Oct 10, 2016): I'm pretty sure nothing of that has changed. It might be that it only happens in certain situations. I'll keep my eyes open.
Author
Owner

@ghost commented on GitHub (Oct 12, 2016):

I'm not sure what I did in the first place. Thinking better, this 'mask selection' is based on:

  • the mask itself
  • mask_int_cand_target (a number that 'changes').

That might be the explanation of what I saw in my old hardware. Anyway: I need to thing about what happens if one buys a new powerful GPU to replace his (old/weak) one: how restore/everything else will behave?

<!-- gh-comment-id:253334470 --> @ghost commented on GitHub (Oct 12, 2016): I'm not sure what I did in the first place. Thinking better, this 'mask selection' is based on: - the mask itself - mask_int_cand_target (a number that 'changes'). That might be the explanation of what I saw in my old hardware. Anyway: I need to thing about what happens if one buys a new powerful GPU to replace his (old/weak) one: how restore/everything else will behave?
Author
Owner

@sayan1an commented on GitHub (Oct 13, 2016):

Guys, mask_int_cand_target is your knob. So for same mask input, if you dont change this parameter, unless there is bug, you should see same task being sent to GPU. For beefier GPUs, this value is usually higher. So, yes resume won't work if you replace you GPU, since a new value for mask_int_cand_target is chosen by the format.

<!-- gh-comment-id:253559913 --> @sayan1an commented on GitHub (Oct 13, 2016): Guys, mask_int_cand_target is your knob. So for same mask input, if you dont change this parameter, unless there is bug, you should see same task being sent to GPU. For beefier GPUs, this value is usually higher. So, yes resume won't work if you replace you GPU, since a new value for mask_int_cand_target is chosen by the format.
Author
Owner

@magnumripper commented on GitHub (Oct 13, 2016):

Thanks for the input. I wonder if we could change the code without too much work so this no longer happens. I mean, regardless of what portion of mask is on CPU and which is on GPU, the resume file should read the same.

Another aspect of that: If starting a session with -format:nt and then stopping, then editing the session file to use nt-opencl instead, resuming should ideally work flawlessly (it does in all other cases I know of).

<!-- gh-comment-id:253571497 --> @magnumripper commented on GitHub (Oct 13, 2016): Thanks for the input. I wonder if we could change the code without too much work so this no longer happens. I mean, regardless of what portion of mask is on CPU and which is on GPU, the resume file should read the same. Another aspect of that: If starting a session with -format:nt and then stopping, then editing the session file to use nt-opencl instead, resuming should ideally work flawlessly (it does in all other cases I know of).
Author
Owner

@magnumripper commented on GitHub (Oct 13, 2016):

A quick-fix for a subset of the problems would be to store mask_int_cand_target in the rec file and re-use it (completely ignoring changes in GPU speed) on resume. This is the least we should do.

In edge cases, even a different OC setting for same GPU could ruin resuming as it is now.

<!-- gh-comment-id:253573985 --> @magnumripper commented on GitHub (Oct 13, 2016): A quick-fix for a subset of the problems would be to store mask_int_cand_target in the rec file and re-use it (completely ignoring changes in GPU speed) on resume. This is the least we should do. In edge cases, even a different OC setting for same GPU could ruin resuming as it is now.
Author
Owner

@magnumripper commented on GitHub (Oct 13, 2016):

Here's a patch for that

diff --git a/src/mask.c b/src/mask.c
index 9c50864..2d4f3ca 100644
--- a/src/mask.c
+++ b/src/mask.c
@@ -1824,6 +1824,7 @@ void mask_save_state(FILE *file)
        }
        for (i = 0; i < rec_ctx.count; i++)
                fprintf(file, "%u\n", (unsigned)rec_ctx.ranges[i].iter);
+       fprintf(file, "%d\n", mask_int_cand_target);
 }

 int mask_restore_state(FILE *file)
@@ -1880,6 +1881,19 @@ int mask_restore_state(FILE *file)
        }
        else
                return fail;
+
+       if (fscanf(file, "%d\n", &d) == 1) {
+               if (d != mask_int_cand_target) {
+                       log_event("Mask mode GPU-side target size changed from %d to %d. "
+                                 "Resetting to saved.", d, mask_int_cand_target);
+                       mask_int_cand_target = d;
+               }
+       }
+#if 0 /* We'll enable this after some grace period */
+       else
+               return fail;
+#endif
+
        restored = 1;
        return 0;
 }

The problem is this is too late. When old value is restored from session file, new value has already been used to set things up incorrectly.

<!-- gh-comment-id:253588580 --> @magnumripper commented on GitHub (Oct 13, 2016): Here's a patch for that ``` diff diff --git a/src/mask.c b/src/mask.c index 9c50864..2d4f3ca 100644 --- a/src/mask.c +++ b/src/mask.c @@ -1824,6 +1824,7 @@ void mask_save_state(FILE *file) } for (i = 0; i < rec_ctx.count; i++) fprintf(file, "%u\n", (unsigned)rec_ctx.ranges[i].iter); + fprintf(file, "%d\n", mask_int_cand_target); } int mask_restore_state(FILE *file) @@ -1880,6 +1881,19 @@ int mask_restore_state(FILE *file) } else return fail; + + if (fscanf(file, "%d\n", &d) == 1) { + if (d != mask_int_cand_target) { + log_event("Mask mode GPU-side target size changed from %d to %d. " + "Resetting to saved.", d, mask_int_cand_target); + mask_int_cand_target = d; + } + } +#if 0 /* We'll enable this after some grace period */ + else + return fail; +#endif + restored = 1; return 0; } ``` The problem is this is too late. When old value is restored from session file, new value has already been used to set things up incorrectly.
Author
Owner

@sayan1an commented on GitHub (Oct 13, 2016):

I am not absolutely sure but I think mask_int_cand_target is also changed during benchmark. So, even when you have same GPU, mask_int_cand_target could change from one run to another.

<!-- gh-comment-id:253595476 --> @sayan1an commented on GitHub (Oct 13, 2016): I am not absolutely sure but I think mask_int_cand_target is also changed during benchmark. So, even when you have same GPU, mask_int_cand_target could change from one run to another.
Author
Owner

@magnumripper commented on GitHub (Oct 13, 2016):

No it's not that bad. The formats set it, eg. nt-opencl sets it to opencl_speed_index(gpu_id) / 300. Then nothing else will change it.

<!-- gh-comment-id:253596248 --> @magnumripper commented on GitHub (Oct 13, 2016): No it's not that bad. The formats set it, eg. nt-opencl sets it to `opencl_speed_index(gpu_id) / 300`. Then nothing else will change it.
Author
Owner

@magnumripper commented on GitHub (Mar 15, 2018):

We may want to open a separate issue for the "resume on GPU with different speed" case.

One can safely ignore the mask_gpu_is_static hint, right? The regular candidates generation will happen and it will work (it worked for every test case I have tried).

As far as I understand, it can be ignored but then you'll waste performance in set_key().

<!-- gh-comment-id:373287869 --> @magnumripper commented on GitHub (Mar 15, 2018): We may want to open a separate issue for the "resume on GPU with different speed" case. > One can safely ignore the mask_gpu_is_static hint, right? The regular candidates generation will happen and it will work (it worked for every test case I have tried). As far as I understand, it can be ignored but then you'll waste performance in `set_key()`.
Author
Owner

@ghost commented on GitHub (Dec 15, 2018):

Bug closed because it:

  • Low Priority - They have a tendency to become high priority if enough of the users complain.

  • WontFix - Covers all the reasons we chose to close the bug without taking action (can't repro, working as intended, obsolete).

<!-- gh-comment-id:447585518 --> @ghost commented on GitHub (Dec 15, 2018): Bug closed because it: * **Low Priority** - They have a tendency to become high priority if enough of the users complain. * **WontFix** - Covers all the reasons we chose to close the bug without taking action (can't repro, working as intended, obsolete).
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#1360
No description provided.