LegalizeJSInterface: heap-use-after-free in Fixer::visitCall when a function named $legalfunc$<import> already exists
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
The crash involves makeLegalStubForCalledImport and Fixer::visitCall in src/passes/LegalizeJSInterface.cpp. Read how the stub's unique_ptr is handled when a function with the same name already exists, and how illegalImportsToLegal keeps its pointer. Build with ASan and run the three-line reproducer from the issue with --legalize-js-interface. Done when that run is clean and the call is legalized correctly even when a user function named $legalfunc$imp exists.
由索引模型根據 Issue 內容生成。
描述
--legalize-js-interface reads freed memory, and the release build segfaults, when the module already has a function whose name is the one the pass picks for its stub ($legalfunc$imp here).
(module
(import "env" "imp" (func $imp (param i64) (result i32)))
(func $legalfunc$imp (param i64) (result i32) (i32.const 7))
(func $f (result i32) (call $imp (i64.const 1)))
)
wasm-opt input.wat --legalize-js-interface -o /dev/null
ASan build (with BINARYEN_PASS_DEBUG=1):
==192075==ERROR: AddressSanitizer: heap-use-after-free on address 0x516000000f80 at pc 0x557ea312a1f1 bp 0x7fa01da45390 sp 0x7fa01da45380
READ of size 8 at 0x516000000f80 thread T2
#0 0x557ea312a1f0 in visitCall src/passes/LegalizeJSInterface.cpp:138
#1 0x557ea312a1f0 in doVisitCall src/wasm-delegations.def:23
#2 0x557ea30b5738 in walk src/wasm-traversal.h:318
freed by thread T0 here:
#3 0x557ea311338d in std::unique_ptr<wasm::Function, std::default_delete<wasm::Function> >::~unique_ptr() /usr/include/c++/11/bits/unique_ptr.h:361
#4 0x557ea311338d in makeLegalStubForCalledImport src/passes/LegalizeJSInterface.cpp:319
I expected the pass to legalize the call normally. The module is valid (wasm-opt input.wat -o /dev/null exits 0) and function names are free-form, so a user function called $legalfunc$imp should not break the pass.
Found at commit 93d6e9de7e1d99be22a49b8952426906a65df397 and still reproduces at 207bbaec4b30 (ASan build). A normal release build crashes with SIGSEGV and prints nothing. -all is not needed.
Looks like makeLegalStubForCalledImport in src/passes/LegalizeJSInterface.cpp builds the stub in a unique_ptr, keeps stub.get(), and only adds the stub to the module if no function with that name exists. Here one exists, so the stub is freed on return, and the dangling pointer stored in illegalImportsToLegal is later read by Fixer::visitCall.
Found with an LLM-based testing tool; I used Claude to reduce it and look for the cause.
- 主要語言
- WebAssembly
- 星號
- 8.7k
- 分支
- 897
- 平均合併
- 2 天 4 小時
- 30 天內合併 PR
- 103
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
WebAssembly/binaryen 的其他 Issue
-
難度 1/5 1 小時以內 新手友好度 88/100
WebAssembly/binaryen#9135 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 半天 新手友好度 76/100
WebAssembly/binaryen#9018 · 3 則留言 ·
維護者通常 1 天內回覆
-
難度 5/5 一週以上 新手友好度 15/100
WebAssembly/binaryen#9260 · 5 則留言 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 62/100
WebAssembly/binaryen#9257 · 2 則留言 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 45/100
WebAssembly/binaryen#9249 ·
維護者通常 1 天內回覆
查看 WebAssembly/binaryen 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 62/100
-
A binding pattern element named `from` or `as` fails with "Expected destructuring pattern": `const [from] = [1]`, `const { a: from } = o`, `([from]) => from`可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉bug engine spec compliance
難度 2/5 1-3 小時 新手友好度 78/100
frostney/GocciaScript#1737 ·
維護者通常 1 天內回覆
-
build enhancement medium priority
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
bug frontend rt sev-3
難度 2/5 1-3 小時 新手友好度 72/100
-
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆