Skip to content

Conversation

gilles-peskine-arm
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm commented Nov 15, 2022

Fix two kinds of typically harmless undefined behavior in bignum:

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

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 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 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
@gilles-peskine-arm
Copy link
Contributor Author

@daverodgman @tom-cosgrove-arm This is a subset of #6614 which you've approved. I'll make a backport ASAP

@daverodgman daverodgman removed the needs-reviewer This PR needs someone to pick it up for review label Nov 17, 2022
Copy link
Contributor

@tom-cosgrove-arm tom-cosgrove-arm left a 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 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
@gilles-peskine-arm
Copy link
Contributor Author

Backport is up: #6618

@gilles-peskine-arm gilles-peskine-arm merged commit 339406d into Mbed-TLS:development Nov 21, 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 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)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants