Bug 800591 (CVE-2012-1133)

Summary: CVE-2012-1133 freetype: heap buffer underflow in BDF parser _bdf_parse_glyphs() (#35607)
Product: [Other] Security Response Reporter: Jan Lieskovsky <jlieskov>
Component: vulnerabilityAssignee: Red Hat Product Security <security-response-team>
Status: CLOSED NOTABUG QA Contact:
Severity: high Docs Contact:
Priority: high    
Version: unspecifiedCC: behdad, fonts-bugs, jrusnack, kevin, mkasik
Target Milestone: ---Keywords: Security
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-02-24 22:03:12 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: 806270, 806271, 889398    
Bug Blocks: 800639    

Description Jan Lieskovsky 2012-03-06 18:51:19 UTC
An out-of heap-based buffer write flaw was found in the way FreeType font rendering engine performed parsing of glyph information and bitmaps for certain glyph bitmap distribution format (BDF) fonts. A remote attacker could provide a specially-crafted BDF font file, which once opened in an application linked against FreeType would lead to that application crash, or, potentially, arbitrary code execution with the privileges of the user running the application.

Upstream bug report:
[1] https://savannah.nongnu.org/bugs/?35607

Upstream patch:
[2] http://git.savannah.gnu.org/cgit/freetype/freetype2.git/commit/?id=28dd2c45957278e962f95633157b6139de8170aa

Acknowledgements:

Red Hat would like to thank Mateusz Jurczyk of the Google Security Team for reporting this issue.

Comment 1 Kurt Seifried 2012-03-06 20:52:23 UTC
Added CVE as per http://www.openwall.com/lists/oss-security/2012/03/06/16

Comment 2 Jan Lieskovsky 2012-03-14 18:41:53 UTC
This issue did NOT affect the versions of the freetype package, as shipped with Red Hat Enterprise Linux 5 and 6.

--

This issue affects the versions of the freetype package, as shipped with Fedora release of 15 and 16.

Comment 7 Tomas Hoger 2012-03-15 20:43:51 UTC
This problem is triggered by a negative value of the glyph's ENCODING parameter and can cause freetype to index glyphs array (an array of bdf_glyph_t) using index -1.  The glyph structure is both read and written to.

Comment 8 Tomas Hoger 2012-03-16 07:50:21 UTC
It seems this issue existed in old freetype versions.  It was later resolved via the following commit:

http://git.savannah.gnu.org/cgit/freetype/freetype2.git/commit/?id=481838e2

That commit addresses a security issue CVE-2006-1861 (bug 484437, bug 190593) related to the large ENCODING values causing buffer overflow.  The fix ensures that ENCODING value is not negative and not too large.

The fix was backported to freetype packages in Red Hat Enterprise Linux 2.1, 3, and 4:

https://access.redhat.com/security/cve/CVE-2006-1861

The freetype packages in Red Hat Enterprise Linux 5 and 6 are based on upstream versions that include the fix.

However, the fix introduced a regression and caused valid ENCODING value of -1 to be rejected as invalid.  This was reported upstream and resolved via:

https://savannah.nongnu.org/bugs/?33663
http://git.savannah.gnu.org/cgit/freetype/freetype2.git/commit/?id=96ddc679

That regression fix re-introduced the security problem.  The regression fix is no included in freetype packages in Red Hat Enterprise Linux 4, 5 and 6.

Statement:

Not vulnerable. This issue did not affect freetype packages as shipped with Red Hat Enterprise Linux 3, 4, 5, and 6.

Comment 9 Tomas Hoger 2012-03-16 12:41:00 UTC
(In reply to comment #8)
> It seems this issue existed in old freetype versions.  It was later resolved
> via the following commit:
> 
> http://git.savannah.gnu.org/cgit/freetype/freetype2.git/commit/?id=481838e2

Note there is additional follow up patch:

http://git.savannah.gnu.org/cgit/freetype/freetype2.git/commit/?id=b698eeda

That patch add explicit conversion of p->glyph_enc to size_t for comparison (which causes negative values to be converted to large positive unsigned value).  However, as glyph_enc is (signed) long and the right side of the comparison is of the size_t type, gcc does implicit conversion of the p->glyph_enc to unsigned long and hence error is reported.

> The freetype packages in Red Hat Enterprise Linux 5 and 6 are based on
> upstream versions that include the fix.

freetype packages in Red Hat Enterprise Linux 5 and 6 include explicit conversion to size_t, patch that was added to earlier Red Hat Enterprise Linux versions does not include explicit type conversion.