Closed Bug 1011283 Opened 6 years ago Closed 6 years ago

Assertion failure: *to != *moves_[i].to(), at jit/LIR.cpp

Categories

(Core :: JavaScript Engine: JIT, defect, critical)

x86
All
defect
Not set
critical

Tracking

()

VERIFIED FIXED
mozilla33
Tracking Status
firefox30 --- unaffected
firefox31 --- verified
firefox32 + verified
firefox33 + verified
firefox-esr24 --- unaffected
b2g-v1.3 --- unaffected
b2g-v1.3T --- unaffected
b2g-v1.4 --- unaffected
b2g-v2.0 --- fixed
b2g-v2.1 --- fixed

People

(Reporter: gkw, Assigned: sunfish)

References

(Blocks 1 open bug)

Details

(5 keywords, Whiteboard: [jsbugmon:])

Attachments

(4 files)

Attached file stack
valueOf = function(a, b, c) {
    var d = (2 ^ 9) / 9
    var e = g
    b = d / 9
    a + c | d
    return b
}
function f(x) {
    x | 0
}
f(this)


asserts js debug shell on m-c changeset 6d32bbffc7e4 with --ion-eager --ion-parallel-compile=off at Assertion failure: *to != *moves_[i].to(), at jit/LIR.cpp

My configure flags are:

LD=ld CROSS_COMPILE=1 CC="clang -Qunused-arguments -msse2 -mfpmath=sse -arch i386" RANLIB=ranlib CXX="clang++ -Qunused-arguments -msse2 -mfpmath=sse -arch i386" AS=$CC AR=ar STRIP="strip -x -S" HOST_CC="clang -Qunused-arguments -msse2 -mfpmath=sse" HOST_CXX="clang++ -Qunused-arguments -msse2 -mfpmath=sse" sh /Users/skywalker/trees/mozilla-central/js/src/configure --target=i386-apple-darwin9.2.0 --enable-macos-target=10.5 --enable-optimize --enable-debug --enable-profiling --enable-gczeal --enable-debug-symbols --disable-tests --enable-more-deterministic --with-ccache --enable-threadsafe <other NSPR options>

autoBisect shows this is probably related to the following changeset:

The first bad revision is:
changeset:   http://hg.mozilla.org/mozilla-central/rev/c7925215ca32
user:        Mauricio Collares Neto
date:        Sat Apr 19 10:37:51 2014 -0700
summary:     Bug 976110 - Part 1: Optimize signed integer division by constants; r=sunfish

:sunfish, is bug 976110 a likely regressor?

(after the recent adventures of LIR/MIR bugs not being marked s-s by default (which turned out wrong), I'm turning this s-s and sec-critical as a start just in case, feel free to change this as necessary)
Flags: needinfo?(sunfish)
Whiteboard: [jsbugmon:update] → [jsbugmon:]
JSBugMon: Cannot process bug: Unable to automatically reproduce, please track manually.
(In reply to Christian Holler (:decoder) from comment #1)
> JSBugMon: Cannot process bug: Unable to automatically reproduce, please
> track manually.

This seems 32-bit only.
JSBugMon will use 32 bit builds, it's likely something else, build options maybe.
(In reply to Christian Holler (:decoder) from comment #3)
> JSBugMon will use 32 bit builds, it's likely something else, build options
> maybe.

Or maybe even Mac-only, I haven't tried Linux 32-bit builds though.
I can reproduce it on 32-bit Linux.
Flags: needinfo?(sunfish)
At a first look, it looks like a register allocator bug. The problem goes away with --ion-regalloc=backtracking, and is not reproducible on x64. The crash is in the register allocator; it is trying to add two moves with the same output to a MoveGroup. I'll investigate further.
Group: javascript-core-security
Assignee: nobody → sunfish
Keywords: reproducible
OS: Mac OS X → All
I'm still investigating this. LSRA is putting two independent reloads of %eax in the same move group. Due to the use of LNops to model fixed-register dependencies, it's quite tricky to determine what's actually supposed to happen here.
A patch containing some related debugging code is in bug 1020468.
Any updates here?  Did the debugging code help?
I'm still working on this. I've tried a few approaches to fixing it, but so far they all cause breakage elsewhere.

If a fix is needed urgently, I could probably construct a workaround patch. If we make the Div/Mod nodes take arbitrary registers as inputs and outputs, and have them manually copy into the registers they need, it would probably avoid this problem, at the expense of being mildly suboptimal.
Firefox 30, which just shipped, isn't affected by this. Firefox 31 is. We'd like to not ship this security issue in five weeks.
The attached patch works around the LSRA problem by having LDivOrModConstantI copy its output. It's unfortunate, but the performance impact ought to be pretty minimal.
Attachment #8442519 - Flags: review?(nicolas.b.pierron)
Comment on attachment 8442519 [details] [diff] [review]
divmod-move-output.patch

Review of attachment 8442519 [details] [diff] [review]:
-----------------------------------------------------------------

::: js/src/jit/shared/Lowering-x86-shared.cpp
@@ -161,3 @@
>              if (div->fallible() && !assignSnapshot(lir, Bailout_DoubleOutput))
>                  return false;
> -            return defineFixed(lir, div, LAllocation(AnyRegister(edx)));

As long as we do not have an explanation, and we decide to go that way without a clear understanding of why, then we should remove defineFixed from the set of instructions compilable from Ion.

This includes LUdivOrMod and some VMFunction LIR instructions.
Attachment #8442519 - Flags: review?(nicolas.b.pierron)
defineFixed is used by lots of things, and I don't think we can reasonably remove it from Ion.

The best alternative I can provide quickly is to completely revert the divide-by-constant feature which exposed this bug. Whatever LSRA bug may exist will remain, but we'll at least be back to where we were before we knew about this bug. I'll start preparing a patch to do this.

For completeness, another quick way to fix this would be to disable LSRA and switch to backtracking by default. This something we're hoping to do eventually anyway, though currently it does regress performance in some cases. It is an alternative that we could consider if we needed to.
(In reply to Dan Gohman [:sunfish] from comment #14)
> The best alternative I can provide quickly is to completely revert the
> divide-by-constant feature which exposed this bug. Whatever LSRA bug may
> exist will remain, but we'll at least be back to where we were before we
> knew about this bug. I'll start preparing a patch to do this.

My point is if we are fixing a bug we should better fix it without leaving hints behind us in the patch. Having a work-around which disables the feature sounds nicer as it does not leave hints about the register allocation.

(In reply to Dan Gohman [:sunfish] from comment #14)
> For completeness, another quick way to fix this would be to disable LSRA and
> switch to backtracking by default.

I don't think this is a good idea to enable the backtracking allocator without making it ride the train. This sounds like a huge risk from my point of view, and this is unlikely to be acceptable for landing on beta.
This patch disables the div/mod by constant optimization which triggers the bug. I chose to make a small change which just disables the feature instead of fully reverting the patches because the original patches don't reverse-apply cleanly anymore, and a small change is easier to understand.
Attachment #8442956 - Flags: review?(nicolas.b.pierron)
Attachment #8442956 - Flags: review?(nicolas.b.pierron) → review+
Comment on attachment 8442956 [details] [diff] [review]
disable-div-or-mod-constanti.patch

[Security approval request comment]
How easily could an exploit be constructed based on the patch?

Not easily. The patch disables a feature which triggers a bug elsewhere, so an exploit would need to combine several constructs to work.

Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem?

No, they disable a feature which triggers a bug somewhere else, so it's fairly indirect.

Which older supported branches are affected by this flaw?

mozilla-beta and mozilla-aurora are both also affected.

If not all supported branches, which bug introduced the flaw?

Bug 976110.

Do you have backports for the affected branches? If not, how different, hard to create, and risky will they be?

Backports for all affected branches would be very easy to create, and low-risk. The patch is small and straight-forward.

How likely is this patch to cause regressions; how much testing does it need?

Not especially likely. The patch is just disabling an optimization.
Attachment #8442956 - Flags: sec-approval?
Comment on attachment 8442956 [details] [diff] [review]
disable-div-or-mod-constanti.patch

sec-approval+ for trunk. Once trunk is green, I'd like to see Aurora and Beta patches nominated so we can fix this everywhere.
Attachment #8442956 - Flags: sec-approval? → sec-approval+
Here is a port of disable-div-or-mod-constanti.patch which applies cleanly to mozilla-aurora and mozilla-beta.
https://hg.mozilla.org/mozilla-central/rev/bf47f42c33c8
Status: NEW → RESOLVED
Closed: 6 years ago
Flags: in-testsuite?
Resolution: --- → FIXED
Target Milestone: --- → mozilla33
Comment on attachment 8443841 [details] [diff] [review]
aurora-beta.patch

[Approval Request Comment]
Bug caused by (feature/regressing bug #):

Bug 976110

User impact if declined:

Security bug

Testing completed (on m-c, etc.):

On m-c.

Risk to taking this patch (and alternatives if risky): 

Low. The patch just disables an optimization.

String or IDL/UUID changes made by this patch:

None.
Attachment #8443841 - Flags: approval-mozilla-beta?
Attachment #8443841 - Flags: approval-mozilla-aurora?
Attachment #8443841 - Flags: approval-mozilla-beta?
Attachment #8443841 - Flags: approval-mozilla-beta+
Attachment #8443841 - Flags: approval-mozilla-aurora?
Attachment #8443841 - Flags: approval-mozilla-aurora+
Reproduced the original issue on m-c using changeset 6d32bbffc7e4 with the flags from comment #0, received the following assert:

Assertion failure: *to != *moves_[i].to(), at /home/kjozwiak/mozilla/mozilla-central/js/src/jit/LIR.cpp:453
Segmentation fault (core dumped)

Went through verification using the following builds:
* m-c using changeset 613bc15ccf05
* aurora using changeset 07f644c5ca48
* beta using changeset 635e32a71297
Group: javascript-core-security
QA Whiteboard: [qa!]
Group: core-security → core-security-release
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.