[GH-ISSUE #2094] pbkdf2-hmac-sha1-opencl segfaults #1401

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

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

Originally assigned to: @magnumripper on GitHub.

eff5a92 broke pbkdf2-hmac-sha1-opencl. Segfaults every time during auto-tune (so eg. --test=0 works fine while --test does not). Given the problem I wonder whether you verified performance before/after at all?

Originally created by @magnumripper on GitHub (Mar 17, 2016). Original GitHub issue: https://github.com/openwall/john/issues/2094 Originally assigned to: @magnumripper on GitHub. eff5a92 broke pbkdf2-hmac-sha1-opencl. Segfaults every time during auto-tune (so eg. --test=0 works fine while --test does not). Given the problem I wonder whether you verified performance before/after at all?
Author
Owner

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

Also, please note more formats use the same kernel:

$ git grep -l opencl_pbkdf2_hmac_sha1.h
opencl/pbkdf2_hmac_sha1_kernel.cl
opencl_encfs_fmt_plug.c
opencl_iwork_fmt_plug.c
opencl_krb5pa-sha1_fmt_plug.c
opencl_pbkdf2_hmac_sha1_fmt_plug.c

So three formats that use this shared kernel were not adapted at all. They seem to work fine, I just hope we don't have latent problems in them now?

<!-- gh-comment-id:198086662 --> @magnumripper commented on GitHub (Mar 17, 2016): Also, please note more formats use the same kernel: ``` $ git grep -l opencl_pbkdf2_hmac_sha1.h opencl/pbkdf2_hmac_sha1_kernel.cl opencl_encfs_fmt_plug.c opencl_iwork_fmt_plug.c opencl_krb5pa-sha1_fmt_plug.c opencl_pbkdf2_hmac_sha1_fmt_plug.c ``` So three formats that use this shared kernel were not adapted at all. They seem to work fine, I just hope we don't have latent problems in them now?
Author
Owner

@jfoug commented on GitHub (Mar 18, 2016):

I for the life of me, can not find this. It only happens during auto-tune. The thing is, the format will crack just fine and ST just fine, if LWS/GWS are given. I have found a couple issues, but nothing that was any kind of core, just things which should have been copied over to 'common' coding.

<!-- gh-comment-id:198149813 --> @jfoug commented on GitHub (Mar 18, 2016): I for the life of me, can not find this. It only happens during auto-tune. The thing is, the format will crack just fine and ST just fine, if LWS/GWS are given. I have found a couple issues, but nothing that was any kind of core, just things which should have been copied over to 'common' coding.
Author
Owner

@jfoug commented on GitHub (Mar 18, 2016):

The bug had to do with change to salt. Nothing past split() expected to ever see . chars again. Split removes them and replaces them with '$' chars (which really should have been proper normalization from start).

BUT finding GWS and LWS did not call split (only prepare).

I have added split call after prepare, and am testing all opencl hash types. I do not expect any problems from that addition, but want to check other formats just to be sure.

So there was no 'latent' problems with buffer size changes or anything like that within the CPU<->GPU code. It was simply my lack of understanding how the auto-tune was doing self test work, and possibly an issue all along in that part of the ST work chain.

<!-- gh-comment-id:198166728 --> @jfoug commented on GitHub (Mar 18, 2016): The bug had to do with change to salt. Nothing past split() expected to ever see . chars again. Split removes them and replaces them with '$' chars (which really should have been proper normalization from start). BUT finding GWS and LWS did not call split (only prepare). I have added split call after prepare, and am testing all opencl hash types. I do not expect any problems from that addition, but want to check other formats just to be sure. So there was no 'latent' problems with buffer size changes or anything like that within the CPU<->GPU code. It was simply my lack of understanding how the auto-tune was doing self test work, and possibly an issue all along in that part of the ST work chain.
Author
Owner

@jfoug commented on GitHub (Mar 18, 2016):

This is the change I am validating

$ git diff common-opencl.c
diff --git a/src/common-opencl.c b/src/common-opencl.c
index 96ea7e3..6f3a408 100644
--- a/src/common-opencl.c
+++ b/src/common-opencl.c
@@ -1208,6 +1208,7 @@ static cl_ulong gws_test(size_t gws, unsigned int rounds, int sequential_id)
        if (!self->params.tests[0].fields[1])
                self->params.tests[0].fields[1] = self->params.tests[0].ciphertext;
        ciphertext = self->methods.prepare(self->params.tests[0].fields, self);
+       ciphertext = self->methods.split(ciphertext, 0, self);
        salt = self->methods.salt(ciphertext);
        if (salt)
                dyna_salt_create(salt);
@@ -1420,6 +1421,7 @@ void opencl_find_best_lws(size_t group_size_limit, int sequential_id,
        if (!self->params.tests[0].fields[1])
                self->params.tests[0].fields[1] = self->params.tests[0].ciphertext;
        ciphertext = self->methods.prepare(self->params.tests[0].fields, self);
+       ciphertext = self->methods.split(ciphertext, 0, self);
        salt = self->methods.salt(ciphertext);
        if (salt)
                dyna_salt_create(salt);
<!-- gh-comment-id:198167019 --> @jfoug commented on GitHub (Mar 18, 2016): This is the change I am validating ``` diff $ git diff common-opencl.c diff --git a/src/common-opencl.c b/src/common-opencl.c index 96ea7e3..6f3a408 100644 --- a/src/common-opencl.c +++ b/src/common-opencl.c @@ -1208,6 +1208,7 @@ static cl_ulong gws_test(size_t gws, unsigned int rounds, int sequential_id) if (!self->params.tests[0].fields[1]) self->params.tests[0].fields[1] = self->params.tests[0].ciphertext; ciphertext = self->methods.prepare(self->params.tests[0].fields, self); + ciphertext = self->methods.split(ciphertext, 0, self); salt = self->methods.salt(ciphertext); if (salt) dyna_salt_create(salt); @@ -1420,6 +1421,7 @@ void opencl_find_best_lws(size_t group_size_limit, int sequential_id, if (!self->params.tests[0].fields[1]) self->params.tests[0].fields[1] = self->params.tests[0].ciphertext; ciphertext = self->methods.prepare(self->params.tests[0].fields, self); + ciphertext = self->methods.split(ciphertext, 0, self); salt = self->methods.salt(ciphertext); if (salt) dyna_salt_create(salt); ```
Author
Owner

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

Wow, so that was a bug long before eff5a92 yet it never showed up until that commit. Your proposed patch definitely makes sense.

<!-- gh-comment-id:198230511 --> @magnumripper commented on GitHub (Mar 18, 2016): Wow, so that was a bug long before eff5a92 yet it never showed up until that commit. Your proposed patch definitely makes sense.
Author
Owner

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

Thanks, will test.

<!-- gh-comment-id:198232201 --> @magnumripper commented on GitHub (Mar 18, 2016): Thanks, will test.
Author
Owner

@jfoug commented on GitHub (Mar 18, 2016):

Yup, this issue has been there forever, but until a format came across which 'required' it, nothing bad ever showed up. Now pbkdf2-hmac-sha1* requires split to normalize out all the '.' separators so bam, a strange crash that really was NOT apparent. I kept looking in the code where the CPU/GPU interfaced, thinking that was likely the bad stuff. The thing that bothered me most, was the this format WORKED just fine. It would crack, ST, everything, as long as it did not have to go through the auto-tune code.

<!-- gh-comment-id:198464097 --> @jfoug commented on GitHub (Mar 18, 2016): Yup, this issue has been there forever, but until a format came across which 'required' it, nothing bad ever showed up. Now pbkdf2-hmac-sha1\* requires split to normalize out all the '.' separators so bam, a strange crash that really was NOT apparent. I kept looking in the code where the CPU/GPU interfaced, thinking that was likely the bad stuff. The thing that bothered me most, was the this format WORKED just fine. It would crack, ST, everything, as long as it did not have to go through the auto-tune code.
Author
Owner

@jfoug commented on GitHub (Mar 18, 2016):

NOTE, I also did find a couple minor issues (like binary doing up to 4 limb length binaries). NOTE, I simply added the code to do that. We only use the first binary limb, which is all we really need no matter what. If we have 20 bytes of matched binary, then there is NO REASON at all to get more of it, UNLESS we were going to use that data for a key or something. Since we are simply doing this as a validation that the password is right, then a 1 limb binary is all we need to care about.

<!-- gh-comment-id:198465180 --> @jfoug commented on GitHub (Mar 18, 2016): NOTE, I also did find a couple minor issues (like binary doing up to 4 limb length binaries). NOTE, I simply added the code to do that. We only use the first binary limb, which is all we really need no matter what. If we have 20 bytes of matched binary, then there is NO REASON at all to get more of it, UNLESS we were going to use that data for a key or something. Since we are simply doing this as a validation that the password is right, then a 1 limb binary is all we need to care about.
Author
Owner

@jfoug commented on GitHub (Mar 18, 2016):

That is the correct order for the format methods, correct?

prepare()
split()
salt()
set_salt()
crypt_all()

<!-- gh-comment-id:198465966 --> @jfoug commented on GitHub (Mar 18, 2016): That is the correct order for the format methods, correct? prepare() split() salt() set_salt() crypt_all()
Author
Owner

@frank-dittrich commented on GitHub (Mar 18, 2016):

IIRC, split(), get_salt(), etc. are allowed to assume that all the hashes have passed valid().

<!-- gh-comment-id:198472107 --> @frank-dittrich commented on GitHub (Mar 18, 2016): IIRC, split(), get_salt(), etc. are allowed to assume that all the hashes have passed valid().
Author
Owner

@jfoug commented on GitHub (Mar 18, 2016):

I thought split() was called prior to valid(). Nope, you are 100% correct. Let me check my common code to make sure valid is fine.

However, it is NOT valid for the salt() function to be called prior to split and prepare being called.

<!-- gh-comment-id:198514892 --> @jfoug commented on GitHub (Mar 18, 2016): I thought split() was called prior to valid(). Nope, you are 100% correct. Let me check my common code to make sure valid is fine. However, it is NOT valid for the salt() function to be called prior to split and prepare being called.
Author
Owner

@jfoug commented on GitHub (Mar 18, 2016):

This is in the common code:

int pbkdf2_hmac_sha1_valid(char *ciphertext, struct fmt_main *self) {
    char *ptr, *ctcopy, *keeptr;
    size_t len;
    char *delim;

    if (strncasecmp(ciphertext, PBKDF2_SHA1_FORMAT_TAG, PBKDF2_SHA1_TAG_LEN))
        return 0;
    if (strlen(ciphertext) > PBKDF2_SHA1_MAX_CIPHERTEXT_LENGTH)
        return 0;
    ciphertext += PBKDF2_SHA1_TAG_LEN;
    delim = strchr(ciphertext, '.') ? "." : "$";
    if (!(ctcopy = strdup(ciphertext)))

So valid DOES look for both a . and a $. But functions like salt(), binary(), etc do NOT spend time looking for a '.' They assume there never will be one in any data which they are given.

<!-- gh-comment-id:198515961 --> @jfoug commented on GitHub (Mar 18, 2016): This is in the common code: ``` C int pbkdf2_hmac_sha1_valid(char *ciphertext, struct fmt_main *self) { char *ptr, *ctcopy, *keeptr; size_t len; char *delim; if (strncasecmp(ciphertext, PBKDF2_SHA1_FORMAT_TAG, PBKDF2_SHA1_TAG_LEN)) return 0; if (strlen(ciphertext) > PBKDF2_SHA1_MAX_CIPHERTEXT_LENGTH) return 0; ciphertext += PBKDF2_SHA1_TAG_LEN; delim = strchr(ciphertext, '.') ? "." : "$"; if (!(ctcopy = strdup(ciphertext))) ``` So valid DOES look for both a . and a $. But functions like salt(), binary(), etc do NOT spend time looking for a '.' They assume there never will be one in any data which they are given.
Author
Owner

@jfoug commented on GitHub (Mar 18, 2016):

So the 'correct' order of method calls is:

That is the correct order for the format methods, correct?

// during load
prepare();
valid();
split();
salt();
binary();
//during crack
  set_key() ... set_key()
    set_salt()
      crypt_all()
      cmp_all() [ _one() _exact() log crack, etc ]
    set_salt()
      crypt_all()
      cmp_all()
    ....

And during some ST runs, certain things are not done (like cmp_all() ?) or valid(), etc

<!-- gh-comment-id:198531342 --> @jfoug commented on GitHub (Mar 18, 2016): So the 'correct' order of method calls is: That is the correct order for the format methods, correct? ``` // during load prepare(); valid(); split(); salt(); binary(); //during crack set_key() ... set_key() set_salt() crypt_all() cmp_all() [ _one() _exact() log crack, etc ] set_salt() crypt_all() cmp_all() .... ``` And during some ST runs, certain things are not done (like cmp_all() ?) or valid(), etc
Author
Owner

@frank-dittrich commented on GitHub (Mar 18, 2016):

And, from formats.h:
prepare(), valid(), and split() are the only methods that are allowed to be called before a call to init()

<!-- gh-comment-id:198564097 --> @frank-dittrich commented on GitHub (Mar 18, 2016): And, from formats.h: `prepare(), valid(), and split() are the only methods that are allowed to be called before a call to init()`
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#1401
No description provided.