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

Added check for the return value of the RAND_bytes() function #21706

Closed
wants to merge 4 commits into from

Conversation

Klavishnik
Copy link
Contributor

The return value of the RAND_bytes() function is not checked. At the same time, the function might return 0 without changing the value of the out variable passed to it. This variable will be used later on, so a check for the function's return value has been added.

Perhaps this would be more correct:

  if (RAND_bytes(out, 16) <= 0)
        goto err;

@github-actions github-actions bot added the severity: fips change The pull request changes FIPS provider sources label Aug 10, 2023
apps/speed.c Outdated
Comment on lines 4750 to 4757
if (RAND_bytes(out, 16) > 0) {
len += 16;
aad[11] = (unsigned char)(len >> 8);
aad[12] = (unsigned char)(len);
pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
EVP_AEAD_TLS1_AAD_LEN, aad);
ciph_success = EVP_Cipher(ctx, out, inp, len + pad);
}
Copy link
Member

@t8m t8m Aug 10, 2023

Choose a reason for hiding this comment

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

Instead, I would use app_bail_out() in case of RAND_bytes() failure. However it is not clear to me why the RAND_bytes() call is there at all - the out buffer should be overwritten by the EVP_Cipher call anyway.

@mattcaswell any idea why the RAND_bytes() call is there?

Copy link
Member

Choose a reason for hiding this comment

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

No, I don't see an obvious reason for it.

Copy link
Member

Choose a reason for hiding this comment

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

In that case I wouldn't bother checking the return value, just explicitly cast to (void) as we do not want to change what is the speed command measuring to keep the results stable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I wonder if it's meant to be setting inp rather than out, since - unless OPENSSL_malloc() initialises the memory it returns - it doesn't look like inp is being initialised here

Copy link
Member

Choose a reason for hiding this comment

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

Possibly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What should we do about this issue?

Copy link
Member

Choose a reason for hiding this comment

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

Use app_bail_out if RAND_bytes() fails instead. And also change the output parameter of RAND_bytes() to inp.

@t8m t8m added branch: master Merge to master branch triaged: cleanup The issue/pr deals with cleanup of comments/docs not altering code significantly labels Aug 10, 2023
@paulidale paulidale added the stalled: awaiting contributor response This pull request is awaiting a response by the contributor label Oct 4, 2023
Changed the output parameter of RAND_bytes() to inp.
@paulidale paulidale removed the stalled: awaiting contributor response This pull request is awaiting a response by the contributor label Oct 5, 2023
apps/speed.c Outdated
len += 16;
aad[11] = (unsigned char)(len >> 8);
aad[12] = (unsigned char)(len);
pad = EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_TLS1_AAD,
EVP_AEAD_TLS1_AAD_LEN, aad);
EVP_AEAD_TLS1_AAD_LEN, aad);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't fix the indentation here, it was already correct as per our coding style.

@github-actions github-actions bot removed the severity: fips change The pull request changes FIPS provider sources label Oct 5, 2023
@t8m t8m added the tests: exempted The PR is exempt from requirements for testing label Oct 6, 2023
@t8m t8m added triaged: bug The issue/pr is/fixes a bug branch: 3.0 Merge to openssl-3.0 branch branch: 3.1 Merge to openssl-3.1 approval: review pending This pull request needs review by a committer labels Oct 9, 2023
@tom-cosgrove-arm tom-cosgrove-arm 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 Oct 9, 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 Oct 10, 2023
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

@t8m
Copy link
Member

t8m commented Oct 10, 2023

Squashed and merged to master, 3.1 and 3.0 branches. Thank you for your contribution.

@t8m t8m closed this Oct 10, 2023
openssl-machine pushed a commit that referenced this pull request Oct 10, 2023
Call app_bail_out if RAND_bytes() fails.

Also changed the output parameter of RAND_bytes() to inp as
writing to encrypted output buffer does not make sense.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #21706)

(cherry picked from commit 8d120ae)
openssl-machine pushed a commit that referenced this pull request Oct 10, 2023
Call app_bail_out if RAND_bytes() fails.

Also changed the output parameter of RAND_bytes() to inp as
writing to encrypted output buffer does not make sense.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #21706)
openssl-machine pushed a commit that referenced this pull request Oct 10, 2023
Call app_bail_out if RAND_bytes() fails.

Also changed the output parameter of RAND_bytes() to inp as
writing to encrypted output buffer does not make sense.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #21706)

(cherry picked from commit 8d120ae)
wanghao75 pushed a commit to openeuler-mirror/openssl that referenced this pull request Oct 16, 2023
Call app_bail_out if RAND_bytes() fails.

Also changed the output parameter of RAND_bytes() to inp as
writing to encrypted output buffer does not make sense.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from openssl/openssl#21706)

Signed-off-by: fly2x <fly2x@hitls.org>
wanghao75 pushed a commit to openeuler-mirror/openssl that referenced this pull request Oct 16, 2023
Call app_bail_out if RAND_bytes() fails.

Also changed the output parameter of RAND_bytes() to inp as
writing to encrypted output buffer does not make sense.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from openssl/openssl#21706)

(cherry picked from commit 8d120ae)
Signed-off-by: fly2x <fly2x@hitls.org>
wanghao75 pushed a commit to openeuler-mirror/openssl that referenced this pull request Oct 16, 2023
Call app_bail_out if RAND_bytes() fails.

Also changed the output parameter of RAND_bytes() to inp as
writing to encrypted output buffer does not make sense.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from openssl/openssl#21706)

(cherry picked from commit 8d120ae)
Signed-off-by: fly2x <fly2x@hitls.org>
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 branch: 3.1 Merge to openssl-3.1 tests: exempted The PR is exempt from requirements for testing triaged: bug The issue/pr is/fixes a bug triaged: cleanup The issue/pr deals with cleanup of comments/docs not altering code significantly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants