Bug 977992 (CVE-2016-4343) - VUL-0: CVE-2016-4343: php: Uninitialized pointer in phar_make_dirstream()
Summary: VUL-0: CVE-2016-4343: php: Uninitialized pointer in phar_make_dirstream()
Status: RESOLVED FIXED
Alias: CVE-2016-4343
Product: SUSE Security Incidents
Classification: Novell Products
Component: Incidents (show other bugs)
Version: unspecified
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Security Team bot
QA Contact: Security Team bot
URL: https://smash.suse.de/issue/168407/
Whiteboard: CVSSv2:SUSE:CVE-2015-2326:6.8:(AV:N/A...
Keywords:
Depends on:
Blocks:
 
Reported: 2016-05-02 08:17 UTC by Sebastian Krahmer
Modified: 2020-06-12 20:48 UTC (History)
3 users (show)

See Also:
Found By: Security Response Team
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
test tar (2.50 KB, application/x-tar)
2016-05-02 13:02 UTC, Petr Gajdos
Details

Note You need to log in before you can comment on or make changes to this bug.
Comment 1 Petr Gajdos 2016-05-02 12:40:37 UTC
The situation is different for 13.2 and 12:

13.2:

Breakpoint 1, phar_make_dirstream (dir=0x7ffff7fdc088 "/", manifest=0x7ffff7fdbbb8) at /usr/src/debug/php-5.6.1/ext/phar/dirstream.c:183
183		int dirlen = strlen(dir);
(gdb) p *manifest->pInternalPointer
$7 = {h = 5381, nKeyLength = 0, pData = 0x7ffff7fdc940, pDataPtr = 0x0, pListNext = 0x7ffff7fdbdc0, pListLast = 0x0, pNext = 0x0, 
  pLast = 0x0, arKey = 0x7ffff7fdd030 "Y"}

12:

Breakpoint 1, phar_make_dirstream (dir=0x7ffff7fd9f88 "/", manifest=0x7ffff7fd9ab8) at /usr/src/debug/php-5.5.14/ext/phar/dirstream.c:191
191		int dirlen = strlen(dir);
(gdb)  p *manifest->pInternalPointer
$7 = {h = 13895175661579615935, nKeyLength = 11, pData = 0x7ffff7fd9d28, pDataPtr = 0x0, pListNext = 0x0, pListLast = 0x0, pNext = 0x0, 
  pLast = 0x0, arKey = 0x7ffff7fd9d08 "testit/link\272\272\272\272\272\271"}

You see that nKeyLength is not zero in 12, so, via this testcase at least, the vulnerability is not proven. Will fix for 13.2 only.
Comment 2 Petr Gajdos 2016-05-02 13:02:18 UTC
Created attachment 675203 [details]
test tar

How to reproduce on 13.2:

Installed packages: php5, php5-phar

$ cat test.php
<?php
new PharData($argv[1]);
?>

BEFORE

$ USE_ZEND_ALLOC=0 valgrind php test.php 000.tar
  .. many valgrind errors, sometimes segfault ..
$

AFTER

$ USE_ZEND_ALLOC=0 valgrind php test.php 000.tar
PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'phar error: "/977992/000.tar" is a corrupted tar file (invalid entry size)' in /977992/test.php:2
Stack trace:
#0 /977992/test.php(2): PharData->__construct('000.tar')
#1 {main}
  thrown in /977992/test.php on line 2
$
Comment 3 Petr Gajdos 2016-05-04 12:37:30 UTC
In the phar_wrapper_open_dir(), phar_get_archive() is called second time and it uses cache data. As of the nature of the bug, it my conclusion in comment 1 is probably precipitate and because the code seems to be similar in 5.6.1 and older distros, I am going to submit everywhere where phar extension exists. This will ensure the processing of damaged file stops in time.

Nonetheless, the testcase is unreliable as far as I tested, as implies. Anyway, running the testcase AFTER should bail out with:

$ php test.php 000.tar
PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'phar error: "/977992/000.tar" is a corrupted tar file (invalid entry size)' in /977992/test.php:2
Stack trace:
#0 /977992/test.php(2): PharData->__construct('000.tar')
#1 {main}
  thrown in /977992/test.php on line 2

$
Comment 4 Bernhard Wiedemann 2016-05-05 07:01:18 UTC
This is an autogenerated message for OBS integration:
This bug (977992) was mentioned in
https://build.opensuse.org/request/show/393784 13.2 / php5
Comment 5 Petr Gajdos 2016-05-05 08:33:17 UTC
Packages submitted.
Comment 6 Bernhard Wiedemann 2016-05-10 12:00:47 UTC
This is an autogenerated message for OBS integration:
This bug (977992) was mentioned in
https://build.opensuse.org/request/show/394633 13.2 / php5
Comment 7 Bernhard Wiedemann 2016-05-18 14:00:29 UTC
This is an autogenerated message for OBS integration:
This bug (977992) was mentioned in
https://build.opensuse.org/request/show/396629 13.2 / php5
Comment 8 Swamp Workflow Management 2016-05-19 12:09:05 UTC
openSUSE-SU-2016:1357-1: An update that fixes 11 vulnerabilities is now available.

Category: security (moderate)
Bug References: 977991,977992,977994,978827,978828,978829,978830
CVE References: CVE-2016-4342,CVE-2016-4343,CVE-2016-4346,CVE-2016-4537,CVE-2016-4538,CVE-2016-4539,CVE-2016-4540,CVE-2016-4541,CVE-2016-4542,CVE-2016-4543,CVE-2016-4544
Sources used:
openSUSE 13.2 (src):    php5-5.6.1-61.1
Comment 9 Marcus Meissner 2016-08-01 09:44:40 UTC
released