|
| 1 | +From ac3f4b082dcc61ba69eef605c7b4a22c7a0df711 Mon Sep 17 00:00:00 2001 |
| 2 | +From: AllSpark <allspark@microsoft.com> |
| 3 | +Date: Mon, 15 Jun 2026 06:57:10 +0000 |
| 4 | +Subject: [PATCH] Reject potentially forged encrypted CMS AuthEnvelopedData |
| 5 | + messages |
| 6 | + |
| 7 | +Signed-off-by: rpm-build <rpm-build> |
| 8 | +Upstream-reference: AI Backport of https://github.com/openssl/openssl/commit/7947e6a81eb8776802f159fb6762cb7fcf7e34c7.patch |
| 9 | +Signed-off-by: rpm-build <rpm-build> |
| 10 | +Upstream-reference: https://raw.githubusercontent.com/azurelinux-security/azurelinux/b7c81988963e1e843a851e5e96be250d910e233a/SPECS/edk2/CVE-2026-34182.patch |
| 11 | +--- |
| 12 | + .../OpensslLib/openssl/crypto/cms/cms_enc.c | 18 +++++++++++++----- |
| 13 | + .../OpensslLib/openssl/crypto/cms/cms_env.c | 7 ++++--- |
| 14 | + .../OpensslLib/openssl/crypto/cms/cms_local.h | 2 +- |
| 15 | + 3 files changed, 18 insertions(+), 9 deletions(-) |
| 16 | + |
| 17 | +diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/cms/cms_enc.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/cms/cms_enc.c |
| 18 | +index a3909ba..64f7389 100644 |
| 19 | +--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/cms/cms_enc.c |
| 20 | ++++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/cms/cms_enc.c |
| 21 | +@@ -22,7 +22,8 @@ |
| 22 | + /* Return BIO based on EncryptedContentInfo and key */ |
| 23 | + |
| 24 | + BIO *ossl_cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec, |
| 25 | +- const CMS_CTX *cms_ctx) |
| 26 | ++ const CMS_CTX *cms_ctx, |
| 27 | ++ int auth) |
| 28 | + { |
| 29 | + BIO *b; |
| 30 | + EVP_CIPHER_CTX *ctx; |
| 31 | +@@ -99,13 +100,20 @@ BIO *ossl_cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec, |
| 32 | + goto err; |
| 33 | + } |
| 34 | + if ((EVP_CIPHER_get_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER)) { |
| 35 | ++ if (!auth) { |
| 36 | ++ ERR_raise(ERR_LIB_CMS, CMS_R_CIPHER_AEAD_IN_ENVELOPED_DATA); |
| 37 | ++ goto err; |
| 38 | ++ } |
| 39 | + piv = aparams.iv; |
| 40 | +- if (ec->taglen > 0 |
| 41 | +- && EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, |
| 42 | +- ec->taglen, ec->tag) <= 0) { |
| 43 | ++ |
| 44 | ++ if (ec->taglen < 4 || ec->taglen > 16 |
| 45 | ++ || EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, (int)ec->taglen, ec->tag) <= 0) { |
| 46 | + ERR_raise(ERR_LIB_CMS, CMS_R_CIPHER_AEAD_SET_TAG_ERROR); |
| 47 | + goto err; |
| 48 | + } |
| 49 | ++ } else if (auth) { |
| 50 | ++ ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_CONTENT_ENCRYPTION_ALGORITHM); |
| 51 | ++ goto err; |
| 52 | + } |
| 53 | + } |
| 54 | + len = EVP_CIPHER_CTX_get_key_length(ctx); |
| 55 | +@@ -250,5 +258,5 @@ BIO *ossl_cms_EncryptedData_init_bio(const CMS_ContentInfo *cms) |
| 56 | + if (enc->encryptedContentInfo->cipher && enc->unprotectedAttrs) |
| 57 | + enc->version = 2; |
| 58 | + return ossl_cms_EncryptedContent_init_bio(enc->encryptedContentInfo, |
| 59 | +- ossl_cms_get0_cmsctx(cms)); |
| 60 | ++ ossl_cms_get0_cmsctx(cms), 0); |
| 61 | + } |
| 62 | +diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/cms/cms_env.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/cms/cms_env.c |
| 63 | +index 156a3f7..cb11d8c 100644 |
| 64 | +--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/cms/cms_env.c |
| 65 | ++++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/cms/cms_env.c |
| 66 | +@@ -1111,7 +1111,8 @@ static BIO *cms_EnvelopedData_Decryption_init_bio(CMS_ContentInfo *cms) |
| 67 | + { |
| 68 | + CMS_EncryptedContentInfo *ec = cms->d.envelopedData->encryptedContentInfo; |
| 69 | + BIO *contentBio = ossl_cms_EncryptedContent_init_bio(ec, |
| 70 | +- ossl_cms_get0_cmsctx(cms)); |
| 71 | ++ ossl_cms_get0_cmsctx(cms), |
| 72 | ++ 0); |
| 73 | + EVP_CIPHER_CTX *ctx = NULL; |
| 74 | + |
| 75 | + if (contentBio == NULL) |
| 76 | +@@ -1147,7 +1148,7 @@ static BIO *cms_EnvelopedData_Encryption_init_bio(CMS_ContentInfo *cms) |
| 77 | + /* Get BIO first to set up key */ |
| 78 | + |
| 79 | + ec = env->encryptedContentInfo; |
| 80 | +- ret = ossl_cms_EncryptedContent_init_bio(ec, ossl_cms_get0_cmsctx(cms)); |
| 81 | ++ ret = ossl_cms_EncryptedContent_init_bio(ec, ossl_cms_get0_cmsctx(cms), 0); |
| 82 | + |
| 83 | + /* If error end of processing */ |
| 84 | + if (!ret) |
| 85 | +@@ -1199,7 +1200,7 @@ BIO *ossl_cms_AuthEnvelopedData_init_bio(CMS_ContentInfo *cms) |
| 86 | + ec->tag = aenv->mac->data; |
| 87 | + ec->taglen = aenv->mac->length; |
| 88 | + } |
| 89 | +- ret = ossl_cms_EncryptedContent_init_bio(ec, ossl_cms_get0_cmsctx(cms)); |
| 90 | ++ ret = ossl_cms_EncryptedContent_init_bio(ec, ossl_cms_get0_cmsctx(cms), 1); |
| 91 | + |
| 92 | + /* If error or no cipher end of processing */ |
| 93 | + if (ret == NULL || ec->cipher == NULL) |
| 94 | +diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/cms/cms_local.h b/CryptoPkg/Library/OpensslLib/openssl/crypto/cms/cms_local.h |
| 95 | +index 15b4a29..6f6f954 100644 |
| 96 | +--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/cms/cms_local.h |
| 97 | ++++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/cms/cms_local.h |
| 98 | +@@ -429,7 +429,7 @@ int ossl_cms_set1_ias(CMS_IssuerAndSerialNumber **pias, X509 *cert); |
| 99 | + int ossl_cms_set1_keyid(ASN1_OCTET_STRING **pkeyid, X509 *cert); |
| 100 | + |
| 101 | + BIO *ossl_cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec, |
| 102 | +- const CMS_CTX *ctx); |
| 103 | ++ const CMS_CTX *ctx, int auth); |
| 104 | + BIO *ossl_cms_EncryptedData_init_bio(const CMS_ContentInfo *cms); |
| 105 | + int ossl_cms_EncryptedContent_init(CMS_EncryptedContentInfo *ec, |
| 106 | + const EVP_CIPHER *cipher, |
| 107 | +-- |
| 108 | +2.45.4 |
| 109 | + |
0 commit comments