Fix int overflow in mbedtls_asn1_get_int #297

Merged
gilles-peskine-arm merged 6 commits from asn1_get_int-undefined_shift into development 2019-10-11 10:31:17 -05:00
gilles-peskine-arm commented 2019-10-10 12:43:11 -05:00 (Migrated from github.com)

Fix an int overflow in mbedtls_asn1_get_int() introduced by #75 (so not present in any released version).

The signed int overflow in mbedtls_asn1_get_int() happened for numbers between INT_MAX+1 and UINT_MAX (typically 0x80000000..0xffffffff). This was undefined behavior which in practice would typically have resulted in an incorrect value, but which may plausibly also have caused the postcondition (*p == initial<*p> + len) to be violated.

Also fix up the ASN.1 INTEGER parsing tests a bit.

Credit to OSS-Fuzz (private link: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18102). To fix this in OSS-Fuzz, we'll need to update the crypto submodule in mbedtls after merging this PR.

Internal ref: IOTCRYPT-947

Fix an int overflow in `mbedtls_asn1_get_int()` introduced by #75 (so not present in any released version). The signed int overflow in `mbedtls_asn1_get_int()` happened for numbers between `INT_MAX+1` and `UINT_MAX` (typically 0x80000000..0xffffffff). This was undefined behavior which in practice would typically have resulted in an incorrect value, but which may plausibly also have caused the postcondition `(*p == initial<*p> + len)` to be violated. Also fix up the ASN.1 INTEGER parsing tests a bit. Credit to OSS-Fuzz (private link: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=18102). To fix this in OSS-Fuzz, we'll need to update the crypto submodule in mbedtls after merging this PR. Internal ref: IOTCRYPT-947
k-stachowiak (Migrated from github.com) reviewed 2019-10-10 12:43:11 -05:00
athoelke (Migrated from github.com) approved these changes 2019-10-10 18:59:13 -05:00
athoelke (Migrated from github.com) left a comment

That works for me.

That works for me.
Patater (Migrated from github.com) approved these changes 2019-10-11 08:32:59 -05:00
@ -230,0 +255,4 @@
INTEGER -0x100
get_integer:"0202ff00":"-100":0
Patater (Migrated from github.com) commented 2019-10-11 08:12:02 -05:00

Not super important, but if you wanted decreasing digits, use 0xfedcba9876543210. (swap a and b).

Not super important, but if you wanted decreasing digits, use `0xfedcba9876543210`. (swap `a` and `b`).
AndrzejKurek (Migrated from github.com) approved these changes 2019-10-11 08:57:38 -05:00
gilles-peskine-arm commented 2019-10-11 10:30:58 -05:00 (Migrated from github.com)

CI only failed on atecc608a-K64F jobs which is a known issue that's unrelated to this PR. Ok to merge.

CI only failed on atecc608a-K64F jobs which is a known issue that's unrelated to this PR. Ok to merge.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-ARMmbed/mbed-crypto!297
No description provided.