mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-29 22:20:30 +00:00
Fix stack buffer overflow in ECDSA signature format conversions
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
f6275b745f
commit
4269ee6f2d
4
ChangeLog.d/ecdsa-conversion-overflow.txt
Normal file
4
ChangeLog.d/ecdsa-conversion-overflow.txt
Normal file
@ -0,0 +1,4 @@
|
||||
Security
|
||||
* Fix a stack buffer overflow in mbedtls_ecdsa_der_to_raw() and
|
||||
mbedtls_ecdsa_raw_to_der() when curve_bits is larger than the
|
||||
largest supported curve.
|
@ -443,6 +443,9 @@ int mbedtls_ecdsa_raw_to_der(size_t bits, const unsigned char *raw, size_t raw_l
|
||||
if (raw_len != (2 * coordinate_len)) {
|
||||
return MBEDTLS_ERR_ASN1_INVALID_DATA;
|
||||
}
|
||||
if (coordinate_len > sizeof(r)) {
|
||||
return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
|
||||
}
|
||||
|
||||
/* Since raw and der buffers might overlap, dump r and s before starting
|
||||
* the conversion. */
|
||||
@ -561,6 +564,9 @@ int mbedtls_ecdsa_der_to_raw(size_t bits, const unsigned char *der, size_t der_l
|
||||
if (raw_size < coordinate_size * 2) {
|
||||
return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
|
||||
}
|
||||
if (2 * coordinate_size > sizeof(raw_tmp)) {
|
||||
return MBEDTLS_ERR_ASN1_BUF_TOO_SMALL;
|
||||
}
|
||||
|
||||
/* Check that the provided input DER buffer has the right header. */
|
||||
ret = mbedtls_asn1_get_tag(&p, der + der_len, &data_len,
|
||||
|
@ -6,6 +6,9 @@ ECDSA Raw -> DER, 256bit, DER buffer too small
|
||||
depends_on:PSA_VENDOR_ECC_MAX_CURVE_BITS >= 256
|
||||
ecdsa_raw_to_der:256:"11111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222":"304402201111111111111111111111111111111111111111111111111111111111111111022022222222222222222222222222222222222222222222222222222222222222":MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
|
||||
ECDSA Raw -> DER, very large input (544-bit)
|
||||
ecdsa_raw_to_der:544:"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222":"deadbeef":MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
|
||||
ECDSA Raw -> DER, 256bit, Null r
|
||||
depends_on:PSA_VENDOR_ECC_MAX_CURVE_BITS >= 256
|
||||
ecdsa_raw_to_der:256:"00000000000000000000000000000000000000000000000000000000000000002222222222222222222222222222222222222222222222222222222222222222":"30440220111111111111111111111111111111111111111111111111111111111111111102202222222222222222222222222222222222222222222222222222222222222222":MBEDTLS_ERR_ASN1_INVALID_DATA
|
||||
@ -58,6 +61,9 @@ ECDSA DER -> Raw, 256bit, Raw buffer too small
|
||||
depends_on:PSA_VENDOR_ECC_MAX_CURVE_BITS >= 256
|
||||
ecdsa_der_to_raw:256:"30440220111111111111111111111111111111111111111111111111111111111111111102202222222222222222222222222222222222222222222222222222222222222222":"111111111111111111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222":MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
|
||||
ECDSA DER -> Raw, very large input (544-bit)
|
||||
ecdsa_der_to_raw:544:"30818c0244111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111102442222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222":"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222":MBEDTLS_ERR_ASN1_BUF_TOO_SMALL
|
||||
|
||||
ECDSA DER -> Raw, 256bit, Wrong sequence tag
|
||||
depends_on:PSA_VENDOR_ECC_MAX_CURVE_BITS >= 256
|
||||
ecdsa_der_to_raw:256:"40440220111111111111111111111111111111111111111111111111111111111111111102202222222222222222222222222222222222222222222222222222222222222222":"11111111111111111111111111111111111111111111111111111111111111112222222222222222222222222222222222222222222222222222222222222222":MBEDTLS_ERR_ASN1_UNEXPECTED_TAG
|
||||
|
Loading…
x
Reference in New Issue
Block a user