Skip to content

Commit 9332e02

Browse files
committed
Fix OpenSSL NULL pointer de-reference.
Approved by: so Security: FreeBSD-SA-20:33.openssl Security: CVE-2020-1971
1 parent 056c8d4 commit 9332e02

File tree

7 files changed

+90
-7
lines changed

7 files changed

+90
-7
lines changed

UPDATING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ from older versions of FreeBSD, try WITHOUT_CLANG and WITH_GCC to bootstrap to
1616
the tip of head, and then rebuild without this option. The bootstrap process
1717
from older version of current across the gcc/clang cutover is a bit fragile.
1818

19+
20201215: p6 FreeBSD-SA-20:33.openssl
20+
21+
Fix OpenSSL NULL pointer de-reference. [SA-20:33.openssl]
22+
1923
20201201: p5 FreeBSD-EN-20:19.audit
2024
FreeBSD-EN-20:20.tzdata
2125
FreeBSD-EN-20:22.callout

crypto/openssl/crypto/asn1/asn1.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,7 @@ void ERR_load_ASN1_strings(void);
12031203
# define ASN1_F_ASN1_ITEM_DUP 191
12041204
# define ASN1_F_ASN1_ITEM_EX_COMBINE_NEW 121
12051205
# define ASN1_F_ASN1_ITEM_EX_D2I 120
1206+
# define ASN1_F_ASN1_ITEM_EX_I2D 224
12061207
# define ASN1_F_ASN1_ITEM_I2D_BIO 192
12071208
# define ASN1_F_ASN1_ITEM_I2D_FP 193
12081209
# define ASN1_F_ASN1_ITEM_PACK 198
@@ -1304,6 +1305,7 @@ void ERR_load_ASN1_strings(void);
13041305
# define ASN1_R_BAD_OBJECT_HEADER 102
13051306
# define ASN1_R_BAD_PASSWORD_READ 103
13061307
# define ASN1_R_BAD_TAG 104
1308+
# define ASN1_R_BAD_TEMPLATE 221
13071309
# define ASN1_R_BMPSTRING_IS_WRONG_LENGTH 214
13081310
# define ASN1_R_BN_LIB 105
13091311
# define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 106

crypto/openssl/crypto/asn1/asn1_err.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* crypto/asn1/asn1_err.c */
22
/* ====================================================================
3-
* Copyright (c) 1999-2018 The OpenSSL Project. All rights reserved.
3+
* Copyright (c) 1999-2020 The OpenSSL Project. All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
66
* modification, are permitted provided that the following conditions
@@ -103,6 +103,7 @@ static ERR_STRING_DATA ASN1_str_functs[] = {
103103
{ERR_FUNC(ASN1_F_ASN1_ITEM_DUP), "ASN1_item_dup"},
104104
{ERR_FUNC(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW), "ASN1_ITEM_EX_COMBINE_NEW"},
105105
{ERR_FUNC(ASN1_F_ASN1_ITEM_EX_D2I), "ASN1_ITEM_EX_D2I"},
106+
{ERR_FUNC(ASN1_F_ASN1_ITEM_EX_I2D), "ASN1_item_ex_i2d"},
106107
{ERR_FUNC(ASN1_F_ASN1_ITEM_I2D_BIO), "ASN1_item_i2d_bio"},
107108
{ERR_FUNC(ASN1_F_ASN1_ITEM_I2D_FP), "ASN1_item_i2d_fp"},
108109
{ERR_FUNC(ASN1_F_ASN1_ITEM_PACK), "ASN1_item_pack"},
@@ -207,6 +208,7 @@ static ERR_STRING_DATA ASN1_str_reasons[] = {
207208
{ERR_REASON(ASN1_R_BAD_OBJECT_HEADER), "bad object header"},
208209
{ERR_REASON(ASN1_R_BAD_PASSWORD_READ), "bad password read"},
209210
{ERR_REASON(ASN1_R_BAD_TAG), "bad tag"},
211+
{ERR_REASON(ASN1_R_BAD_TEMPLATE), "bad template"},
210212
{ERR_REASON(ASN1_R_BMPSTRING_IS_WRONG_LENGTH),
211213
"bmpstring is wrong length"},
212214
{ERR_REASON(ASN1_R_BN_LIB), "bn lib"},

crypto/openssl/crypto/asn1/tasn_dec.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,15 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
223223
break;
224224

225225
case ASN1_ITYPE_MSTRING:
226+
/*
227+
* It never makes sense for multi-strings to have implicit tagging, so
228+
* if tag != -1, then this looks like an error in the template.
229+
*/
230+
if (tag != -1) {
231+
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_BAD_TEMPLATE);
232+
goto err;
233+
}
234+
226235
p = *in;
227236
/* Just read in tag and class */
228237
ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL,
@@ -240,6 +249,7 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
240249
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MSTRING_NOT_UNIVERSAL);
241250
goto err;
242251
}
252+
243253
/* Check tag matches bit map */
244254
if (!(ASN1_tag2bit(otag) & it->utype)) {
245255
/* If OPTIONAL, assume this is OK */
@@ -316,6 +326,15 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
316326
goto err;
317327

318328
case ASN1_ITYPE_CHOICE:
329+
/*
330+
* It never makes sense for CHOICE types to have implicit tagging, so
331+
* if tag != -1, then this looks like an error in the template.
332+
*/
333+
if (tag != -1) {
334+
ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_BAD_TEMPLATE);
335+
goto err;
336+
}
337+
319338
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
320339
goto auxerr;
321340
if (*pval) {

crypto/openssl/crypto/asn1/tasn_enc.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,25 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
151151
break;
152152

153153
case ASN1_ITYPE_MSTRING:
154+
/*
155+
* It never makes sense for multi-strings to have implicit tagging, so
156+
* if tag != -1, then this looks like an error in the template.
157+
*/
158+
if (tag != -1) {
159+
ASN1err(ASN1_F_ASN1_ITEM_EX_I2D, ASN1_R_BAD_TEMPLATE);
160+
return -1;
161+
}
154162
return asn1_i2d_ex_primitive(pval, out, it, -1, aclass);
155163

156164
case ASN1_ITYPE_CHOICE:
165+
/*
166+
* It never makes sense for CHOICE types to have implicit tagging, so
167+
* if tag != -1, then this looks like an error in the template.
168+
*/
169+
if (tag != -1) {
170+
ASN1err(ASN1_F_ASN1_ITEM_EX_I2D, ASN1_R_BAD_TEMPLATE);
171+
return -1;
172+
}
157173
if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
158174
return 0;
159175
i = asn1_get_choice_selector(pval, it);

crypto/openssl/crypto/x509v3/v3_genn.c

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ ASN1_SEQUENCE(OTHERNAME) = {
7272
IMPLEMENT_ASN1_FUNCTIONS(OTHERNAME)
7373

7474
ASN1_SEQUENCE(EDIPARTYNAME) = {
75-
ASN1_IMP_OPT(EDIPARTYNAME, nameAssigner, DIRECTORYSTRING, 0),
76-
ASN1_IMP_OPT(EDIPARTYNAME, partyName, DIRECTORYSTRING, 1)
75+
/* DirectoryString is a CHOICE type so use explicit tagging */
76+
ASN1_EXP_OPT(EDIPARTYNAME, nameAssigner, DIRECTORYSTRING, 0),
77+
ASN1_EXP(EDIPARTYNAME, partyName, DIRECTORYSTRING, 1)
7778
} ASN1_SEQUENCE_END(EDIPARTYNAME)
7879

7980
IMPLEMENT_ASN1_FUNCTIONS(EDIPARTYNAME)
@@ -107,6 +108,37 @@ GENERAL_NAME *GENERAL_NAME_dup(GENERAL_NAME *a)
107108
(char *)a);
108109
}
109110

111+
static int edipartyname_cmp(const EDIPARTYNAME *a, const EDIPARTYNAME *b)
112+
{
113+
int res;
114+
115+
if (a == NULL || b == NULL) {
116+
/*
117+
* Shouldn't be possible in a valid GENERAL_NAME, but we handle it
118+
* anyway. OTHERNAME_cmp treats NULL != NULL so we do the same here
119+
*/
120+
return -1;
121+
}
122+
if (a->nameAssigner == NULL && b->nameAssigner != NULL)
123+
return -1;
124+
if (a->nameAssigner != NULL && b->nameAssigner == NULL)
125+
return 1;
126+
/* If we get here then both have nameAssigner set, or both unset */
127+
if (a->nameAssigner != NULL) {
128+
res = ASN1_STRING_cmp(a->nameAssigner, b->nameAssigner);
129+
if (res != 0)
130+
return res;
131+
}
132+
/*
133+
* partyName is required, so these should never be NULL. We treat it in
134+
* the same way as the a == NULL || b == NULL case above
135+
*/
136+
if (a->partyName == NULL || b->partyName == NULL)
137+
return -1;
138+
139+
return ASN1_STRING_cmp(a->partyName, b->partyName);
140+
}
141+
110142
/* Returns 0 if they are equal, != 0 otherwise. */
111143
int GENERAL_NAME_cmp(GENERAL_NAME *a, GENERAL_NAME *b)
112144
{
@@ -116,8 +148,11 @@ int GENERAL_NAME_cmp(GENERAL_NAME *a, GENERAL_NAME *b)
116148
return -1;
117149
switch (a->type) {
118150
case GEN_X400:
151+
result = ASN1_TYPE_cmp(a->d.x400Address, b->d.x400Address);
152+
break;
153+
119154
case GEN_EDIPARTY:
120-
result = ASN1_TYPE_cmp(a->d.other, b->d.other);
155+
result = edipartyname_cmp(a->d.ediPartyName, b->d.ediPartyName);
121156
break;
122157

123158
case GEN_OTHERNAME:
@@ -164,8 +199,11 @@ void GENERAL_NAME_set0_value(GENERAL_NAME *a, int type, void *value)
164199
{
165200
switch (type) {
166201
case GEN_X400:
202+
a->d.x400Address = value;
203+
break;
204+
167205
case GEN_EDIPARTY:
168-
a->d.other = value;
206+
a->d.ediPartyName = value;
169207
break;
170208

171209
case GEN_OTHERNAME:
@@ -199,8 +237,10 @@ void *GENERAL_NAME_get0_value(GENERAL_NAME *a, int *ptype)
199237
*ptype = a->type;
200238
switch (a->type) {
201239
case GEN_X400:
240+
return a->d.x400Address;
241+
202242
case GEN_EDIPARTY:
203-
return a->d.other;
243+
return a->d.ediPartyName;
204244

205245
case GEN_OTHERNAME:
206246
return a->d.otherName;

sys/conf/newvers.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
TYPE="FreeBSD"
4646
REVISION="11.4"
47-
BRANCH="RELEASE-p5"
47+
BRANCH="RELEASE-p6"
4848
if [ -n "${BRANCH_OVERRIDE}" ]; then
4949
BRANCH=${BRANCH_OVERRIDE}
5050
fi

0 commit comments

Comments
 (0)