alexcrichton opened PR #12928 from alexcrichton:fiber-less-asan-false-positive to bytecodealliance:main:
This commit is aimed at fixing the ASAN false positives in #12899. Initially the fix there was to invoke some
__asan_*intrinsics, and I ended up finding a sort of smaller set of__asan_*intrinsics to call as well. In the end what's happening though is that fibers, upon terminating, have a few frames of Rust code on the stack before switching off. To ASAN these frames never returned so when a stack is subsequently reused ASAN is tricked into thinking this is buffer overflow or use-after-free since it's stomping on frames that haven't returned.The fix in this commit is to avoid this style of function which doesn't returns. Functions which don't return in Rust are easy to leak memory from and are a hazard from a safety perspective as well (e.g. it's unsafe to skip running destructors of stack variables). I feel we've had better success over time with "all Rust functions always return" and so what's what was applied here. Unlike #12899 or my thoughts on that PR this does not have any new
__asan_*intrinsic calls. Instead what this does is it shuffles around responsibility for what exact piece of the infrastructure is responsible for what. Specificallyfiber_startfunctions now actually return, meaning thewasmtime_fiber_startnaked function actually resumes execution, unlike before. Thewasmtime_fiber_startthen delegates towasmtime_fiber_switchimmediately to perform the final switch.Effectively there's now only two function frames that never return, and both of these frames are handwritten inline assembly. This means that ASAN gets to see that all normal functions return and updates all of its metadata accordingly. The end result is that the original issue from #12899 is fixed and this I feel is in general more robust as well.
One caveat is that the handwritten
wasmtime_fiber_startassembly needs to invoke a siblingwasmtime_fiber_switch_function. In lieu of trying to figure out how to get PIC-vs-not calls working (e.g. static calls) I've opted to use indirect function calls and pointers instead. This mirrors historical changes in our fiber implementation too.<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
alexcrichton requested pchickey for a review on PR #12928.
alexcrichton requested wasmtime-core-reviewers for a review on PR #12928.
pchickey submitted PR review.
alexcrichton added PR #12928 Update fibers to avoid no-return functions to the merge queue.
github-merge-queue[bot] removed PR #12928 Update fibers to avoid no-return functions from the merge queue.
alexcrichton updated PR #12928.
alexcrichton has enabled auto merge for PR #12928.
alexcrichton added PR #12928 Update fibers to avoid no-return functions to the merge queue.
github-merge-queue[bot] removed PR #12928 Update fibers to avoid no-return functions from the merge queue.
alexcrichton updated PR #12928.
alexcrichton has enabled auto merge for PR #12928.
alexcrichton added PR #12928 Update fibers to avoid no-return functions to the merge queue.
alexcrichton merged PR #12928.
alexcrichton removed PR #12928 Update fibers to avoid no-return functions from the merge queue.
Last updated: Apr 12 2026 at 23:10 UTC