IonMonkey: GetPropertyIC allows Proxy stubs on idempotent caches.

RESOLVED FIXED in Firefox 26

Status

()

defect
RESOLVED FIXED
6 years ago
5 years ago

People

(Reporter: efaust, Assigned: efaust)

Tracking

({sec-high})

unspecified
mozilla27
x86_64
Linux
Points:
---
Dependency tree / graph
Bug Flags:
in-testsuite ?

Firefox Tracking Flags

(firefox24 unaffected, firefox25 unaffected, firefox26 fixed, firefox27+ fixed, firefox-esr17 unaffected, firefox-esr24 unaffected, b2g18 unaffected, b2g-v1.1hd unaffected, b2g-v1.2 fixed)

Details

(Whiteboard: [qa-])

Attachments

(2 attachments)

This leads to hilariously wrong results. I stumbled across it when an idempotent IC moved, then didn't invalidate, then called a resolve hook, which inferred the proper flags based on the pc of the active script, which was bogus because the IC had moved.

We should not do this, and assert in the code generation paths that the cache is not idempotent.

Marking s-s as it causes fairly arbitrary behavior.
Improve the robustness of various invariant checking.

The patch does 3 things:

1) Fix the bug mentioned above
2) Allow for generation of slotful unshadowed proxy reads on idempotent caches, which is a real feature and a good cover.
3) Adds 243567543213456754324567865433 asserts, as mentioned on IRC.
Attachment #812762 - Flags: review?(kvijayan)
Marking ESR17 and B2G as unaffected since Ionmonkey isn't on there.

We'll need a security rating on this.
Comment on attachment 812762 [details] [diff] [review]
Make GetPropIC more obsessive

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

::: js/src/jit/IonCaches.cpp
@@ +1484,5 @@
>              // EmitGetterCall() expects |obj| to be the object the property is
>              // on to do some checks. Since we actually looked at checkObj, and
>              // no extra guards will be generated, we can just pass that instead.
>              JS_ASSERT_IF(canCache != CanAttachCallGetter, canCache == CanAttachArrayLength);
> +            JS_ASSERT(!idempotent());

I'm not sure how we can guarantee that idempotent() doesn't flow to this location.  The check added higher up in this function only ensures |idempotent()| is false in when |holder| is false.  But this code executes when |holder| is true.

Also, we call EmitGetterCall below, but canCache can be either CanAttachCallGetter or CanAttachArrayLength.  the JS_ASSERT_IF above is confusing.
(In reply to Kannan Vijayan [:djvj] from comment #3)
> Comment on attachment 812762 [details] [diff] [review]
> Make GetPropIC more obsessive
> 
> Review of attachment 812762 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: js/src/jit/IonCaches.cpp
> @@ +1484,5 @@
> >              // EmitGetterCall() expects |obj| to be the object the property is
> >              // on to do some checks. Since we actually looked at checkObj, and
> >              // no extra guards will be generated, we can just pass that instead.
> >              JS_ASSERT_IF(canCache != CanAttachCallGetter, canCache == CanAttachArrayLength);
> > +            JS_ASSERT(!idempotent());
> 
> I'm not sure how we can guarantee that idempotent() doesn't flow to this
> location.  The check added higher up in this function only ensures
> |idempotent()| is false in when |holder| is false.  But this code executes
> when |holder| is true.
> 
> Also, we call EmitGetterCall below, but canCache can be either
> CanAttachCallGetter or CanAttachArrayLength.  the JS_ASSERT_IF above is
> confusing.
The reason we call EmitGetterCall here is CanAttachArrayLength just says that we could do an array length optimization if we wanted. In reality, the array length stub is a getter, so we can call it like one, and do "for simplicity's sake".

allowGetters() includes an idempotent() check for GetPropertyIC, which should cover that assertion for the CanAttachCallGetter case.

Your point is well taken about the assert in the CanAttachArrayLength case, though. I think there should be an additional

if (canCache == CanAttachArrayLength && (!idempotent() || !output().hasValue())
    return true;

before we set |emitted|, since we are treating the optimization as something that requires those qualities. Since CanAttachNative() is pure, this shouldn't be a problem.

The other option is to further complicate CanAttachNative() and include some notion of "I'm not optimizing array length" and we will just not take that path and we won't have the confusing CanAttachArrayLength value returned. This is in some ways cleaner (maybe a default parameter, and later a bitmask if we find other things we desperately want to special case out?), as it gets rid of the strange "array length is just a getter" concept that has tripped up multiple people, but adding more complexity to that function makes me a little squeamish. Thoughts?
(In reply to Eric Faust [:efaust] from comment #4)
> Your point is well taken about the assert in the CanAttachArrayLength case,
> though. I think there should be an additional
> 
> if (canCache == CanAttachArrayLength && (!idempotent() ||
> !output().hasValue())
>     return true;
> 
> before we set |emitted|, since we are treating the optimization as something
> that requires those qualities. Since CanAttachNative() is pure, this
> shouldn't be a problem.

That sounds good.

> The other option is to further complicate CanAttachNative() and include some
> notion of "I'm not optimizing array length" and we will just not take that
> path and we won't have the confusing CanAttachArrayLength value returned.
> This is in some ways cleaner (maybe a default parameter, and later a bitmask
> if we find other things we desperately want to special case out?), as it
> gets rid of the strange "array length is just a getter" concept that has
> tripped up multiple people, but adding more complexity to that function
> makes me a little squeamish. Thoughts?

Agreed, let's go with the former option above.

R+-ing.
Comment on attachment 812762 [details] [diff] [review]
Make GetPropIC more obsessive

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

Let's do the first option you suggested in comment 4.
Attachment #812762 - Flags: review?(kvijayan) → review+
Yeah, we said option 1, but I think 2 is actually prettier.
Attachment #812832 - Flags: review?(kvijayan)
Comment on attachment 812832 [details] [diff] [review]
skipArrayLen.patch

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

This is nicer.
Attachment #812832 - Flags: review?(kvijayan) → review+
Blocks: 922861
Keywords: sec-high
Sigh.

This should have sec-approval+ before it goes to inbound or trunk. This is a sec-high rated security bug that is not trunk only.

See https://wiki.mozilla.org/Security/Bug_Approval_Process for how this should work.
Specifically, this is so we don't zero day our own users.
Comment on attachment 812832 [details] [diff] [review]
skipArrayLen.patch

Siiigh.

I'm an idiot. Somehow I just went "oh, it's only trunk, go for it."

Nominating on the second patch, but they will land merged.

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

You could maybe find the problem based on the patch. I don't know how hard it would be to weaponize it. If you did find it, you could sure cause strange things to happen.

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

Nope.

Which older supported branches are affected by this flaw?

26 and up, since that was the milestone for 875452.

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

The bug was introduced by bug 875452.

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

This would be fine as a backport.

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

Landed (now...) on inbound. Also tested against shell tests.
Attachment #812832 - Flags: sec-approval?
Unless I'm totally missing something, this should only affect 26 and forward, since it came from bug 875452. It's not the DOM specific proxy stubs that were mistaken, just the generic ones. Unsetting affected flags on earlier versions.
Comment on attachment 812832 [details] [diff] [review]
skipArrayLen.patch

Nominating for uplift in parallel. Again, this stands for both patches, as they will landed folded.

[Approval Request Comment]
Bug caused by (feature/regressing bug #): 875452
User impact if declined: Potential security hazard
Testing completed (on m-c, etc.): now erroneously on trunk, as well as shell tests
Risk to taking this patch (and alternatives if risky): low. Just trimming a bad case
String or IDL/UUID changes made by this patch: None
Attachment #812832 - Flags: approval-mozilla-aurora?
Comment on attachment 812832 [details] [diff] [review]
skipArrayLen.patch

sec-approval+ for trunk and then approved for aurora after it lands fine there. Let's get 'er done.

Firefox 25 is unaffected though so we don't need it on beta or ESR24.
Attachment #812832 - Flags: sec-approval?
Attachment #812832 - Flags: sec-approval+
Attachment #812832 - Flags: approval-mozilla-aurora?
Attachment #812832 - Flags: approval-mozilla-aurora+
https://hg.mozilla.org/mozilla-central/rev/22c06187aee2
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Flags: in-testsuite?
Resolution: --- → FIXED
Target Milestone: --- → mozilla27
Keywords: verifyme
Is there any user facing way to verify this?
(In reply to [:tracy] Tracy Walker - QA Mentor from comment #18)
> Is there any user facing way to verify this?

Unlikely, unfortunately. I was thinking about this myself. I verified at least that it stopped failing the test that I had for it, and I have a very high confidence that the current code does not suffer from the old mistake, but the circumstances of failure were so contrived that it's hard to write a directed test for it. In particular, it probably requires running with a non-release feature (ion-eager compilation) to get it to reproduce. The test I tracked it down in was an utterly unrelated mochitest.
(In reply to Eric Faust [:efaust] from comment #19)
> (In reply to [:tracy] Tracy Walker - QA Mentor from comment #18)
> > Is there any user facing way to verify this?
> 
> Unlikely, unfortunately. I was thinking about this myself. I verified at
> least that it stopped failing the test that I had for it, and I have a very
> high confidence that the current code does not suffer from the old mistake,
> but the circumstances of failure were so contrived that it's hard to write a
> directed test for it. In particular, it probably requires running with a
> non-release feature (ion-eager compilation) to get it to reproduce. The test
> I tracked it down in was an utterly unrelated mochitest.

ok, given that, there's probably nothing I can do here.  marking it [qa-]. Thanks Eric.
Keywords: verifyme
Whiteboard: [qa-]
Group: core-security
You need to log in before you can comment on or make changes to this bug.