Bug 155679 - Crash in stress/regexp-matches-array-slow-put.js due to stomping on memory when having bad time
Summary: Crash in stress/regexp-matches-array-slow-put.js due to stomping on memory wh...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Michael Saboff
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2016-03-18 22:09 PDT by Michael Saboff
Modified: 2016-03-20 23:00 PDT (History)
5 users (show)

See Also:


Attachments
Patch (2.84 KB, patch)
2016-03-19 21:39 PDT, Michael Saboff
saam: review+
Details | Formatted Diff | Diff
Performance results of the patch (65.56 KB, text/plain)
2016-03-19 21:42 PDT, Michael Saboff
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Saboff 2016-03-18 22:09:53 PDT
When we allocate the matches array in createRegExpMatchesArray() when globalObject->isHavingABadTime(), we don't allocate out of line storage needed for the match start index and source string.  This results on stepping on whatever object is immediately prior to the butterfly allocated for the array.  When testing a change I was working on, this caused a crash in stress/regexp-matches-array-slow-put.js.  The memory being stepped on all depends on allocation patterns.
Comment 1 Radar WebKit Bug Importer 2016-03-18 22:13:02 PDT
<rdar://problem/25254505>
Comment 2 Michael Saboff 2016-03-19 21:39:52 PDT
Created attachment 274534 [details]
Patch
Comment 3 Michael Saboff 2016-03-19 21:42:34 PDT
Created attachment 274535 [details]
Performance results of the patch

Performance overall is neutral.  The results on the major benchmarks appear unchanged.  There are a few individual regression tests that show regression or slight progression.  I ran the tests s few times to validate the regressions.
Comment 4 Saam Barati 2016-03-19 23:10:02 PDT
Comment on attachment 274534 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=274534&action=review

> Source/JavaScriptCore/runtime/JSArray.h:243
> +    unsigned outOfLineStorage = structure->outOfLineCapacity();

Can we add a test to go with this? What about the having a bad time richards that we spoke about?

> Source/JavaScriptCore/runtime/JSArray.h:244
> +

Or maybe it can just be another test that more directly stresses this.
Comment 5 Michael Saboff 2016-03-20 16:06:53 PDT
(In reply to comment #4)
> Comment on attachment 274534 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=274534&action=review
> 
> > Source/JavaScriptCore/runtime/JSArray.h:243
> > +    unsigned outOfLineStorage = structure->outOfLineCapacity();
> 
> Can we add a test to go with this? What about the having a bad time richards
> that we spoke about?
> 
> > Source/JavaScriptCore/runtime/JSArray.h:244
> > +
> 
> Or maybe it can just be another test that more directly stresses this.

I tried modifying several tests and the best that I could do is change the failure of the test, but I couldn't any of those modified tests to crash.  First off, the bug is triggered by executing a regular expression.  That rules out richards and most other benchmark tests.  I tried both the Octane and SunSpider regexp tests, but could only get bad results and no crashing.

Remember, the bug is that createRegExpMatchesArray() is writing two JSValues in the 16 bytes right before the allocated array storage.  Those values are a String and a number.  They are both valid values overwriting other values.  To get a crash, the prior object in memory must crash due to those writes.

We do have a test that will crash after I land the RegExp.prototype[@@match] change.  I think that is good enough.
Comment 6 Michael Saboff 2016-03-20 16:08:52 PDT
Committed r198478: <http://trac.webkit.org/changeset/198478>
Comment 7 Saam Barati 2016-03-20 23:00:22 PDT
(In reply to comment #5)
> (In reply to comment #4)
> > Comment on attachment 274534 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=274534&action=review
> > 
> > > Source/JavaScriptCore/runtime/JSArray.h:243
> > > +    unsigned outOfLineStorage = structure->outOfLineCapacity();
> > 
> > Can we add a test to go with this? What about the having a bad time richards
> > that we spoke about?
> > 
> > > Source/JavaScriptCore/runtime/JSArray.h:244
> > > +
> > 
> > Or maybe it can just be another test that more directly stresses this.
> 
> I tried modifying several tests and the best that I could do is change the
> failure of the test, but I couldn't any of those modified tests to crash. 
> First off, the bug is triggered by executing a regular expression.  That
> rules out richards and most other benchmark tests.  I tried both the Octane
> and SunSpider regexp tests, but could only get bad results and no crashing.
> 
> Remember, the bug is that createRegExpMatchesArray() is writing two JSValues
> in the 16 bytes right before the allocated array storage.  Those values are
> a String and a number.  They are both valid values overwriting other values.
> To get a crash, the prior object in memory must crash due to those writes.
> 
> We do have a test that will crash after I land the RegExp.prototype[@@match]
> change.  I think that is good enough.

Right, I realized that richards was a bad idea after I posted. I think it's worth having a version of octane/regexp with having a bad time checked in.