Fix CVE-2021-3712、CVE-2022-0778
Signed-off-by: ShenYage <shenyage1@huawei.com> (cherry picked from commit d398ef925fb6ad1623786aff816455551da3c159)
This commit is contained in:
parent
a9d2e65173
commit
9d33580bd5
148
0080-Fix-i2v_GENERAL_NAME-to-not-assume-NUL-terminated-st.patch
Normal file
148
0080-Fix-i2v_GENERAL_NAME-to-not-assume-NUL-terminated-st.patch
Normal file
@ -0,0 +1,148 @@
|
||||
From 380b8db5b1310e2242a6d29d77682593d10ee266 Mon Sep 17 00:00:00 2001
|
||||
From: Matt Caswell <matt@openssl.org>
|
||||
Date: Wed, 18 Aug 2021 12:24:22 +0100
|
||||
Subject: [PATCH 1/9] Fix i2v_GENERAL_NAME to not assume NUL terminated strings
|
||||
|
||||
ASN.1 strings may not be NUL terminated. Don't assume they are.
|
||||
|
||||
CVE-2021-3712
|
||||
|
||||
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
---
|
||||
.../OpensslLib/openssl/crypto/x509v3/v3_alt.c | 10 +++--
|
||||
.../OpensslLib/openssl/crypto/x509v3/v3_utl.c | 38 ++++++++++++++++---
|
||||
.../OpensslLib/openssl/include/crypto/x509.h | 5 +++
|
||||
3 files changed, 44 insertions(+), 9 deletions(-)
|
||||
|
||||
diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_alt.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_alt.c
|
||||
index 7ac2911..79f0f14 100644
|
||||
--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_alt.c
|
||||
+++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_alt.c
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include "internal/cryptlib.h"
|
||||
+#include "crypto/x509.h"
|
||||
#include <openssl/conf.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include "ext_dat.h"
|
||||
@@ -99,17 +100,20 @@ STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method,
|
||||
break;
|
||||
|
||||
case GEN_EMAIL:
|
||||
- if (!X509V3_add_value_uchar("email", gen->d.ia5->data, &ret))
|
||||
+ if (!x509v3_add_len_value_uchar("email", gen->d.ia5->data,
|
||||
+ gen->d.ia5->length, &ret))
|
||||
return NULL;
|
||||
break;
|
||||
|
||||
case GEN_DNS:
|
||||
- if (!X509V3_add_value_uchar("DNS", gen->d.ia5->data, &ret))
|
||||
+ if (!x509v3_add_len_value_uchar("DNS", gen->d.ia5->data,
|
||||
+ gen->d.ia5->length, &ret))
|
||||
return NULL;
|
||||
break;
|
||||
|
||||
case GEN_URI:
|
||||
- if (!X509V3_add_value_uchar("URI", gen->d.ia5->data, &ret))
|
||||
+ if (!x509v3_add_len_value_uchar("URI", gen->d.ia5->data,
|
||||
+ gen->d.ia5->length, &ret))
|
||||
return NULL;
|
||||
break;
|
||||
|
||||
diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_utl.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_utl.c
|
||||
index 7281a7b..004ef55 100644
|
||||
--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_utl.c
|
||||
+++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_utl.c
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "e_os.h"
|
||||
#include "internal/cryptlib.h"
|
||||
#include <stdio.h>
|
||||
+#include <string.h>
|
||||
#include "crypto/ctype.h"
|
||||
#include <openssl/conf.h>
|
||||
#include <openssl/crypto.h>
|
||||
@@ -34,17 +35,26 @@ static int ipv6_hex(unsigned char *out, const char *in, int inlen);
|
||||
|
||||
/* Add a CONF_VALUE name value pair to stack */
|
||||
|
||||
-int X509V3_add_value(const char *name, const char *value,
|
||||
- STACK_OF(CONF_VALUE) **extlist)
|
||||
+static int x509v3_add_len_value(const char *name, const char *value,
|
||||
+ size_t vallen, STACK_OF(CONF_VALUE) **extlist)
|
||||
{
|
||||
CONF_VALUE *vtmp = NULL;
|
||||
char *tname = NULL, *tvalue = NULL;
|
||||
int sk_allocated = (*extlist == NULL);
|
||||
|
||||
- if (name && (tname = OPENSSL_strdup(name)) == NULL)
|
||||
- goto err;
|
||||
- if (value && (tvalue = OPENSSL_strdup(value)) == NULL)
|
||||
+ if (name != NULL && (tname = OPENSSL_strdup(name)) == NULL)
|
||||
goto err;
|
||||
+ if (value != NULL && vallen > 0) {
|
||||
+ /*
|
||||
+ * We tolerate a single trailing NUL character, but otherwise no
|
||||
+ * embedded NULs
|
||||
+ */
|
||||
+ if (memchr(value, 0, vallen - 1) != NULL)
|
||||
+ goto err;
|
||||
+ tvalue = OPENSSL_strndup(value, vallen);
|
||||
+ if (tvalue == NULL)
|
||||
+ goto err;
|
||||
+ }
|
||||
if ((vtmp = OPENSSL_malloc(sizeof(*vtmp))) == NULL)
|
||||
goto err;
|
||||
if (sk_allocated && (*extlist = sk_CONF_VALUE_new_null()) == NULL)
|
||||
@@ -67,10 +77,26 @@ int X509V3_add_value(const char *name, const char *value,
|
||||
return 0;
|
||||
}
|
||||
|
||||
+int X509V3_add_value(const char *name, const char *value,
|
||||
+ STACK_OF(CONF_VALUE) **extlist)
|
||||
+{
|
||||
+ return x509v3_add_len_value(name, value,
|
||||
+ value != NULL ? strlen((const char *)value) : 0,
|
||||
+ extlist);
|
||||
+}
|
||||
+
|
||||
int X509V3_add_value_uchar(const char *name, const unsigned char *value,
|
||||
STACK_OF(CONF_VALUE) **extlist)
|
||||
{
|
||||
- return X509V3_add_value(name, (const char *)value, extlist);
|
||||
+ return x509v3_add_len_value(name, (const char *)value,
|
||||
+ value != NULL ? strlen((const char *)value) : 0,
|
||||
+ extlist);
|
||||
+}
|
||||
+
|
||||
+int x509v3_add_len_value_uchar(const char *name, const unsigned char *value,
|
||||
+ size_t vallen, STACK_OF(CONF_VALUE) **extlist)
|
||||
+{
|
||||
+ return x509v3_add_len_value(name, (const char *)value, vallen, extlist);
|
||||
}
|
||||
|
||||
/* Free function for STACK_OF(CONF_VALUE) */
|
||||
diff --git a/CryptoPkg/Library/OpensslLib/openssl/include/crypto/x509.h b/CryptoPkg/Library/OpensslLib/openssl/include/crypto/x509.h
|
||||
index b53c2b0..7ffb8ab 100644
|
||||
--- a/CryptoPkg/Library/OpensslLib/openssl/include/crypto/x509.h
|
||||
+++ b/CryptoPkg/Library/OpensslLib/openssl/include/crypto/x509.h
|
||||
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
|
||||
#include "internal/refcount.h"
|
||||
+#include <openssl/x509.h>
|
||||
+#include <openssl/conf.h>
|
||||
|
||||
/* Internal X509 structures and functions: not for application use */
|
||||
|
||||
@@ -284,3 +286,6 @@ int a2i_ipadd(unsigned char *ipout, const char *ipasc);
|
||||
int x509_set1_time(ASN1_TIME **ptm, const ASN1_TIME *tm);
|
||||
|
||||
void x509_init_sig_info(X509 *x);
|
||||
+
|
||||
+int x509v3_add_len_value_uchar(const char *name, const unsigned char *value,
|
||||
+ size_t vallen, STACK_OF(CONF_VALUE) **extlist);
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,53 @@
|
||||
From 87e959f14e82b34fcb29bd11274b7039678639f1 Mon Sep 17 00:00:00 2001
|
||||
From: Matt Caswell <matt@openssl.org>
|
||||
Date: Wed, 18 Aug 2021 12:31:38 +0100
|
||||
Subject: [PATCH 2/9] Fix POLICYINFO printing to not assume NUL terminated
|
||||
strings
|
||||
|
||||
ASN.1 strings may not be NUL terminated. Don't assume they are.
|
||||
|
||||
CVE-2021-3712
|
||||
|
||||
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
---
|
||||
.../Library/OpensslLib/openssl/crypto/x509v3/v3_cpols.c | 9 ++++++---
|
||||
1 file changed, 6 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_cpols.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_cpols.c
|
||||
index 1d12c89..861e845 100644
|
||||
--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_cpols.c
|
||||
+++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_cpols.c
|
||||
@@ -422,7 +422,8 @@ static void print_qualifiers(BIO *out, STACK_OF(POLICYQUALINFO) *quals,
|
||||
qualinfo = sk_POLICYQUALINFO_value(quals, i);
|
||||
switch (OBJ_obj2nid(qualinfo->pqualid)) {
|
||||
case NID_id_qt_cps:
|
||||
- BIO_printf(out, "%*sCPS: %s\n", indent, "",
|
||||
+ BIO_printf(out, "%*sCPS: %.*s\n", indent, "",
|
||||
+ qualinfo->d.cpsuri->length,
|
||||
qualinfo->d.cpsuri->data);
|
||||
break;
|
||||
|
||||
@@ -447,7 +448,8 @@ static void print_notice(BIO *out, USERNOTICE *notice, int indent)
|
||||
if (notice->noticeref) {
|
||||
NOTICEREF *ref;
|
||||
ref = notice->noticeref;
|
||||
- BIO_printf(out, "%*sOrganization: %s\n", indent, "",
|
||||
+ BIO_printf(out, "%*sOrganization: %.*s\n", indent, "",
|
||||
+ ref->organization->length,
|
||||
ref->organization->data);
|
||||
BIO_printf(out, "%*sNumber%s: ", indent, "",
|
||||
sk_ASN1_INTEGER_num(ref->noticenos) > 1 ? "s" : "");
|
||||
@@ -470,7 +472,8 @@ static void print_notice(BIO *out, USERNOTICE *notice, int indent)
|
||||
BIO_puts(out, "\n");
|
||||
}
|
||||
if (notice->exptext)
|
||||
- BIO_printf(out, "%*sExplicit Text: %s\n", indent, "",
|
||||
+ BIO_printf(out, "%*sExplicit Text: %.*s\n", indent, "",
|
||||
+ notice->exptext->length,
|
||||
notice->exptext->data);
|
||||
}
|
||||
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
From 68557991614b61629dce4a6ab4510087ff28022c Mon Sep 17 00:00:00 2001
|
||||
From: Matt Caswell <matt@openssl.org>
|
||||
Date: Wed, 18 Aug 2021 14:02:40 +0100
|
||||
Subject: [PATCH 3/9] Fix printing of PROXY_CERT_INFO_EXTENSION to not assume
|
||||
NUL terminated strings
|
||||
|
||||
ASN.1 strings may not be NUL terminated. Don't assume they are.
|
||||
|
||||
CVE-2021-3712
|
||||
|
||||
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
---
|
||||
CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_pci.c | 3 ++-
|
||||
1 file changed, 2 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_pci.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_pci.c
|
||||
index 3d124fa..98b6ef2 100644
|
||||
--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_pci.c
|
||||
+++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_pci.c
|
||||
@@ -77,7 +77,8 @@ static int i2r_pci(X509V3_EXT_METHOD *method, PROXY_CERT_INFO_EXTENSION *pci,
|
||||
i2a_ASN1_OBJECT(out, pci->proxyPolicy->policyLanguage);
|
||||
BIO_puts(out, "\n");
|
||||
if (pci->proxyPolicy->policy && pci->proxyPolicy->policy->data)
|
||||
- BIO_printf(out, "%*sPolicy Text: %s\n", indent, "",
|
||||
+ BIO_printf(out, "%*sPolicy Text: %.*s\n", indent, "",
|
||||
+ pci->proxyPolicy->policy->length,
|
||||
pci->proxyPolicy->policy->data);
|
||||
return 1;
|
||||
}
|
||||
--
|
||||
2.33.0
|
||||
|
||||
190
0083-Fix-the-name-constraints-code-to-not-assume-NUL-term.patch
Normal file
190
0083-Fix-the-name-constraints-code-to-not-assume-NUL-term.patch
Normal file
@ -0,0 +1,190 @@
|
||||
From 1339d0d1c2ff45d1a846c3df2cf66f2ca24f4c9b Mon Sep 17 00:00:00 2001
|
||||
From: Matt Caswell <matt@openssl.org>
|
||||
Date: Wed, 18 Aug 2021 17:08:58 +0100
|
||||
Subject: [PATCH 4/9] Fix the name constraints code to not assume NUL
|
||||
terminated strings
|
||||
|
||||
ASN.1 strings may not be NUL terminated. Don't assume they are.
|
||||
|
||||
CVE-2021-3712
|
||||
|
||||
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
---
|
||||
.../openssl/crypto/x509v3/v3_ncons.c | 77 +++++++++++++------
|
||||
1 file changed, 52 insertions(+), 25 deletions(-)
|
||||
|
||||
diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_ncons.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_ncons.c
|
||||
index 2a7b4f0..cb701c4 100644
|
||||
--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_ncons.c
|
||||
+++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_ncons.c
|
||||
@@ -63,8 +63,31 @@ ASN1_SEQUENCE(NAME_CONSTRAINTS) = {
|
||||
IMPLEMENT_ASN1_ALLOC_FUNCTIONS(GENERAL_SUBTREE)
|
||||
IMPLEMENT_ASN1_ALLOC_FUNCTIONS(NAME_CONSTRAINTS)
|
||||
|
||||
+
|
||||
+#define IA5_OFFSET_LEN(ia5base, offset) \
|
||||
+ ((ia5base)->length - ((unsigned char *)(offset) - (ia5base)->data))
|
||||
+
|
||||
+/* Like memchr but for ASN1_IA5STRING. Additionally you can specify the
|
||||
+ * starting point to search from
|
||||
+ */
|
||||
+# define ia5memchr(str, start, c) memchr(start, c, IA5_OFFSET_LEN(str, start))
|
||||
+
|
||||
+/* Like memrrchr but for ASN1_IA5STRING */
|
||||
+static char *ia5memrchr(ASN1_IA5STRING *str, int c)
|
||||
+{
|
||||
+ int i;
|
||||
+
|
||||
+ for (i = str->length; i > 0 && str->data[i - 1] != c; i--);
|
||||
+
|
||||
+ if (i == 0)
|
||||
+ return NULL;
|
||||
+
|
||||
+ return (char *)&str->data[i - 1];
|
||||
+}
|
||||
+
|
||||
/*
|
||||
- * We cannot use strncasecmp here because that applies locale specific rules.
|
||||
+ * We cannot use strncasecmp here because that applies locale specific rules. It
|
||||
+ * also doesn't work with ASN1_STRINGs that may have embedded NUL characters.
|
||||
* For example in Turkish 'I' is not the uppercase character for 'i'. We need to
|
||||
* do a simple ASCII case comparison ignoring the locale (that is why we use
|
||||
* numeric constants below).
|
||||
@@ -89,20 +112,12 @@ static int ia5ncasecmp(const char *s1, const char *s2, size_t n)
|
||||
|
||||
/* c1 > c2 */
|
||||
return 1;
|
||||
- } else if (*s1 == 0) {
|
||||
- /* If we get here we know that *s2 == 0 too */
|
||||
- return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int ia5casecmp(const char *s1, const char *s2)
|
||||
-{
|
||||
- return ia5ncasecmp(s1, s2, SIZE_MAX);
|
||||
-}
|
||||
-
|
||||
static void *v2i_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method,
|
||||
X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
|
||||
{
|
||||
@@ -337,7 +352,7 @@ static int cn2dnsid(ASN1_STRING *cn, unsigned char **dnsid, size_t *idlen)
|
||||
--utf8_length;
|
||||
|
||||
/* Reject *embedded* NULs */
|
||||
- if ((size_t)utf8_length != strlen((char *)utf8_value)) {
|
||||
+ if (memchr(utf8_value, 0, utf8_length) != NULL) {
|
||||
OPENSSL_free(utf8_value);
|
||||
return X509_V_ERR_UNSUPPORTED_NAME_SYNTAX;
|
||||
}
|
||||
@@ -536,9 +551,14 @@ static int nc_dns(ASN1_IA5STRING *dns, ASN1_IA5STRING *base)
|
||||
{
|
||||
char *baseptr = (char *)base->data;
|
||||
char *dnsptr = (char *)dns->data;
|
||||
+
|
||||
/* Empty matches everything */
|
||||
- if (!*baseptr)
|
||||
+ if (base->length == 0)
|
||||
return X509_V_OK;
|
||||
+
|
||||
+ if (dns->length < base->length)
|
||||
+ return X509_V_ERR_PERMITTED_VIOLATION;
|
||||
+
|
||||
/*
|
||||
* Otherwise can add zero or more components on the left so compare RHS
|
||||
* and if dns is longer and expect '.' as preceding character.
|
||||
@@ -549,7 +569,7 @@ static int nc_dns(ASN1_IA5STRING *dns, ASN1_IA5STRING *base)
|
||||
return X509_V_ERR_PERMITTED_VIOLATION;
|
||||
}
|
||||
|
||||
- if (ia5casecmp(baseptr, dnsptr))
|
||||
+ if (ia5ncasecmp(baseptr, dnsptr, base->length))
|
||||
return X509_V_ERR_PERMITTED_VIOLATION;
|
||||
|
||||
return X509_V_OK;
|
||||
@@ -560,16 +580,17 @@ static int nc_email(ASN1_IA5STRING *eml, ASN1_IA5STRING *base)
|
||||
{
|
||||
const char *baseptr = (char *)base->data;
|
||||
const char *emlptr = (char *)eml->data;
|
||||
+ const char *baseat = ia5memrchr(base, '@');
|
||||
+ const char *emlat = ia5memrchr(eml, '@');
|
||||
+ size_t basehostlen, emlhostlen;
|
||||
|
||||
- const char *baseat = strchr(baseptr, '@');
|
||||
- const char *emlat = strchr(emlptr, '@');
|
||||
if (!emlat)
|
||||
return X509_V_ERR_UNSUPPORTED_NAME_SYNTAX;
|
||||
/* Special case: initial '.' is RHS match */
|
||||
- if (!baseat && (*baseptr == '.')) {
|
||||
+ if (!baseat && base->length > 0 && (*baseptr == '.')) {
|
||||
if (eml->length > base->length) {
|
||||
emlptr += eml->length - base->length;
|
||||
- if (ia5casecmp(baseptr, emlptr) == 0)
|
||||
+ if (ia5ncasecmp(baseptr, emlptr, base->length) == 0)
|
||||
return X509_V_OK;
|
||||
}
|
||||
return X509_V_ERR_PERMITTED_VIOLATION;
|
||||
@@ -589,8 +610,10 @@ static int nc_email(ASN1_IA5STRING *eml, ASN1_IA5STRING *base)
|
||||
baseptr = baseat + 1;
|
||||
}
|
||||
emlptr = emlat + 1;
|
||||
+ basehostlen = IA5_OFFSET_LEN(base, baseptr);
|
||||
+ emlhostlen = IA5_OFFSET_LEN(eml, emlptr);
|
||||
/* Just have hostname left to match: case insensitive */
|
||||
- if (ia5casecmp(baseptr, emlptr))
|
||||
+ if (basehostlen != emlhostlen || ia5ncasecmp(baseptr, emlptr, emlhostlen))
|
||||
return X509_V_ERR_PERMITTED_VIOLATION;
|
||||
|
||||
return X509_V_OK;
|
||||
@@ -601,10 +624,14 @@ static int nc_uri(ASN1_IA5STRING *uri, ASN1_IA5STRING *base)
|
||||
{
|
||||
const char *baseptr = (char *)base->data;
|
||||
const char *hostptr = (char *)uri->data;
|
||||
- const char *p = strchr(hostptr, ':');
|
||||
+ const char *p = ia5memchr(uri, (char *)uri->data, ':');
|
||||
int hostlen;
|
||||
+
|
||||
/* Check for foo:// and skip past it */
|
||||
- if (!p || (p[1] != '/') || (p[2] != '/'))
|
||||
+ if (p == NULL
|
||||
+ || IA5_OFFSET_LEN(uri, p) < 3
|
||||
+ || p[1] != '/'
|
||||
+ || p[2] != '/')
|
||||
return X509_V_ERR_UNSUPPORTED_NAME_SYNTAX;
|
||||
hostptr = p + 3;
|
||||
|
||||
@@ -612,13 +639,13 @@ static int nc_uri(ASN1_IA5STRING *uri, ASN1_IA5STRING *base)
|
||||
|
||||
/* Look for a port indicator as end of hostname first */
|
||||
|
||||
- p = strchr(hostptr, ':');
|
||||
+ p = ia5memchr(uri, hostptr, ':');
|
||||
/* Otherwise look for trailing slash */
|
||||
- if (!p)
|
||||
- p = strchr(hostptr, '/');
|
||||
+ if (p == NULL)
|
||||
+ p = ia5memchr(uri, hostptr, '/');
|
||||
|
||||
- if (!p)
|
||||
- hostlen = strlen(hostptr);
|
||||
+ if (p == NULL)
|
||||
+ hostlen = IA5_OFFSET_LEN(uri, hostptr);
|
||||
else
|
||||
hostlen = p - hostptr;
|
||||
|
||||
@@ -626,7 +653,7 @@ static int nc_uri(ASN1_IA5STRING *uri, ASN1_IA5STRING *base)
|
||||
return X509_V_ERR_UNSUPPORTED_NAME_SYNTAX;
|
||||
|
||||
/* Special case: initial '.' is RHS match */
|
||||
- if (*baseptr == '.') {
|
||||
+ if (base->length > 0 && *baseptr == '.') {
|
||||
if (hostlen > base->length) {
|
||||
p = hostptr + hostlen - base->length;
|
||||
if (ia5ncasecmp(p, baseptr, base->length) == 0)
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
From 13213d2f8a0003e51f89732e639a7783ce82c94f Mon Sep 17 00:00:00 2001
|
||||
From: Matt Caswell <matt@openssl.org>
|
||||
Date: Wed, 18 Aug 2021 17:37:41 +0100
|
||||
Subject: [PATCH 5/9] Fix test code to not assume NUL terminated strings
|
||||
|
||||
ASN.1 strings may not be NUL terminated. Don't assume they are.
|
||||
|
||||
CVE-2021-3712
|
||||
|
||||
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
---
|
||||
.../Library/OpensslLib/openssl/test/x509_time_test.c | 10 ++++++----
|
||||
1 file changed, 6 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/CryptoPkg/Library/OpensslLib/openssl/test/x509_time_test.c b/CryptoPkg/Library/OpensslLib/openssl/test/x509_time_test.c
|
||||
index b6fd38a..d0993d9 100644
|
||||
--- a/CryptoPkg/Library/OpensslLib/openssl/test/x509_time_test.c
|
||||
+++ b/CryptoPkg/Library/OpensslLib/openssl/test/x509_time_test.c
|
||||
@@ -330,10 +330,12 @@ static int test_x509_time(int idx)
|
||||
|
||||
/* if t is not NULL but expected_string is NULL, it is an 'OK' case too */
|
||||
if (t != NULL && x509_format_tests[idx].expected_string) {
|
||||
- if (!TEST_str_eq((const char *)t->data,
|
||||
- x509_format_tests[idx].expected_string)) {
|
||||
- TEST_info("test_x509_time(%d) failed: expected_string %s, got %s\n",
|
||||
- idx, x509_format_tests[idx].expected_string, t->data);
|
||||
+ if (!TEST_mem_eq((const char *)t->data, t->length,
|
||||
+ x509_format_tests[idx].expected_string,
|
||||
+ strlen(x509_format_tests[idx].expected_string))) {
|
||||
+ TEST_info("test_x509_time(%d) failed: expected_string %s, got %.*s\n",
|
||||
+ idx, x509_format_tests[idx].expected_string, t->length,
|
||||
+ t->data);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,55 @@
|
||||
From 2c44830ce3b1b2daa18c7b1c5a47877cf728c851 Mon Sep 17 00:00:00 2001
|
||||
From: Matt Caswell <matt@openssl.org>
|
||||
Date: Wed, 18 Aug 2021 17:58:23 +0100
|
||||
Subject: [PATCH 6/9] Fix append_ia5 function to not assume NUL terminated
|
||||
strings
|
||||
|
||||
ASN.1 strings may not be NUL terminated. Don't assume they are.
|
||||
|
||||
CVE-2021-3712
|
||||
|
||||
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
---
|
||||
.../OpensslLib/openssl/crypto/x509v3/v3_utl.c | 18 +++++++++++++-----
|
||||
1 file changed, 13 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_utl.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_utl.c
|
||||
index 004ef55..513dc68 100644
|
||||
--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_utl.c
|
||||
+++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/x509v3/v3_utl.c
|
||||
@@ -528,18 +528,26 @@ static int append_ia5(STACK_OF(OPENSSL_STRING) **sk, const ASN1_IA5STRING *email
|
||||
/* First some sanity checks */
|
||||
if (email->type != V_ASN1_IA5STRING)
|
||||
return 1;
|
||||
- if (!email->data || !email->length)
|
||||
+ if (email->data == NULL || email->length == 0)
|
||||
+ return 1;
|
||||
+ if (memchr(email->data, 0, email->length) != NULL)
|
||||
return 1;
|
||||
if (*sk == NULL)
|
||||
*sk = sk_OPENSSL_STRING_new(sk_strcmp);
|
||||
if (*sk == NULL)
|
||||
return 0;
|
||||
+
|
||||
+ emtmp = OPENSSL_strndup((char *)email->data, email->length);
|
||||
+ if (emtmp == NULL)
|
||||
+ return 0;
|
||||
+
|
||||
/* Don't add duplicates */
|
||||
- if (sk_OPENSSL_STRING_find(*sk, (char *)email->data) != -1)
|
||||
+ if (sk_OPENSSL_STRING_find(*sk, emtmp) != -1) {
|
||||
+ OPENSSL_free(emtmp);
|
||||
return 1;
|
||||
- emtmp = OPENSSL_strdup((char *)email->data);
|
||||
- if (emtmp == NULL || !sk_OPENSSL_STRING_push(*sk, emtmp)) {
|
||||
- OPENSSL_free(emtmp); /* free on push failure */
|
||||
+ }
|
||||
+ if (!sk_OPENSSL_STRING_push(*sk, emtmp)) {
|
||||
+ OPENSSL_free(emtmp); /* free on push failure */
|
||||
X509_email_free(*sk);
|
||||
*sk = NULL;
|
||||
return 0;
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
From a3c789bd414c69c703c49a10b83acf81853f6df6 Mon Sep 17 00:00:00 2001
|
||||
From: Matt Caswell <matt@openssl.org>
|
||||
Date: Thu, 19 Aug 2021 12:23:38 +0100
|
||||
Subject: [PATCH 7/9] Fix NETSCAPE_SPKI_print function to not assume NUL
|
||||
terminated strings
|
||||
|
||||
ASN.1 strings may not be NUL terminated. Don't assume they are.
|
||||
|
||||
CVE-2021-3712
|
||||
|
||||
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
---
|
||||
CryptoPkg/Library/OpensslLib/openssl/crypto/asn1/t_spki.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/asn1/t_spki.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/asn1/t_spki.c
|
||||
index 51b56d0..64ee77e 100644
|
||||
--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/asn1/t_spki.c
|
||||
+++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/asn1/t_spki.c
|
||||
@@ -38,7 +38,7 @@ int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki)
|
||||
}
|
||||
chal = spki->spkac->challenge;
|
||||
if (chal->length)
|
||||
- BIO_printf(out, " Challenge String: %s\n", chal->data);
|
||||
+ BIO_printf(out, " Challenge String: %.*s\n", chal->length, chal->data);
|
||||
i = OBJ_obj2nid(spki->sig_algor.algorithm);
|
||||
BIO_printf(out, " Signature Algorithm: %s",
|
||||
(i == NID_undef) ? "UNKNOWN" : OBJ_nid2ln(i));
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
From 0d71cee87b0bce7d3729ac4bbefbb42bda6cdb3c Mon Sep 17 00:00:00 2001
|
||||
From: Matt Caswell <matt@openssl.org>
|
||||
Date: Thu, 19 Aug 2021 12:24:17 +0100
|
||||
Subject: [PATCH 8/9] Fix EC_GROUP_new_from_ecparameters to check the base
|
||||
length
|
||||
|
||||
Check that there's at least one byte in params->base before trying to
|
||||
read it.
|
||||
|
||||
CVE-2021-3712
|
||||
|
||||
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
---
|
||||
CryptoPkg/Library/OpensslLib/openssl/crypto/ec/ec_asn1.c | 5 ++++-
|
||||
1 file changed, 4 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/ec/ec_asn1.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/ec/ec_asn1.c
|
||||
index 336afc9..98a742d 100644
|
||||
--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/ec/ec_asn1.c
|
||||
+++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/ec/ec_asn1.c
|
||||
@@ -747,7 +747,10 @@ EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params)
|
||||
ret->seed_len = params->curve->seed->length;
|
||||
}
|
||||
|
||||
- if (!params->order || !params->base || !params->base->data) {
|
||||
+ if (params->order == NULL
|
||||
+ || params->base == NULL
|
||||
+ || params->base->data == NULL
|
||||
+ || params->base->length == 0) {
|
||||
ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR);
|
||||
goto err;
|
||||
}
|
||||
--
|
||||
2.33.0
|
||||
|
||||
69
0088-Fix-possible-infinite-loop-in-BN_mod_sqrt.patch
Normal file
69
0088-Fix-possible-infinite-loop-in-BN_mod_sqrt.patch
Normal file
@ -0,0 +1,69 @@
|
||||
From 8c40007cee48ac54f0644a1c8e01809ee47ecf1b Mon Sep 17 00:00:00 2001
|
||||
From: Tomas Mraz <tomas@openssl.org>
|
||||
Date: Mon, 28 Feb 2022 18:26:21 +0100
|
||||
Subject: [PATCH 9/9] Fix possible infinite loop in BN_mod_sqrt()
|
||||
|
||||
The calculation in some cases does not finish for non-prime p.
|
||||
|
||||
This fixes CVE-2022-0778.
|
||||
|
||||
Based on patch by David Benjamin <davidben@google.com>.
|
||||
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||
---
|
||||
.../OpensslLib/openssl/crypto/bn/bn_sqrt.c | 30 +++++++++++--------
|
||||
1 file changed, 18 insertions(+), 12 deletions(-)
|
||||
|
||||
diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/bn/bn_sqrt.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/bn/bn_sqrt.c
|
||||
index 1723d5d..53b0f55 100644
|
||||
--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/bn/bn_sqrt.c
|
||||
+++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/bn/bn_sqrt.c
|
||||
@@ -14,7 +14,8 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
|
||||
/*
|
||||
* Returns 'ret' such that ret^2 == a (mod p), using the Tonelli/Shanks
|
||||
* algorithm (cf. Henri Cohen, "A Course in Algebraic Computational Number
|
||||
- * Theory", algorithm 1.5.1). 'p' must be prime!
|
||||
+ * Theory", algorithm 1.5.1). 'p' must be prime, otherwise an error or
|
||||
+ * an incorrect "result" will be returned.
|
||||
*/
|
||||
{
|
||||
BIGNUM *ret = in;
|
||||
@@ -301,18 +302,23 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
|
||||
goto vrfy;
|
||||
}
|
||||
|
||||
- /* find smallest i such that b^(2^i) = 1 */
|
||||
- i = 1;
|
||||
- if (!BN_mod_sqr(t, b, p, ctx))
|
||||
- goto end;
|
||||
- while (!BN_is_one(t)) {
|
||||
- i++;
|
||||
- if (i == e) {
|
||||
- BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
|
||||
- goto end;
|
||||
+ /* Find the smallest i, 0 < i < e, such that b^(2^i) = 1. */
|
||||
+ for (i = 1; i < e; i++) {
|
||||
+ if (i == 1) {
|
||||
+ if (!BN_mod_sqr(t, b, p, ctx))
|
||||
+ goto end;
|
||||
+
|
||||
+ } else {
|
||||
+ if (!BN_mod_mul(t, t, t, p, ctx))
|
||||
+ goto end;
|
||||
}
|
||||
- if (!BN_mod_mul(t, t, t, p, ctx))
|
||||
- goto end;
|
||||
+ if (BN_is_one(t))
|
||||
+ break;
|
||||
+ }
|
||||
+ /* If not found, a is not a square or p is not prime. */
|
||||
+ if (i >= e) {
|
||||
+ BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
|
||||
+ goto end;
|
||||
}
|
||||
|
||||
/* t := y^2^(e - i - 1) */
|
||||
--
|
||||
2.33.0
|
||||
|
||||
16
edk2.spec
16
edk2.spec
@ -5,7 +5,7 @@
|
||||
|
||||
Name: edk2
|
||||
Version: %{stable_date}
|
||||
Release: 19
|
||||
Release: 20
|
||||
Summary: EFI Development Kit II
|
||||
License: BSD-2-Clause-Patent
|
||||
URL: https://github.com/tianocore/edk2
|
||||
@ -115,6 +115,17 @@ Patch0077: 0077-MdeModulePkg-Potential-UINT32-overflow-in-S3-ResumeC.patch
|
||||
Patch0078: 0078-Fix-SSL_select_next_proto-and-add-ALPN-validation-in.patch
|
||||
Patch0079: 0079-Add-a-test-for-ALPN-and-NPN.patch
|
||||
|
||||
# fix CVE-2021-3712、CVE-2022-0778
|
||||
Patch0080: 0080-Fix-i2v_GENERAL_NAME-to-not-assume-NUL-terminated-st.patch
|
||||
Patch0081: 0081-Fix-POLICYINFO-printing-to-not-assume-NUL-terminated.patch
|
||||
Patch0082: 0082-Fix-printing-of-PROXY_CERT_INFO_EXTENSION-to-not-ass.patch
|
||||
Patch0083: 0083-Fix-the-name-constraints-code-to-not-assume-NUL-term.patch
|
||||
Patch0084: 0084-Fix-test-code-to-not-assume-NUL-terminated-strings.patch
|
||||
Patch0085: 0085-Fix-append_ia5-function-to-not-assume-NUL-terminated.patch
|
||||
Patch0086: 0086-Fix-NETSCAPE_SPKI_print-function-to-not-assume-NUL-t.patch
|
||||
Patch0087: 0087-Fix-EC_GROUP_new_from_ecparameters-to-check-the-base.patch
|
||||
Patch0088: 0088-Fix-possible-infinite-loop-in-BN_mod_sqrt.patch
|
||||
|
||||
BuildRequires: acpica-tools gcc gcc-c++ libuuid-devel python3 bc nasm python3-unversioned-command
|
||||
|
||||
%description
|
||||
@ -315,6 +326,9 @@ chmod +x %{buildroot}%{_bindir}/Rsa2048Sha256GenerateKeys
|
||||
%endif
|
||||
|
||||
%changelog
|
||||
* Tue Sep 3 2024 shenyage<shenyage1@huawei.com> - 202011-20
|
||||
- fix CVE-2021-3712、CVE-2022-0778
|
||||
|
||||
* Thu Jul 11 2024 shenyage<shenyage1@huawei.com> - 202011-19
|
||||
- fix CVE-2024-5535
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user