Skip to content
Disclosed report

Regexp object allows arbitrary memory reading

Christian Holler Follow

Originally disclosed on Mozilla

  • Fixed in 11 days
  • Paid in 2.7 years
  • Disclosed after 11 days
Text
User-Agent:       Mozilla/5.0 (X11; Linux i686; rv:2.0b6) Gecko/20100101 Firefox/4.0b6
Build Identifier: Mozilla/5.0 (X11; Linux i686; rv:2.0b6) Gecko/20100101 Firefox/4.0b6

Firefox 4.0b6 JavaScript Engine Arbitrary Memory Reading

Original release date: <undisclosed>
Last revised: 2010-11-07
Source: Christian Holler <http://users.own-hero.net/~decoder/>

Credits: Christian Holler <[address removed]>
         Maximilian Grothusmann <[address removed]>


Systems Affected:

 Mozilla Firefox 4.0b6 (http://www.mozilla.com/en/firefox/beta/) - Web Browser Beta

Severity: High


Overview:

I. Description

 The Mozilla Firefox 4 JavaScript engine supports the Regexp.input property to set
 the input string used for a regular expression match. When assigning Regexp.input,
 the engine fails to reset the submatch properties Regexp.$1..$9. When accessing
 these properties, they are provided as dependent strings to Regexp.input at the
 time of access to the submatch property. When matching some large string and then
 setting Regexp.input to another object or an empty string, the whole memory starting
 at the provided object with the length of the submatch is returned.

II. Impact

 The described weakness can be used to read arbitrary memory starting at the location
 of any object in memory that we can refer to. This includes reading beyond our own 
 document,  leaking information of other tabs or add-ons that are open, including any 
 sensitive information that might be contained in there.

III. Proof of concept

 === Explanation ===

 In our proof of concept exploit, we first create a large string "haystack" that has
 approximately 16 MB size (which should be enough for demonstration purposes) with
 a repeating pattern. We then create a regular expression "needle" containing a single 
 match which encloses roughly 512 KB of memory (the limit for a single pattern is 1 MB,
 but we can use the "global" flag and simply match multiple times to read further).

 We then execute the regular expression and then set Regexp.input to some different
 object. In our case, we choose the "document" object to demonstrate reading beyond
 our own document to disclose other tabs and add-ons.

 === Demonstration ===

 Exploit is attached to this bug report. Open the poc.html file and you'll see a dump
 of 512 KB memory, starting at the object "document". You can alter both the starting
 point within "document" by increasing the "repeat" variable on top (if you get a crash
 you've gone too far), or choose a different object to start with (any object that can
 be referenced in the script context, including all global objects).

 The proof-of-concept exploit was tested in Firefox 4b6 and verified to also work
 against nightly builds.

 In our tests, we were able to read browser history, data from other tabs and even 
 sensitive information such as the password of the "Firefox Sync" feature.

IV. Solution

The following patch will fix the described problem, we do however not claim 
completeness for this fix:

diff -r 633e895d5e84 js/src/jscntxt.h
--- a/js/src/jscntxt.h	Thu Sep 09 12:19:50 2010 -0700
+++ b/js/src/jscntxt.h	Sun Nov 07 16:18:09 2010 +0100
@@ -1797,6 +1797,7 @@
 
     void setInput(JSString *newInput) {
         input = newInput;
+        matchPairs.clear();
     }
 
     /* Accessors. */

Timeline:

 2010-11-07: Reported to Mozilla
 2010-11-05: Vulnerability discovered

Reproducible: Always

Steps to Reproduce:
1. Open the attached proof-of-concept exploit (poc.html).
2. Inspect memory dump.
Actual Results:  
Memory is revealed to the script's context.

Expected Results:  
Submatch properties should have been reset when the input property is changed, hence empty string or undefined should be returned.

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

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

What is known

A security bug in JavaScript Engine. Mozilla made it public on 18 November 2010.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

More by Christian Holler

View all

34 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.