Closed Bug 975387 Opened 6 years ago Closed 6 years ago

TextComposition should clear mPresContext when the PresContext is destroyed

Categories

(Core :: User events and focus handling, defect)

defect
Not set

Tracking

()

RESOLVED FIXED
mozilla30
Tracking Status
firefox27 --- unaffected
firefox28 --- unaffected
firefox29 + fixed
firefox30 + fixed
firefox-esr24 --- unaffected
b2g-v1.2 --- unaffected
b2g-v1.3 --- unaffected
b2g-v1.4 --- fixed

People

(Reporter: masayuki, Assigned: masayuki)

References

Details

(Keywords: csectype-uaf, sec-critical, Whiteboard: [qa-])

Attachments

(2 files, 1 obsolete file)

This may be dangerous.

The TextComposition::mPresContext may be referred after destroyed.

We should fix this bug on Aurora too.
Group: dom-core-security, core-security
Attached patch PatchSplinter Review
I realized this bug when I was writing a patch for another bug. Therefore, I'm not sure this bug actually causes crash or something.

At compositionstart event handler, JS may do something to destroy its presContext. Then, mPresContext may be already released.

However, when this method is called, the caller's PresShell is held by nsViewManager with local variable:
http://mxr.mozilla.org/mozilla-central/source/view/src/nsViewManager.cpp#751

And PresShell::mPresContext must be alive while PresShell instance is alive because its destructor releases mPresContext:
http://mxr.mozilla.org/mozilla-central/source/layout/base/nsPresShell.cpp#769

Although, I don't know the reason why PresShell checks mPresContext at a lot of plases...

So, I think that this is safe, but may not be so in the future. So, we should make a wall with this patch.
Attachment #8379724 - Attachment is obsolete: true
Attachment #8379751 - Flags: review?(bugs)
Attachment #8379751 - Flags: review?(bugs) → review+
Comment on attachment 8379751 [details] [diff] [review]
Patch

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

As I said in my previous comment, the mPresContext is always held luckily.

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

The check-in comment might be so. I'd like you to suggest other commit message if you think it's bad.

Which older supported branches are affected by this flaw?

Aurora has this bug too. Beta and Release don't have this.

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

The referencing code of mPresContext after dispatching an event is added by bug 935821.

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

It's easy. I'll post the patch for Aurora soon.

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

Even if this causes regressions, it's only affected to e10s. But e10s hasn't supported IME completely yet.
Attachment #8379751 - Flags: sec-approval?
Attached patch Patch for AuroraSplinter Review
[Approval Request Comment]
Bug caused by (feature/regressing bug #): Bug 935821
User impact if declined: As far as I researched, this doesn't cause actual trouble. But this makes a wall for the dangerous scenario.
Testing completed (on m-c, etc.): Not yet landed on m-c. Waiting sec-approval.
Risk to taking this patch (and alternatives if risky): No idea. After nsIMEStateManager stops managing TextComposition instances, they shouldn't be used for dispatching any events. (Others cannot retrieve the destroyed instance in expected scenarios)
String or IDL/UUID changes made by this patch: Nothing.
Attachment #8380472 - Flags: review+
Attachment #8380472 - Flags: approval-mozilla-aurora?
Comment on attachment 8379751 [details] [diff] [review]
Patch

Hmm, I'm sorry. I found this patch is not enough.
Attachment #8379751 - Flags: sec-approval?
Attachment #8379751 - Flags: review-
Attachment #8379751 - Flags: review+
Comment on attachment 8380472 [details] [diff] [review]
Patch for Aurora

cancelling the request because I found that this is not enough.
Attachment #8380472 - Flags: review-
Attachment #8380472 - Flags: review+
Attachment #8380472 - Flags: approval-mozilla-aurora?
Comment on attachment 8379751 [details] [diff] [review]
Patch

Sorry for the spam. I misunderstood as that nsIMEStateManager::DispatchCompositionEvent() will create new composition with destroyed PresContext. However, I confirmed that my concern is wrong.

So, this patch's wall works as I expected.

Please see comment 3 for the sec-approval.
Attachment #8379751 - Flags: sec-approval?
Attachment #8379751 - Flags: review-
Attachment #8379751 - Flags: review+
Comment on attachment 8380472 [details] [diff] [review]
Patch for Aurora

Sorry for the spam.

See comment 4 and comment 7. This patch is enough for avoiding the reported bug completely.
Attachment #8380472 - Flags: review-
Attachment #8380472 - Flags: review+
Attachment #8380472 - Flags: approval-mozilla-aurora?
Anyway, we need to redesign the cases at destroying a document from composition event handlers. Even with these patches, IME state is still confused even in the next focused editor.
Comment on attachment 8379751 [details] [diff] [review]
Patch

sec-approval+ for trunk. I'm not concerned about the commit message as long as we take this on Aurora as well.
Attachment #8379751 - Flags: sec-approval? → sec-approval+
Attachment #8380472 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
(In reply to Al Billings [:abillings] from comment #10)
> sec-approval+ for trunk. I'm not concerned about the commit message as long
> as we take this on Aurora as well.

Thank you for the sec-review.

You said "sec-approval+ for trunk", but you gives + for approval-mozilla-aurora too. Can I land them now? Or do I need to request sec-review for tha patch for Aurora again?
Flags: needinfo?(abillings)
Once you have sec-approval for trunk, the patches can be landed anywhere, as long as they go through the usual approval process.  So the patch can be landed immediately on trunk and Aurora.  The idea is that once a patch lands on any branch, a bad guy could see it, so it doesn't matter much from a security perspective if it lands on other branches, too.
Flags: needinfo?(abillings)
landed on https://hg.mozilla.org/mozilla-central/rev/f2fcc1dea688
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Flags: in-testsuite?
Resolution: --- → FIXED
Target Milestone: --- → mozilla30
The tree rules are clear that you are not to double-land patches on Aurora and inbound. Please wait until the patch has stuck on trunk before uplifting. Also, when landing on the release branches, please set the status flag appropriately.
Flags: needinfo?(masayuki)
(In reply to Ryan VanderMeulen [:RyanVM UTC-5] from comment #16)
> The tree rules are clear that you are not to double-land patches on Aurora
> and inbound. Please wait until the patch has stuck on trunk before
> uplifting. Also, when landing on the release branches, please set the status
> flag appropriately.

I see. Thank you for your explanation.
Flags: needinfo?(masayuki)
Yes, generally "sec-approval+" is an approval for trunk landing. After it lands on trunk, you can get approval for any branch patches as necessary. We want it to go green on trunk though.
Group: dom-core-security
Marking [qa-] due to lack of test case, but feel free to provide one if you'd like verification. Thanks.
Whiteboard: [qa-]
Group: core-security
Component: Event Handling → User events and focus handling
You need to log in before you can comment on or make changes to this bug.