Closed Bug 1915105 Opened 2 years ago Closed 2 years ago

out-of-bounds-read with wasm_experimental_compile_pipeline

Categories

(Core :: JavaScript: WebAssembly, defect, P1)

defect

Tracking

()

RESOLVED FIXED
132 Branch
Tracking Status
firefox-esr115 --- unaffected
firefox-esr128 --- disabled
firefox129 --- disabled
firefox130 --- disabled
firefox131 --- disabled
firefox132 --- fixed

People

(Reporter: neseesun, Assigned: jseward)

References

Details

(Keywords: csectype-bounds, reporter-external, sec-high)

Attachments

(1 file, 1 external file)

1009 bytes, application/x-zip-compressed
Details
Attached file 3.zip —

Steps to reproduce:

this can be reproduced with current head

build with:
../configure --enable-debug --enable-wasm-js-string-builtins --enable-optimize --disable-tests --enable-wasm-simd --enable-wasm-avx --enable-wasm-moz-intgemm

run with:
js -P wasm_experimental_compile_pipeline=true out.js

component is js => wasm

Actual results:

The root cause is probably a GC related thread race,the poc sometimes hang,some times crash with a null deref,and sometimes trigger a release_assert.
GDB release_assert context:
───────────────────────────────────────────[ REGISTERS / show-flags off / show-compact-regs off ]───────────────────────────────────────────
RAX 0x6150a6a904f0 ◂— 'MOZ_RELEASE_ASSERT(localIndex < rangeInModule.length)'
RBX 0x77cf181fa4c0 ◂— 0
RCX 0x6150ab4ce160 (gMozCrashReason) —▸ 0x6150a6a904f0 ◂— 'MOZ_RELEASE_ASSERT(localIndex < rangeInModule.length)'
RDX 0x77cf19a1b723 (IO_2_1_stderr+131) ◂— 0xa1ca600000000000
RDI 0x77cf19a1ca60 (_IO_stdfile_2_lock) ◂— 0
RSI 0
R8 0
R9 0x6150ab4d4a70 (__afl_area_initial) ◂— 0x10000000002
R10 1
R11 0x293
R12 0x6150ab210938 (__afl_area_ptr) —▸ 0x6150ab4d4a70 (__afl_area_initial) ◂— 0x10000000002
R13 0x77cf19606260 —▸ 0x77cf19606280 ◂— 0xef9e32c0c330c9
R14 0x77cf181fa4e0 ◂— 0xaaaaaaaa00000000
R15 0x6a
RBP 0x77cf181fa3e0 —▸ 0x77cf181fa460 —▸ 0x77cf181faec0 —▸ 0x77cf181fcc20 —▸ 0x77cf181fcc60 ◂— ...
RSP 0x77cf181fa100 —▸ 0x77cf196061b8 —▸ 0x77cf196061d8 ◂— 0xe5e5e5e5e5e5e5e5
RIP 0x6150aa8b0cec (EmitCallRef((anonymous namespace)::FunctionCompiler&)+4172) ◂— mov dword ptr [0], 0x1449
────────────────────────────────────────────────────[ DISASM / x86-64 / set emulate on ]────────────────────────────────────────────────────
► 0x6150aa8b0cec <EmitCallRef((anonymous namespace)::FunctionCompiler&)+4172> mov dword ptr [0], 0x1449 <Cannot dereference [0]>
0x6150aa8b0cf7 <EmitCallRef((anonymous namespace)::FunctionCompiler&)+4183> call abort <abort>

0x6150aa8b0cfc <EmitCallRef((anonymous namespace)::FunctionCompiler&)+4188> movsxd rax, dword ptr [rip + 0xba8ab9] RAX, [_start___sancov_guards+2395724]
0x6150aa8b0d03 <EmitCallRef((anonymous namespace)::FunctionCompiler&)+4195> lea rcx, [rip + 0x95fc2e] RCX => 0x6150ab210938 (afl_area_ptr)
0x6150aa8b0d0a <EmitCallRef((anonymous namespace)::FunctionCompiler&)+4202> mov rcx, qword ptr [rcx]
0x6150aa8b0d0d <EmitCallRef((anonymous namespace)::FunctionCompiler&)+4205> movzx edx, byte ptr [rcx + rax]
0x6150aa8b0d11 <EmitCallRef((anonymous namespace)::FunctionCompiler&)+4209> inc dl
0x6150aa8b0d13 <EmitCallRef((anonymous namespace)::FunctionCompiler&)+4211> movzx edx, dl
0x6150aa8b0d16 <EmitCallRef((anonymous namespace)::FunctionCompiler&)+4214> cmp dl, 2
0x6150aa8b0d19 <EmitCallRef((anonymous namespace)::FunctionCompiler&)+4217> mov esi, 1 ESI => 1
0x6150aa8b0d1e <EmitCallRef((anonymous namespace)::FunctionCompiler&)+4222> cmovae esi, edx
─────────────────────────────────────────────────────────────[ SOURCE (CODE) ]──────────────────────────────────────────────────────────────
In file: /home/r00t/firefox/js/src/wasm/WasmIonCompile.cpp:5193
5188 }
5189
5190 CallRefMetricsRange rangeInModule =
5191 codeMeta
.getFuncDefCallRefs(funcIndex());
5192 uint32_t localIndex = numCallRefs
++;
► 5193 MOZ_RELEASE_ASSERT(localIndex < rangeInModule.length);
5194 uint32_t moduleIndex = rangeInModule.begin + localIndex;
5195 return codeMeta
.getCallRefHint(moduleIndex);
5196 }
5197
5198 #if DEBUG
─────────────────────────────────────────────────────────────────[ STACK ]──────────────────────────────────────────────────────────────────
00:0000│ rsp 0x77cf181fa100 —▸ 0x77cf196061b8 —▸ 0x77cf196061d8 ◂— 0xe5e5e5e5e5e5e5e5
01:0008│-2d8 0x77cf181fa108 —▸ 0x77cf181fa4e0 ◂— 0xaaaaaaaa00000000
02:0010│-2d0 0x77cf181fa110 —▸ 0x6150ab210938 (__afl_area_ptr) —▸ 0x6150ab4d4a70 (__afl_area_initial) ◂— 0x10000000002
03:0018│-2c8 0x77cf181fa118 ◂— 0
04:0020│-2c0 0x77cf181fa120 ◂— 0
05:0028│-2b8 0x77cf181fa128 ◂— 0xef9e32c0c330c9
06:0030│-2b0 0x77cf181fa130 —▸ 0x77cf181fa190 —▸ 0x77cf181fa1b0 ◂— 0xaaaaaaaaaaaaaaaa
07:0038│-2a8 0x77cf181fa138 —▸ 0x6150aa8fdd5e (js::wasm::OpIter<(anonymous namespace)::IonCompilePolicy>::checkIsSubtypeOf(js::wasm::ResultType, js::wasm::ResultType)+1950) ◂— test al, al

Since 0xe5e5e5e5e5e5e5e5 is the "jemalloc freed memory" marker,and null deref sometimes trigger,so file this as a GC related thread race security issue

Group: firefox-core-security → core-security
Component: Untriaged → JavaScript: WebAssembly
Product: Firefox → Core
Version: other → unspecified
Group: core-security → javascript-core-security
Invalid read of size 4
   at 0x3C5448F: js::wasm::Instance::submitCallRefHints(unsigned int) (src/wasm/WasmInstance.cpp:2731)
   by 0x3BD4519: WasmHandleRequestTierUp(js::wasm::Instance*) (src/wasm/WasmBuiltins.cpp:715)
   by 0x1F58C64223ED: wasmSharedStubs:RequestTierUpStub@..c6422310 (in ???)
   by 0x1F58C644209B: wasmBL:Function-but-no-CM::namePayload@..c6442000 (in ???)
   by 0x1F58C6442103: wasmBL:InterpEntry@..c64420b0 (in ???)
   by 0x3C56A9F: js::wasm::Instance::callExport(JSContext*, unsigned int, JS::CallArgs const&, js::wasm::CoercionLevel) (src/wasm/WasmInstance.cpp:3610)
 Address 0x74291d0 is 0 bytes after a block of size 0 alloc'd
   at 0x4C0EEC8: calloc (vg_replace_malloc.c:1675)
   by 0x21E77EC: SystemMalloc::calloc(unsigned long, unsigned long) (memory/build/malloc_decls.h:52)

It pretty much goes south after that:

Invalid read of size 4
   at 0x21DCCE1: store (atomic_base.h:481)
   by 0x21DCCE1: mozilla::detail::IntrinsicMemoryOps<unsigned int, (mozilla::MemoryOrdering)2>::store(std::atomic<unsigned int>&, unsigned int) (dist/include/mozilla/Atomics.h:203)
   by 0x21DCC3A: mozilla::detail::AtomicBase<unsigned int, (mozilla::MemoryOrdering)2>::operator=(unsigned int) (dist/include/mozilla/Atomics.h:305)
   by 0x3CD3FE2: js::wasm::CodeMetadata::setCallRefHint(unsigned int, js::wasm::CallRefHint) const (src/wasm/WasmMetadata.h:301)
 Address 0x74277e0 is 0 bytes after a block of size 0 alloc'd
   at 0x4C0EEC8: calloc (vg_replace_malloc.c:1675)
   by 0x21E77EC: SystemMalloc::calloc(unsigned long, unsigned long) (memory/build/malloc_decls.h:52)

Conditional jump or move depends on uninitialised value(s)
   at 0x3C54492: js::wasm::Instance::submitCallRefHints(unsigned int) (src/wasm/WasmInstance.cpp:2731)
   by 0x3BD4519: WasmHandleRequestTierUp(js::wasm::Instance*) (src/wasm/WasmBuiltins.cpp:715)
   by 0x1F58C64223ED: wasmSharedStubs:RequestTierUpStub@..c6422310 (in ???)
   by 0x1F58C644209B: wasmBL:Function-but-no-CM::namePayload@..c6442000 (in ???)
   by 0x1F58C6442103: wasmBL:InterpEntry@..c64420b0 (in ???)
   by 0x3C56A9F: js::wasm::Instance::callExport(JSContext*, unsigned int, JS::CallArgs const&, js::wasm::CoercionLevel) (src/wasm/WasmInstance.cpp:3610)

I wonder if this is another tracked-callsite-in-dead-code bug, similar to
one we fixed recently -- bug 1913876.

Right, it is call_ref in the dead code. It is preceded by return_call. Reduced test case:

var ins = wasmEvalText(
  `(module
    (type $t (func))
    (func $f (export "f")
      return_call $f
      call_ref $t
    )
  )
`);
ins.exports.f(100);

Are we counting ref hints for tail calls?

I'm changing the summary to sound more severe and marking it as new because is sounds like jseward was able to reproduce. We can further adjust it as needed.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: nullptr deref with wasm_experimental_compile_pipeline → use-after-free with wasm_experimental_compile_pipeline

Hi,sorry forget the credit information,reporter please credit as:
"Sun ZhiWei from Lenovo GIC security lab"

Thanks

Severity: -- → S2
Priority: -- → P1

Bumping down to sec-moderate in accordance with the guidelines here ("Moderate severity represents a fairly wide range of issues, that include: Vulnerabilities that would be considered a sec-high but require the user to perform unusual or complex actions or is limited in scope of affected users or capability...")

Keywords: sec-high → sec-moderate
Severity: S2 → S3

What is limiting the scope of this? That it only reproduces intermittently? Do we know what the failure rate is?

Flags: needinfo?(iireland)

"-P wasm_experimental_compile_pipeline" flag is experimental and disabled in nightly by default https://searchfox.org/mozilla-central/source/modules/libpref/init/StaticPrefList.yaml#8275

Flags: needinfo?(iireland)

For disabled features, we rate them as though they were enabled, so if that's the reason, this should remain high. Unfortunately the bot is not smart enough to understand disabled so you'll have to ignore it when it asks you to increase the severity.

Hmm. It seems like this is a somewhat unintended consequence of bug 1877193. We made it easier to add prefs (which work in both the browser and the shell), and so we're using them for things that would previously only be shell flags.

Is there a way to specify prefs so that they don't count as enabled for the purpose of rating sec bugs? Or should we just avoid making prefs for this kind of code?

(Also, is there somewhere else I should be looking for sec bug ratings? The wiki page I linked doesn't say anything about disabled features. Maybe it just needs to be updated?)

This is off topic for the bug. Maybe we could discuss the approach to rating of disabled features in the #security channel on MoCo Slack? It is certainly a frequent Firefox developer complaint.

The severity field for this bug is set to S3. However, the bug is flagged with the sec-high keyword.
:rhunt, could you consider increasing the severity of this security bug?

For more information, please visit BugBot documentation.

Flags: needinfo?(rhunt)
Flags: needinfo?(rhunt)
Assignee: nobody → jseward
Attached file Bug 1915105. r=yury. —
Summary: use-after-free with wasm_experimental_compile_pipeline → out-of-bounds-read with wasm_experimental_compile_pipeline

Comment on attachment 9422042 [details]
Bug 1915105. r=yury.

Security Approval Request

  • How easily could an exploit be constructed based on the patch?: I don't see how an exploit could be constructed. At worst the bug causes an optimisation mechanism in the new wasm experimental compile pipeline to make optimisation decisions based on garbage data, and possibly segfault the wasm engine in the process. It won't affect correctness of generated code. Note, this functionality is experimental and disabled in nightly by default.
  • Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem?: No
  • Which branches (beta, release, and/or ESR) are affected by this flaw, and do the release status flags reflect this affected/unaffected state correctly?: release, probably beta
  • 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?: We have a feasible backport for 131.
  • How likely is this patch to cause regressions; how much testing does it need?: Unlikely; it is in experimental, disabled-by-default code.
  • Is the patch ready to land after security approval is given?: Yes
  • Is Android affected?: Yes
Attachment #9422042 - Flags: sec-approval?

Comment on attachment 9422042 [details]
Bug 1915105. r=yury.

Approved to land and request uplift

Attachment #9422042 - Flags: sec-approval? → sec-approval+
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 132 Branch
Group: javascript-core-security → core-security-release
QA Whiteboard: [post-critsmash-triage]
Flags: qe-verify-

Hi,is this qualify for CVE and/or bug bounty?What is Mozilla's standard for bug bounty?

(In reply to neseesun from comment #17)

Hi,is this qualify for CVE and/or bug bounty?What is Mozilla's standard for bug bounty?

See this page for more information on our bug bounty program. Please email security@mozilla.org if you want this bug to be considered for a bug bounty. As you have seen, posting comments in bugs can easily be overlooked, so questions about the bug bounty program should be directed to that email address.

Flags: needinfo?(neseesun)

(In reply to Andrew McCreight [:mccr8] from comment #18)

(In reply to neseesun from comment #17)

Hi,is this qualify for CVE and/or bug bounty?What is Mozilla's standard for bug bounty?

See this page for more information on our bug bounty program. Please email security@mozilla.org if you want this bug to be considered for a bug bounty. As you have seen, posting comments in bugs can easily be overlooked, so questions about the bug bounty program should be directed to that email address.

I send an email to security@mozilla.org about bug bounty questions, we can talk about in that email thread, thanks

Flags: needinfo?(neseesun)
Flags: sec-bounty?

Unfortunately this bug was found in a disabled feature that is still under development and is out of scope for our bounty program. Unfinished features will have lots of bugs and in most cases that means our own testing processes hasn't finished with that feature.

Flags: sec-bounty? → sec-bounty-
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: