Fix use-after-free when __clone() retains the stylesheet copy - #23199
Open
iliaal wants to merge 1 commit into
Open
Fix use-after-free when __clone() retains the stylesheet copy#23199iliaal wants to merge 1 commit into
iliaal wants to merge 1 commit into
Conversation
importStylesheet() clones the stylesheet document and hands the copy to libxslt, which owns it and frees it together with the stylesheet. The clone goes through zend_objects_clone_members(), so a DOMDocument subclass __clone() can retain the copy, or a node proxy into it, and dereference freed memory once the processor is destroyed. Require the clone to be exclusively owned before libxslt takes it.
devnexen
reviewed
Aug 10, 2026
|
|
||
| if (GC_REFCOUNT(clone) > 1 || clone_lxml_obj->document->refcount > 1) { | ||
| OBJ_RELEASE(clone); | ||
| zend_throw_error(NULL, "XSLTProcessor::importStylesheet(): Argument #1 ($stylesheet) must not have its clone retained by __clone()"); |
Member
There was a problem hiding this comment.
after giving some thoughts, zend_argument_value_error is more appropriate here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
XSLTProcessor::importStylesheet()clones the stylesheet document through the object's clone handler and hands the copy to libxslt, which frees it with the stylesheet. ADOMDocumentsubclass__clone()runs while that copy is fully wired up and can stash either the copy itself or a node proxy into it, leaving a dangling pointer once the processor is destroyed. The clone must now be exclusively owned before libxslt takes it.That aborts with a double free on 8.4, 8.5 and master. Stashing
$this->documentElementinstead gives a silent read of freed memory indom_objects_free_storage. 8.3 is unaffected because it copies at the libxml level and never builds a PHP object for the copy.