Blame SOURCES/php-5.6.5-CVE-2015-6831.patch

925b0d
From 7381b6accc5559b2de039af3a22f6ec1003b03b3 Mon Sep 17 00:00:00 2001
925b0d
From: Stanislav Malyshev <stas@php.net>
925b0d
Date: Sat, 1 Aug 2015 21:45:19 -0700
925b0d
Subject: [PATCH] Fixed bug #70166 - Use After Free Vulnerability in
925b0d
 unserialize() with SPLArrayObject
925b0d
925b0d
---
925b0d
 ext/spl/spl_array.c         |  3 +++
925b0d
 ext/spl/tests/bug70166.phpt | 29 +++++++++++++++++++++++++++++
925b0d
 2 files changed, 32 insertions(+)
925b0d
 create mode 100644 ext/spl/tests/bug70166.phpt
925b0d
925b0d
diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c
925b0d
index a37eced..86608c0 100644
925b0d
--- a/ext/spl/spl_array.c
925b0d
+++ b/ext/spl/spl_array.c
925b0d
@@ -1773,6 +1773,7 @@ SPL_METHOD(Array, unserialize)
925b0d
 		goto outexcept;
925b0d
 	}
925b0d
 
925b0d
+	var_push_dtor(&var_hash, &pflags);
925b0d
 	--p; /* for ';' */
925b0d
 	flags = Z_LVAL_P(pflags);
925b0d
 	/* flags needs to be verified and we also need to verify whether the next
925b0d
@@ -1796,6 +1797,7 @@ SPL_METHOD(Array, unserialize)
925b0d
 		if (!php_var_unserialize(&intern->array, &p, s + buf_len, &var_hash TSRMLS_CC)) {
925b0d
 			goto outexcept;
925b0d
 		}
925b0d
+		var_push_dtor(&var_hash, &intern->array);
925b0d
 	}
925b0d
 	if (*p != ';') {
925b0d
 		goto outexcept;
925b0d
@@ -1814,6 +1816,7 @@ SPL_METHOD(Array, unserialize)
925b0d
 		goto outexcept;
925b0d
 	}
925b0d
 
925b0d
+	var_push_dtor(&var_hash, &pmembers);
925b0d
 	/* copy members */
925b0d
 	if (!intern->std.properties) {
925b0d
 		rebuild_object_properties(&intern->std);
925b0d
diff --git a/ext/spl/tests/bug70166.phpt b/ext/spl/tests/bug70166.phpt
925b0d
new file mode 100644
925b0d
index 0000000..51a3596
925b0d
--- /dev/null
925b0d
+++ b/ext/spl/tests/bug70166.phpt
925b0d
@@ -0,0 +1,29 @@
925b0d
+--TEST--
925b0d
+SPL: Bug #70166 Use After Free Vulnerability in unserialize() with SPLArrayObject
925b0d
+--FILE--
925b0d
+
925b0d
+$inner = 'x:i:1;a:0:{};m:a:0:{}';
925b0d
+$exploit = 'a:2:{i:0;C:11:"ArrayObject":'.strlen($inner).':{'.$inner.'}i:1;R:5;}';
925b0d
+
925b0d
+$data = unserialize($exploit);
925b0d
+
925b0d
+for($i = 0; $i < 5; $i++) {
925b0d
+    $v[$i] = 'hi'.$i;
925b0d
+}
925b0d
+
925b0d
+var_dump($data);
925b0d
+?>
925b0d
+===DONE===
925b0d
+--EXPECTF--
925b0d
+array(2) {
925b0d
+  [0]=>
925b0d
+  object(ArrayObject)#%d (1) {
925b0d
+    ["storage":"ArrayObject":private]=>
925b0d
+    array(0) {
925b0d
+    }
925b0d
+  }
925b0d
+  [1]=>
925b0d
+  array(0) {
925b0d
+  }
925b0d
+}
925b0d
+===DONE===
925b0d
-- 
925b0d
2.1.4
925b0d
925b0d
From c2e197e4efc663ca55f393bf0e799848842286f3 Mon Sep 17 00:00:00 2001
925b0d
From: Stanislav Malyshev <stas@php.net>
925b0d
Date: Sat, 1 Aug 2015 21:12:38 -0700
925b0d
Subject: [PATCH] Fix bug #70168 - Use After Free Vulnerability in
925b0d
 unserialize() with SplObjectStorage
925b0d
925b0d
---
925b0d
 ext/spl/spl_observer.c      | 68 +++++++++++++++++++++++----------------------
925b0d
 ext/spl/tests/bug70168.phpt | 19 +++++++++++++
925b0d
 2 files changed, 54 insertions(+), 33 deletions(-)
925b0d
 create mode 100644 ext/spl/tests/bug70168.phpt
925b0d
925b0d
diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c
925b0d
index da9110b..5d94a3b 100644
925b0d
--- a/ext/spl/spl_observer.c
925b0d
+++ b/ext/spl/spl_observer.c
925b0d
@@ -848,6 +848,7 @@ SPL_METHOD(SplObjectStorage, unserialize
925b0d
 		goto outexcept;
925b0d
 	}
925b0d
 
925b0d
+	var_push_dtor(&var_hash, &pcount);
925b0d
 	--p; /* for ';' */
925b0d
 	count = Z_LVAL_P(pcount);
925b0d
 		
925b0d
@@ -919,6 +920,7 @@ SPL_METHOD(SplObjectStorage, unserialize
925b0d
 		goto outexcept;
925b0d
 	}
925b0d
 
925b0d
+	var_push_dtor(&var_hash, &pmembers);
925b0d
 	/* copy members */
925b0d
 	if (!intern->std.properties) {
925b0d
 		rebuild_object_properties(&intern->std);
925b0d
diff --git a/ext/spl/tests/bug70168.phpt b/ext/spl/tests/bug70168.phpt
925b0d
new file mode 100644
925b0d
index 0000000..192f0f3
925b0d
--- /dev/null
925b0d
+++ b/ext/spl/tests/bug70168.phpt
925b0d
@@ -0,0 +1,19 @@
925b0d
+--TEST--
925b0d
+SPL: Bug #70168 Use After Free Vulnerability in unserialize() with SplObjectStorage
925b0d
+--FILE--
925b0d
+
925b0d
+$inner = 'x:i:1;O:8:"stdClass":0:{};m:a:0:{}';
925b0d
+$exploit = 'a:2:{i:0;C:16:"SplObjectStorage":'.strlen($inner).':{'.$inner.'}i:1;R:3;}';
925b0d
+
925b0d
+$data = unserialize($exploit);
925b0d
+
925b0d
+for($i = 0; $i < 5; $i++) {
925b0d
+    $v[$i] = 'hi'.$i;
925b0d
+}
925b0d
+
925b0d
+var_dump($data[1]);
925b0d
+?>
925b0d
+===DONE===
925b0d
+--EXPECT--
925b0d
+int(1)
925b0d
+===DONE===
925b0d
-- 
925b0d
2.1.4
925b0d
925b0d
From 863bf294feb9ad425eadb94f288bc7f18673089d Mon Sep 17 00:00:00 2001
925b0d
From: Stanislav Malyshev <stas@php.net>
925b0d
Date: Sat, 1 Aug 2015 21:51:08 -0700
925b0d
Subject: [PATCH] Fixed bug #70169 (Use After Free Vulnerability in
925b0d
 unserialize() with SplDoublyLinkedList)
925b0d
925b0d
---
925b0d
 ext/spl/spl_dllist.c        | 25 +++++++++++++------------
925b0d
 ext/spl/tests/bug70169.phpt | 30 ++++++++++++++++++++++++++++++
925b0d
 2 files changed, 43 insertions(+), 12 deletions(-)
925b0d
 create mode 100644 ext/spl/tests/bug70169.phpt
925b0d
925b0d
diff --git a/ext/spl/spl_dllist.c b/ext/spl/spl_dllist.c
925b0d
index b5ddfc0..011d7a6 100644
925b0d
--- a/ext/spl/spl_dllist.c
925b0d
+++ b/ext/spl/spl_dllist.c
925b0d
@@ -1207,6 +1207,7 @@ SPL_METHOD(SplDoublyLinkedList, unserialize)
925b0d
 		zval_ptr_dtor(&flags);
925b0d
 		goto error;
925b0d
 	}
925b0d
+	var_push_dtor(&var_hash, &flags);
925b0d
 	intern->flags = Z_LVAL_P(flags);
925b0d
 	zval_ptr_dtor(&flags);
925b0d
 
925b0d
diff --git a/ext/spl/tests/bug70169.phpt b/ext/spl/tests/bug70169.phpt
925b0d
new file mode 100644
925b0d
index 0000000..9d814be
925b0d
--- /dev/null
925b0d
+++ b/ext/spl/tests/bug70169.phpt
925b0d
@@ -0,0 +1,30 @@
925b0d
+--TEST--
925b0d
+SPL: Bug #70169	Use After Free Vulnerability in unserialize() with SplDoublyLinkedList
925b0d
+--FILE--
925b0d
+
925b0d
+$inner = 'i:1;';
925b0d
+$exploit = 'a:2:{i:0;C:19:"SplDoublyLinkedList":'.strlen($inner).':{'.$inner.'}i:1;R:3;}';
925b0d
+
925b0d
+$data = unserialize($exploit);
925b0d
+
925b0d
+for($i = 0; $i < 5; $i++) {
925b0d
+    $v[$i] = 'hi'.$i;
925b0d
+}
925b0d
+
925b0d
+var_dump($data);
925b0d
+?>
925b0d
+===DONE===
925b0d
+--EXPECTF--
925b0d
+array(2) {
925b0d
+  [0]=>
925b0d
+  object(SplDoublyLinkedList)#%d (2) {
925b0d
+    ["flags":"SplDoublyLinkedList":private]=>
925b0d
+    int(1)
925b0d
+    ["dllist":"SplDoublyLinkedList":private]=>
925b0d
+    array(0) {
925b0d
+    }
925b0d
+  }
925b0d
+  [1]=>
925b0d
+  int(1)
925b0d
+}
925b0d
+===DONE===
925b0d
-- 
925b0d
2.1.4
925b0d