Stream: git-wasmtime

Topic: wasmtime / PR #13321 Harden Wasmtime's compiled GC code a...


view this post on Zulip Wasmtime GitHub notifications bot (May 07 2026 at 23:07):

alexcrichton opened PR #13321 from alexcrichton:harden-gc-compild-code to bytecodealliance:main:

In the spirit of #13320 this commit goes through the compiled code for the GC proposal to ensure that, in the face of GC corruption, Wasmtime by default can recover and return a "bug" to the embedder. This was also discussed a bit in #13112 as well, and the changes made here are:

The end state is that faults in the GC heap in compiled code itself should show up as a bug! on the other end by default. This requires extra metadata in *.cwasms mapping traps, but this is similar to linear-memory-using-wasms which have lots of trap metadata for loads/stores. Being able to catch InternalAssert as a first-class error (as opposed to a signal) is a debugging nicety I've added here but remains off-by-default to avoid bloating *.cwasms for internal debugging.

Closes #13112

<!--
Please make sure you include the following information:

Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.html

Please ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->

view this post on Zulip Wasmtime GitHub notifications bot (May 07 2026 at 23:07):

alexcrichton requested fitzgen for a review on PR #13321.

view this post on Zulip Wasmtime GitHub notifications bot (May 07 2026 at 23:07):

alexcrichton requested wasmtime-compiler-reviewers for a review on PR #13321.

view this post on Zulip Wasmtime GitHub notifications bot (May 07 2026 at 23:07):

alexcrichton requested wasmtime-core-reviewers for a review on PR #13321.

view this post on Zulip Wasmtime GitHub notifications bot (May 07 2026 at 23:07):

alexcrichton requested wasmtime-fuzz-reviewers for a review on PR #13321.

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

alexcrichton updated PR #13321.

view this post on Zulip Wasmtime GitHub notifications bot (May 08 2026 at 03:54):

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

view this post on Zulip Wasmtime GitHub notifications bot (May 08 2026 at 03:54):

github-actions[bot] added the label wasmtime:config on PR #13321.

view this post on Zulip Wasmtime GitHub notifications bot (May 08 2026 at 03:54):

github-actions[bot] added the label fuzzing on PR #13321.

view this post on Zulip Wasmtime GitHub notifications bot (May 08 2026 at 03:55):

github-actions[bot] commented on PR #13321:

Subscribe to Label Action

cc @fitzgen

<details>
This issue or pull request has been labeled: "fuzzing", "wasmtime:api", "wasmtime:config"

Thus the following users have been cc'd because of the following labels:

To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.

Learn more.
</details>

view this post on Zulip Wasmtime GitHub notifications bot (May 08 2026 at 05:34):

github-actions[bot] commented on PR #13321:

Label Messager: wasmtime:config

It looks like you are changing Wasmtime's configuration options. Make sure to
complete this check list:

[fuzzing-config]: https://github.com/bytecodealliance/wasmtime/blob/ca0e8d0a1d8cefc0496dba2f77a670571d8fdcab/crates/fuzzing/src/generators.rs#L182-L194
[fuzzing-docs]: https://docs.wasmtime.dev/contributing-fuzzing.html


<details>

To modify this label's message, edit the <code>.github/label-messager/wasmtime-config.md</code> file.

To add new label messages or remove existing label messages, edit the
<code>.github/label-messager.json</code> configuration file.

Learn more.

</details>

view this post on Zulip Wasmtime GitHub notifications bot (May 08 2026 at 16:45):

alexcrichton requested wasmtime-default-reviewers for a review on PR #13321.

view this post on Zulip Wasmtime GitHub notifications bot (May 08 2026 at 16:45):

alexcrichton updated PR #13321.

view this post on Zulip Wasmtime GitHub notifications bot (May 08 2026 at 16:48):

alexcrichton commented on PR #13321:

I've pushed up a significant follow-up for this as well now to get tests passing. Notably Pulley and the Cranelift backend for Pulley didn't support loads/stores with custom trap codes. Previously the only possible trapping loads/stores were those with the HeapOutOfBounds trap code that were little endian (aka wasm loads/stores). The stores here now have different trap codes (custom ones for Wasmtime) and additionally might be big-endian (as not all GC data is little-endian). To handle that I've done two changes to Pulley:

Together these are then able to handle all possible loads/stores that can trap coming out of GC translation.

view this post on Zulip Wasmtime GitHub notifications bot (May 08 2026 at 19:08):

alexcrichton updated PR #13321.

view this post on Zulip Wasmtime GitHub notifications bot (May 08 2026 at 19:09):

alexcrichton commented on PR #13321:

The AddrZ addressing mode now carries a custom u8 payload for a trap code

Just kidding, that ran into trap encoding issues. Now the Cranelift *_z instructions have a Cranelift TrapCode and that gets plumbed into the MachBuffer like usual. The trap code associated in the interpreter with AddrZ is now None, meaning that we look up in trap side tables for the actual code. That gets everything to align correctly.

view this post on Zulip Wasmtime GitHub notifications bot (May 08 2026 at 20:40):

alexcrichton updated PR #13321.

view this post on Zulip Wasmtime GitHub notifications bot (May 09 2026 at 00:02):

github-actions[bot] added the label cranelift on PR #13321.

view this post on Zulip Wasmtime GitHub notifications bot (May 09 2026 at 00:02):

github-actions[bot] added the label cranelift:meta on PR #13321.

view this post on Zulip Wasmtime GitHub notifications bot (May 09 2026 at 00:02):

github-actions[bot] added the label isle on PR #13321.

view this post on Zulip Wasmtime GitHub notifications bot (May 09 2026 at 00:02):

github-actions[bot] commented on PR #13321:

Subscribe to Label Action

cc @cfallin, @fitzgen

<details>
This issue or pull request has been labeled: "cranelift", "cranelift:meta", "isle"

Thus the following users have been cc'd because of the following labels:

To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.

Learn more.
</details>

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 18:12):

:thumbs_up: fitzgen submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 18:12):

:speech_balloon: fitzgen created PR review comment:

Doc comment for this?

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 18:12):

:speech_balloon: fitzgen created PR review comment:

This should still have readonly set

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 18:12):

:speech_balloon: fitzgen created PR review comment:

And this should also have readonly

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 18:12):

:speech_balloon: fitzgen created PR review comment:

readonly

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 18:12):

:speech_balloon: fitzgen created PR review comment:

readonly

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 18:12):

:speech_balloon: fitzgen created PR review comment:

Maybe provide more details here about what the consequences of enabling and disabling these options are? As a user, I would not have any idea after reading these docs.

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 18:12):

:speech_balloon: fitzgen created PR review comment:

            CompiledTrap::Normal(trap) => {
                let b = *trap as u8;
                debug_assert_ne!(b, CompiledTrap::InternalAssert.as_u8());
                debug_assert_ne!(b, CompiledTrap::GcHeapCorrupt.as_u8());
                b
            }
            CompiledTrap::InternalAssert => 0xFF,
            CompiledTrap::GcHeapCorrupt => 0xFE,

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 18:12):

:speech_balloon: fitzgen created PR review comment:

This is loading out of vmctx, not the GC heap, so should continue using trusted flags (and readonly)

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 18:12):

:speech_balloon: fitzgen created PR review comment:

This is loading out of the vmctx, not the GC heap, so should remain as trusted (and readonly)

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 18:12):

:speech_balloon: fitzgen created PR review comment:

readonly

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 19:53):

:memo: alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 19:53):

:speech_balloon: alexcrichton created PR review comment:

Is that safe to do? For example if a memory location of a readonly load is actually modified, isn't that technically UB in Cranelift? If it's "produces odd result" I think that's fine, but from other compilers my expectation is that if a flag like readonly is violated it's UB

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 19:59):

alexcrichton updated PR #13321.

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 22:00):

:memo: fitzgen submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 22:00):

:speech_balloon: fitzgen created PR review comment:

readonly just allows for GVNing these loads, which means if it is misconfigured then we can get stale values. Cranelift won't ever "take advantage" of seeing a readonly load from a location that is later stored to and go crazy poisoning/undefing everything like LLVM can.

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 22:11):

:memo: cfallin submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 22:11):

:speech_balloon: cfallin created PR review comment:

More broadly, one can think of Cranelift's CLIF semantics w.r.t. UB (which we define and control, since we maintain Cranelift!) as: violations of memory-related contracts may remove certain memory operations, or cause them to get incorrect (e.g. stale) results, but will not cause arbitrary other side effects including memory accesses.

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 22:21):

alexcrichton updated PR #13321.

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 22:25):

alexcrichton has enabled auto merge for PR #13321.

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 22:35):

alexcrichton added PR #13321 Harden Wasmtime's compiled GC code against corruption to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (May 12 2026 at 23:01):

github-merge-queue[bot] removed PR #13321 Harden Wasmtime's compiled GC code against corruption from the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (May 13 2026 at 14:32):

alexcrichton updated PR #13321.

view this post on Zulip Wasmtime GitHub notifications bot (May 13 2026 at 14:32):

alexcrichton has enabled auto merge for PR #13321.

view this post on Zulip Wasmtime GitHub notifications bot (May 13 2026 at 14:47):

alexcrichton added PR #13321 Harden Wasmtime's compiled GC code against corruption to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (May 13 2026 at 15:13):

:check: alexcrichton merged PR #13321.

view this post on Zulip Wasmtime GitHub notifications bot (May 13 2026 at 15:13):

alexcrichton removed PR #13321 Harden Wasmtime's compiled GC code against corruption from the merge queue.


Last updated: Jun 01 2026 at 09:49 UTC