Skip to content

GHSA-q9wj-f4qw-6vfj CVE-2021-3712 RUSTSEC-2021-0098

Read buffer overruns processing ASN.1 strings

High crates.io
Severity
7.4 / 10
High · CVSS 3.1
Exploit chance (EPSS)
50.44%
Chance of exploitation in the next 30 days. Higher than 98.91% of scored vulnerabilities.
Known exploited
No
Not in CISA's catalog
Weakness
CWE-125 Out-of-bounds Read
Fix
111.16.0
Upgrade openssl-src to this version or later

Description

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). Fixed in OpenSSL 1.1.1j (Affected 1.1.1-1.1.1k). Fixed in OpenSSL 1.0.2za (Affected 1.0.2-1.0.2y).

Affected versions

crates.io

PackageVulnerableFixed in
openssl-src
< 111.16.0
111.16.0
openssl-src
>= 0.0.0-0, < 111.16.0
111.16.0

How to fix

Move to the fixed version or later with your package manager, update the lockfile, and run your tests. If the package only arrives through another dependency, upgrade that dependency first. If none of its releases pulls a fixed version yet, force the version with your package manager's override.

openssl-src crates.io → 111.16.0

cargo
cargo update -p openssl-src --precise 111.16.0

Severity breakdown

CVSS 3.1 7.4

CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:H

Attack vector
Network
Attack complexity
High
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
None
Availability
High

Weakness

CWE-125: Out-of-bounds Read

The product reads data past the end, or before the beginning, of the intended buffer.

How to prevent it
  • Implementation: Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does. When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue." Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright. To reduce the likelihood of introducing an out-of-bounds read, ensure that you validate and ensure correct calculations for any length argument, buffer size calculation, or offset. Be especially careful of relying on a sentinel (i.e. special character such as NUL) in untrusted inputs.
  • Architecture and Design: Use a language that provides appropriate memory abstractions.

References

Advisories

Packages

Other links

Timeline

  1. Published
  2. Last updated by the source
  3. Latest EPSS score
AdvisorySeverityWhy it's related
GHSA-w67w-mw4j-8qrv
openssl-src contains Read Buffer Overflow in X.509 Name Constraint
Medium Also affects openssl-src
GHSA-vrh7-x64v-7vxq
openssl-src contains `NULL` dereference during PKCS7 data verification
High Also affects openssl-src
GHSA-vxrh-cpg7-8vjr
openssl-src subject to NULL dereference validating DSA public key
High Also affects openssl-src
GHSA-r7jw-wp68-3xch
openssl-src vulnerable to Use-after-free following `BIO_new_NDEF`
High Also affects openssl-src
GHSA-v5w6-wcm8-jm4q
openssl-src contains Double free after calling `PEM_read_bio_ex`
High Also affects openssl-src
GHSA-p52g-cm5j-mjv4
openssl-src subject to Timing Oracle in RSA Decryption
Medium Also affects openssl-src
GHSA-29xx-hcv2-c4cp
openssl-src subject to Invalid pointer dereference in `d2i_PKCS7` functions
High Also affects openssl-src
GHSA-x4qr-2fvf-3mr5
Vulnerable OpenSSL included in cryptography wheels
High Also affects openssl-src
Is this in your code?

MergeHarbor checks every repository's dependencies against this database, ranks what matters by exploitability and reachability, routes it to the owning team and opens the fix pull request.

Check your repos with MergeHarbor