Skip to content

providers/implementations/exchange/kdf_exch.c: Fix kdf_derive() - #18533

Closed
levitte wants to merge 3 commits into
openssl:openssl-3.0from
levitte:fix-18517
Closed

levitte wants to merge 3 commits into
openssl:openssl-3.0from
levitte:fix-18517

Conversation

@levitte

@levitte levitte commented Jun 11, 2022 •

Copy link
Copy Markdown
Member

kdf_derive() calls EVP_KDF_derive(), but didn't do enough to adapt its input
buffer length arguments to fit the requirements to call EVP_KDF_derive().

Fixes #18517

@levitte levitte added triaged: bug The issue/pr is/fixes a bug branch: 3.0 Applies to openssl-3.0 branch (EOL) branch: master Applies to master branch labels Jun 11, 2022
@levitte

levitte commented Jun 11, 2022

Copy link
Copy Markdown
Member Author

This is currently in draft, pending a proper test

@github-actions github-actions Bot added the severity: fips change The pull request changes FIPS provider sources label Jun 11, 2022
EVP_PKEY_derive() should be able to cope with a too big buffer for fixed
size outputs.  However, we don't test that.

This change modifies the PKEYKDF tests to ask EVP_PKEY_derive() what the
desired output buffer size is, and as long as the returned value isn't
absurd (indicating that anything goes), the output buffer is made to be
twice as big as what is expected.

Tests openssl#18517
@levitte

levitte commented Jun 12, 2022

Copy link
Copy Markdown
Member Author

The test that checks this is in #18536

@levitte
levitte marked this pull request as ready for review June 12, 2022 04:11
levitte added 2 commits June 12, 2022 07:27
kdf_derive() calls EVP_KDF_derive(), but didn't do enough to adapt its input
buffer length arguments to fit the requirements to call EVP_KDF_derive().

Fixes openssl#18517
@levitte

levitte commented Jun 12, 2022

Copy link
Copy Markdown
Member Author

The test that checks this is in #18536

I decided to rebase this PR on top of that one

@t8m t8m added the approval: review pending This pull request needs review by a committer label Jun 13, 2022
}

return EVP_KDF_derive(pkdfctx->kdfctx, secret, outlen, NULL);
if (kdfsize != SIZE_MAX) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks odd. Why is this necessary?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Because depending on the mode (EXTRACT_AND_EXPAND, EXTRACT_ONLY or EXPAND_ONLY), the output size may be fixed or indefinite. Kinda documented here:

EVP_KDF_CTX_get_kdf_size() returns the output size if the algorithm produces a fixed amount
of output and B<SIZE_MAX> otherwise. If an error occurs then 0 is returned.
For some algorithms an error may result if input parameters necessary to
calculate a fixed output size have not yet been supplied.

@levitte

levitte commented Jun 14, 2022

Copy link
Copy Markdown
Member Author

Ping

@levitte levitte 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 Jun 14, 2022
@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 Jun 15, 2022
@openssl-machine

Copy link
Copy Markdown
Collaborator

This pull request is ready to merge

openssl-machine pushed a commit that referenced this pull request Jun 15, 2022
EVP_PKEY_derive() should be able to cope with a too big buffer for fixed
size outputs.  However, we don't test that.

This change modifies the PKEYKDF tests to ask EVP_PKEY_derive() what the
desired output buffer size is, and as long as the returned value isn't
absurd (indicating that anything goes), the output buffer is made to be
twice as big as what is expected.

Tests #18517

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #18533)
openssl-machine pushed a commit that referenced this pull request Jun 15, 2022
kdf_derive() calls EVP_KDF_derive(), but didn't do enough to adapt its input
buffer length arguments to fit the requirements to call EVP_KDF_derive().

Fixes #18517

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #18533)
@levitte

levitte commented Jun 15, 2022

Copy link
Copy Markdown
Member Author

Merged

3.0:
a0587aa test/evp_test.c: Check too big output buffer sizes in PKEYKDF tests
e906eab providers/implementations/exchange/kdf_exch.c: Fix kdf_derive()

master:
f68283c test/evp_test.c: Check too big output buffer sizes in PKEYKDF tests
0feb138 providers/implementations/exchange/kdf_exch.c: Fix kdf_derive()

@levitte levitte closed this Jun 15, 2022
@levitte
levitte deleted the fix-18517 branch June 15, 2022 13:22
openssl-machine pushed a commit that referenced this pull request Jun 15, 2022
EVP_PKEY_derive() should be able to cope with a too big buffer for fixed
size outputs.  However, we don't test that.

This change modifies the PKEYKDF tests to ask EVP_PKEY_derive() what the
desired output buffer size is, and as long as the returned value isn't
absurd (indicating that anything goes), the output buffer is made to be
twice as big as what is expected.

Tests #18517

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

(cherry picked from commit a0587aa)
openssl-machine pushed a commit that referenced this pull request Jun 15, 2022
kdf_derive() calls EVP_KDF_derive(), but didn't do enough to adapt its input
buffer length arguments to fit the requirements to call EVP_KDF_derive().

Fixes #18517

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

(cherry picked from commit e906eab)
@paulidale

Copy link
Copy Markdown
Contributor

I have a suspicion this might have broken some tests...

https://github.com/paulidale/openssl/runs/6910341376?check_suite_focus=true#step:12:318

Why this didn't show up before it was merged is odd.

@levitte

levitte commented Jun 16, 2022 •

Copy link
Copy Markdown
Member Author

That's interesting... that run is as if only the test/evp_test.c change was there, but not the correction of kdf_exch.c (i.e, it looks exactly the same as the runs of #18536)

@levitte

levitte commented Jun 16, 2022 •

Copy link
Copy Markdown
Member Author

Side note: why are you building 3.0 in fips-provider-master?
Never mind this, got it

@levitte

levitte commented Jun 16, 2022

Copy link
Copy Markdown
Member Author

Ah, found it... your master branch is behind, so doesn't contain the fix of kdf_exch.c, but you're testing with a more up to date 3.0, which tests exactly the bug in question. Update the master branch in paulidale/openssl and you're gonna be fine

jquepi pushed a commit to jquepi/openssl7555 that referenced this pull request Jun 18, 2022
EVP_PKEY_derive() should be able to cope with a too big buffer for fixed
size outputs.  However, we don't test that.

This change modifies the PKEYKDF tests to ask EVP_PKEY_derive() what the
desired output buffer size is, and as long as the returned value isn't
absurd (indicating that anything goes), the output buffer is made to be
twice as big as what is expected.

Tests #18517

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

(cherry picked from commit a0587aa)
jquepi pushed a commit to jquepi/openssl7555 that referenced this pull request Jun 18, 2022
kdf_derive() calls EVP_KDF_derive(), but didn't do enough to adapt its input
buffer length arguments to fit the requirements to call EVP_KDF_derive().

Fixes #18517

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

(cherry picked from commit e906eab)
jquepi pushed a commit to jquepi/openssl7555 that referenced this pull request Jun 19, 2022
EVP_PKEY_derive() should be able to cope with a too big buffer for fixed
size outputs.  However, we don't test that.

This change modifies the PKEYKDF tests to ask EVP_PKEY_derive() what the
desired output buffer size is, and as long as the returned value isn't
absurd (indicating that anything goes), the output buffer is made to be
twice as big as what is expected.

Tests #18517

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

(cherry picked from commit a0587aa)
jquepi pushed a commit to jquepi/openssl7555 that referenced this pull request Jun 19, 2022
kdf_derive() calls EVP_KDF_derive(), but didn't do enough to adapt its input
buffer length arguments to fit the requirements to call EVP_KDF_derive().

Fixes #18517

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

(cherry picked from commit e906eab)
jquepi pushed a commit to jquepi/openssl7555 that referenced this pull request Jun 19, 2022
EVP_PKEY_derive() should be able to cope with a too big buffer for fixed
size outputs.  However, we don't test that.

This change modifies the PKEYKDF tests to ask EVP_PKEY_derive() what the
desired output buffer size is, and as long as the returned value isn't
absurd (indicating that anything goes), the output buffer is made to be
twice as big as what is expected.

Tests #18517

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

(cherry picked from commit a0587aa)
jquepi pushed a commit to jquepi/openssl7555 that referenced this pull request Jun 19, 2022
kdf_derive() calls EVP_KDF_derive(), but didn't do enough to adapt its input
buffer length arguments to fit the requirements to call EVP_KDF_derive().

Fixes #18517

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

(cherry picked from commit e906eab)
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
EVP_PKEY_derive() should be able to cope with a too big buffer for fixed
size outputs.  However, we don't test that.

This change modifies the PKEYKDF tests to ask EVP_PKEY_derive() what the
desired output buffer size is, and as long as the returned value isn't
absurd (indicating that anything goes), the output buffer is made to be
twice as big as what is expected.

Tests openssl#18517

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

(cherry picked from commit a0587aa)
sftcd pushed a commit to sftcd/openssl that referenced this pull request Sep 24, 2022
kdf_derive() calls EVP_KDF_derive(), but didn't do enough to adapt its input
buffer length arguments to fit the requirements to call EVP_KDF_derive().

Fixes openssl#18517

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

(cherry picked from commit e906eab)
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) 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.

5 participants