CVE-2021-3711: SM2 Decryption Buffer Overflow
A flaw was found in openssl. A miscalculation of a buffer size was found in openssl's SM2 decryption function, allowing up to 62 arbitrary bytes to be written outside of the buffer. A remote attacker could use this flaw to crash an application supporting SM2 signature or encryption algorithm, or, possibly, execute arbitrary code with the permissions of the user running that application. The highest threat from this vulnerability is to data confidentiality and integrity as well as system availability.
Other sources
In order to decrypt SM2 encrypted data an application is expected to call the API function EVPPKEYdecrypt(). Typically an application will call this function twice. The first time, on entry, the "out" parameter can be NULL and, on exit, the "outlen" parameter is populated with the buffer size required to hold the decrypted plaintext. The application can then allocate a sufficiently sized buffer and call EVPPKEYdecrypt() again, but this time passing a non-NULL value for the "out" parameter. A bug in the implementation of the SM2 decryption code means that the calculation of the buffer size required to hold the plaintext returned by the first call to EVPPKEYdecrypt() can be smaller than the actual size required by the second call. This can lead to a buffer overflow when EVPPKEYdecrypt() is called by the application a second time with a buffer that is too small. A malicious attacker who is able present SM2 content for decryption to an application could cause attacker chosen data to overflow the buffer by up to a maximum of 62 bytes altering the contents of other data held after the buffer, possibly changing application behaviour or causing the application to crash. The location of the buffer is application dependent but is typically heap allocated. Fixed in OpenSSL 1.1.1l (Affected 1.1.1-1.1.1k).
OpenSSL is vulnerable to a buffer overflow, caused by improper bounds checking by the EVPPKEYdecrypt() function within implementation of the SM2 decryption. By sending specially crafted SM2 content, a remote attacker could overflow a buffer and execute arbitrary code on the system or cause the application to crash.
— IBM
Severity: High
In order to decrypt SM2 encrypted data an application is expected to call the API function EVPPKEYdecrypt(). Typically an application will call this function twice. The first time, on entry, the "out" parameter can be NULL and, on exit, the "outlen" parameter is populated with the buffer size required to hold the decrypted plaintext. The application can then allocate a sufficiently sized buffer and call EVPPKEYdecrypt() again, but this time passing a non-NULL value for the "out" parameter.
A bug in the implementation of the SM2 decryption code means that the calculation of the buffer size required to hold the plaintext returned by the first call to EVPPKEYdecrypt() can be smaller than the actual size required by the second call. This can lead to a buffer overflow when EVPPKEYdecrypt() is called by the application a second time with a buffer that is too small.
A malicious attacker who is able present SM2 content for decryption to an application could cause attacker chosen data to overflow the buffer by up to a maximum of 62 bytes altering the contents of other data held after the buffer, possibly changing application behaviour or causing the application to crash. The location of the buffer is application dependent but is typically heap allocated.
OpenSSL versions 1.1.1k and below are affected by this issue. Users of these versions should upgrade to OpenSSL 1.1.1l.
OpenSSL 1.0.2 is not impacted by this issue.
OpenSSL 3.0 alpha/beta releases are also affected but this issue will be addressed before the final release.
This issue was reported to OpenSSL on 12th August 2021 by John Ouyang. The fix was developed by Matt Caswell.
— Red Hat
Affected Software
Remediation
Patch Available
Patch Available
Patch Available
Event History
Frequently Asked Questions
What is the vulnerability ID for this OpenSSL vulnerability?
The vulnerability ID for this OpenSSL vulnerability is CVE-2021-3711.
What is the severity level of CVE-2021-3711?
CVE-2021-3711 has a severity level of critical.
Which software versions are affected by CVE-2021-3711?
CVE-2021-3711 affects OpenSSL versions 1.1.1 and earlier, IBM Cognos Analytics 11.2.x, IBM Cognos Analytics 11.1.x, and various other software products.
How can I fix this vulnerability?
To fix CVE-2021-3711, upgrade to OpenSSL version 1.1.1n or later.
Where can I find more information about CVE-2021-3711?
More information about CVE-2021-3711 can be found in the references: [link1](https://github.com/openssl/openssl/commit/59f5e75f3bced8fc0e130d72a3f582cf7b480b46), [link2](https://bugzilla.redhat.com/show_bug.cgi/show_bug.cgi?id=1997212), [link3](https://bugzilla.redhat.com/show_bug.cgi/show_bug.cgi?id=1997210).