Bug 871700 (CVE-2012-4564) - CVE-2012-4564 libtiff: Missing return value check in ppm2tiff leading to heap-buffer overflow when reading a tiff file
Summary: CVE-2012-4564 libtiff: Missing return value check in ppm2tiff leading to heap...
Keywords:
Status: CLOSED ERRATA
Alias: CVE-2012-4564
Product: Security Response
Classification: Other
Component: vulnerability
Version: unspecified
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Red Hat Product Security
QA Contact:
URL:
Whiteboard: impact=moderate,public=20121102,repor...
Depends On: 880907 885308 885309 885310 885311
Blocks: 837581
TreeView+ depends on / blocked
 
Reported: 2012-10-31 06:04 UTC by Huzaifa S. Sidhpurwala
Modified: 2019-06-11 10:09 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-12-21 08:47:09 UTC


Attachments (Terms of Use)
proposed patch (1.18 KB, patch)
2012-10-31 06:26 UTC, Huzaifa S. Sidhpurwala
no flags Details | Diff


Links
System ID Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2012:1590 normal SHIPPED_LIVE Moderate: libtiff security update 2012-12-19 02:06:23 UTC

Description Huzaifa S. Sidhpurwala 2012-10-31 06:04:34 UTC
A flaw was found in the way ppm2tiff, a tool to create a TIFF file from PPM, PGM and PBM image files, did not check the return value of TIFFScanlineSize() function. When TIFFScanlineSize encountered an integer-overflow and returned zero, this value was not checked. A remote attacker could provide a specially-crafted PPM image format file, that when processed by ppm2tiff would lead to ppm2tiff executable crash or, potentially, arbitrary code execution with the privileges of the user running the ppm2tiff binary.

Comment 2 Huzaifa S. Sidhpurwala 2012-10-31 06:24:55 UTC
Analysis (I am using libtiff-4.0.3 as the base for the line numbers):
====================================================================

In ppm2tiff.c:241 the following code is used:

buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(out));

However TIFFScanlineSize() detects an integer overflow using the following code segment:

        if ((uint64)n!=m)
        {
                TIFFErrorExt(tif->tif_clientdata,module,"Integer arithmetic overflow");
                n=0;
        }
        return(n);
}

Due to overflow the return value from TIFFScanlineSize is zero. However ppm2tiff.c does not check this return value and uses zero to malloc memory via _TIFFmalloc. 
_TIFFmalloc is just a wrapper around glibc malloc. As per glibc:

       Even a request for zero bytes (i.e., malloc(0)) returns a
       pointer to something of the minimum allocatable size.

So this causes some memory to be allocated to buf. Later data is written into buf via:

                if (TIFFWriteScanline(out, buf, row, 0) < 0)

This causes a heap-based buffer overflow.

Comment 3 Huzaifa S. Sidhpurwala 2012-10-31 06:26:00 UTC
Created attachment 635949 [details]
proposed patch

Comment 4 Huzaifa S. Sidhpurwala 2012-11-02 10:28:25 UTC
Public via the following Changelog committed upstream:

2012-11-01  Frank Warmerdam  <warmerdam@pobox.com>

        * tools/ppm2tiff.c: avoid zero size buffer vulnerability.
        CVE-2012-4564 - Thanks to Huzaifa Sidhpurwala of the
        Red Hat Security Response team for the fix.

Comment 5 Huzaifa S. Sidhpurwala 2012-11-02 10:32:02 UTC
This issue affects the version of libtiff as shipped with Red Hat Enterprise Linux 5 and 6.

This issue affects the version of libtiff as shipped with Fedora 16 and Fedora 17.

Comment 6 Jan Lieskovsky 2012-11-02 10:33:43 UTC
Acknowledgements:

This issue was discovered by Huzaifa S. Sidhpurwala of Red Hat Security Response Team.

Comment 7 Huzaifa S. Sidhpurwala 2012-11-28 06:13:05 UTC
Created libtiff tracking bugs for this issue

Affects: fedora-all [bug 880907]

Comment 9 errata-xmlrpc 2012-12-18 21:10:42 UTC
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 10 Fedora Update System 2012-12-31 03:24:20 UTC
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 11 Fedora Update System 2012-12-31 03:28:03 UTC
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 12 Fedora Update System 2013-01-12 00:27:50 UTC
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.


Note You need to log in before you can comment on or make changes to this bug.