Closed Bug 2059577 Opened 3 months ago Closed 2 months ago

WasmCodegenTypes.h's InlinedCallerOffsetIndex bookkeeping is corrupted by the inliner

Categories

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

defect

Tracking

()

RESOLVED FIXED
156 Branch
Tracking Status
firefox-esr115 --- unaffected
firefox-esr140 --- wontfix
firefox-esr153 --- fixed
firefox154 --- wontfix
firefox155 --- wontfix
firefox156 --- fixed

People

(Reporter: yury, Assigned: rhunt)

References

(Blocks 2 open bugs, Regression)

Details

(4 keywords)

Attachments

(1 file, 2 external files)

Found that in the NOTES.md of bug 2058673. It looks unrelated to the initial issue filling it separately:

Related metadata-corruption defect in the same feature (documented)

WasmCodegenTypes.h's InlinedCallerOffsetIndex bookkeeping is also corrupted by
the inliner: RootCompiler::finishInlineCall (WasmIonCompile.cpp:11093) pops
inlinedCallerOffsets_ but never restores inlinedCallerOffsetsIndex_, so every
TrapSiteDesc/CallSiteDesc created in the caller after an inlined call carries
the finished callee's inlined-caller-offsets index. Observable with the same
prefs:

const bin = wasmTextToBinary(`(module
  (func $a (param i32) (result i32) (i32.add (local.get 0) (i32.const 1)))
  (func $root (export "run") (param i32) (result i32)
    (drop (call $a (local.get 0)))
    (if (local.get 0) (then unreachable))
    (i32.const 7)))`);
const inst = new WebAssembly.Instance(new WebAssembly.Module(bin));
for (let i = 0; i < 50; i++) inst.exports.run(0);
try { inst.exports.run(1); } catch (e) { print(e.stack); }

prints a phantom extra 'root' frame (the trap site in root code after the
inlined call reports the inlined-caller offsets of the earlier call to $a).'

Observation

root@…wasm-function[1]:0x34 ← the unreachable trap in $root
root@…wasm-function[1]:0x2d ← phantom frame (the earlier call $a site)
@…phantom-frame-testcase.js:38

Error: Assertion failed: got 2, expected 1 (exit 3)

Severity: -- → S3
Priority: -- → P3

RootCompiler stored inlinedCallerOffsetsIndex_ as a single shared field, but it
is really a per-inlined-function value. finishInlineCall popped
inlinedCallerOffsets_ without restoring the index, so TrapSiteDesc/CallSiteDesc
created in the caller after an inlined call carried the finished callee's index
and reported phantom inlined frames.

Move the index onto FunctionCompiler, which is already constructed and destroyed
per inline frame, and have startInlineCall hand it back for the callee compiler.

Assignee: nobody → rhunt
Status: NEW → ASSIGNED

:rhunt, please update all release status flags to reflect the affected/unaffected/disabled state correctly. Which branches (beta, release, and/or ESR) are affected by this flaw?

Flags: needinfo?(rhunt)

Is this the same as bug 2036252?

Yes this is a dupe. This isn't a security bug either.

Group: javascript-core-security
Keywords: sec-other
Duplicate of this bug: 2036252
Attachment #9629550 - Attachment description: (secure) → Bug 2059577 - Track inlinedCallerOffsetsIndex per inline frame. r?yury
Flags: needinfo?(rhunt)
Keywords: regression
Regressed by: 1961915

Set release status flags based on info from the regressing bug 1961915

Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 156 Branch

:rhunt, should ESR153 be a wontfix, or should the fix be uplifted?

Flags: needinfo?(rhunt)

This is a pretty simple patch that fixes the error stack when wasm functions are inlined. I think that's worth having in ESR. If it's not taken, that is okay too. It only fixes how the stack trace we report on JS exceptions, code should work as is.

Flags: needinfo?(rhunt)

firefox-esr153 Uplift Approval Request

  • User impact if declined/Reason for urgency: Stack traces reported to scripts may be wrong when a wasm function is inlined.
  • Code covered by automated testing?: yes
  • Fix verified in Nightly?: yes
  • Needs manual QE testing?: no
  • Steps to reproduce for manual QE testing: N/A
  • Risk associated with taking this patch: low
  • Explanation of risk level: Simple patch to our stack trace reporting code.
  • String changes made/needed?: None
  • Is Android affected?: yes
Attachment #9632898 - Flags: approval-mozilla-esr153?

RootCompiler stored inlinedCallerOffsetsIndex_ as a single shared field, but it
is really a per-inlined-function value. finishInlineCall popped
inlinedCallerOffsets_ without restoring the index, so TrapSiteDesc/CallSiteDesc
created in the caller after an inlined call carried the finished callee's index
and reported phantom inlined frames.

Move the index onto FunctionCompiler, which is already constructed and destroyed
per inline frame, and have startInlineCall hand it back for the callee compiler.

Original Revision: https://phabricator.services.mozilla.com/D320554

Attachment #9632898 - Flags: approval-mozilla-esr153? → approval-mozilla-esr153+
QA Whiteboard: [qa-triage-done-c157/b156]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: