Bug 1359698 (CVE-2016-6289) - CVE-2016-6289 php: Integer overflow leads to buffer overflow in virtual_file_ex
Summary: CVE-2016-6289 php: Integer overflow leads to buffer overflow in virtual_file_ex
Keywords:
Status: CLOSED ERRATA
Alias: CVE-2016-6289
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:
Depends On: 1359837
Blocks: 1359830
TreeView+ depends on / blocked
 
Reported: 2016-07-25 10:19 UTC by Adam Mariš
Modified: 2020-01-17 15:50 UTC (History)
14 users (show)

Fixed In Version: php 5.5.38, php 5.6.24, php 7.0.9
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-09-26 20:06:51 UTC
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2016:2750 0 normal SHIPPED_LIVE Moderate: rh-php56 security, bug fix, and enhancement update 2016-11-15 16:40:02 UTC

Description Adam Mariš 2016-07-25 10:19:56 UTC
An integer overflow vulnerability was found in CWD_API virtual_file_ex in php-src/Zend/zend_virtual_cwd.c that allows to memcpy a large chunk of memory leading to buffer overflow.

Upstream bug:

https://bugs.php.net/bug.php?id=72513

Upstream patch:

http://git.php.net/?p=php-src.git;a=commit;h=0218acb7e756a469099c4ccfb22bce6c2bd1ef87

CVE assignment:

http://seclists.org/oss-sec/2016/q3/137

Comment 1 Adam Mariš 2016-07-25 14:12:53 UTC
Created php tracking bugs for this issue:

Affects: fedora-all [bug 1359837]

Comment 2 Huzaifa S. Sidhpurwala 2016-08-04 06:14:54 UTC
Analysis:

This is a flaw in the Thread Safe Resource Manager virtual_file_ex() function of PHP, which is defined as:

CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path, int use_realpath)

Inside the function, path_length is calculated by using:

int path_length = (int)strlen(path);

So, if path variable is attacker controller, the attacker could give an extremely long path, which may cause the output of strlen to wrap, causing an integer overflow. Later in the function the following memcpy() is used.

memcpy(resolved_path , path, path_length + 1);

Depending on the value of path_length (because of the integer overflow), this may cause large chunk of data to copied into the stack based variable resolved_path, resulting in a possible crash.

As described in the upstream bug, one way to trigger this crash would be via a PHP zip handling functions. In the POC the following is used:

        $a->extractTo(".", str_repeat("/",0xfffffff0));

Here the path variable fed to virtual_file_ex is specially-crafted and can cause a crash.

So, this attack can only be triggered if the path variable can be in some way controlled by the attacker.

Comment 3 errata-xmlrpc 2016-11-15 11:43:08 UTC
This issue has been addressed in the following products:

  Red Hat Software Collections for Red Hat Enterprise Linux 6
  Red Hat Software Collections for Red Hat Enterprise Linux 6.7 EUS
  Red Hat Software Collections for Red Hat Enterprise Linux 7
  Red Hat Software Collections for Red Hat Enterprise Linux 7.2 EUS
  Red Hat Software Collections for Red Hat Enterprise Linux 7.3 EUS

Via RHSA-2016:2750 https://rhn.redhat.com/errata/RHSA-2016-2750.html


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