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

Fix usage of custom EVP_CIPHER objects #19300

Closed
wants to merge 5 commits into from

Conversation

mattcaswell
Copy link
Member

If a custom EVP_CIPHER object has been passed to EVP_CipherInit() then it
should be used in preference to a fetched cipher.

We also fix a possible NULL pointer deref in the same code for digests.

If the custom cipher passed to EVP_CipherInit() happens to use NID_undef
(which should be a discouraged practice), then in the previous
implementation this could result in the NULL cipher being fetched and
hence NULL encryption being unexpectedly used.

CVE-2022-3358

Fixes #18970

Note that this has been assessed as a low severity security issue. As per our policy, since it is low, it is being fixed in public and will be included in the next release.

We also fix a bug where the cleanup function for an EVP_CIPHER was not always being called when it should, which was highlighted by writing the test for the original issue.

If a custom EVP_CIPHER object has been passed to EVP_CipherInit() then it
should be used in preference to a fetched cipher.

We also fix a possible NULL pointer deref in the same code for digests.

If the custom cipher passed to EVP_CipherInit() happens to use NID_undef
(which should be a discouraged practice), then in the previous
implementation this could result in the NULL cipher being fetched and
hence NULL encryption being unexpectedly used.

CVE-2022-3358

Fixes openssl#18970
In some circumstances we were not calling the cleanup() function to
remove cipher specific data from an EVP_CIPHER_CTX.
Test that a custom EVP_CIPHER gets used in EVP_CipherInit_ex() calls.
@mattcaswell mattcaswell added branch: master Merge to master branch approval: review pending This pull request needs review by a committer approval: otc review pending This pull request needs review by an OTC member severity: important Important bugs affecting a released version branch: 3.0 Merge to openssl-3.0 branch labels Sep 29, 2022
@github-actions github-actions bot added the severity: fips change The pull request changes FIPS provider sources label Sep 29, 2022
@t8m t8m added the triaged: bug The issue/pr is/fixes a bug label Sep 29, 2022
crypto/evp/evp_enc.c Outdated Show resolved Hide resolved
test/evp_extra_test.c Outdated Show resolved Hide resolved
@mattcaswell
Copy link
Member Author

Feedback addressed.

@togtalk
Copy link

togtalk commented Sep 29, 2022

Yes nice please share

@t8m t8m removed the approval: otc review pending This pull request needs review by an OTC member label Sep 29, 2022

ciphctx = EVP_CIPHER_CTX_new();
if (!TEST_ptr(ciphctx)
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the indentation off here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is

@paulidale paulidale added the approval: done This pull request has the required number of approvals label Sep 29, 2022
@openssl-machine openssl-machine removed the approval: done This pull request has the required number of approvals label Oct 1, 2022
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

@openssl-machine openssl-machine added the approval: ready to merge The 24 hour grace period has passed, ready to merge label Oct 1, 2022
@paulidale
Copy link
Contributor

Needs an indentation fix before merge.

openssl-machine pushed a commit that referenced this pull request Oct 3, 2022
If a custom EVP_CIPHER object has been passed to EVP_CipherInit() then it
should be used in preference to a fetched cipher.

We also fix a possible NULL pointer deref in the same code for digests.

If the custom cipher passed to EVP_CipherInit() happens to use NID_undef
(which should be a discouraged practice), then in the previous
implementation this could result in the NULL cipher being fetched and
hence NULL encryption being unexpectedly used.

CVE-2022-3358

Fixes #18970

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #19300)
openssl-machine pushed a commit that referenced this pull request Oct 3, 2022
In some circumstances we were not calling the cleanup() function to
remove cipher specific data from an EVP_CIPHER_CTX.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #19300)
openssl-machine pushed a commit that referenced this pull request Oct 3, 2022
Test that a custom EVP_CIPHER gets used in EVP_CipherInit_ex() calls.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #19300)
@mattcaswell
Copy link
Member Author

Pushed to master and 3.0. I fixed the indentation issue during merge. There was a trivial conflict cherry-picking to 3.0 that I also resolved during the merge.

@mattcaswell mattcaswell closed this Oct 3, 2022
openssl-machine pushed a commit that referenced this pull request Oct 3, 2022
If a custom EVP_CIPHER object has been passed to EVP_CipherInit() then it
should be used in preference to a fetched cipher.

We also fix a possible NULL pointer deref in the same code for digests.

If the custom cipher passed to EVP_CipherInit() happens to use NID_undef
(which should be a discouraged practice), then in the previous
implementation this could result in the NULL cipher being fetched and
hence NULL encryption being unexpectedly used.

CVE-2022-3358

Fixes #18970

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #19300)

(cherry picked from commit 25d47cc)
openssl-machine pushed a commit that referenced this pull request Oct 3, 2022
In some circumstances we were not calling the cleanup() function to
remove cipher specific data from an EVP_CIPHER_CTX.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #19300)

(cherry picked from commit f817a74)
openssl-machine pushed a commit that referenced this pull request Oct 3, 2022
Test that a custom EVP_CIPHER gets used in EVP_CipherInit_ex() calls.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #19300)

(cherry picked from commit 8c7d847)
beldmit pushed a commit to beldmit/openssl that referenced this pull request Dec 26, 2022
If a custom EVP_CIPHER object has been passed to EVP_CipherInit() then it
should be used in preference to a fetched cipher.

We also fix a possible NULL pointer deref in the same code for digests.

If the custom cipher passed to EVP_CipherInit() happens to use NID_undef
(which should be a discouraged practice), then in the previous
implementation this could result in the NULL cipher being fetched and
hence NULL encryption being unexpectedly used.

CVE-2022-3358

Fixes openssl#18970

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from openssl#19300)
beldmit pushed a commit to beldmit/openssl that referenced this pull request Dec 26, 2022
In some circumstances we were not calling the cleanup() function to
remove cipher specific data from an EVP_CIPHER_CTX.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from openssl#19300)
beldmit pushed a commit to beldmit/openssl that referenced this pull request Dec 26, 2022
Test that a custom EVP_CIPHER gets used in EVP_CipherInit_ex() calls.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from openssl#19300)
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 approval: review pending This pull request needs review by a committer 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 severity: important Important bugs affecting a released version triaged: bug The issue/pr is/fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Silent Failure in OpenSSL leads to use of NULL Cipher
6 participants