|
| 1 | +From 1cbd2e0aef0cc6f6b6300408835cd6a3078c1ac4 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Bob Beck <beck@openssl.org> |
| 3 | +Date: Wed, 7 Jan 2026 11:29:48 -0700 |
| 4 | +Subject: [PATCH] Ensure ASN1 types are checked before use. |
| 5 | + |
| 6 | +Some of these were fixed by LibreSSL in commit https://github.com/openbsd/src/commit/aa1f637d454961d22117b4353f98253e984b3ba8 |
| 7 | +this fix includes the other fixes in that commit, as well as fixes for others found by a scan |
| 8 | +for a similar unvalidated access paradigm in the tree. |
| 9 | + |
| 10 | +Reviewed-by: Kurt Roeckx <kurt@roeckx.be> |
| 11 | +Reviewed-by: Shane Lontis <shane.lontis@oracle.com> |
| 12 | +Reviewed-by: Tomas Mraz <tomas@openssl.org> |
| 13 | +(Merged from https://github.com/openssl/openssl/pull/29582) |
| 14 | + |
| 15 | +Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> |
| 16 | +Upstream-reference: https://github.com/openssl/openssl/commit/572844beca95068394c916626a6d3a490f831a49.patch |
| 17 | +--- |
| 18 | + CryptoPkg/Library/OpensslLib/openssl/apps/s_client.c | 3 ++- |
| 19 | + .../OpensslLib/openssl/crypto/pkcs12/p12_kiss.c | 10 ++++++++-- |
| 20 | + .../Library/OpensslLib/openssl/crypto/pkcs7/pk7_doit.c | 2 ++ |
| 21 | + 3 files changed, 12 insertions(+), 3 deletions(-) |
| 22 | + |
| 23 | +diff --git a/CryptoPkg/Library/OpensslLib/openssl/apps/s_client.c b/CryptoPkg/Library/OpensslLib/openssl/apps/s_client.c |
| 24 | +index 00effc80..6e8cc6e9 100644 |
| 25 | +--- a/CryptoPkg/Library/OpensslLib/openssl/apps/s_client.c |
| 26 | ++++ b/CryptoPkg/Library/OpensslLib/openssl/apps/s_client.c |
| 27 | +@@ -2698,8 +2698,9 @@ int s_client_main(int argc, char **argv) |
| 28 | + goto end; |
| 29 | + } |
| 30 | + atyp = ASN1_generate_nconf(genstr, cnf); |
| 31 | +- if (atyp == NULL) { |
| 32 | ++ if (atyp == NULL || atyp->type != V_ASN1_SEQUENCE) { |
| 33 | + NCONF_free(cnf); |
| 34 | ++ ASN1_TYPE_free(atyp); |
| 35 | + BIO_printf(bio_err, "ASN1_generate_nconf failed\n"); |
| 36 | + goto end; |
| 37 | + } |
| 38 | +diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/pkcs12/p12_kiss.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/pkcs12/p12_kiss.c |
| 39 | +index 7ab98385..d90404dd 100644 |
| 40 | +--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/pkcs12/p12_kiss.c |
| 41 | ++++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/pkcs12/p12_kiss.c |
| 42 | +@@ -183,11 +183,17 @@ static int parse_bag(PKCS12_SAFEBAG *bag, const char *pass, int passlen, |
| 43 | + ASN1_BMPSTRING *fname = NULL; |
| 44 | + ASN1_OCTET_STRING *lkid = NULL; |
| 45 | + |
| 46 | +- if ((attrib = PKCS12_SAFEBAG_get0_attr(bag, NID_friendlyName))) |
| 47 | ++ if ((attrib = PKCS12_SAFEBAG_get0_attr(bag, NID_friendlyName))) { |
| 48 | ++ if (attrib->type != V_ASN1_BMPSTRING) |
| 49 | ++ return 0; |
| 50 | + fname = attrib->value.bmpstring; |
| 51 | ++ } |
| 52 | + |
| 53 | +- if ((attrib = PKCS12_SAFEBAG_get0_attr(bag, NID_localKeyID))) |
| 54 | ++ if ((attrib = PKCS12_SAFEBAG_get0_attr(bag, NID_localKeyID))) { |
| 55 | ++ if (attrib->type != V_ASN1_OCTET_STRING) |
| 56 | ++ return 0; |
| 57 | + lkid = attrib->value.octet_string; |
| 58 | ++ } |
| 59 | + |
| 60 | + switch (PKCS12_SAFEBAG_get_nid(bag)) { |
| 61 | + case NID_keyBag: |
| 62 | +diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/pkcs7/pk7_doit.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/pkcs7/pk7_doit.c |
| 63 | +index f63fbc50..4e0eb1e8 100644 |
| 64 | +--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/pkcs7/pk7_doit.c |
| 65 | ++++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/pkcs7/pk7_doit.c |
| 66 | +@@ -1092,6 +1092,8 @@ ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk) |
| 67 | + ASN1_TYPE *astype; |
| 68 | + if ((astype = get_attribute(sk, NID_pkcs9_messageDigest)) == NULL) |
| 69 | + return NULL; |
| 70 | ++ if (astype->type != V_ASN1_OCTET_STRING) |
| 71 | ++ return NULL; |
| 72 | + return astype->value.octet_string; |
| 73 | + } |
| 74 | + |
| 75 | +-- |
| 76 | +2.45.4 |
| 77 | + |
0 commit comments