From 26124be17aedbb6984d824d932dea0d1f7b2b33d Mon Sep 17 00:00:00 2001 From: Andres AG Date: Wed, 1 Mar 2017 15:14:30 +0000 Subject: [PATCH] Fix potential integer overflow parsing DER CRL This patch prevents a potential signed integer overflow during the CRL version verification checks. --- ChangeLog | 4 ++++ library/x509_crl.c | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 081bcf1b6..e50604d2a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,10 @@ Bugfix Found by redplait #590 * Add MPI_CHK to check for error value of mpi_fill_random. Backported from a report and fix suggestion by guidovranken in #740 + * Fix a potential integer overflow in the version verification for DER + encoded X509 CRLs. The overflow would enable maliciously constructed CRLs + 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_crl.c b/library/x509_crl.c index b2b0bed6e..96120a97d 100644 --- a/library/x509_crl.c +++ b/library/x509_crl.c @@ -353,14 +353,14 @@ int x509_crl_parse_der( x509_crl *chain, return( ret ); } - crl->version++; - - if( crl->version > 2 ) + if( crl->version < 0 || crl->version > 1 ) { x509_crl_free( crl ); return( POLARSSL_ERR_X509_UNKNOWN_VERSION ); } + crl->version++; + if( ( ret = x509_get_sig_alg( &crl->sig_oid1, &sig_params1, &crl->sig_md, &crl->sig_pk, &crl->sig_opts ) ) != 0 )