com php-src: Fix bug #78599 (env_path_info underflow can lead to RCE) (CVE-2019-11043 ): NEWS sapi/fpm/fpm/fpm_main.c sapi/fpm/tests/bu
g78599-path-info-underflow.phpt sapi/fpm/tests/te ster.inc
| From: | Christoph Michael Becker | Date: | Tue, 22 Oct 2019 07:11:10 +0000 |
| Subject: | com php-src: Fix bug #78599 (env_path_info underflow can lead to RCE) (CVE-2019-11043 ): NEWS sapi/fpm/fpm/fpm_main.c sapi/fpm/tests/bu g78599-path-info-underflow.phpt sapi/fpm/tests/te ster.inc |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-108987@lists.php.net to get a copy of this message | ||
Commit: 19e17d3807e6cc0b1ba9443ec5facbd33a61f8fe
Author: Jakub Zelenka <bukka@php.net> Sat, 12 Oct 2019 15:56:16 +0100
Committer: Christoph M. Becker <cmbecker69@gmx.de> Tue, 22 Oct 2019 09:11:10 +0200
Parents: 12cca48ff67587e9aabaa41b80466cb9ff418d57
Branches: PHP-7.3..11
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=19e17d3807e6cc0b1ba9443ec5facbd33a61f8fe
Log:
Fix bug #78599 (env_path_info underflow can lead to RCE) (CVE-2019-11043)
(cherry picked from commit ab061f95ca966731b1c84cf5b7b20155c0a1c06a)
Bugs:
https://bugs.php.net/78599
Changed paths:
M NEWS
M sapi/fpm/fpm/fpm_main.c
A sapi/fpm/tests/bug78599-path-info-underflow.phpt
M sapi/fpm/tests/tester.inc
Diff:
diff --git a/NEWS b/NEWS
index 6231ff72ac9..c8e83940c94 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,8 @@ PHP NEWS
(Kalle)
- FPM:
+ . Fixed bug #78599 (env_path_info underflow in fpm_main.c can lead to RCE).
+ (CVE-2019-11043) (Jakub Zelenka)
. Fixed bug #78413 (request_terminate_timeout does not take effect after
fastcgi_finish_request). (Sergei Turchanov)
diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c
index 483fabe9d85..dfc0d8f7413 100644
--- a/sapi/fpm/fpm/fpm_main.c
+++ b/sapi/fpm/fpm/fpm_main.c
@@ -1148,8 +1148,8 @@ static void init_request_info(void)
path_info = script_path_translated + ptlen;
tflag = (slen != 0 && (!orig_path_info || strcmp(orig_path_info, path_info) != 0));
} else {
- path_info = env_path_info ? env_path_info + pilen - slen : NULL;
- tflag = (orig_path_info != path_info);
+ path_info = (env_path_info && pilen > slen) ? env_path_info + pilen - slen :
NULL;
+ tflag = path_info && (orig_path_info != path_info);
}
if (tflag) {
diff --git a/sapi/fpm/tests/bug78599-path-info-underflow.phpt
b/sapi/fpm/tests/bug78599-path-info-underflow.phpt
new file mode 100644
index 00000000000..edd4e0d4969
--- /dev/null
+++ b/sapi/fpm/tests/bug78599-path-info-underflow.phpt
@@ -0,0 +1,61 @@
+--TEST--
+FPM: bug78599 - env_path_info underflow - CVE-2019-11043
+--SKIPIF--
+<?php include "skipif.inc"; ?>
+--FILE--
+<?php
+
+require_once "tester.inc";
+
+$cfg = <<<EOT
+[global]
+error_log = {{FILE:LOG}}
+[unconfined]
+listen = {{ADDR}}
+pm = dynamic
+pm.max_children = 5
+pm.start_servers = 1
+pm.min_spare_servers = 1
+pm.max_spare_servers = 3
+EOT;
+
+$code = <<<EOT
+<?php
+echo "Test Start\n";
+var_dump(\$_SERVER["PATH_INFO"]);
+echo "Test End\n";
+EOT;
+
+$tester = new FPM\Tester($cfg, $code);
+$tester->start();
+$tester->expectLogStartNotices();
+$uri = $tester->makeSourceFile();
+$tester
+ ->request(
+ '',
+ [
+ 'SCRIPT_FILENAME' => $uri . "/" . str_repeat('A', 35),
+ 'PATH_INFO' => '',
+ 'HTTP_HUI' => str_repeat('PTEST', 1000),
+ ],
+ $uri
+ )
+ ->expectBody(
+ [
+ 'Test Start',
+ 'string(0) ""',
+ 'Test End'
+ ]
+ );
+$tester->terminate();
+$tester->close();
+
+?>
+Done
+--EXPECT--
+Done
+--CLEAN--
+<?php
+require_once "tester.inc";
+FPM\Tester::clean();
+?>
diff --git a/sapi/fpm/tests/tester.inc b/sapi/fpm/tests/tester.inc
index 001b7d6a54e..188fd488594 100644
--- a/sapi/fpm/tests/tester.inc
+++ b/sapi/fpm/tests/tester.inc
@@ -513,7 +513,7 @@ class Tester
return new Response(null, true);
}
if (is_null($uri)) {
- $uri = $this->makeFile('src.php', $this->code);
+ $uri = $this->makeSourceFile();
}
$params = array_merge(
@@ -538,7 +538,6 @@ class Tester
],
$headers
);
-
try {
$this->response = new Response(
$this->getClient($address, $connKeepAlive)->request_data($params, false)
@@ -945,6 +944,14 @@ class Tester
}
/**
+ * @return string
+ */
+ public function makeSourceFile()
+ {
+ return $this->makeFile('src.php', $this->code);
+ }
+
+ /**
* @param string|null $msg
*/
private function message($msg)