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.
Created attachment 954810 [details]
proposed upstream patch
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
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).
Created gnutls tracking bugs for this issue:
Affects: fedora-all [bug 1162086]
Red Hat would like to thank GnuTLS upstream for reporting this issue. Upstream acknowledges Sean Burford as the original reporter.
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
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.
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.