Skip to content

Make DSA_sign() test for negative p,q,g values. - #20553

Closed
slontis wants to merge 1 commit into
openssl:masterfrom
slontis:dsa_sign_fixes
Closed

slontis wants to merge 1 commit into
openssl:masterfrom
slontis:dsa_sign_fixes

Conversation

@slontis

@slontis slontis commented Mar 21, 2023 •

Copy link
Copy Markdown
Member

Related to #20268

DSA_sign() assumes that the signature passed in is related to DSA_size(). If q is negative then DSA_size() actually fails and returns 0.

A test that tries to allocate the signature buffer using DSA_size() and then pass it to DSA_sign() will then either.

(1) Have a signature buffer of NULL. In this case it was leaking data returned via i2d_DSA_SIG.

(2) Cause a seg fault because we created a buffer that was not large enough to hold the signature. As it already checked zero we also now check for negative values also.

Checklist
  • documentation is added or updated
  • tests are added or updated

Related to openssl#20268

DSA_sign() assumes that the signature passed in is related to DSA_size().
If q is negative then DSA_size() actually fails and returns 0.

A test that tries to allocate the signature buffer using DSA_size() and then
pass it to DSA_sign() will then either.

(1) Have a signature buffer of NULL. In this case it was leaking data
returned via i2d_DSA_SIG.

(2) Cause a seg fault because we created a buffer that was not large
enough to hold the signature. As it already checked zero we also now
check for negative values also.
@slontis slontis added branch: master Applies to master branch approval: review pending This pull request needs review by a committer approval: otc review pending tests: present The PR has suitable tests present labels Mar 21, 2023
@paulidale paulidale added branch: 3.0 Applies to openssl-3.0 branch (EOL) branch: 3.1 Applies to openssl-3.1 (EOL) and removed approval: otc review pending labels Mar 21, 2023
@paulidale

Copy link
Copy Markdown
Contributor

I think this is a bug and able to be back ported.

@paulidale paulidale added the branch: 1.1.1 Applies to OpenSSL_1_1_1-stable branch (EOL) label Mar 21, 2023
@github-actions github-actions Bot added the severity: fips change The pull request changes FIPS provider sources label Mar 21, 2023
@paulidale

Copy link
Copy Markdown
Contributor

Consider 1.1.1 is this has security relevance. It's a heap walk but I'm not sure if an attacker can control things.

slontis added a commit to slontis/openssl that referenced this pull request Mar 21, 2023
Similiar to the issue found in PR openssl#20553 for DSA_sign().
ECDSA_sign() leaked memory if the signature was NULL
when i2d_ECDSA_SIG was called.

Note that this does not affect the higher level EVP
functions as they correctly handle NULL.
@slontis slontis mentioned this pull request Mar 21, 2023
1 of 2 tasks
@t8m t8m added the triaged: bug The issue/pr is/fixes a bug label Mar 21, 2023
@t8m

t8m commented Mar 21, 2023

Copy link
Copy Markdown
Member

I do not see this being a security issue. A security hardening perhaps. It also won't cherry-pick cleanly to 1.1.1.

@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 labels Mar 21, 2023
@paulidale paulidale removed the branch: 1.1.1 Applies to OpenSSL_1_1_1-stable branch (EOL) label Mar 21, 2023
@openssl-machine openssl-machine 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 Mar 22, 2023
@openssl-machine

Copy link
Copy Markdown
Collaborator

This pull request is ready to merge

openssl-machine pushed a commit that referenced this pull request Mar 31, 2023
Similiar to the issue found in PR #20553 for DSA_sign().
ECDSA_sign() leaked memory if the signature was NULL
when i2d_ECDSA_SIG was called.

Note that this does not affect the higher level EVP
functions as they correctly handle NULL.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from #20554)
openssl-machine pushed a commit that referenced this pull request Mar 31, 2023
Similiar to the issue found in PR #20553 for DSA_sign().
ECDSA_sign() leaked memory if the signature was NULL
when i2d_ECDSA_SIG was called.

Note that this does not affect the higher level EVP
functions as they correctly handle NULL.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from #20554)

(cherry picked from commit 4befe81)
openssl-machine pushed a commit that referenced this pull request Mar 31, 2023
Similiar to the issue found in PR #20553 for DSA_sign().
ECDSA_sign() leaked memory if the signature was NULL
when i2d_ECDSA_SIG was called.

Note that this does not affect the higher level EVP
functions as they correctly handle NULL.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from #20554)

(cherry picked from commit 4befe81)
(cherry picked from commit 680b4be)
@tmshort tmshort self-assigned this Mar 31, 2023
openssl-machine pushed a commit that referenced this pull request Mar 31, 2023
Related to #20268

DSA_sign() assumes that the signature passed in is related to DSA_size().
If q is negative then DSA_size() actually fails and returns 0.

A test that tries to allocate the signature buffer using DSA_size() and then
pass it to DSA_sign() will then either.

(1) Have a signature buffer of NULL. In this case it was leaking data
returned via i2d_DSA_SIG.

(2) Cause a seg fault because we created a buffer that was not large
enough to hold the signature. As it already checked zero we also now
check for negative values also.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from #20553)
openssl-machine pushed a commit that referenced this pull request Mar 31, 2023
Related to #20268

DSA_sign() assumes that the signature passed in is related to DSA_size().
If q is negative then DSA_size() actually fails and returns 0.

A test that tries to allocate the signature buffer using DSA_size() and then
pass it to DSA_sign() will then either.

(1) Have a signature buffer of NULL. In this case it was leaking data
returned via i2d_DSA_SIG.

(2) Cause a seg fault because we created a buffer that was not large
enough to hold the signature. As it already checked zero we also now
check for negative values also.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from #20553)

(cherry picked from commit 9559ad0)
@tmshort

tmshort commented Mar 31, 2023

Copy link
Copy Markdown
Contributor

Merged to master, openssl-3.1 and openssl-3.0. Thank you for your contribution!

@tmshort tmshort closed this Mar 31, 2023
openssl-machine pushed a commit that referenced this pull request Mar 31, 2023
Related to #20268

DSA_sign() assumes that the signature passed in is related to DSA_size().
If q is negative then DSA_size() actually fails and returns 0.

A test that tries to allocate the signature buffer using DSA_size() and then
pass it to DSA_sign() will then either.

(1) Have a signature buffer of NULL. In this case it was leaking data
returned via i2d_DSA_SIG.

(2) Cause a seg fault because we created a buffer that was not large
enough to hold the signature. As it already checked zero we also now
check for negative values also.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from #20553)

(cherry picked from commit 9559ad0)
(cherry picked from commit ce90b5e)
bernd-edlinger pushed a commit to bernd-edlinger/openssl that referenced this pull request May 2, 2023
Similiar to the issue found in PR openssl#20553 for DSA_sign().
ECDSA_sign() leaked memory if the signature was NULL
when i2d_ECDSA_SIG was called.

Note that this does not affect the higher level EVP
functions as they correctly handle NULL.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from openssl#20554)

(cherry picked from commit 4befe81)
(cherry picked from commit 680b4be)
bernd-edlinger pushed a commit to bernd-edlinger/openssl that referenced this pull request May 4, 2023
Related to openssl#20268

DSA_sign() assumes that the signature passed in is related to DSA_size().
If q is negative then DSA_size() actually fails and returns 0.

A test that tries to allocate the signature buffer using DSA_size() and then
pass it to DSA_sign() will then either.

(1) Have a signature buffer of NULL. In this case it was leaking data
returned via i2d_DSA_SIG.

(2) Cause a seg fault because we created a buffer that was not large
enough to hold the signature. As it already checked zero we also now
check for negative values also.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from openssl#20553)

(cherry picked from commit 9559ad0)
(cherry picked from commit ce90b5e)
bernd-edlinger pushed a commit to bernd-edlinger/openssl that referenced this pull request May 13, 2023
Similiar to the issue found in PR openssl#20553 for DSA_sign().
ECDSA_sign() leaked memory if the signature was NULL
when i2d_ECDSA_SIG was called.

Note that this does not affect the higher level EVP
functions as they correctly handle NULL.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from openssl#20554)

(cherry picked from commit 4befe81)
(cherry picked from commit 680b4be)
bernd-edlinger pushed a commit to bernd-edlinger/openssl that referenced this pull request May 13, 2023
Related to openssl#20268

DSA_sign() assumes that the signature passed in is related to DSA_size().
If q is negative then DSA_size() actually fails and returns 0.

A test that tries to allocate the signature buffer using DSA_size() and then
pass it to DSA_sign() will then either.

(1) Have a signature buffer of NULL. In this case it was leaking data
returned via i2d_DSA_SIG.

(2) Cause a seg fault because we created a buffer that was not large
enough to hold the signature. As it already checked zero we also now
check for negative values also.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from openssl#20553)

(cherry picked from commit 9559ad0)
(cherry picked from commit ce90b5e)
bernd-edlinger pushed a commit to bernd-edlinger/openssl that referenced this pull request May 17, 2023
Similiar to the issue found in PR openssl#20553 for DSA_sign().
ECDSA_sign() leaked memory if the signature was NULL
when i2d_ECDSA_SIG was called.

Note that this does not affect the higher level EVP
functions as they correctly handle NULL.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from openssl#20554)

(cherry picked from commit 4befe81)
(cherry picked from commit 680b4be)
bernd-edlinger pushed a commit to bernd-edlinger/openssl that referenced this pull request May 17, 2023
Related to openssl#20268

DSA_sign() assumes that the signature passed in is related to DSA_size().
If q is negative then DSA_size() actually fails and returns 0.

A test that tries to allocate the signature buffer using DSA_size() and then
pass it to DSA_sign() will then either.

(1) Have a signature buffer of NULL. In this case it was leaking data
returned via i2d_DSA_SIG.

(2) Cause a seg fault because we created a buffer that was not large
enough to hold the signature. As it already checked zero we also now
check for negative values also.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from openssl#20553)

(cherry picked from commit 9559ad0)
(cherry picked from commit ce90b5e)
bernd-edlinger pushed a commit to bernd-edlinger/openssl that referenced this pull request May 30, 2023
Similiar to the issue found in PR openssl#20553 for DSA_sign().
ECDSA_sign() leaked memory if the signature was NULL
when i2d_ECDSA_SIG was called.

Note that this does not affect the higher level EVP
functions as they correctly handle NULL.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from openssl#20554)

(cherry picked from commit 4befe81)
(cherry picked from commit 680b4be)
bernd-edlinger pushed a commit to bernd-edlinger/openssl that referenced this pull request May 30, 2023
Related to openssl#20268

DSA_sign() assumes that the signature passed in is related to DSA_size().
If q is negative then DSA_size() actually fails and returns 0.

A test that tries to allocate the signature buffer using DSA_size() and then
pass it to DSA_sign() will then either.

(1) Have a signature buffer of NULL. In this case it was leaking data
returned via i2d_DSA_SIG.

(2) Cause a seg fault because we created a buffer that was not large
enough to hold the signature. As it already checked zero we also now
check for negative values also.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from openssl#20553)

(cherry picked from commit 9559ad0)
(cherry picked from commit ce90b5e)
bernd-edlinger pushed a commit to bernd-edlinger/openssl that referenced this pull request Jul 19, 2023
Similiar to the issue found in PR openssl#20553 for DSA_sign().
ECDSA_sign() leaked memory if the signature was NULL
when i2d_ECDSA_SIG was called.

Note that this does not affect the higher level EVP
functions as they correctly handle NULL.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from openssl#20554)

(cherry picked from commit 4befe81)
(cherry picked from commit 680b4be)
bernd-edlinger pushed a commit to bernd-edlinger/openssl that referenced this pull request Jul 19, 2023
Related to openssl#20268

DSA_sign() assumes that the signature passed in is related to DSA_size().
If q is negative then DSA_size() actually fails and returns 0.

A test that tries to allocate the signature buffer using DSA_size() and then
pass it to DSA_sign() will then either.

(1) Have a signature buffer of NULL. In this case it was leaking data
returned via i2d_DSA_SIG.

(2) Cause a seg fault because we created a buffer that was not large
enough to hold the signature. As it already checked zero we also now
check for negative values also.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from openssl#20553)

(cherry picked from commit 9559ad0)
(cherry picked from commit ce90b5e)
bernd-edlinger pushed a commit to bernd-edlinger/openssl that referenced this pull request Aug 1, 2023
Similiar to the issue found in PR openssl#20553 for DSA_sign().
ECDSA_sign() leaked memory if the signature was NULL
when i2d_ECDSA_SIG was called.

Note that this does not affect the higher level EVP
functions as they correctly handle NULL.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from openssl#20554)

(cherry picked from commit 4befe81)
(cherry picked from commit 680b4be)
bernd-edlinger pushed a commit to bernd-edlinger/openssl that referenced this pull request Aug 1, 2023
Related to openssl#20268

DSA_sign() assumes that the signature passed in is related to DSA_size().
If q is negative then DSA_size() actually fails and returns 0.

A test that tries to allocate the signature buffer using DSA_size() and then
pass it to DSA_sign() will then either.

(1) Have a signature buffer of NULL. In this case it was leaking data
returned via i2d_DSA_SIG.

(2) Cause a seg fault because we created a buffer that was not large
enough to hold the signature. As it already checked zero we also now
check for negative values also.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from openssl#20553)

(cherry picked from commit 9559ad0)
(cherry picked from commit ce90b5e)
bernd-edlinger pushed a commit to bernd-edlinger/openssl that referenced this pull request Aug 19, 2023
Similiar to the issue found in PR openssl#20553 for DSA_sign().
ECDSA_sign() leaked memory if the signature was NULL
when i2d_ECDSA_SIG was called.

Note that this does not affect the higher level EVP
functions as they correctly handle NULL.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from openssl#20554)

(cherry picked from commit 4befe81)
(cherry picked from commit 680b4be)
bernd-edlinger pushed a commit to bernd-edlinger/openssl that referenced this pull request Aug 19, 2023
Related to openssl#20268

DSA_sign() assumes that the signature passed in is related to DSA_size().
If q is negative then DSA_size() actually fails and returns 0.

A test that tries to allocate the signature buffer using DSA_size() and then
pass it to DSA_sign() will then either.

(1) Have a signature buffer of NULL. In this case it was leaking data
returned via i2d_DSA_SIG.

(2) Cause a seg fault because we created a buffer that was not large
enough to hold the signature. As it already checked zero we also now
check for negative values also.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from openssl#20553)

(cherry picked from commit 9559ad0)
(cherry picked from commit ce90b5e)
bernd-edlinger pushed a commit to bernd-edlinger/openssl that referenced this pull request Sep 12, 2023
Similiar to the issue found in PR openssl#20553 for DSA_sign().
ECDSA_sign() leaked memory if the signature was NULL
when i2d_ECDSA_SIG was called.

Note that this does not affect the higher level EVP
functions as they correctly handle NULL.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from openssl#20554)

(cherry picked from commit 4befe81)
(cherry picked from commit 680b4be)
bernd-edlinger pushed a commit to bernd-edlinger/openssl that referenced this pull request Sep 12, 2023
Related to openssl#20268

DSA_sign() assumes that the signature passed in is related to DSA_size().
If q is negative then DSA_size() actually fails and returns 0.

A test that tries to allocate the signature buffer using DSA_size() and then
pass it to DSA_sign() will then either.

(1) Have a signature buffer of NULL. In this case it was leaking data
returned via i2d_DSA_SIG.

(2) Cause a seg fault because we created a buffer that was not large
enough to hold the signature. As it already checked zero we also now
check for negative values also.

Reviewed-by: Tomas Mraz <[email protected]>
Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Todd Short <[email protected]>
(Merged from openssl#20553)

(cherry picked from commit 9559ad0)
(cherry picked from commit ce90b5e)
kafei-cy added a commit to kafei-cy/Tongsuo that referenced this pull request Mar 26, 2026
DSA_sign() assumes that the signature passed in is related to DSA_size().
If q is negative then DSA_size() actually fails and returns 0.

A test that tries to allocate the signature buffer using DSA_size() and then
pass it to DSA_sign() will then either.

(1) Have a signature buffer of NULL. In this case it was leaking data
returned via i2d_DSA_SIG.

(2) Cause a seg fault because we created a buffer that was not large
enough to hold the signature. As it already checked zero we also now
check for negative values also.

(Merged from openssl/openssl#20553)
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 Applies to master branch branch: 3.0 Applies to openssl-3.0 branch (EOL) branch: 3.1 Applies to openssl-3.1 (EOL) severity: fips change The pull request changes FIPS provider sources tests: present The PR has suitable tests present triaged: bug The issue/pr is/fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants