out of bounds read crashes php-cgi
PHP's CGI component, when using mmap to read a .php file, failed to consider the mapping length when processing an invalid file starting with a # and lacking a newline, causing an out-of-bounds read. This could let remote attackers obtain sensitive information from php-cgi process memory by uploading a .php file, or trigger unexpected code execution if a valid PHP script is adjacent in memory.
- Fixed in 6 months
- Paid in 6 months
- Disclosed after 13 days
I found and disclosed CVE-2014-9427 to the PHP dev team on 17 December 2014 (https://bugs.php.net/bug.php?id=68618) and a patch was committed on 30 December 2014 (http://git.php.net/?p=php-src.git;a=commit;h=f9ad3086693fce680fbe246e4a45aa92edd2ac35) and the flaw is now fixed.
Details of the flaw: sapi/cgi/cgi_main.c in the CGI component in PHP through 5.4.36, 5.5.x through 5.5.20, and 5.6.x through 5.6.4, when mmap is used to read a .php file, does not properly consider the mapping's length during processing of an invalid file that begins with a # character and lacks a newline character, which causes an out-of-bounds read and might (1) allow remote attackers to obtain sensitive information from php-cgi process memory by leveraging the ability to upload a .php file or (2) trigger unexpected code execution if a valid PHP script is present in memory locations adjacent to the mapping.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the CGI SAPI's mmap-based file reader did not bound its scan to the mapped length when handling a file beginning with '#' and lacking a newline.
Impact
Remote attackers might obtain sensitive information from php-cgi process memory by uploading a .php file, and might trigger unexpected code execution if a valid PHP script is in adjacent memory.
What the attacker needed
Ability to upload a .php file; PHP CGI using mmap to read the file
The fix
The flaw was fixed by a committed patch.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When PHP runs as a CGI program, it can read script files using a memory-mapping trick called mmap, which maps the file into memory. If the file is malformed in a specific way (starts with a hash and has no newline), PHP reads past the end of the mapped file, which is an out-of-bounds read. That can leak memory contents or, in rare cases, run code that happens to sit next to the file in memory.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.