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

mbedtls: fix possible false success in mbedtls_cipher_check_tag() #6381

Merged
merged 5 commits into from
Nov 25, 2022

Conversation

tom-cosgrove-arm
Copy link
Contributor

@tom-cosgrove-arm tom-cosgrove-arm commented Sep 30, 2022

Originally this was PR #2164 - creating a new PR as that was based off user's development branch

I've taken the commit in the original PR, fixed the conflict, and updated the tests to reflect the new return values in the "you shouldn't call these functions in this mode" cases.

This is not a bug fix - calling AEAD-specific functions on non-AEAD algorithms is misuse of the library - rather, this is a change of library behaviour to help badly-written calling code fail safe. Both the previous behaviour and this new behaviour comply with the documentation of these functions. Accordingly I don't think it needs a backport.

Original description:

We should report a error when the security check of the security
tag was not made. In the other case false success is possible and
is not observable by the software.

Technically this could lead to a security flaw.

Signed-off-by: Denis V. Lunev den@openvz.org

Gatekeeper checklist

  • Tests
  • ChangeLog.d entry
  • Backport: not required

dlunev and others added 2 commits September 30, 2022 17:15
We should report a error when the security check of the security
tag was not made. In the other case false success is possible and
is not observable by the software.

Technically this could lead to a security flaw.

Signed-off-by: Denis V. Lunev <dlunev@gmail.com>
…icated alg

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
* MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, but at the time I write this our
* unit tests assume 0. */
ret = 0;
/* Status to return on a non-authenticated algorithm. */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While the removed text suggests using MBEDTLS_ERR_CIPHER_INVALID_CONTEXT or MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, the original PR uses MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE as recommended by Gilles in a comment

@tom-cosgrove-arm tom-cosgrove-arm added needs-review Every commit must be reviewed by at least two team members, component-crypto Crypto primitives and low-level interfaces needs-ci Needs to pass CI tests needs-reviewer This PR needs someone to pick it up for review size-s Estimated task size: small (~2d) labels Sep 30, 2022
@tom-cosgrove-arm tom-cosgrove-arm marked this pull request as draft September 30, 2022 16:28
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
@tom-cosgrove-arm tom-cosgrove-arm marked this pull request as ready for review September 30, 2022 17:11
@gilles-peskine-arm gilles-peskine-arm removed needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review labels Oct 4, 2022
@gilles-peskine-arm
Copy link
Contributor

FYI CI is failing

@daverodgman daverodgman added the priority-medium Medium priority - this can be reviewed as time permits label Oct 10, 2022
…bedtls_cipher_mode_t

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
@tom-cosgrove-arm tom-cosgrove-arm added needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review and removed needs-work labels Oct 14, 2022
Comment on lines 2 to 4
* Calling AEAD tag-specific functions for non-AEAD algorithms (which should not
be done - they are documented for use only by AES-GCM and ChaCha20+Poly1305)
now returns MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE instead of success (0).
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Calling AEAD tag-specific functions for non-AEAD algorithms (which should not
be done - they are documented for use only by AES-GCM and ChaCha20+Poly1305)
now returns MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE instead of success (0).
* Calling AEAD tag-specific functions for non-AEAD algorithms (which should
not be done - they are documented for use only by AES-GCM and
ChaCha20+Poly1305) now returns MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE
instead of success (0).

Fix line length

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did wonder about this, but the slightly longer line length makes the right margin much less ragged (I'm sure TeX would approve!)

Copy link
Contributor

Choose a reason for hiding this comment

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

Changes
   * Calling AEAD tag-specific functions for non-AEAD algorithms (which should n
ot
     be done - they are documented for use only by AES-GCM and ChaCha20+Poly1305
)
     now returns MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE instead of success (0).

The margin may not be ragged, but having not split like this is not easy to read. Please privilege readability over aesthetics.

Copy link
Contributor

Choose a reason for hiding this comment

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

which to my eye the first is definitely superior

The first is impossible on my system. What's currently in the file looks like what I posted above.

daverodgman
daverodgman previously approved these changes Nov 7, 2022
Copy link
Contributor

@daverodgman daverodgman left a comment

Choose a reason for hiding this comment

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

Approved (but needs trivial fix to Changelog line length)

AndrzejKurek
AndrzejKurek previously approved these changes Nov 16, 2022
@AndrzejKurek
Copy link
Contributor

There's still one issue to fix with the changelog.

@tom-cosgrove-arm
Copy link
Contributor Author

Does the ChangeLog absolutely need a maximum of 80 chars per line? Im my view it's much neater with the only very slightly longer lines, and we already have lines > 80 chars in that file.

@gilles-peskine-arm
Copy link
Contributor

More than 80 characters per line won't break any automated system, but it's not neat.

   * Fix a potential side channel vulnerability in ECDSA ephemeral key generati>
     An adversary who is capable of very precise timing measurements could
     learn partial information about the leading bits of the nonce used for the
     signature, allowing the recovery of the private key after observing a
     large number of signature operations. This completes a partial fix in
     Mbed TLS 2.20.0.

@AndrzejKurek AndrzejKurek added needs-work and removed needs-review Every commit must be reviewed by at least two team members, needs-ci Needs to pass CI tests needs-reviewer This PR needs someone to pick it up for review labels Nov 16, 2022
@tom-cosgrove-arm
Copy link
Contributor Author

here, this is the difference between

   * Calling AEAD tag-specific functions for non-AEAD algorithms (which should not
     be done - they are documented for use only by AES-GCM and ChaCha20+Poly1305)
     now returns MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE instead of success (0).

and

   * Calling AEAD tag-specific functions for non-AEAD algorithms (which should
     not be done - they are documented for use only by AES-GCM and
     ChaCha20+Poly1305) now returns MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE
     instead of success (0).

which to my eye the first is definitely superior

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
@tom-cosgrove-arm tom-cosgrove-arm added needs-review Every commit must be reviewed by at least two team members, and removed needs-work labels Nov 18, 2022
@tom-cosgrove-arm
Copy link
Contributor Author

tom-cosgrove-arm commented Nov 18, 2022

CI previously passed; only a ChangeLog entry change; only OpenCI is failing with

tests/ssl-opt.sh: 989: kill: No such process
:
^^^^test_psa_crypto_config_accel_hash_use_psa: test: ssl-opt.sh, MBEDTLS_PSA_CRYPTO_CONFIG with accelerated hash and USE_PSA:

so "something weird happened" on OpenCI - same job on internal CI passes

@tom-cosgrove-arm tom-cosgrove-arm added approved Design and code approved - may be waiting for CI or backports needs-ci Needs to pass CI tests and removed needs-review Every commit must be reviewed by at least two team members, labels Nov 24, 2022
@tom-cosgrove-arm
Copy link
Contributor Author

Internal CI has passed - failures are OpenCI

@tom-cosgrove-arm tom-cosgrove-arm added historical-reviewing Currently reviewing (for legacy PR/issues) and removed needs-ci Needs to pass CI tests labels Nov 25, 2022
@daverodgman daverodgman merged commit f1419db into Mbed-TLS:development Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Design and code approved - may be waiting for CI or backports component-crypto Crypto primitives and low-level interfaces historical-reviewing Currently reviewing (for legacy PR/issues) priority-medium Medium priority - this can be reviewed as time permits size-s Estimated task size: small (~2d)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants