dhil requested alexcrichton for a review on PR #14538.
dhil requested wasmtime-compiler-reviewers for a review on PR #14538.
dhil requested wasmtime-core-reviewers for a review on PR #14538.
dhil updated PR #14538.
dhil opened PR #14538 from dhil:stack-switching-asan-panic to bytecodealliance:main:
This patch fixes an issue with stack-switching on ASan-enabled builds where resuming continuations from a different host-to-Wasm invocation causes a panic. Because each host invocation creates a fresh initial stack information, it would inadvertently discard the previous stack bounds on a suspended continuation, leaving it without the
asan_stack_bottominformation.The fix is to extend the ASan stack-switch handshake with both source and target
VMCommonStackInformationpointers:
- Before switching, the start hook receives
(source_csi, target_csi).- It supplies the target's known bounds to
__sanitizer_start_switch_fiber.- It temporarily records the source CSI in a thread-local in-flight slot.
- Immediately after switching, the finish hook obtains the previous stack’s bounds from
__sanitizer_finish_switch_fiber.- It stores those bounds in the recorded source CSI and clears the in-flight slot.
Resolves #14508
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
How come these annotations are necessary? These aren't present in the craters/fiber code so I'm mostly just curious
:speech_balloon: alexcrichton created PR review comment:
I'm personally always a bit loathe to introduce more global/thread-local state -- would it be possibel to use some preexisting pointer storage for this? I'm not fully following what this is used for, but given the pointers and/or
VMCommonStackInformationit naively seems like one of those can be used, but I'm also likely missing something
github-actions[bot] added the label wasmtime:api on PR #14538.
:memo: dhil submitted PR review.
:speech_balloon: dhil created PR review comment:
I have put them conservatively here. Based on my understanding the wrapper functions invoking the ASan primitives shouldn't themselves be instrumented as it can lead to false-positives or crashes under certain ASan configuration, e.g. I got it from reading this issue https://github.com/google/sanitizers/issues/1760. Maybe it is being overly cautious?
:speech_balloon: dhil edited PR review comment.
:memo: dhil submitted PR review.
:speech_balloon: dhil created PR review comment:
The purpose of this global is to serve as a sort of mailbox for transferring bookkeeping data between stack switches. It is needed because ASan reports the old stack's bounds only after execution has moved to the destination stack. I don't think the API provides any way to transfer the necessary source metadata across that switch. I think it is important to note that this slot holds only the state during the switch handshake, i.e. its lifetime is brief and not dependent on the lifetime of the suspended continuation.
Regarding using a global: I tend to agree, but in this case I think a private global is the right thing, because it is used only in an esoteric debug build. So in a certain sense everything is nicely localised here. An alternative would be to stash it on the
VMCommonStackInformation. I don't like this because it affects the continuation layout for production builds (relatedly I do plan to look into making the layout leaner).
:memo: dhil submitted PR review.
:speech_balloon: dhil created PR review comment:
I will try to experiment with adding it to
VMCommonStackInformation, seeing that there are two other ASan-related things there already I figured it is better to bundle them together such that I have all the bits in one place then I later get to optimise the representation.
dhil updated PR #14538.
dhil updated PR #14538.
:memo: dhil submitted PR review.
:speech_balloon: dhil created PR review comment:
I've implemented the change now. Note I had to slightly reorganise the fields of
VMCommonStackInformationto ensure thatrevisionremains at an 8-aligned offset.
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
I didn't even realize that rustc supported these annotations today anyway, but I suppose if it works it works like most of the other ASAN stuff
:thumbs_up: alexcrichton submitted PR review.
alexcrichton added PR #14538 [stack-switching] Fix ASan-host interop to the merge queue.
:check: alexcrichton merged PR #14538.
alexcrichton removed PR #14538 [stack-switching] Fix ASan-host interop from the merge queue.
Last updated: Oct 11 2026 at 02:20 UTC