Stream: git-wasmtime

Topic: wasmtime / PR #14538 [stack-switching] Fix ASan-host interop


view this post on Zulip Wasmtime GitHub notifications bot (Oct 05 2026 at 14:55):

dhil requested alexcrichton for a review on PR #14538.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 05 2026 at 14:55):

dhil requested wasmtime-compiler-reviewers for a review on PR #14538.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 05 2026 at 14:55):

dhil requested wasmtime-core-reviewers for a review on PR #14538.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 05 2026 at 14:55):

dhil updated PR #14538.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 05 2026 at 14:56):

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_bottom information.

The fix is to extend the ASan stack-switch handshake with both source and target VMCommonStackInformation pointers:

  1. Before switching, the start hook receives (source_csi, target_csi).
  2. It supplies the target's known bounds to __sanitizer_start_switch_fiber.
  3. It temporarily records the source CSI in a thread-local in-flight slot.
  4. Immediately after switching, the finish hook obtains the previous stack’s bounds from __sanitizer_finish_switch_fiber.
  5. It stores those bounds in the recorded source CSI and clears the in-flight slot.

Resolves #14508

view this post on Zulip Wasmtime GitHub notifications bot (Oct 05 2026 at 16:23):

:memo: alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 05 2026 at 16:23):

: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

view this post on Zulip Wasmtime GitHub notifications bot (Oct 05 2026 at 16:23):

: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 VMCommonStackInformation it naively seems like one of those can be used, but I'm also likely missing something

view this post on Zulip Wasmtime GitHub notifications bot (Oct 05 2026 at 17:48):

github-actions[bot] added the label wasmtime:api on PR #14538.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 06 2026 at 10:30):

:memo: dhil submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 06 2026 at 10:30):

: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?

view this post on Zulip Wasmtime GitHub notifications bot (Oct 06 2026 at 10:31):

:speech_balloon: dhil edited PR review comment.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 06 2026 at 11:05):

:memo: dhil submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 06 2026 at 11:05):

: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).

view this post on Zulip Wasmtime GitHub notifications bot (Oct 06 2026 at 16:49):

:memo: dhil submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 06 2026 at 16:49):

: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.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 07 2026 at 10:47):

dhil updated PR #14538.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 07 2026 at 11:17):

dhil updated PR #14538.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 07 2026 at 11:34):

:memo: dhil submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 07 2026 at 11:34):

:speech_balloon: dhil created PR review comment:

I've implemented the change now. Note I had to slightly reorganise the fields of VMCommonStackInformation to ensure that revision remains at an 8-aligned offset.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 07 2026 at 22:24):

:memo: alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 07 2026 at 22:24):

: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

view this post on Zulip Wasmtime GitHub notifications bot (Oct 07 2026 at 22:24):

:thumbs_up: alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 07 2026 at 22:24):

alexcrichton added PR #14538 [stack-switching] Fix ASan-host interop to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 07 2026 at 22:48):

:check: alexcrichton merged PR #14538.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 07 2026 at 22:48):

alexcrichton removed PR #14538 [stack-switching] Fix ASan-host interop from the merge queue.


Last updated: Oct 11 2026 at 02:20 UTC