heap-use-after-free in SpeechEvent
Categories
(Core :: Web Speech, defect)
Tracking
()
People
(Reporter: kirin.say, Assigned: smaug)
Details
(Keywords: csectype-uaf, reporter-external, sec-high, Whiteboard: [reporter-external] [client-bounty-form] [verif?])
Attachments
(2 files, 1 external file, 1 obsolete file)
heap-use-after-free in SpeechEvent
VERSION
Firefox Nightly Build ( 101.0a1 )
VULNERABILITY DETAILS
I noticed that the SpeechEvent only hold a Raw Pointer to SpeechRecognition (mRecognition) (1):
class SpeechEvent : public Runnable {
public:
SpeechEvent(SpeechRecognition* aRecognition,
SpeechRecognition::EventType aType);
~SpeechEvent();
NS_IMETHOD Run() override;
......
......
private:
SpeechRecognition* mRecognition; // **** 1 ****
......
};
}
SpeechEvent::Run() {
mRecognition->ProcessEvent(this); // **** 2 ****
return NS_OK;
}
When a SpeechEvent dispatch to MainThread, the SpeechRecognition can be released in the JavaScript context of MainThread. And when the MainThread completes the current task and trigger SpeechEvent::Run, it will lead to a use-after-free issue in (2).
REPRODUCTION CASE
To support SpeechRecognition, the media.webspeech.recognition.force_enable and media.webspeech.recognition.enable should be enable.
POC:
<html>
<script>
forceGC = () => {
// To trigger easily => fuzzing.enabled: true
FuzzingFunctions.garbageCollect();
FuzzingFunctions.cycleCollect();
}
var recognition = new SpeechRecognition();
recognition.abort(); // or stop()
recognition=null;
forceGC();
</script>
</html>
ASAN LOG
See asan.log in attachment.
Suggestion
Hold a reference of SpeechRecognition in SpeechEvent to avoid it be released before SpeechEvent::Run.
Updated•4 years ago
|
Updated•4 years ago
|
| Assignee | ||
Comment 1•4 years ago
|
||
Updated•4 years ago
|
Updated•4 years ago
|
| Assignee | ||
Comment 2•4 years ago
|
||
Comment on attachment 9271870 [details]
Bug 1764112, ensure there is a reasonable SpeechRecognition object around when handling SpeechEvents, r=eeejay
Security Approval Request
- How easily could an exploit be constructed based on the patch?: The patch does pinpoint where the issue is.
- Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem?: Yes
- Which older supported branches are affected by this flaw?: all, but behind a pref
- If not all supported branches, which bug introduced the flaw?: None
- Do you have backports for the affected branches?: Yes
- If not, how different, hard to create, and risky will they be?: the same patch should work everywhere.
- How likely is this patch to cause regressions; how much testing does it need?: This is disabled by default (so I'm not even sure approval is needed)
https://searchfox.org/mozilla-central/source/dom/webidl/SpeechRecognition.webidl#13
https://searchfox.org/mozilla-central/source/modules/libpref/init/StaticPrefList.yaml#9207,9209
I just noticed a change in the status of this issue.
Thanks for your patch and such a quick CONFIRM and response!
Comment 4•4 years ago
|
||
Comment on attachment 9271870 [details]
Bug 1764112, ensure there is a reasonable SpeechRecognition object around when handling SpeechEvents, r=eeejay
Approved to land and uplift
| Assignee | ||
Comment 5•4 years ago
|
||
Comment on attachment 9271870 [details]
Bug 1764112, ensure there is a reasonable SpeechRecognition object around when handling SpeechEvents, r=eeejay
Beta/Release Uplift Approval Request
- User impact if declined: This code is disabled by default, so this affects only some unusual cases
- Is this code covered by automated tests?: No
- Has the fix been verified in Nightly?: No
- Needs manual test from QE?: No
- If yes, steps to reproduce:
- List of other uplifts needed: None
- Risk to taking this patch: Low
- Why is the change risky/not risky? (and alternatives if risky): Modifies preffed off code to be safer.
- String changes made/needed:
ESR Uplift Approval Request
- If this is not a sec:{high,crit} bug, please state case for ESR consideration:
- User impact if declined:
- Fix Landed on Version:
- Risk to taking this patch: Low
- Why is the change risky/not risky? (and alternatives if risky):
Comment 6•4 years ago
|
||
Landed: https://hg.mozilla.org/integration/autoland/rev/3399a9be4b03f746f62cb7aa77521a1547d4c205
Backed out for causing mda crashes on test_abort.html:
https://hg.mozilla.org/integration/autoland/rev/7be9ddd96b212916a3881039bc37004f58e77110
Push with failures: https://treeherder.mozilla.org/jobs?repo=autoland&group_state=expanded&selectedTaskRun=c3JBzTo9T82umZ8p7Mfy9Q.0&resultStatus=testfailed%2Cbusted%2Cexception%2Cretry&revision=3399a9be4b03f746f62cb7aa77521a1547d4c205
Failure log: https://treeherder.mozilla.org/logviewer?job_id=375278163&repo=autoland
PROCESS-CRASH | dom/media/webspeech/recognition/test/test_abort.html | application crashed [@ nsAutoOwningThread::AssertCurrentThreadOwnsMe(char const*) const]
| Assignee | ||
Comment 7•4 years ago
|
||
oh, interesting. That is actually a valid issue I guess
Comment 8•4 years ago
•
|
||
Comment on attachment 9271870 [details]
Bug 1764112, ensure there is a reasonable SpeechRecognition object around when handling SpeechEvents, r=eeejay
Declining the nomination given that the patch had to be backed out for causing crashes and that there are no more betas left in 100. I think it is safer to let it ride the trains, but feel free to NI me if there is strong need to get this into an RC build once a patch is ready given that its sec-high.
I'm not sure why there's a crash here. It seems like there is a invalid nsCycleCollector (Null Dereference) in the Context of SpeechRecognition::FeedAudioData (in GraphRunner thread):
* thread #49, name = 'GraphRunner', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
frame #0: 0x000000010b0ee08c XUL`RefPtr<nsCycleCollector>::operator!(this=0x0000000000000000) const at RefPtr.h:311:36
308 // needed separately? Shouldn't the compiler prefer using the non-deleted
309 // operator bool instead of the deleted operator T*?
310 explicit operator bool() const { return !!mRawPtr; }
-> 311 bool operator!() const { return !mRawPtr; }
312
313 T* operator->() const MOZ_NO_ADDREF_RELEASE_ON_RETURN {
314 MOZ_ASSERT(mRawPtr != nullptr,
Target 0: (plugin-container) stopped.
(lldb) bt
* thread #49, name = 'GraphRunner', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
* frame #0: 0x000000010b0ee08c XUL`RefPtr<nsCycleCollector>::operator!(this=0x0000000000000000) const at RefPtr.h:311:36
frame #1: 0x000000010b0edf17 XUL`::NS_CycleCollectorSuspect3(aPtr=0x0000000150ea9400, aCp=0x0000000000000000, aRefCnt=0x0000000150ea9438, aShouldDelete=0x0000000000000000) at nsCycleCollector.cpp:3764:7
frame #2: 0x000000010f913c8b XUL`mozilla::DOMEventTargetHelper::AddRef() [inlined] unsigned long nsCycleCollectingAutoRefCnt::incr<&(NS_CycleCollectorSuspect3)>(this=0x0000000150ea9438, aOwner=0x0000000150ea9400, aCp=0x0000000000000000) at nsISupportsImpl.h:248:7
frame #3: 0x000000010f913c3a XUL`mozilla::DOMEventTargetHelper::AddRef() [inlined] unsigned long nsCycleCollectingAutoRefCnt::incr<&(NS_CycleCollectorSuspect3)>(this=0x0000000150ea9438, aOwner=0x0000000150ea9400) at nsISupportsImpl.h:234
frame #4: 0x000000010f913c1e XUL`mozilla::DOMEventTargetHelper::AddRef(this=0x0000000150ea9400) at DOMEventTargetHelper.cpp:85
frame #5: 0x0000000110b95875 XUL`mozilla::dom::SpeechRecognition::AddRef(this=0x0000000150ea9400) at SpeechRecognition.cpp:145:1
frame #6: 0x000000010e6d4f85 XUL`mozilla::RefPtrTraits<mozilla::dom::SpeechRecognition>::AddRef(aPtr=0x0000000150ea9400) at RefPtr.h:49:39
frame #7: 0x000000010e6d4f25 XUL`RefPtr<mozilla::dom::SpeechRecognition>::ConstRemovingRefPtrTraits<mozilla::dom::SpeechRecognition>::AddRef(aPtr=0x0000000150ea9400) at RefPtr.h:380:35
frame #8: 0x0000000110ba5a15 XUL`RefPtr<mozilla::dom::SpeechRecognition>::RefPtr(this=0x0000000150f16d18, aRawPtr=0x0000000150ea9400) at RefPtr.h:109:7
frame #9: 0x0000000110b9679d XUL`RefPtr<mozilla::dom::SpeechRecognition>::RefPtr(this=0x0000000150f16d18, aRawPtr=0x0000000150ea9400) at RefPtr.h:107:54
frame #10: 0x0000000110b9b7cf XUL`mozilla::dom::SpeechEvent::SpeechEvent(this=0x0000000150f16ce0, aRecognition=0x0000000150ea9400, aType=EVENT_AUDIO_DATA) at SpeechRecognition.cpp:1149:7
frame #11: 0x0000000110b91473 XUL`mozilla::dom::SpeechEvent::SpeechEvent(this=0x0000000150f16ce0, aRecognition=0x0000000150ea9400, aType=EVENT_AUDIO_DATA) at SpeechRecognition.cpp:1151:21
frame #12: 0x0000000110b9b5cf XUL`mozilla::dom::SpeechRecognition::FeedAudioData(this=0x0000000150ea9400, aSamples=already_AddRefed<mozilla::SharedBuffer> @ 0x0000700003c023f8, aDuration=480, aProvider=0x0000000150e47160, aTrackRate=48000) at SpeechRecognition.cpp:1101:35
......
......
| Assignee | ||
Comment 10•4 years ago
|
||
The crash is clear. We're in a wrong thread.
Updated•4 years ago
|
Comment 11•4 years ago
|
||
The severity field is not set for this bug.
:anatal, could you have a look please?
For more information, please visit auto_nag documentation.
| Reporter | ||
Comment 12•4 years ago
|
||
Hi, will you update a new patch for this issue recently? Thanks.
| Assignee | ||
Comment 13•4 years ago
|
||
Yes I will. ( Obviously this issue doesn't happen unless on changes the pref )
| Assignee | ||
Updated•4 years ago
|
Updated•4 years ago
|
| Reporter | ||
Comment 14•4 years ago
|
||
| Reporter | ||
Comment 15•4 years ago
|
||
Hello,
Anything update for this issue?
Comment 16•4 years ago
|
||
Olli and I talked a bit - we were not sure if sec-high is the right rating for this issue, given the feature is disabled by default.
Comment 17•4 years ago
|
||
Security bugs are rated as though the feature is enabled, which can be a bit awkward in cases like this. However, it does mean that sec-high bugs are not always actually high priority bugs to fix.
[Tracking Requested - why for this release]: This feature is disabled by default, so we probably don't need to fix it right away.
Updated•4 years ago
|
| Reporter | ||
Comment 18•4 years ago
|
||
Thank you for still working on this vulnerability.
I don't know the detailed rules of rating here. But I suggest you consider that this vulnerability does not require user interaction to trigger. And I have found that some developers and a small number of users will enable this configuration to make the website compatible.(Just a suggestion).
| Reporter | ||
Comment 19•4 years ago
|
||
Since vulnerabilities are not easily fixed in imperfect modules(and its patch was back out once), I agree to delay the fix of the issue.
But will you commit a valid patch before the end of the 90-day deadline?
Updated•4 years ago
|
| Assignee | ||
Comment 22•4 years ago
|
||
| Assignee | ||
Comment 23•4 years ago
|
||
Comment on attachment 9282336 [details]
Bug 1764112, ensure there is a reasonable SpeechRecognition object around when handling SpeechEvents, r=eeejay
Security Approval Request
- How easily could an exploit be constructed based on the patch?: The patch does pinpoint where the issue is.
- Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem?: Yes
- Which older supported branches are affected by this flaw?: all, but behind a pref
- If not all supported branches, which bug introduced the flaw?: None
- Do you have backports for the affected branches?: Yes
- If not, how different, hard to create, and risky will they be?: the same patch should work everywhere.
- How likely is this patch to cause regressions; how much testing does it need?: This is disabled by default (so I'm not even sure approval is needed)
- Is Android affected?: Yes
Comment 24•4 years ago
|
||
Comment on attachment 9282336 [details]
Bug 1764112, ensure there is a reasonable SpeechRecognition object around when handling SpeechEvents, r=eeejay
Approved to land and uplift
Comment 25•4 years ago
|
||
ensure there is a reasonable SpeechRecognition object around when handling SpeechEvents, r=eeejay
https://hg.mozilla.org/integration/autoland/rev/1bc2769872aa43a9a820ecb0037d60d8816073b1
https://hg.mozilla.org/mozilla-central/rev/1bc2769872aa
Comment 26•4 years ago
|
||
Since nightly and release are affected, beta will likely be affected too.
For more information, please visit auto_nag documentation.
Updated•4 years ago
|
Updated•4 years ago
|
Updated•4 years ago
|
Comment 28•4 years ago
|
||
Are we intending to nominate this for Beta/ESR102/ESR91 uplift? Please do so if yes. It grafts cleanly as-landed.
| Assignee | ||
Comment 29•4 years ago
|
||
I don't know whether we need this elsewhere. The code is disabled by a pref by default.
Do we have some generic rule about this kind of case?
Updated•4 years ago
|
Comment 30•4 years ago
|
||
This is a hard question. Normally we'd consider this an unfinished experimental feature and wouldn't back-port it. But on Chrome's stats site it appears to be used quite a lot. This might encourage more people that we expect to turn this feature on and therefore make themselves vulnerable. We are not, unfortunately, gathering our own stats on the use of this feature or pref setting as far as I can see which makes everything a big guess.
In the short term we don't need to worry about ESR-91 (but it doesn't really hurt to fix it if it grafts cleanly)
In the longer term do we need to worry about ESR-102? From the Chrome stats it appears the number of sites using the API is growing. It might just be sites using it as part of a fingerprinting API, but maybe it's really for compatibility with sites that have worked in Chrome for a while. hard to say. The "better safe than sorry" principal says to land this on ESR-102 and beta at least. It might be easier to simply land this on ESR-91 than to have to justify why we think the risk is remote.
Comment 31•4 years ago
|
||
It's too late for Beta 103 at this point, but we could still take it for 91.13/102.2esr next cycle. I thought in general we were being more proactive about backports for preffed-off features these days given some of the recent incidents.
Updated•3 years ago
|
Updated•2 years ago
|
Description
•