Bug 1161443 (CVE-2014-8564)

Summary: CVE-2014-8564 gnutls: Heap corruption when generating key ID for ECC (GNUTLS-SA-2014-5)
Product: [Other] Security Response Reporter: Siddharth Sharma <sisharma>
Component: vulnerabilityAssignee: Red Hat Product Security <security-response-team>
Status: CLOSED ERRATA QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: unspecifiedCC: carnil, jrusnack, mivicaf210, nmavrogi, security-response-team, szidek
Target Milestone: ---Keywords: Security
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: gnutls 3.1.28, gnutls 3.2.20, gnutls 3.3.10 Doc Type: Bug Fix
Doc Text:
An out-of-bounds memory write flaw was found in the way GnuTLS parsed certain ECC (Elliptic Curve Cryptography) certificates or certificate signing requests (CSR). A malicious user could create a specially crafted ECC certificate or a certificate signing request that, when processed by an application compiled against GnuTLS (for example, certtool), could cause that application to crash or execute arbitrary code with the permissions of the user running the application.
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-11-12 05:46:37 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1161472, 1161473, 1162086    
Bug Blocks: 1159291    
Attachments:
Description Flags
proposed upstream patch none

Description Siddharth Sharma 2014-11-07 07:13:34 UTC
IssueDescription:

An out-of-bounds memory write flaw was found in the way GnuTLS parsed certain ECC (Elliptic Curve Cryptography) certificates or certificate signing requests (CSR). A malicious user could create a specially crafted ECC certificate or a certificate signing request that, when processed by an application compiled against GnuTLS (for example, certtool), could cause that application to crash or execute arbitrary code with the permissions of the user running the application.

Comment 1 Huzaifa S. Sidhpurwala 2014-11-07 07:56:46 UTC
Created attachment 954810 [details]
proposed upstream patch

Comment 2 Huzaifa S. Sidhpurwala 2014-11-07 08:19:34 UTC
Analysis:

The issue exists in the _gnutls_ecc_ansi_x963_export() function in gnutls_ecc.c

The function starts with a call to gnutls_ecc_curve_get_size() at:

 36   int numlen = gnutls_ecc_curve_get_size (curve);

This gets the size of the curve parameters as given in the standards. The value is stored in the numlen variable.  

Since there are two numbers which need to be stores (bigint x and bigint y in this case), this number is multiplied by two and one byte is used to store "0x04"

 43   out->size = 1 + 2 * numlen;

After that out->size amount of memory is malloced, zero'ed out and the first byte (0x04) is written. 

Now bigint x needs to be converted to ascii to be stored in the "out" variable. This starts by estimating the size of bigint by using the _gnutls_mpi_get_nbits() macros. In this case it turns out to be bigger than numlen and is stored in the byte_size variable.

Now since there is no check on byte_size, the following results in a overflow.

 56   size = out->size - (1 + (numlen - byte_size));

In the above case numlen < byte_size 

Later when an attempt is made to store x in "out" it causes an OOB write at:

 57   ret = _gnutls_mpi_print (x, &out->data[1 + (numlen - byte_size)], &size);

portions of x are written before memory location of out->data array and causes heap corruption.

Same can happen when an attempt is made to store y in out->data

Comment 3 Huzaifa S. Sidhpurwala 2014-11-07 08:20:22 UTC
Statement:

This issue does not affect the version of gnutls as shipped with Red Hat Enterprise Linux 5 and 6, since it does not have support for ECC (Elliptic Curve Cryptography).

Comment 7 Huzaifa S. Sidhpurwala 2014-11-10 09:07:34 UTC
Public via:

http://www.gnutls.org/security.html#GNUTLS-SA-2014-5

Comment 8 Huzaifa S. Sidhpurwala 2014-11-10 09:10:29 UTC
Created gnutls tracking bugs for this issue:

Affects: fedora-all [bug 1162086]

Comment 9 Huzaifa S. Sidhpurwala 2014-11-10 09:14:51 UTC
Upstream patches:

gnutls-3.1.28:
https://gitorious.org/gnutls/gnutls/commit/7429872b74c8216bbf15e241e47aba94369ef083

Comment 14 Huzaifa S. Sidhpurwala 2014-11-11 03:38:29 UTC
Acknowledgements:

Red Hat would like to thank GnuTLS upstream for reporting this issue. Upstream acknowledges Sean Burford as the original reporter.

Comment 15 errata-xmlrpc 2014-11-12 05:40:25 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 7

Via RHSA-2014:1846 https://rhn.redhat.com/errata/RHSA-2014-1846.html

Comment 16 Fedora Update System 2014-11-13 18:22:45 UTC
gnutls-3.1.28-1.fc20 has been pushed to the Fedora 20 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 17 Fedora Update System 2014-11-16 14:40:51 UTC
gnutls-3.3.10-1.fc21 has been pushed to the Fedora 21 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 18 Jordan Holt 2022-02-02 15:26:57 UTC
The issue has already been resolved. ttps://www.plastererswollongong.com.au