com php-src: Fix bug #70365 - use-after-free vulnerability in unserialize() with SplObjectStorage: ext/spl/spl_observer.c ext/spl/tes ts/bug70365.phpt
| From: | Stanislav Malyshev | Date: | Tue, 01 Sep 2015 07:14:15 +0000 |
| Subject: | com php-src: Fix bug #70365 - use-after-free vulnerability in unserialize() with SplObjectStorage: ext/spl/spl_observer.c ext/spl/tes ts/bug70365.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-88824@lists.php.net to get a copy of this message | ||
Commit: f06a069c462d37c2e009f6d1d93b8c8e7b713393
Author: Stanislav Malyshev <stas@php.net> Tue, 1 Sep 2015 00:14:15 -0700
Parents: e8429400d40e3c3aa4b22ba701991d698a2f3b2f
Branches: PHP-5.4 PHP-5.4.45
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=f06a069c462d37c2e009f6d1d93b8c8e7b713393
Log:
Fix bug #70365 - use-after-free vulnerability in unserialize() with SplObjectStorage
Bugs:
https://bugs.php.net/70365
Changed paths:
M ext/spl/spl_observer.c
A ext/spl/tests/bug70365.phpt
Diff:
diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c
index 5d94a3b..6a2e321 100644
--- a/ext/spl/spl_observer.c
+++ b/ext/spl/spl_observer.c
@@ -853,6 +853,7 @@ SPL_METHOD(SplObjectStorage, unserialize)
zval_ptr_dtor(&pentry);
goto outexcept;
}
+ var_push_dtor(&var_hash, &pentry);
if(Z_TYPE_P(pentry) != IS_OBJECT) {
zval_ptr_dtor(&pentry);
goto outexcept;
@@ -864,6 +865,7 @@ SPL_METHOD(SplObjectStorage, unserialize)
zval_ptr_dtor(&pinf);
goto outexcept;
}
+ var_push_dtor(&var_hash, &pinf);
}
hash = spl_object_storage_get_hash(intern, getThis(), pentry, &hash_len TSRMLS_CC);
diff --git a/ext/spl/tests/bug70365.phpt b/ext/spl/tests/bug70365.phpt
new file mode 100644
index 0000000..bd57360
--- /dev/null
+++ b/ext/spl/tests/bug70365.phpt
@@ -0,0 +1,50 @@
+--TEST--
+SPL: Bug #70365 yet another use-after-free vulnerability in unserialize() with SplObjectStorage
+--FILE--
+<?php
+class obj {
+ var $ryat;
+ function __wakeup() {
+ $this->ryat = 1;
+ }
+}
+
+$fakezval = ptr2str(1122334455);
+$fakezval .= ptr2str(0);
+$fakezval .= "\x00\x00\x00\x00";
+$fakezval .= "\x01";
+$fakezval .= "\x00";
+$fakezval .= "\x00\x00";
+
+$inner = 'x:i:1;O:8:"stdClass":0:{},i:1;;m:a:0:{}';
+$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.'";}';
+
+$data = unserialize($exploit);
+
+var_dump($data);
+
+function ptr2str($ptr)
+{
+ $out = '';
+ for ($i = 0; $i < 8; $i++) {
+ $out .= chr($ptr & 0xff);
+ $ptr >>= 8;
+ }
+ return $out;
+}
+--EXPECTF--
+array(5) {
+ [0]=>
+ int(1)
+ [1]=>
+ &int(1)
+ [2]=>
+ object(obj)#%d (1) {
+ ["ryat"]=>
+ &int(1)
+ }
+ [3]=>
+ int(1)
+ [4]=>
+ string(24) "%s"
+}