-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 undefined behavior in bignum: NULL+0 and -most-negative-sint #6609
Merged
gilles-peskine-arm
merged 4 commits into
Mbed-TLS:development
from
gilles-peskine-arm:mpi_sint-min-ub
Nov 21, 2022
Merged
Fix undefined behavior in bignum: NULL+0 and -most-negative-sint #6609
gilles-peskine-arm
merged 4 commits into
Mbed-TLS:development
from
gilles-peskine-arm:mpi_sint-min-ub
Nov 21, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Since they're part of the public API (even if only through a few functions), they should be documented. I deliberately skipped documenting how to configure the size of the type. Right now, MBEDTLS_HAVE_INT32 and MBEDTLS_HAVE_INT64 have no Doxygen documentation, so it's ambiguous whether they're part of the public API. Resolving this ambiguity is out of scope of my current work. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Fix undefined behavior (typically harmless in practice) of mbedtls_mpi_add_mpi(), mbedtls_mpi_add_abs() and mbedtls_mpi_add_int() when both operands are 0 and the left operand is represented with 0 limbs. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
When x is the most negative value of a two's complement type, `(unsigned_type)(-x)` has undefined behavior, whereas `-(unsigned_type)x` has well-defined behavior and does what was intended. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
gilles-peskine-arm
added
bug
component-crypto
Crypto primitives and low-level interfaces
needs-ci
Needs to pass CI tests
size-s
Estimated task size: small (~2d)
labels
Nov 15, 2022
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
gilles-peskine-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
needs-backports
Backports are missing or are pending review and approval.
and removed
needs-ci
Needs to pass CI tests
labels
Nov 16, 2022
3 tasks
@daverodgman @tom-cosgrove-arm This is a subset of #6614 which you've approved. I'll make a backport ASAP |
daverodgman
approved these changes
Nov 17, 2022
daverodgman
removed
the
needs-reviewer
This PR needs someone to pick it up for review
label
Nov 17, 2022
tom-cosgrove-arm
approved these changes
Nov 17, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
tom-cosgrove-arm
added
approved
Design and code approved - may be waiting for CI or backports
and removed
needs-review
Every commit must be reviewed by at least two team members,
labels
Nov 17, 2022
3 tasks
Backport is up: #6618 |
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
bug
component-crypto
Crypto primitives and low-level interfaces
needs-backports
Backports are missing or are pending review and approval.
size-s
Estimated task size: small (~2d)
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix two kinds of typically harmless undefined behavior in bignum:
mbedtls_mpi_add_abs()
A reasonably modern UBSan with Clang (Ubuntu 20.04 with Clang 10) complains about both (but not GCC 12 from Ubuntu 22.04 or Clang 6 from Ubuntu 18.04). The addition bug already had a test, but we only run an ancient UBSan on our CI. I added a test for -SINT_MIN, without using the test framework to pass function arguments because you can't easily pass the interesting values.
Gatekeeper checklist