Bug 1297710 (CVE-2016-5114)

Summary: CVE-2016-5114 php: out-of-bounds write in fpm_log.c
Product: [Other] Security Response Reporter: Adam Mariš <amaris>
Component: vulnerabilityAssignee: Red Hat Product Security <security-response-team>
Status: CLOSED ERRATA QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: unspecifiedCC: abhgupta, carnil, cbuissar, dmcphers, fedora, jialiu, jokerman, jorton, kseifried, lmeyer, mmaslano, mmccomas, rcollet, tiwillia, webstack-team
Target Milestone: ---Keywords: Security
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: php 5.6.17, php 5.5.31 Doc Type: Bug Fix
Doc Text:
An out-of-bounds write flaw was found in the fpm_log_write() logging function of PHP's FastCGI Process Manager service. A remote attacker could repeatedly send maliciously crafted requests to force FPM to exhaust file system space, creating a denial of service and preventing further logging.
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-02-03 13:05:20 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1297711    
Bug Blocks: 1297732    

Description Adam Mariš 2016-01-12 09:55:27 UTC
A memory leak and out-of-bounds write was found in fpm_log.c.

At line 237 (php 5.6.14):
len2 = snprintf(b, FPM_LOG_BUFFER - len, "%s", env ? env : "-");

The functions snprintf() and vsnprintf() do not write more than size bytes (including the terminating null byte ('\0')). If the output was truncated due to this limit then the return value is the number of characters (excluding the terminating null byte) which would have been written to the final string if enough space had been available.


The full length (len) is increased by len2 (line 449):
len += len2;

After exiting the loop, a \n byte is written outside of the compiled buffer and the log line along with some memory area lying after it is flushed into the access log:

	if (!test && strlen(buffer) > 0) {
 		buffer[len] = '\n';
		write(fpm_log_fd, buffer, len + 1);
	}

This results in one byte written out-of-bounds and several bytes read out-of-bounds.

Upstream patch:

https://git.php.net/?p=php-src.git;a=commitdiff;h=2721a0148649e07ed74468f097a28899741eb58f

Upstream bug (contains reproducer):

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

Comment 1 Adam Mariš 2016-01-12 09:55:59 UTC
Created php tracking bugs for this issue:

Affects: fedora-all [bug 1297711]

Comment 2 Fedora Update System 2016-01-16 13:22:34 UTC
php-5.6.17-1.fc23 has been pushed to the Fedora 23 stable repository. If problems still persist, please make note of it in this bug report.

Comment 3 Fedora Update System 2016-01-16 14:20:07 UTC
php-5.6.17-1.fc22 has been pushed to the Fedora 22 stable repository. If problems still persist, please make note of it in this bug report.

Comment 7 errata-xmlrpc 2016-11-15 11:49:01 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