Bug 1995634 (CVE-2021-3712) - CVE-2021-3712 openssl: Read buffer overruns processing ASN.1 strings
Summary: CVE-2021-3712 openssl: Read buffer overruns processing ASN.1 strings
Status: NEW
Alias: CVE-2021-3712
Product: Security Response
Classification: Other
Component: vulnerability
Version: unspecified
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Red Hat Product Security
QA Contact:
Depends On: 1996054 1997219 1997220 1997221 1997223 1997297 1997298 1997300 1997301 1997473 2005400 2005402 1996053 1996185 1996186 1997299 2005401
Blocks: 1995569
TreeView+ depends on / blocked
Reported: 2021-08-19 14:14 UTC by Cedric Buissart
Modified: 2021-10-12 16:32 UTC (History)
36 users (show)

Fixed In Version: openssl 1.1.1l
Doc Type: If docs needed, set a value
Doc Text:
It was found that openssl assumed ASN.1 strings to be NUL terminated. A malicious actor may be able to force an application into calling openssl function with a specially crafted, non-NUL terminated string to deliberately hit this bug, which may result in a crash of the application, causing a Denial of Service attack, or possibly, memory disclosure. The highest threat from this vulnerability is to data confidentiality and system availability.
Clone Of:
Last Closed:

Attachments (Terms of Use)

Description Cedric Buissart 2021-08-19 14:14:16 UTC
Severity: Moderate

ASN.1 strings are represented internally within OpenSSL as an ASN1_STRING
structure which contains a buffer holding the string data and a field holding
the buffer length. This contrasts with normal C strings which are repesented as
a buffer for the string data which is terminated with a NUL (0) byte.

Although not a strict requirement, ASN.1 strings that are parsed using OpenSSL's
own "d2i" functions (and other similar parsing functions) as well as any string
whose value has been set with the ASN1_STRING_set() function will additionally
NUL terminate the byte array in the ASN1_STRING structure.

However, it is possible for applications to directly construct valid ASN1_STRING
structures which do not NUL terminate the byte array by directly setting the
"data" and "length" fields in the ASN1_STRING array. This can also happen by
using the ASN1_STRING_set0() function.

Numerous OpenSSL functions that print ASN.1 data have been found to assume that
the ASN1_STRING byte array will be NUL terminated, even though this is not
guaranteed for strings that have been directly constructed. Where an application
requests an ASN.1 structure to be printed, and where that ASN.1 structure
contains ASN1_STRINGs that have been directly constructed by the application
without NUL terminating the "data" field, then a read buffer overrun can occur.

The same thing can also occur during name constraints processing of certificates
(for example if a certificate has been directly constructed by the application
instead of loading it via the OpenSSL parsing functions, and the certificate
contains non NUL terminated ASN1_STRING structures). It can also occur in the
X509_get1_email(), X509_REQ_get1_email() and X509_get1_ocsp() functions.

If a malicious actor can cause an application to directly construct an
ASN1_STRING and then process it through one of the affected OpenSSL functions
then this issue could be hit. This might result in a crash (causing a Denial of
Service attack). It could also result in the disclosure of private memory
contents (such as private keys, or sensitive plaintext).

OpenSSL versions 1.1.1k and below are affected by this issue. Users of these
versions should upgrade to OpenSSL 1.1.1l.

OpenSSL versions 1.0.2y and below are affected by this issue. However OpenSSL
1.0.2 is out of support and no longer receiving public updates. Premium support
customers of OpenSSL 1.0.2 should upgrade to 1.0.2z. Other users should upgrade
to 1.1.1l.

An initial instance of this issue in the X509_aux_print() function was reported
to OpenSSL on 18th July 2021 by Ingo Schwarze. The bugfix was developed by Ingo
Schwarze and first publicly released in OpenBSD-current on 10th July 2021 and
subsequently in OpenSSL on 20th July 2021 (commit d9d838d). Subsequent
analysis by David Benjamin on 17th August 2021 identified more instances of the
same bug. Additional analysis was performed by Matt Caswell. Fixes for the
additional instances of this issue were developed by Matt Caswell.

Comment 6 Cedric Buissart 2021-08-20 13:16:22 UTC
Description of the flaw:

It was found that several functions internal to openssl were assuming thata given string would be NUL ('\0') terminated.

However, it may happen that a given application using openssl libraries is tricked by an attacker into calling these functions with specially crafted, non-NUL terminated strings.

This would result in these functions reading past the string's allocated buffer, into the application memory (until a NUL byte is read).

This may result in the crash of the application, or, if the attacker is able to retrieve the content read, disclosure of the application's memory.

The affected functions are X.509 certificate related, and likely used for logging purpose. The memory disclosure is thus likely to be local only (not sent back to a remote attacker).

Comment 13 Cedric Buissart 2021-08-24 16:06:29 UTC
Created mingw-openssl tracking bugs for this issue:

Affects: fedora-all [bug 1997221]

Created openssl tracking bugs for this issue:

Affects: fedora-all [bug 1997219]

Created openssl11 tracking bugs for this issue:

Affects: epel-7 [bug 1997220]

Note You need to log in before you can comment on or make changes to this bug.