Prevent signed integer overflow in CSR parsing
Modify the function x509_csr_parse_der() so that it checks the parsed
CSR version integer before it increments the value. This prevents a
potential signed integer overflow, as these have undefined behaviour in
the C standard.
diff --git a/ChangeLog b/ChangeLog
index e847b65..90c6e6b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -20,6 +20,10 @@
* Fix a potential integer overflow in the version verification for DER
encoded X509 certificates. The overflow would enable maliciously
constructed certificates to bypass the certificate verification check.
+ * Fix potential integer overflow in the version verification for DER
+ encoded X509 CSRs. The overflow would enable maliciously constructed CSRs
+ to bypass the version verification check. Found by Peng Li/Yueh-Hsun Lin,
+ KNOX Security, Samsung Research America
= mbed TLS 1.3.20 branch released 2017-06-21
diff --git a/library/x509_csr.c b/library/x509_csr.c
index 9bdfe88..b3c8f29 100644
--- a/library/x509_csr.c
+++ b/library/x509_csr.c
@@ -169,14 +169,14 @@
return( ret );
}
- csr->version++;
-
- if( csr->version != 1 )
+ if( csr->version != 0 )
{
x509_csr_free( csr );
return( POLARSSL_ERR_X509_UNKNOWN_VERSION );
}
+ csr->version++;
+
/*
* subject Name
*/