CVE-2016-4473: Use After Free

Published Jun 17, 2016
·
Updated

/ext/phar/pharobject.c in PHP 7.0.7 and 5.6.x allows remote attackers to execute arbitrary code. NOTE: Introduced as part of an incomplete fix to CVE-2015-6833.

Other sources

Fixed bug (invalid free in pharextractfile()). (CVE-2016-4473)

PHP

It was reported that invalid free may occur under certain conditions when processing phar-compatible archives in php 7.0.7 and 5.6.22.

Vulnerable code (php-7.0.7/ext/phar/pharobject.c):

| 4063 static int pharextractfile(zendbool overwrite, pharentryinfo entry, char dest, int destlen, char error) / {{{ / | 4064 { | .... | 4071 cwdstate newstate; | .... | 4084 newstate.cwd = (char)emalloc(2); // (1) | 4085 newstate.cwd[0] = DEFAULTSLASH; | 4086 newstate.cwd[1] = '\0'; | 4087 newstate.cwdlength = 1; | 4088 if (virtualfileex(&newstate, entry->filename, NULL, CWDEXPAND) != 0 || | 4089 newstate.cwdlength <= 1) { | .... | 4099 } | .... | 4163 | 4164 if (FAILURE == phpstreamstatpath(fullpath, &ssb)) { | 4165 if (entry->isdir) { | 4166 if (!phpstreammkdir(fullpath, entry->flags & PHARENTPERMMASK, PHPSTREAMMKDIRRECURSIVE, NULL)) { // (2) | .... | 4169 free(newstate.cwd); | .... | 4171 } | 4172 } else { | 4173 if (!phpstreammkdir(fullpath, 0777, PHPSTREAMMKDIRRECURSIVE, NULL)) { // (3) | .... | 4176 free(newstate.cwd); | .... | 4178 } | 4179 } | 4180 } | .... | 4246 }

newstate.cwd' is initially allocated through the internal zend allocator in (1) and is later reallocated as the file path is resolved.

In virtualfileex' (php-7.0.7/Zend/zendvirtualcwd.c):

| 1178 CWDAPI int virtualfileex(cwdstate state, const char path, verifypathfunc verifypath, int userealpath) / {{{ / | 1179 { | .... | 1336 if (verifypath) { | .... | 1342 tmp = erealloc(state->cwd, state->cwdlength+1); | .... | 1349 state->cwd = (char ) tmp; | 1350 | 1351 memcpy(state->cwd, resolvedpath, state->cwdlength+1); | .... | 1360 } else { | .... | 1362 tmp = erealloc(state->cwd, state->cwdlength+1); | .... | 1369 state->cwd = (char ) tmp; | 1370 | 1371 memcpy(state->cwd, resolvedpath, state->cwdlength+1); | .... | 1373 } | .... | 1379 }

If phpstreammkdir' fails in (2) or (3), cwd' is freed by the underlying libc allocator. If cwd' is user-controlled, this could potentially result in code execution.

Red Hat

Affected Software

36 affected componentsFixes available
redhat/php<5.6.23
5.6.23
PHP PHP=5.6.0-alpha1
PHP PHP=5.6.0-alpha2
PHP PHP=5.6.0-alpha3
PHP PHP=5.6.0-alpha4
PHP PHP=5.6.0-alpha5
PHP PHP=5.6.0-beta1
PHP PHP=5.6.0-beta2
PHP PHP=5.6.0-beta3
PHP PHP=5.6.0-beta4
PHP PHP=5.6.1
PHP PHP=5.6.2
PHP PHP=5.6.3
PHP PHP=5.6.4
PHP PHP=5.6.5
PHP PHP=5.6.6
PHP PHP=5.6.7
PHP PHP=5.6.8
PHP PHP=5.6.9
PHP PHP=5.6.10
PHP PHP=5.6.11
PHP PHP=5.6.12
PHP PHP=5.6.13
PHP PHP=5.6.14
PHP PHP=5.6.15
PHP PHP=5.6.16
PHP PHP=5.6.17
PHP PHP=5.6.18
PHP PHP=5.6.19
PHP PHP=5.6.20
PHP PHP=5.6.21
PHP PHP=5.6.22
PHP PHP=7.0.7
SUSE Linux Enterprise Module For Web Scripting=12
SUSE Linux Enterprise Software Development Kit=12-sp1
PHP PHP<7.0.8
7.0.8

Event History

Jun 8, 2017
CVE Published
via MITRE·08:00 PM
Data Sourced
via MITRE·08:00 PM
Description

Frequently Asked Questions

1

What is the severity of CVE-2016-4473?

CVE-2016-4473 is classified as a critical vulnerability allowing remote code execution.

2

How do I fix CVE-2016-4473?

To fix CVE-2016-4473, upgrade PHP to versions 5.6.23 or 7.0.8 or later.

3

What versions of PHP are affected by CVE-2016-4473?

CVE-2016-4473 affects PHP versions 5.6.0 to 5.6.22 and 7.0.0 to 7.0.7.

4

Can CVE-2016-4473 be exploited without user interaction?

Yes, CVE-2016-4473 can be exploited remotely without user interaction.

5

What is the nature of the vulnerability in CVE-2016-4473?

CVE-2016-4473 involves an invalid free issue in the phar_extract_file() function, enabling arbitrary code execution.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203