|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Sec Bug #68710 Use After Free Vulnerability in PHP's unserialize() (Still Exploitable)
Submitted: 2015-01-01 22:35 UTC Modified: 2015-02-10 15:27 UTC
From: Assigned: stas
Status: Closed Package: Reproducible crash
PHP Version: 5.4Git-2015-01-01 (Git) OS: *
Private report: No CVE-ID: 2015-0231
 [2015-01-01 22:35 UTC]
Reported by


today I wanted to write a write up of the use after free vulnerability
in unserialize() that was fixed last month. Remember: I reported it on
2nd December, sent in a patch on 10th December, because Julien Pauli
asked for one. You later released updates. Unfortunately around that
time I was too busy to actually look into what you released and in a way
I thought it would be not necessary, because I sent in the correct patch.

However today I see that you changed my patch. Instead of using my
correct patch, you applied the following wrong patch.

        } else {
            /* object properties should include no integers */
            if (zend_symtable_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key)
+ 1, (void **)&old_data)==SUCCESS) {
                var_push_dtor(var_hash, old_data);
            zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1,
                    sizeof data, NULL);

There is a small but important difference to the patch I sent on 10th
December. You use zend_symtable_find instead of zend_hash_find from my
patch. Because of this change the fix is incomplete. It now detects
attacks that try to replace a key like "AAA", but it does not fix
attacks where the key is a numerical string like "123".

The reason for this is that we do not want integer keys in objects. That
is why the code was added in the first place. The object properties are
therefore inserted via zend_hash_update, instead of
zend_symtable_update. Therefore something like "123" will be inserted as
a string and not as a numerical 123. On the attempt to do the overwrite
attack you now check with zend_symtable_find(). This function will turn
the "123" into a numerical "123" and therefore not see that it is
already there. The protection will not be executed and therefore the
attack works in the same way as before.

Here is the updated diff that shows how the code is still vulnerable to
a slightly modified form of the attack:

Bug #XXXXX Use after free vulnerability in unserialize() (bypassing the
CVE-2014-8142 fix)
for ($i=4; $i<100; $i++) {
    $m = new StdClass();

    $u = array(1);

    $m->aaa = array(1,2,&$u,4,5);
    $m->bbb = 1;
    $m->ccc = &$u;
    $m->ddd = str_repeat("A", $i);

    $z = serialize($m);
    $z = str_replace("aaa", "123", $z);
    $z = str_replace("bbb", "123", $z);
    $y = unserialize($z);
    $z = serialize($y);

Please advice me of the new CVE for the previously incorrectly fixed
problem and a proposed timeframe for disclosure.

PS: I also advice educating the RedHat people, who get this information
forwarded so that they understand the seriousness of remote code
execution in unserialize(). Just because the manual says: bad idea does
not make it go away. Wordpress does still in 2015 unserialize() data
they pull over the network from their server. (Okay if possible they use
SSL for that, but we know for 1-2 years now that there are a bunch of
attackers capable of doing SSL MITM in the wild - nation state or just
another broken in-CA). And Wordpress is just one of so many examples.
Especially if you go away from OpenSource Code and look at all the
self-made websites/self-made CMSes that we see when auditing real world

Kind regards and a productive 2015,
Stefan Esser


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-03 00:52 UTC]
-Summary: se After Free Vulnerability in PHP's unserialize() (Still Exploitable) +Summary: Use After Free Vulnerability in PHP's unserialize() (Still Exploitable)
 [2015-01-19 05:09 UTC]
-CVE-ID: +CVE-ID: 2015-0231
 [2015-01-20 21:32 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: stas
 [2015-01-20 21:32 UTC]
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

 [2015-02-10 15:24 UTC]
-Private report: No +Private report: Yes
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Fri Jul 28 08:01:47 2017 UTC