Skip to content

Commit 01194a8

Browse files
nhormant8m
authored andcommitted
Fix NULL deref in rsa_cms_decrypt
Very simmilar to CVE-2026-28389, ensure that if we are missing parameters in RSA-OAEP SourceFunc in CMS KeyTransportRecipientInfo, we don't segfault when decrypting. Co-authored-by: Tomas Mraz <[email protected]> Fixes CVE-2026-28390 Reviewed-by: Saša Nedvědický <[email protected]> Reviewed-by: Nikola Pajkovsky <[email protected]> Reviewed-by: Matt Caswell <[email protected]> MergeDate: Mon Apr 6 19:03:49 2026
1 parent d6edcec commit 01194a8

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

crypto/cms/cms_rsa.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@ static int rsa_cms_decrypt(CMS_RecipientInfo *ri)
4242
X509_ALGOR *cmsalg;
4343
int nid;
4444
int rv = -1;
45-
unsigned char *label = NULL;
45+
const unsigned char *label = NULL;
4646
int labellen = 0;
4747
const EVP_MD *mgf1md = NULL, *md = NULL;
4848
RSA_OAEP_PARAMS *oaep;
49+
const ASN1_OBJECT *aoid;
50+
const void *parameter = NULL;
51+
int ptype = 0;
4952

5053
pkctx = CMS_RecipientInfo_get0_pkey_ctx(ri);
5154
if (pkctx == NULL)
@@ -75,21 +78,19 @@ static int rsa_cms_decrypt(CMS_RecipientInfo *ri)
7578
goto err;
7679

7780
if (oaep->pSourceFunc != NULL) {
78-
X509_ALGOR *plab = oaep->pSourceFunc;
81+
X509_ALGOR_get0(&aoid, &ptype, &parameter, oaep->pSourceFunc);
7982

80-
if (OBJ_obj2nid(plab->algorithm) != NID_pSpecified) {
83+
if (OBJ_obj2nid(aoid) != NID_pSpecified) {
8184
ERR_raise(ERR_LIB_CMS, CMS_R_UNSUPPORTED_LABEL_SOURCE);
8285
goto err;
8386
}
84-
if (plab->parameter->type != V_ASN1_OCTET_STRING) {
87+
if (ptype != V_ASN1_OCTET_STRING) {
8588
ERR_raise(ERR_LIB_CMS, CMS_R_INVALID_LABEL);
8689
goto err;
8790
}
8891

89-
label = plab->parameter->value.octet_string->data;
90-
/* Stop label being freed when OAEP parameters are freed */
91-
plab->parameter->value.octet_string->data = NULL;
92-
labellen = plab->parameter->value.octet_string->length;
92+
label = ASN1_STRING_get0_data(parameter);
93+
labellen = ASN1_STRING_length(parameter);
9394
}
9495

9596
if (EVP_PKEY_CTX_set_rsa_padding(pkctx, RSA_PKCS1_OAEP_PADDING) <= 0)
@@ -98,10 +99,16 @@ static int rsa_cms_decrypt(CMS_RecipientInfo *ri)
9899
goto err;
99100
if (EVP_PKEY_CTX_set_rsa_mgf1_md(pkctx, mgf1md) <= 0)
100101
goto err;
101-
if (label != NULL
102-
&& EVP_PKEY_CTX_set0_rsa_oaep_label(pkctx, label, labellen) <= 0) {
103-
OPENSSL_free(label);
104-
goto err;
102+
if (label != NULL) {
103+
unsigned char *dup_label = OPENSSL_memdup(label, labellen);
104+
105+
if (dup_label == NULL)
106+
goto err;
107+
108+
if (EVP_PKEY_CTX_set0_rsa_oaep_label(pkctx, dup_label, labellen) <= 0) {
109+
OPENSSL_free(dup_label);
110+
goto err;
111+
}
105112
}
106113
/* Carry on */
107114
rv = 1;

0 commit comments

Comments
 (0)