Bug 867235 (CVE-2012-5581)

Summary: CVE-2012-5581 libtiff: Stack-based buffer overflow when reading a tiled tiff file
Product: [Other] Security Response Reporter: Huzaifa S. Sidhpurwala <huzaifas>
Component: vulnerabilityAssignee: Red Hat Product Security <security-response-team>
Status: CLOSED ERRATA QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: unspecifiedCC: jrusnack, pmatouse, security-response-team, tgl
Target Milestone: ---Keywords: Reopened, Security
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard: impact=moderate,public=20121018,reported=20121017,source=redhat,cvss2=6.8/AV:N/AC:M/Au:N/C:P/I:P/A:P,rhel-5/libtiff=affected,rhel-6/libtiff=affected,fedora-all/libtiff=affected,fedora-all/mingw-libtiff=affected,cwe=CWE-121
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-12-21 04:00:39 EST Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Bug Depends On: 880907, 885308, 885309, 885310, 885311, 889443    
Bug Blocks: 837581    
Attachments:
Description Flags
proposed patch none

Description Huzaifa S. Sidhpurwala 2012-10-17 02:13:21 EDT
A stack-based buffer overflow was found in the way libtiff handled DOTRANGE tags. An attacker could use this flaw to create a specially-crafted TIFF file 
that, when opened, would cause an application linked against libtiff to crash 
or, possibly, execute arbitrary code. 

This issue is fixed in libtiff-4.0.2
Comment 6 Tom Lane 2012-10-30 12:23:34 EDT
(In reply to comment #5)
> Yeah.  I see that libtiff 4.0.x has completely rewritten the special cases
> for DOTRANGE, but it's not clear whether that dodges this problem or not --

Turns out that indeed 4.0.3 does not crash.  It looks like these upstream commits were specifically intended to repair this type of problem:

2012-06-06 00:56:01  fwarmerdam

	* ChangeLog, libtiff/tif_dir.c: avoid special handling of
	PAGENUMBER, HALFTONEHINTS, YCBCRSUBSAMPLING and DOTRANGE in
	non-image directories

2012-06-06 02:06:20  fwarmerdam

	* ChangeLog, libtiff/tif_print.c: improve handling of PAGENUMBER,
	HALFTONEHINTS, YCBCRSUBSAMPLING and DOTRANGE

2012-06-08 01:15:21  fwarmerdam

	* ChangeLog, libtiff/tif_print.c: avoid pretty printing values
	without proper rawdata

I'm not sure about the backwards compatibility implications if we apply these patches --- it seems at least theoretically possible that some apps out there are expecting the original behavior of GetField/SetField.  On the other hand, it's unclear that there is any way to fix this crash without a behavioral change.
Comment 11 Huzaifa S. Sidhpurwala 2012-11-08 00:19:28 EST
I backported the following upstream change and that seems to fix the crash.

2012-06-06 00:56:01  fwarmerdam

	* ChangeLog, libtiff/tif_dir.c: avoid special handling of
	PAGENUMBER, HALFTONEHINTS, YCBCRSUBSAMPLING and DOTRANGE in
	non-image directories
Comment 12 Huzaifa S. Sidhpurwala 2012-11-08 00:20:18 EST
Created attachment 640578 [details]
proposed patch
Comment 14 Kurt Seifried 2012-11-28 00:56:38 EST
Acknowledgements:

This issue was discovered by Huzaifa S. Sidhpurwala of Red Hat Security Response Team.
Comment 15 Huzaifa S. Sidhpurwala 2012-11-28 01:12:37 EST
Created libtiff tracking bugs for this issue

Affects: fedora-all [bug 880907]
Comment 17 Tom Lane 2012-12-10 19:28:37 EST
FWIW, I'm not terribly sure that this patch won't result in any application compatibility problems.  However, the only apparent alternative is to leave the bug unfixed, which is even less attractive.

The saving grace is that the case where an application might have a compatibility problem would be where it had special-case code to handle DotRange or one of the other "weird" TIFF tags whose behavior has been simplified by the patch. Such applications are probably very few and far between, since these tags are little-used.
Comment 20 errata-xmlrpc 2012-12-18 16:10:38 EST
This issue has been addressed in following products:

  Red Hat Enterprise Linux 5
  Red Hat Enterprise Linux 6

Via RHSA-2012:1590 https://rhn.redhat.com/errata/RHSA-2012-1590.html
Comment 21 Huzaifa S. Sidhpurwala 2012-12-21 03:56:23 EST
Created mingw-libtiff tracking bugs for this issue

Affects: fedora-all [bug 889443]
Comment 22 Fedora Update System 2012-12-30 22:24:09 EST
libtiff-3.9.7-1.fc16 has been pushed to the Fedora 16 stable repository.  If problems still persist, please make note of it in this bug report.
Comment 23 Fedora Update System 2012-12-30 22:27:52 EST
libtiff-3.9.7-1.fc17 has been pushed to the Fedora 17 stable repository.  If problems still persist, please make note of it in this bug report.
Comment 24 Fedora Update System 2013-01-11 19:27:40 EST
libtiff-4.0.3-2.fc18 has been pushed to the Fedora 18 stable repository.  If problems still persist, please make note of it in this bug report.