Skip to content
DoS Disclosed report Advanced CVE-2017-7753

logical property on pseudo-element that disallows it (e.g., border-inline-* on ::first-line) causes access violation at 0x14141414

A CSS rule that applies a logical border property to the ::first-line pseudo-element, which does not support it, causes a corrupted style data entry. When the class is toggled, Firefox dereferences a pointer with the value 0x14141414, leading to an access violation and crash.

SkyLined Follow

Originally disclosed on Mozilla

  • Fixed in 3 months
  • Paid in 41 days
  • Disclosed after 3 months
Text
Created attachment 8854374
repro.html

Repro:

<html>
  <head>
    <style id=style>
      * {
        float:left;
      }
      ::first-line {
        border-inline-start: 0;
      }
      .boom ::first-line {
        border: 0;
      }
    </style>
    <script>
      onload = function() {
        document.body.className="boom";
        document.body.offsetTop;
        alert("Click OK to crash Firefox");
        document.body.className="x";
        // On x64, this causes an AV, but not on x86:
        document.body.offsetTop;
        // On x86, this code is reached. Refreshing the page appears to 
        // trigger the AV the next time the page shows the alert.
        location.reload();
      };
    </script>
  </head>
  <body>
    <x>x</x>
  </body>
</html>

Applying and removing the `nsRuleNode` for class "boom" appears to cause the code to attempt to apply the `nsConditionalResetStyleData` for the `nsRuleNode` with a "border-inline-start" property. This data is corrupt in that the `nsConditionalResetStyleData::Entry` instance at index 9 of the `mEntries` property (which deals with CSS border properties) has an `mStyleStruct` member that has the value 0x14141414 (x86) or 0x14141414`14141414 (x64). This causes an AV when the code calls `nsStyleBorder::CalcDifference` with this values as its `aNewData` argument, as that code assumes it is given a pointer to a valid `nsStyleVariables` instance and attempts to access members of this object.

I've attempted to find out where this value comes from by looking at various functions in the call stack at the time of the AV, but it appears to have been created before the JavaScript that causes the AV is executed.

I've also set breakpoints on various functions that create various objects implicated in this bug, before running the repro, but my understanding of Firefox CSS internals is limited, and I was unable to find out where this value comes from and why.

I hope somebody with better understanding of how the code is supposed to work can figure out if this is some kind of "magic value" that is not being special cased correctly, or if it's a type confusion where data from a different kind of object is incorrectly interpreted as containing a pointer where it has the value seen in the crash, or something else entirely.

The original report as published on Mozilla's Bugzilla, by SkyLined. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

The original is short, so this covers everything it reports, then explains this kind of bug in general: how it works, how to test for it and how it is fixed. The general sections are about the bug class, not this target. Written with AI and checked against the original; the original is the record. 4 min read.

What the report shows

The target is Firefox's CSS parsing and computation code, specifically the handling of nsRuleNode and nsConditionalResetStyleData when style rules are applied and removed. The researcher, SkyLined, filed the report against Mozilla and it was disclosed on 6 July 2017 with a severity of high. The report does not describe a fix or a bounty amount.

The trigger is a small HTML page that combines a universal float:left rule, a ::first-line rule setting border-inline-start, and a class-scoped ::first-line rule setting border. The full repro is:

HTML
<html>
  <head>
    <style id=style>
      * {
        float:left;
      }
      ::first-line {
        border-inline-start: 0;
      }
      .boom ::first-line {
        border: 0;
      }
    </style>
    <script>
      onload = function() {
        document.body.className="boom";
        document.body.offsetTop;
        alert("Click OK to crash Firefox");
        document.body.className="x";
        // On x64, this causes an AV, but not on x86:
        document.body.offsetTop;
        // On x86, this code is reached. Refreshing the page appears to
        // trigger the AV the next time the page shows the alert.
        location.reload();
      };
    </script>
  </head>
  <body>
    <x>x</x>
  </body>
</html>

The steps are:

  1. On load, the script sets document.body.className to boom, which makes the .boom ::first-line rule match.
  2. It reads document.body.offsetTop to force a style and layout flush.
  3. It shows an alert, then sets the class to x and reads offsetTop again.
  4. On x64 this second flush causes an access violation. On x86 the code continues to location.reload(), and refreshing the page appears to trigger the access violation the next time the alert is shown.

The researcher's analysis is that applying and removing the nsRuleNode for class boom causes the code to try to apply the nsConditionalResetStyleData of the nsRuleNode carrying the border-inline-start property. That data is corrupt: the nsConditionalResetStyleData::Entry at index 9 of the mEntries property, the entry dealing with CSS border properties, has an mStyleStruct member holding 0x14141414 on x86 or 0x14141414141414 on x64. The access violation happens when nsStyleBorder::CalcDifference is called with that value as its aNewData argument, because the code assumes it is a valid nsStyleVariables instance and dereferences its members.

The researcher could not establish where the value originates. Breakpoints on the functions in the call stack and on the functions that create the implicated objects did not reveal it, and the value appears to have been created before the JavaScript that triggers the crash runs. The report closes by asking whether this is a magic value that is not special-cased correctly, a type confusion where data from another object kind is read as a pointer, or something else.

Root cause

One possibility the researcher raises is a mismatch between the property a conditional reset style entry was built for and the property the code later treats it as. The entry at index 9 is described as dealing with CSS border properties, yet CalcDifference is invoked as though the stored struct were an nsStyleVariables instance. The researcher asks whether this is a sentinel value that is not recognised before being dereferenced, a type confusion, or something else. The report does not identify the exact code path that produces the value.

Impact

What the report demonstrates is a crash: an access violation reachable from a web page through CSS alone, with no script privilege beyond setting a class name. The researcher frames the open question as whether this is a magic value mishandled or a type confusion. The report does not claim exploitability beyond the crash.

How this kind of bug works

Browsers cache computed style in per-node structures and share them aggressively. When a rule stops matching, the engine must undo the properties that rule contributed, which is what conditional reset data is for: it records which structs need to be reset when a rule node is removed. Bugs appear when the bookkeeping that maps a property to its reset entry gets out of step with the struct actually stored, so the engine reads one object type as another. A second family is sentinel or poison values used to mark uninitialised or freed slots; if a code path dereferences the slot without checking for the sentinel, the result is a crash at a recognisable address. Defences are type-tagged storage, assertions that the struct kind matches the property, and checking sentinels before use.

How to test for it

  1. Look for features where style is applied and then removed dynamically: class toggling, pseudo-elements, logical properties, and shorthand versus longhand interactions.
  2. Build a minimal page with a rule that sets a logical or shorthand property on a pseudo-element, then toggle a class that adds or removes a competing rule, forcing a style flush between changes by reading a layout property.
  3. Vary the property pairs (longhand against shorthand, logical against physical) and the order of application and removal.
  4. Run under a debug build or with a crash reporter so that access violations are visible rather than silently recovered.
  5. A positive result is a reproducible crash whose faulting address is constant and whose stack passes through style difference or reset code. Common false positives are crashes caused by unrelated extensions, GPU or font issues, or a single non-reproducible event; confirm with a clean profile and a minimal page.

How it is fixed

The report does not describe a fix. Regression tests that toggle the class and force a flush belong with the fix.

Hunting notes

This class hides in style system code that handles dynamic changes: pseudo-elements, logical properties, shorthand expansion, and inheritance. Recon signals include recent refactors of property storage, new logical properties, and crashes reported with constant faulting addresses.

The original is short, so this covers everything it reports, then explains this kind of bug in general: how it works, how to test for it and how it is fixed. The general sections are about the bug class, not this target. Written with AI and checked against the original; the original is the record. 7 min read.

What happened, in plain words

Firefox is a web browser. Every web page you open is described by HTML (the content) and CSS (the styling: colours, borders, spacing). Firefox has to read those style rules and work out, for each element on the page, what it should look like. That work is called CSS parsing and computation, and it is the part of Firefox this report is about.

A security researcher named SkyLined sent this report to Mozilla, the organisation that makes Firefox. It was made public on 6 July 2017 and rated high severity. The report does not mention a fix or a bounty amount.

The researcher found a small web page that makes Firefox crash. A crash means the browser stops working, like a program that suddenly closes. The page is short enough to read in full:

HTML
<html>
  <head>
    <style id=style>
      * {
        float:left;
      }
      ::first-line {
        border-inline-start: 0;
      }
      .boom ::first-line {
        border: 0;
      }
    </style>
    <script>
      onload = function() {
        document.body.className="boom";
        document.body.offsetTop;
        alert("Click OK to crash Firefox");
        document.body.className="x";
        // On x64, this causes an AV, but not on x86:
        document.body.offsetTop;
        // On x86, this code is reached. Refreshing the page appears to
        // trigger the AV the next time the page shows the alert.
        location.reload();
      };
    </script>
  </head>
  <body>
    <x>x</x>
  </body>
</html>

Let us go through it piece by piece.

  • * { float:left; } applies to every element. float:left pushes an element to the left side of its container.
  • ::first-line { border-inline-start: 0; } targets the first line of text. ::first-line is a pseudo-element: a way to style a part of the page that is not a real element you can point at, here the opening line of a block of text. border-inline-start is a logical border property: instead of saying left or right, it says the side where text starts, which depends on the writing direction.
  • .boom ::first-line { border: 0; } only applies when something has the class boom. A class is a label you can attach to an element and change later. This rule sets the whole border shorthand, which covers all four sides at once.

The script runs when the page finishes loading:

  1. document.body.className="boom"; puts the label boom on the page body, so the third rule starts to match.
  2. document.body.offsetTop; reads a layout measurement. Reading it forces Firefox to stop and actually work out the current styles and positions, rather than waiting. This is called a style flush.
  3. alert("Click OK to crash Firefox"); shows a pop-up box and pauses until you click OK.
  4. document.body.className="x"; swaps the label, so the boom rule no longer matches and Firefox must undo the styles it added.
  5. document.body.offsetTop; forces another flush, this time while removing those styles.
  6. location.reload(); reloads the page.

The comments in the code record what the researcher saw on two kinds of processor. On x64 (64-bit) the second flush causes an access violation, abbreviated AV. An access violation is when a program tries to read or write memory it is not allowed to touch, and the operating system stops it. On x86 (32-bit) the code carries on to the reload, and refreshing the page seems to trigger the access violation the next time the alert appears.

Why does this matter? Because the page uses nothing but ordinary styling and a class change. No special permission, no trick, just CSS. A page like this could crash a visitor's browser.

The researcher then dug into Firefox's internals. Firefox stores the computed style for each element in structures called rule nodes (nsRuleNode). When a rule stops matching, the browser has to undo exactly the properties that rule contributed, and it keeps bookkeeping for that in something called conditional reset style data (nsConditionalResetStyleData).

Applying and removing the rule node for the class boom seemed to make Firefox try to apply the reset data belonging to the rule node that carries border-inline-start. That data was corrupt. The entry at index 9 of a list called mEntries, the entry that deals with CSS border properties, had a member named mStyleStruct holding the value 0x14141414 on x86, or 0x14141414141414 on x64. Those are hexadecimal numbers, a way of writing memory addresses; the repeated pattern 14 is unusual and looks like a marker rather than a real address.

The crash happens when nsStyleBorder::CalcDifference is given that value as its aNewData argument; the code assumes it is a valid nsStyleVariables instance and tries to read its members, so the read fails.

The researcher could not find where the value came from. Setting breakpoints (pauses in the program so you can inspect it) on the functions in the call stack, the chain of function calls leading to the crash, and on functions that create the objects involved, did not reveal it. The value appears to have been created before the JavaScript that triggers the crash even runs. The report ends by asking whether this is a magic value, a special marker number, that is not being handled correctly, or a type confusion, where data belonging to one kind of object is read as if it were another kind, or something else entirely.

In general, how this kind of bug works

Browsers are built for speed, so they cache computed styles and share them between elements instead of recalculating everything constantly. When a rule stops matching, the engine must undo the properties that rule added. Conditional reset data exists to record which stored styles need resetting when a rule is removed.

Bugs appear when that bookkeeping gets out of step with what is actually stored. The engine then reads one kind of object as if it were another, which is the type confusion the researcher mentions. A related family is marker or poison values: numbers like 0x14141414 used to label a slot as empty or invalid. If code reads such a slot without checking for the marker first, it crashes at a recognisable address. Defences include tagging stored data with its type, asserting that the type matches the property, and checking for markers before use.

In general, how to test for it

  1. Look for features where styling is applied and then removed while the page is running: class toggling, pseudo-elements, logical properties, and shorthand versus longhand properties.
  2. Build a minimal page with a rule that sets a logical or shorthand property on a pseudo-element, then toggle a class that adds or removes a competing rule, forcing a style flush between changes by reading a layout property.
  3. Vary the property pairs (longhand against shorthand, logical against physical) and the order of application and removal.
  4. Run a debug build or with crash reporting enabled, so access violations are visible rather than silently recovered.
  5. A positive result is a reproducible crash with a constant faulting address whose stack passes through style difference or reset code. Common false positives are crashes from unrelated extensions, graphics or font problems, or a single event you cannot repeat; confirm with a clean profile and a minimal page.

In general, how it is fixed

The report does not describe a fix. Regression tests that toggle the class and force a flush go with the fix.

In general, hunting notes

This class of bug hides in style code that handles dynamic changes: pseudo-elements, logical properties, shorthand expansion and inheritance. Useful signals include recent refactors of property storage, newly added logical properties, and crash reports with constant faulting addresses.

Glossary

  • HTML: the language that describes the content and structure of a web page.
  • CSS: the language that describes how a web page looks.
  • CSS parsing and computation: the browser's work of reading style rules and working out the final style of each element.
  • Firefox: the web browser made by Mozilla.
  • Mozilla: the organisation that develops Firefox.
  • Crash: when a program stops working unexpectedly.
  • Access violation (AV): when a program tries to use memory it is not allowed to, and the operating system stops it.
  • x86 / x64: 32-bit and 64-bit processor families; the crash behaved differently on each.
  • Pseudo-element: a way to style a part of the page that is not a real element, such as ::first-line for the first line of text.
  • Class: a label attached to an element that can be changed at runtime to switch styling on and off.
  • Logical property: a style property described by writing direction (such as start and end) rather than left and right.
  • Shorthand property: a property such as border that sets several related properties at once.
  • Style flush: forcing the browser to compute current styles and layout immediately.
  • Rule node (nsRuleNode): Firefox's internal structure holding computed style information for an element.
  • Conditional reset style data (nsConditionalResetStyleData): Firefox's bookkeeping for undoing styles when a rule stops matching.
  • mEntries / mStyleStruct: internal list and member names in that bookkeeping; the corrupt entry was at index 9.
  • nsStyleBorder::CalcDifference: the Firefox function that compares border styles and crashed.
  • aNewData: the argument passed to that function, holding the bad value.
  • Hexadecimal: a base-16 way of writing numbers, often used for memory addresses.
  • Magic value / marker value: a special number used to label a slot as empty or invalid.
  • Type confusion: reading data of one kind of object as if it were another kind.
  • Breakpoint: a deliberate pause in a program so you can inspect its state.
  • Call stack: the chain of function calls that led to the current point in a program.
  • Debug build: a version of a program built with extra checks and information for investigation.
  • Regression test: an automated test that checks a fixed bug stays fixed.
  • Severity: a rating of how serious a bug is; this one was rated high.

More by SkyLined

View all

35 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.