Blame SOURCES/php-5.6.5-CVE-2015-6834-2.patch

925b0d
From f06a069c462d37c2e009f6d1d93b8c8e7b713393 Mon Sep 17 00:00:00 2001
925b0d
From: Stanislav Malyshev <stas@php.net>
925b0d
Date: Tue, 1 Sep 2015 00:14:15 -0700
925b0d
Subject: [PATCH] Fix bug #70365 - use-after-free vulnerability in
925b0d
 unserialize() with SplObjectStorage
925b0d
925b0d
---
925b0d
 ext/spl/spl_observer.c      |  2 ++
925b0d
 ext/spl/tests/bug70365.phpt | 50 +++++++++++++++++++++++++++++++++++++++++++++
925b0d
 2 files changed, 52 insertions(+)
925b0d
 create mode 100644 ext/spl/tests/bug70365.phpt
925b0d
925b0d
diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c
925b0d
index 5d94a3b..6a2e321 100644
925b0d
--- a/ext/spl/spl_observer.c
925b0d
+++ b/ext/spl/spl_observer.c
925b0d
@@ -869,6 +869,7 @@ SPL_METHOD(SplObjectStorage, unserialize)
925b0d
 			zval_ptr_dtor(&pentry);
925b0d
 			goto outexcept;
925b0d
 		}
925b0d
+		var_push_dtor(&var_hash, &pentry);
925b0d
 		if(Z_TYPE_P(pentry) != IS_OBJECT) {
925b0d
 			zval_ptr_dtor(&pentry);
925b0d
 			goto outexcept;
925b0d
@@ -880,6 +881,7 @@ SPL_METHOD(SplObjectStorage, unserialize)
925b0d
 				zval_ptr_dtor(&pinf);
925b0d
 				goto outexcept;
925b0d
 			}
925b0d
+			var_push_dtor(&var_hash, &pinf);
925b0d
 		}
925b0d
 
925b0d
 		hash = spl_object_storage_get_hash(intern, getThis(), pentry, &hash_len TSRMLS_CC);
925b0d
diff --git a/ext/spl/tests/bug70365.phpt b/ext/spl/tests/bug70365.phpt
925b0d
new file mode 100644
925b0d
index 0000000..bd57360
925b0d
--- /dev/null
925b0d
+++ b/ext/spl/tests/bug70365.phpt
925b0d
@@ -0,0 +1,50 @@
925b0d
+--TEST--
925b0d
+SPL: Bug #70365 yet another use-after-free vulnerability in unserialize() with SplObjectStorage
925b0d
+--FILE--
925b0d
+
925b0d
+class obj {
925b0d
+	var $ryat;
925b0d
+	function __wakeup() {
925b0d
+		$this->ryat = 1;
925b0d
+	}
925b0d
+}
925b0d
+
925b0d
+$fakezval = ptr2str(1122334455);
925b0d
+$fakezval .= ptr2str(0);
925b0d
+$fakezval .= "\x00\x00\x00\x00";
925b0d
+$fakezval .= "\x01";
925b0d
+$fakezval .= "\x00";
925b0d
+$fakezval .= "\x00\x00";
925b0d
+
925b0d
+$inner = 'x:i:1;O:8:"stdClass":0:{},i:1;;m:a:0:{}';
925b0d
+$exploit = 'a:5:{i:0;i:1;i:1;C:16:"SplObjectStorage":'.strlen($inner).':{'.$inner.'}i:2;O:3:"obj":1:{s:4:"ryat";R:3;}i:3;R:6;i:4;s:'.strlen($fakezval).':"'.$fakezval.'";}';
925b0d
+
925b0d
+$data = unserialize($exploit);
925b0d
+
925b0d
+var_dump($data);
925b0d
+
925b0d
+function ptr2str($ptr)
925b0d
+{
925b0d
+	$out = '';
925b0d
+	for ($i = 0; $i < 8; $i++) {
925b0d
+		$out .= chr($ptr & 0xff);
925b0d
+		$ptr >>= 8;
925b0d
+	}
925b0d
+	return $out;
925b0d
+}
925b0d
+--EXPECTF--
925b0d
+array(5) {
925b0d
+  [0]=>
925b0d
+  int(1)
925b0d
+  [1]=>
925b0d
+  &int(1)
925b0d
+  [2]=>
925b0d
+  object(obj)#%d (1) {
925b0d
+    ["ryat"]=>
925b0d
+    &int(1)
925b0d
+  }
925b0d
+  [3]=>
925b0d
+  int(1)
925b0d
+  [4]=>
925b0d
+  string(24) "%s"
925b0d
+}
925b0d
-- 
925b0d
2.1.4
925b0d
925b0d
From 259057b2a484747a6c73ce54c4fa0f5acbd56179 Mon Sep 17 00:00:00 2001
925b0d
From: Stanislav Malyshev <stas@php.net>
925b0d
Date: Tue, 1 Sep 2015 00:20:45 -0700
925b0d
Subject: [PATCH] Fix bug #70366 - use-after-free vulnerability in
925b0d
 unserialize() with SplDoublyLinkedList
925b0d
925b0d
---
925b0d
 ext/spl/spl_dllist.c        |  1 +
925b0d
 ext/spl/tests/bug70365.phpt |  2 +-
925b0d
 ext/spl/tests/bug70366.phpt | 54 +++++++++++++++++++++++++++++++++++++++++++++
925b0d
 3 files changed, 56 insertions(+), 1 deletion(-)
925b0d
 create mode 100644 ext/spl/tests/bug70366.phpt
925b0d
925b0d
diff --git a/ext/spl/spl_dllist.c b/ext/spl/spl_dllist.c
925b0d
index 011d7a6..ebe61c3 100644
925b0d
--- a/ext/spl/spl_dllist.c
925b0d
+++ b/ext/spl/spl_dllist.c
925b0d
@@ -1219,6 +1219,7 @@ SPL_METHOD(SplDoublyLinkedList, unserialize)
925b0d
 			zval_ptr_dtor(&elem);
925b0d
 			goto error;
925b0d
 		}
925b0d
+		var_push_dtor(&var_hash, &elem);
925b0d
 
925b0d
 		spl_ptr_llist_push(intern->llist, elem TSRMLS_CC);
925b0d
 	}
925b0d
diff --git a/ext/spl/tests/bug70365.phpt b/ext/spl/tests/bug70365.phpt
925b0d
index bd57360..c18110e 100644
925b0d
--- a/ext/spl/tests/bug70365.phpt
925b0d
+++ b/ext/spl/tests/bug70365.phpt
925b0d
@@ -1,5 +1,5 @@
925b0d
 --TEST--
925b0d
-SPL: Bug #70365 yet another use-after-free vulnerability in unserialize() with SplObjectStorage
925b0d
+SPL: Bug #70365 use-after-free vulnerability in unserialize() with SplObjectStorage
925b0d
 --FILE--
925b0d
 
925b0d
 class obj {
925b0d
diff --git a/ext/spl/tests/bug70366.phpt b/ext/spl/tests/bug70366.phpt
925b0d
new file mode 100644
925b0d
index 0000000..c9aa584
925b0d
--- /dev/null
925b0d
+++ b/ext/spl/tests/bug70366.phpt
925b0d
@@ -0,0 +1,54 @@
925b0d
+--TEST--
925b0d
+SPL: Bug #70366 use-after-free vulnerability in unserialize() with SplDoublyLinkedList
925b0d
+--FILE--
925b0d
+
925b0d
+class obj {
925b0d
+	var $ryat;
925b0d
+	function __wakeup() {
925b0d
+		$this->ryat = 1;
925b0d
+	}
925b0d
+}
925b0d
+
925b0d
+$fakezval = ptr2str(1122334455);
925b0d
+$fakezval .= ptr2str(0);
925b0d
+$fakezval .= "\x00\x00\x00\x00";
925b0d
+$fakezval .= "\x01";
925b0d
+$fakezval .= "\x00";
925b0d
+$fakezval .= "\x00\x00";
925b0d
+
925b0d
+$inner = 'i:1234;:i:1;';
925b0d
+$exploit = 'a:5:{i:0;i:1;i:1;C:19:"SplDoublyLinkedList":'.strlen($inner).':{'.$inner.'}i:2;O:3:"obj":1:{s:4:"ryat";R:3;}i:3;a:1:{i:0;R:5;}i:4;s:'.strlen($fakezval).':"'.$fakezval.'";}';
925b0d
+
925b0d
+$data = unserialize($exploit);
925b0d
+
925b0d
+var_dump($data);
925b0d
+
925b0d
+function ptr2str($ptr)
925b0d
+{
925b0d
+	$out = '';
925b0d
+	for ($i = 0; $i < 8; $i++) {
925b0d
+		$out .= chr($ptr & 0xff);
925b0d
+		$ptr >>= 8;
925b0d
+	}
925b0d
+	return $out;
925b0d
+}
925b0d
+?>
925b0d
+--EXPECTF--
925b0d
+array(5) {
925b0d
+  [0]=>
925b0d
+  int(1)
925b0d
+  [1]=>
925b0d
+  &int(1)
925b0d
+  [2]=>
925b0d
+  object(obj)#%d (1) {
925b0d
+    ["ryat"]=>
925b0d
+    &int(1)
925b0d
+  }
925b0d
+  [3]=>
925b0d
+  array(1) {
925b0d
+    [0]=>
925b0d
+    int(1)
925b0d
+  }
925b0d
+  [4]=>
925b0d
+  string(24) "%s"
925b0d
+}
925b0d
\ No newline at end of file
925b0d
-- 
925b0d
2.1.4
925b0d