[go: nahoru, domu]

Skip to content

Commit

Permalink
pk7_doit.c: Check return of BIO_set_md() calls
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
t8m committed Feb 3, 2023
1 parent 2f75300 commit d3b6dfd
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crypto/pkcs7/pk7_doit.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ static int pkcs7_bio_add_digest(BIO **pbio, X509_ALGOR *alg,
}
(void)ERR_pop_to_mark();

BIO_set_md(btmp, md);
if (BIO_set_md(btmp, md) <= 0) {
ERR_raise(ERR_LIB_PKCS7, ERR_R_BIO_LIB);
EVP_MD_free(fetched);
goto err;
}
EVP_MD_free(fetched);
if (*pbio == NULL)
*pbio = btmp;
Expand Down Expand Up @@ -522,7 +526,11 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
}
(void)ERR_pop_to_mark();

BIO_set_md(btmp, md);
if (BIO_set_md(btmp, md) <= 0) {
EVP_MD_free(evp_md);
ERR_raise(ERR_LIB_PKCS7, ERR_R_BIO_LIB);
goto err;
}
EVP_MD_free(evp_md);
if (out == NULL)
out = btmp;
Expand Down

0 comments on commit d3b6dfd

Please sign in to comment.