Skip to content

Commit d3b6dfd

Browse files
committed
pk7_doit.c: Check return of BIO_set_md() calls
These calls invoke EVP_DigestInit() which can fail for digests with implicit fetches. Subsequent EVP_DigestUpdate() from BIO_write() or EVP_DigestFinal() from BIO_read() will segfault on NULL dereference. This can be triggered by an attacker providing PKCS7 data digested with MD4 for example if the legacy provider is not loaded. If BIO_set_md() fails the md BIO cannot be used. CVE-2023-0401 Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
1 parent 2f75300 commit d3b6dfd

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

crypto/pkcs7/pk7_doit.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ static int pkcs7_bio_add_digest(BIO **pbio, X509_ALGOR *alg,
8484
}
8585
(void)ERR_pop_to_mark();
8686

87-
BIO_set_md(btmp, md);
87+
if (BIO_set_md(btmp, md) <= 0) {
88+
ERR_raise(ERR_LIB_PKCS7, ERR_R_BIO_LIB);
89+
EVP_MD_free(fetched);
90+
goto err;
91+
}
8892
EVP_MD_free(fetched);
8993
if (*pbio == NULL)
9094
*pbio = btmp;
@@ -522,7 +526,11 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
522526
}
523527
(void)ERR_pop_to_mark();
524528

525-
BIO_set_md(btmp, md);
529+
if (BIO_set_md(btmp, md) <= 0) {
530+
EVP_MD_free(evp_md);
531+
ERR_raise(ERR_LIB_PKCS7, ERR_R_BIO_LIB);
532+
goto err;
533+
}
526534
EVP_MD_free(evp_md);
527535
if (out == NULL)
528536
out = btmp;

0 commit comments

Comments
 (0)