BN_hex2bn/BN_dec2bn NULL pointer deref/heap corruption (CVE-2016-0797)
The BN_hex2bn and BN_dec2bn functions in OpenSSL miscalculate the size of a buffer when converting very large hexadecimal or decimal strings, leading to either a NULL pointer dereference or heap corruption. An attacker could exploit this only if an application passes very large untrusted input to these functions, which the text describes as a rare occurrence.
- Fixed in 26 days
- Paid in 26 days
- Disclosed after 26 days
Summary by the program
Severity: Low
In the BN_hex2bn function the number of hex digits is calculated using an int value |i|. Later |bn_expand| is called with a value of |i * 4|. For large values of |i| this can result in |bn_expand| not allocating any memory because |i * 4| is negative. This can leave the internal BIGNUM data field as NULL leading to a subsequent NULL ptr deref. For very large values of |i|, the calculation |i * 4| could be a positive value smaller than |i|. In this case memory is allocated to the internal BIGNUM data field, but it is insufficiently sized leading to heap corruption. A similar issue exists in BN_dec2bn. This could have security consequences if BN_hex2bn/BN_dec2bn is ever called by user applications with very large untrusted hex/dec data. This is anticipated to be a rare occurrence.
All OpenSSL internal usage of these functions use data that is not expected to be untrusted, e.g. config file data or application command line arguments. If user developed applications generate config file data based on untrusted data then it is possible that this could also lead to security consequences. This is also anticipated to be rare.
This issue affects OpenSSL versions 1.0.2 and 1.0.1.
OpenSSL 1.0.2 users should upgrade to 1.0.2g OpenSSL 1.0.1 users should upgrade to 1.0.1s
This issue was reported to OpenSSL on February 19th 2016 by Guido Vranken. The fix was developed by Matt Caswell of the OpenSSL development team.
The report
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely an integer overflow in the size calculation for the BIGNUM buffer, where the number of digits is multiplied by 4 without checking for overflow, leading to an undersized or zero allocation.
Impact
This could have security consequences if BN_hex2bn/BN_dec2bn is ever called by user applications with very large untrusted hex/dec data, but this is anticipated to be a rare occurrence.
What the attacker needed
Application passes very large untrusted hex/dec data; OpenSSL version 1.0.2 or 1.0.1
The fix
The issue was fixed in OpenSSL 1.0.2g and 1.0.1s; users should upgrade to those versions.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
OpenSSL is a widely used library for secure connections. Two functions that convert text numbers into a big-number format had a maths mistake: when the input was extremely long, the size calculation overflowed, so the program either tried to use a missing memory area (crash) or wrote past the end of a too-small buffer (memory corruption). This only matters if a program passes very large untrusted text to these functions, which the report says is rare.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.