New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 127417 link

Starred by 1 user

Issue metadata

Status: Fixed
Email to this user bounced
Closed: Dec 2012
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 1
Type: Bug-Security

  • Only users with EditIssue permission may comment.

Sign in to add a comment

Security: Arbitrary memory read in libxslt

Reported by, May 9 2012

Issue description


When parsing a XSLT stylesheet containing a DTD, a structure of type xmlEntity is accessed as another type. The value of cur->ns->href is then compared with a string. Given that this value is controlled by the attacker, it can access arbitrary memory locations.


Chrome: 18.0.1025.162
Chromium: 18.0.1025.151 (Build de développement 130497 Linux) Ubuntu 10.04

$ xsltproc --version
Using libxml 20706, libxslt 10126 and libexslt 815
xsltproc was compiled against libxml 20706, libxslt 10126 and libexslt 815
libxslt 10126 was compiled against libxml 20706
libexslt 815 was compiled against libxml 20706


#0  xmlStrEqual__internal_alias (str1=0x2a2a2a2a <Address 0x2a2a2a2a out of bounds>, 
    str2=0x1cf444 "") at xmlstring.c:162
#1  0x001aa384 in xsltParseTemplateContent (style=0x805cc58, templ=0x80598e8) at xslt.c:4849
#2  0x001ac824 in xsltParseStylesheetProcess (ret=0x805cc58, doc=0x80598e8) at xslt.c:6456
#3  0x001acd2c in xsltParseStylesheetImportedDoc (doc=0x80598e8, parentStyle=0x0) at xslt.c:6627
#4  0x001acddf in xsltParseStylesheetDoc (doc=0x80598e8) at xslt.c:6666
#5  0x0804a7f4 in main (argc=4, argv=0xbffff7e4) at xsltproc.c:830


When magic.xml is opened in a browser, it will load magic.xsl, trigger the bug and crash the current tab.


<!DOCTYPE whatever [
	<!ATTLIST magic blabla CDATA "anything">
	<!ENTITY foobar "abcd_efg****kl_mnop_qrst_uvwx_yzAB_CDEF_GHIK_KLMN_OPQR_STUV_WXYZ">
<magic xsl:version="1.0" xmlns:xsl=""/>


Once the XSL document is parsed, we get the following layout:

      type: xmlDoc
      name: magic.xsl

           | children
      XML_DTD_NODE  +---------------->  XML_ELEMENT_NODE
       type: xmlDtd                       type: xmlNode
       name: whatever                     name: magic

           |  children
     type: xmlAttribute                  type: xmlEntity
     name: blabla                        name: foobar

function xsltParseTemplateContent() at libxslt-1.1.26/libxslt/xslt.c:4830

4837     cur = templ->children;
=> "cur" points to a XML_DTD_NODE structure

4839     while (cur != NULL) {
=> 1st time we enter the "while" loop
4849         if (IS_XSLT_ELEM(cur)) {
=> neither the "if" or "else if" branchs are taken
4966         if (cur->children != NULL) {
4967             if (cur->children->type != XML_ENTITY_DECL) {
4968                 cur = cur->children;
4969                 continue;
4970             }
4971         }
=> "cur" now points to a XML_ATTRIBUTE_DECL structure

4839     while (cur != NULL) {
=> 2nd time we enter the "while" loop
4849         if (IS_XSLT_ELEM(cur)) {
=> neither the "if" or "else if" branchs are taken
4966         if (cur->children != NULL) {
=> "cur" has no child
4973         if (cur->next != NULL) {
4974             cur = cur->next;
4975             continue;
4976         }
=> "cur" now points to a XML_ENTITY_DECL structure

4839     while (cur != NULL) {
=> 3rd time we enter the "while" loop
4849         if (IS_XSLT_ELEM(cur)) {
=> "cur" is of type xmlEntity, which hasn't a "ns" entry
=> "cur->ns->href" points inside the entity value

From libxslt-1.1.26/libxslt/xsltutils.h:
54 #define IS_XSLT_ELEM(n)                                                 \
55     (((n) != NULL) && ((n)->ns != NULL) &&                              \
56      (xmlStrEqual((n)->ns->href, XSLT_NAMESPACE)))
=> crash in xmlStrEqual while dereferencing n->ns->href


It could be enough to test near line 4974 if "cur->next->type != XML_ENTITY_DECL". This wasn't tested.

232 bytes View Download
66 bytes Download
I'll deal with triage / fix of this.
The patch I proposed isn't sufficient. The problem occurs with ENTITY declarations (as shown before) but also with ELEMENT ones. However, ELEMENT will crash the program when reading fixed values near NULL (0x8 to 0xC, depending of the type of the element).

mov    eax,DWORD PTR [esi+0x24] => x->ns
mov    eax,DWORD PTR [eax+0x8]  => x->ns->href

struct _xmlNode {
    xmlNs           *ns;        /* pointer to the associated namespace */

struct _xmlNs {
    struct _xmlNs  *next;       /* next Ns link for this node  */
    xmlNsType      type;        /* global or local */
    const xmlChar *href;        /* URL for the namespace */
    const xmlChar *prefix;      /* prefix for the namespace */
    void           *_private;   /* application data */
    struct _xmlDoc *context;    /* normally an xmlDoc */

struct _xmlEntity {
    xmlChar         *orig;       /* content without ref substitution - Easy to control */

struct _xmlElement {
    xmlElementTypeVal      etype;       /* The type - Crash when dereferencing etype+8 */
280 bytes View Download
_private and context are controlled by the attacker, but I didn't find any interesting path (like free() or some pointers to functions).
34.4 KB View Download
29.1 KB View Download
Using (64 bits) and the same PoC => NULL deref in xmlStrEqual

==11454== ERROR: AddressSanitizer crashed on unknown address 0x000000000000 (pc 0x7f2ad81b644a sp 0x7fffc77e3940 bp 0x7fffc77e3940 T0)

    #0  0000000003f4f44a <xmlStrEqual+0x3a>:
 3f4f44a:       8a 00                   mov    (%rax),%al
    #1  xsltParseTemplateContent+0x36a
    #2  xsltParseStylesheetProcess+0x32b5
    #3  xsltParseStylesheetImportedDoc+0x495
    #4  xsltParseStylesheetDoc+0x1c
    #5  _ZN7WebCore13XSLStyleSheet17compileStyleSheetEv+0x28b
    #6  _ZN7WebCore13XSLTProcessor17transformToStringEPNS_4NodeERN3WTF6StringES5_S5_+0x4de
    #7  _ZN7WebCore8Document17applyXSLTransformEPNS_21ProcessingInstructionE+0x2cb
    #8  _ZN7WebCore8Document24collectActiveStylesheetsERN3WTF6VectorINS1_6RefPtrINS_10StyleSheetEEELm0EEE+0x183e
    #9  _ZN7WebCore8Document23updateActiveStylesheetsENS_23StyleSelectorUpdateFlagE+0x1c4
    #10  _ZN7WebCore8Document20styleSelectorChangedENS_23StyleSelectorUpdateFlagE+0x12b
    #11  _ZN7WebCore8Document18removePendingSheetEv+0x43
    #12  _ZN7WebCore21ProcessingInstruction11sheetLoadedEv+0xc3
    #13  _ZN7WebCore13XSLStyleSheet11checkLoadedEv+0xd1
    #14  _ZN7WebCore19CachedXSLStyleSheet11checkNotifyEv+0x21f
    #15  _ZN7WebCore19CachedXSLStyleSheet4dataEN3WTF10PassRefPtrINS_12SharedBufferEEEb+0x40b
    #16  _ZN7WebCore17SubresourceLoader16didFinishLoadingEd+0x23b
    #17  _ZN11webkit_glue16WebURLLoaderImpl7Context18OnCompletedRequestERKN3net16URLRequestStatusERKSsRKN4base9TimeTicksE+0x7f7

Labels: -Pri-0 -Area-Undefined Pri-1 Area-Internals SecImpacts-Stable SecImpacts-Beta OS-All Mstone-19
Status: Assigned
Labels: SecSeverity-Medium
Chris, please feel to fix the tags. Was doing some tag cleanup :)
Labels: -SecSeverity-Medium
Actually i shouldnt assign the severity, that is a bad practice without verifying.
Sorry I haven't gotten to this yet. It's getting near the top of the list. did you know that we offer reward "bonuses" for patches to security bugs? It sounds like you're well on top of the issue at a source-code level so perhaps you had a patch to propose?
Labels: reward-topanel
Daniel, here's another one. Sorry for taking so long to cc: you.

Comment 10 by, May 31 2012

The small attached patch should fix this, can you verify. Libxslt was
assuming element nodes at that level. At least this fixes the problem for me :-)

536 bytes View Download
Status: Started
Patch seems to work nicely here. I'll land it to Chromium.
Project Member

Comment 12 by, Jun 1 2012

The following revision refers to this bug:

r140041 | | Fri Jun 01 09:47:04 PDT 2012

Changed paths:

Fix crash with unexpected DTD nodes in XSLT.

BUG= 127417 
Review URL:
Labels: -Restrict-View-SecurityTeam -Mstone-19 Restrict-View-SecurityNotify Mstone-20 Merge-Approved
Status: FixUnreleased
Labels: -Merge-Approved Merge-Merged
Project Member

Comment 15 by, Jun 6 2012

Labels: merge-merged-1132
The following revision refers to this bug:

r140843 | | Wed Jun 06 14:41:54 PDT 2012

Changed paths:

Merge 140041 - Fix crash with unexpected DTD nodes in XSLT.

BUG= 127417 
Review URL:
Review URL:
Labels: -reward-topanel reward-500 reward-unpaid
@nicolas.gregoire: thanks for this bug! The arbitrary read might be useful in some exploit scenario therefore we'd be delighted to offer you a $500 Chromium Security Reward.

Boilerplate text:
Please do NOT publicly disclose details until a fix has been released to all our
users. Early public disclosure may cancel the provisional reward.
Also, please be considerate about disclosure when the bug affects a core library
that may be used by other products.
Please do NOT share this information with third parties who are not directly
involved in fixing the bug. Doing so may cancel the provisional reward.
Please be honest if you have already disclosed anything publicly or to third parties.
Labels: CVE-2012-2825
CC'ing Debian libxml maintainer.
Labels: -reward-unpaid
CC'ing Solaris libxml2 maintainer.
Project Member

Comment 21 by, Oct 14 2012

Labels: Restrict-AddIssueComment-Commit
This issue has been closed for some time. No one will pay attention to new comments.
If you are seeing this bug or have new data, please click New Issue to start a new bug.
Status: Fixed
Project Member

Comment 23 by, Mar 10 2013

Labels: -Type-Security -Area-Internals -SecImpacts-Stable -SecImpacts-Beta -Mstone-20 M-20 Security-Impact-Stable Security-Impact-Beta Cr-Internals Type-Bug-Security
Project Member

Comment 24 by, Mar 13 2013

Labels: Restrict-View-EditIssue
Project Member

Comment 25 by, Mar 14 2013

Labels: -Restrict-AddIssueComment-Commit Restrict-AddIssueComment-EditIssue
Labels: -Restrict-View-SecurityNotify -Restrict-View-EditIssue
Project Member

Comment 27 by, Mar 21 2013

Labels: -Security-Impact-Stable Security_Impact-Stable
Project Member

Comment 28 by, Mar 21 2013

Labels: -Security-Impact-Beta Security_Impact-Beta
Project Member

Comment 29 by, Jun 14 2016

Labels: -security_impact-beta
Project Member

Comment 30 by, Oct 1 2016

This bug has been closed for more than 14 weeks. Removing security view restrictions.

For more details visit - Your friendly Sheriffbot
Project Member

Comment 31 by, Oct 2 2016

This bug has been closed for more than 14 weeks. Removing security view restrictions.

For more details visit - Your friendly Sheriffbot
Labels: allpublic
Labels: CVE_description-submitted

Sign in to add a comment