Closed Bug 1655848 Opened 5 years ago Closed 5 years ago

AddressSanitizer: SEGV [@ js::gc::CellWithTenuredGCPointer] or [@ js::gc::detail::GetCellLocation] with ARM64 simulator

Categories

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

All
Linux
defect

Tracking

()

RESOLVED FIXED
81 Branch
Tracking Status
firefox81 --- fixed

People

(Reporter: gkw, Assigned: cfallin)

References

(Blocks 1 open bug)

Details

(Keywords: testcase)

Crash Data

Attachments

(4 files)

Attached file testcase.tar.xz
AddressSanitizer:DEADLYSIGNAL
=================================================================
==1308158==ERROR: AddressSanitizer: SEGV on unknown address 0x40007fff4000 (pc 0x5602ea595668 bp 0x7ffcd1399aa0 sp 0x7ffcd1399980 T0)
==1308158==The signal is caused by a READ memory access.
    #0 0x5602ea595667 in js::gc::CellWithTenuredGCPointer<js::gc::Cell, js::ObjectGroup>::headerPtr() const /home/mini3lin/trees/mozilla-central/js/src/gc/Cell.h:732:42
    #1 0x5602ea595667 in JSObject::groupRaw() const /home/mini3lin/trees/mozilla-central/js/src/vm/JSObject.h:89:46
    #2 0x5602ea595667 in JSObject::isSingleton() const /home/mini3lin/trees/mozilla-central/js/src/vm/JSObject.h:155:37
    #3 0x5602ea595667 in js::TypeSet::ObjectType(JSObject const*) /home/mini3lin/trees/mozilla-central/js/src/vm/TypeInference-inl.h:134:12
    #4 0x5602ea595667 in js::TypeSet::GetValueType(JS::Value const&) /home/mini3lin/trees/mozilla-central/js/src/vm/TypeInference-inl.h:236:12
    #5 0x5602ea595667 in js::jit::JitScript::MonitorArgType(JSContext*, JSScript*, unsigned int, JS::Value const&) /home/mini3lin/trees/mozilla-central/js/src/vm/TypeInference-inl.h:856:35
    #6 0x5602ea595667 in js::jit::DoTypeMonitorFallback(JSContext*, js::jit::BaselineFrame*, js::jit::ICTypeMonitor_Fallback*, JS::Handle<JS::Value>, JS::MutableHandle<JS::Value>) /home/mini3lin/trees/mozilla-central/js/src/jit/BaselineIC.cpp:1276:5
/snip

Run with --fuzzing-safe --no-threads --no-baseline --no-ion --wasm-compiler=cranelift --blinterp --blinterp-warmup-threshold=0, compile with AR=ar sh ./configure --enable-simulator=arm64 --enable-address-sanitizer --disable-jemalloc --with-ccache --enable-gczeal --enable-debug-symbols --disable-tests, tested on m-c rev 2f8d4f1f6608.

Full log coming up. Unsure if this is s-s as this involves cranelift and ARM64 simulator. Please open up if otherwise.

Flags: needinfo?(cfallin)

This may be related to decoder's bug 1655695.

Group: core-security → javascript-core-security
Attached file Debug stack

Stack with the following build: AR=ar sh ./configure --enable-simulator=arm64 --enable-debug --with-ccache --enable-gczeal --enable-debug-symbols --disable-tests

Crash Signature: [@ js::gc::detail::GetCellLocation]
Summary: AddressSanitizer: SEGV [@ js::gc::CellWithTenuredGCPointer] with ARM64 simulator → AddressSanitizer: SEGV [@ js::gc::CellWithTenuredGCPointer] or [@ js::gc::detail::GetCellLocation] with ARM64 simulator

Reproduced locally -- I will look into this ASAP. Thanks!

Assignee: nobody → cfallin
Flags: needinfo?(cfallin)
Flags: needinfo?(cfallin)
The first bad revision is:
changeset:   https://hg.mozilla.org/mozilla-central/rev/7c91f246f03f
user:        Lars T Hansen
date:        Mon Jul 27 14:23:18 2020 +0000
summary:     Bug 1649718 - Introduce fuzzing intercession points in feature switches.  r=bbouvier

Probably related to bug 1649718?

Flags: sec-bounty?
Regressed by: 1649718

The true regression point is likely bug 1633721, which introduced reftypes support in Cranelift/aarch64; the above bug just exposes Cranelift to more fuzzing.

Regressed by: 1633721
No longer regressed by: 1649718
Flags: needinfo?(cfallin)
Flags: needinfo?(cfallin)

This turns out to actually be an issue with value width and ABI assumptions about high bits. I managed to reduce the example down to the helper (function 21) that passes an i32 to a JS import after narrowing it from a 64-bit value with i32.wrap_i64. We follow the usual convention of allowing undefined bits above the value's width until they need to be cleared or sign-extended (this works fine for e.g. adds/subtracts and logical ops). So i32.wrap_i64 is a no-op (and of course the i32 result type will force a zero-extension later to clear the high bits if needed). However the SpiderMonkey ABI really does want an i32 to have zeroed high bits in a 64-bit register.

The following patch to Cranelift (then re-vendoring into m-c) fixes this:

diff --git a/cranelift/codegen/src/isa/aarch64/lower_inst.rs b/cranelift/codegen/src/isa/aarch64/lower_inst.rs
index 5fa0ebdc6..d8f11d8d8 100644
--- a/cranelift/codegen/src/isa/aarch64/lower_inst.rs
+++ b/cranelift/codegen/src/isa/aarch64/lower_inst.rs
@@ -1616,7 +1616,12 @@ pub(crate) fn lower_insn_to_regs<C: LowerCtx<I = Inst>>(
             abi.emit_stack_pre_adjust(ctx);
             assert!(inputs.len() == abi.num_args());
             for (i, input) in inputs.iter().enumerate() {
-                let arg_reg = put_input_in_reg(ctx, *input, NarrowValueMode::None);
+                let input_ty = ctx.input_ty(input.insn, input.input);
+                let narrow_mode = match input_ty {
+                    B1 | I8 | B8 | I16 | B16 | I32 | B32 => NarrowValueMode::ZeroExtend64,
+                    _ => NarrowValueMode::None,
+                };
+                let arg_reg = put_input_in_reg(ctx, *input, narrow_mode);
                 abi.emit_copy_reg_to_arg(ctx, i, arg_reg);
             }
             abi.emit_call(ctx);

I'll clean it up and create a PR tomorrow (and probably put the widening logic in the ABI module instead, conditional on the Baldrdash flag).

Flags: needinfo?(cfallin)
No longer regressed by: 1633721

Cranelift is currently not enabled by default and we don't file Cranelift bugs as s-s yet.

Group: javascript-core-security
Flags: sec-bounty?
Severity: -- → S2
Status: NEW → ASSIGNED
Priority: -- → P1

Cranelift PR at https://github.com/bytecodealliance/wasmtime/pull/2081. Will post a patch here to update vendored Cranelift once the PR merges.

This PR vendors in the latest version of Cranelift, rev
026fb8d388964c7c1bace7019c4fe0d63c584560. This includes a fix for bug
1655848 (from GitHub PR #2081), as well as several other miscellaneous
changes.

Pushed by cfallin@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/e0ac26d4e4a5 vendor in new Cranelift to fix fuzzbug. r=jseward
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → 81 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: