Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DES_set_key(): return values as DES_set_key_checked() but always set #16944

Closed
wants to merge 1 commit into from

Conversation

t8m
Copy link
Member

@t8m t8m commented Nov 1, 2021

This avoids using accidentally uninitialized key schedule in applications that use DES_set_key() not expecting it to check the key which is the default on OpenSSL <= 1.1.1

Fixes #16859

This avoids using accidentally uninitialized key schedule in
applications that use DES_set_key() not expecting it to check the key
which is the default on OpenSSL <= 1.1.1

Fixes openssl#16859
@t8m t8m added branch: master Merge to master branch approval: review pending This pull request needs review by a committer triaged: bug The issue/pr is/fixes a bug hold: need otc decision The OTC needs to make a decision branch: 3.0 Merge to openssl-3.0 branch labels Nov 1, 2021
@github-actions github-actions bot added the severity: fips change The pull request changes FIPS provider sources label Nov 1, 2021
@solardiz
Copy link

solardiz commented Nov 1, 2021

A couple of issues here:

  1. The checks inside DES_check_key_parity and DES_is_weak_key are timing-unsafe, and this adds even further timing-unsafe behavior in DES_set_key (that's OK'ish if we accept calling those functions from here at all while keeping their implementations as-is).
  2. Applications may really not expect a non-zero return from DES_set_key. Just because an application checks for that doesn't mean it handles this right (would reach never-tested code).

So my preference remains to revert the previous change instead. However, failing that, this PR looks good to me in that its code matches its intent.

@t8m
Copy link
Member Author

t8m commented Nov 1, 2021

You have to understand that reverting the change is not an option. We do not want to reintroduce a global variable in OpenSSL-3.x that was removed. And we also cannot make the function to mean DES_set_key_unchecked() unconditionally because we do not want to break the compatibility with the openssl-3.0.0 release.

This is the only compatible option that mitigates the problem with applications ignoring the return value. I do not think timing safety is really an issue here with this kind of legacy API call.

@solardiz
Copy link

solardiz commented Nov 1, 2021

OK, if you say so, but I think 3.0.0's behavior is a CVE-worthy vulnerability or two (making most DES-using applications proceed with an unset key and exposing the really bad timing leaks inside DES_check_key_parity and DES_is_weak_key) and should ideally be fixed as such. Maintaining compatibility with a regression seen in one release feels wrong to me, even if the change involving the regression was documented.

So I recommend to revert the change and explicitly document DES_set_key_checked, DES_check_key_parity, and DES_is_weak_key as timing-unsafe. (As it's probably not worth the effort to try and make these legacy interfaces timing-safe. BTW, that would probably also make them slower.)

The whole of DES (as implemented) is cache-timing-unsafe, though, but that's not exactly as bad as branching on key bits or bytes, and is not unique to DES. Maybe this should be mentioned, too, but I think is more of an expected behavior (for those who know how DES is typically implemented).

@solardiz
Copy link

solardiz commented Nov 1, 2021

That said, I think it's good to merge this PR first, and discuss and maybe revert the original change (and this PR along with it) later. This PR mostly corrects the issue, and is thus a major improvement to what's currently committed.

@paulidale
Copy link
Contributor

I'm not convinced that the timing attack possibilities are all that bad here.

If you use a weak key, the timing changes and an attacker could find this out and potentially which weak key you are using. The weak part is damming here not the timing attack.

The parity check tells an attacker that the key has even parity and possibly the first byte that does. In what way does this give an attacker an advantage?

@t8m
Copy link
Member Author

t8m commented Nov 2, 2021

OTC: agreed to merge this. Timing of the weak key check can be resolved in a separate PR.

@t8m t8m added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer hold: need otc decision The OTC needs to make a decision labels Nov 2, 2021
@solardiz
Copy link

solardiz commented Nov 2, 2021

I'm not convinced that the timing attack possibilities are all that bad here.

Those added with this PR are not that bad compared to what we already had. However, those inside (both) called functions (thus, introduced to common usage in 3.0.0) are per-byte (one of these depends on memcmp implementation, though), so if exploited they can reduce the key space to search substantially.

The weak part is damming here not the timing attack.

That's not so obvious. With just a handful of weak keys in existence, an attacker could have tested them all against ciphertext quickly (as long as there's a way to detect correct decryption) even if the keys were not in any way special. So them also being weak generally does not make a difference.

openssl-machine pushed a commit that referenced this pull request Nov 2, 2021
This avoids using accidentally uninitialized key schedule in
applications that use DES_set_key() not expecting it to check the key
which is the default on OpenSSL <= 1.1.1

Fixes #16859

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #16944)
openssl-machine pushed a commit that referenced this pull request Nov 2, 2021
This avoids using accidentally uninitialized key schedule in
applications that use DES_set_key() not expecting it to check the key
which is the default on OpenSSL <= 1.1.1

Fixes #16859

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #16944)

(cherry picked from commit 6450ea2)
@paulidale paulidale added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Nov 2, 2021
@paulidale
Copy link
Contributor

Merged to master and 3.0.

@paulidale paulidale closed this Nov 2, 2021
paulidale added a commit to paulidale/openssl that referenced this pull request Nov 3, 2021
openssl-machine pushed a commit that referenced this pull request Nov 4, 2021
Fixes #16944
Fixes #16859

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from #16953)
openssl-machine pushed a commit that referenced this pull request Nov 4, 2021
Fixes #16944
Fixes #16859

Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
(Merged from #16953)

(cherry picked from commit 8db9d07)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Merge to master branch branch: 3.0 Merge to openssl-3.0 branch severity: fips change The pull request changes FIPS provider sources triaged: bug The issue/pr is/fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some uses of DES miscompute with OpenSSL 3.0.0
4 participants