Stream: git-wasmtime

Topic: wasmtime / PR #13883 Reserve stack space before writing i...


view this post on Zulip Wasmtime GitHub notifications bot (Jul 15 2026 at 14:01):

max-dau opened PR #13883 from COLORADIO-Project:fix-rv32imac-stack-switching to bytecodealliance:main:

The stackswitching implementation for 32-bit RISC-V IMAC ISAs contained a bug. When saving registers to the stack, these registers were first stored below the current stack pointer, then the stack pointer was decreased so all of the saved values were above it. This left relevant data below the stack pointer while the registers were being saved.

If for example an interrupt occured when registers had already been saved, but the stackpointer had not been moved, the interrupt handler might overwrite some of the data previously saved for stack switching. This PR makes this impossible by first moving the stack pointer, only saving the registers values to the reserved stack space afterwards.

I was able to somewhat reliably have the previous bug lead to a device halting execution by having a Wasm program call async bindings very often and using fuel instrumentation with a fuel_async_yield_interval of 1. I do not currently have the up-to-date version of main running on 32-bit RISC-V, so I was only able to test this fix with an older version of Wasmtime. The stackswitching implementation has only been changed by commit f3156fe since then, those changes do not appear relevant to this fix.

I suspect this bug to be present in other stack switching implementations as well but do not have the hardware available to test a fix. For this reason, I have started a Zulip topic about this.

<!--
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 (Jul 15 2026 at 14:01):

max-dau requested wasmtime-core-reviewers for a review on PR #13883.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 15 2026 at 14:01):

max-dau requested pchickey for a review on PR #13883.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 15 2026 at 14:02):

max-dau edited PR #13883:

The stackswitching implementation for 32-bit RISC-V IMAC ISAs contained a bug. When saving registers to the stack, these registers were first stored below the current stack pointer, then the stack pointer was decreased so all of the saved values were above it. This left relevant data below the stack pointer while the registers were being saved.

If for example an interrupt occured when registers had already been saved, but the stackpointer had not been moved, the interrupt handler might overwrite some of the data previously saved for stack switching. This PR makes this impossible by first moving the stack pointer, only saving the registers values to the reserved stack space afterwards.

I was able to somewhat reliably have the previous bug lead to a device halting execution by having a Wasm program call async bindings very often and using fuel instrumentation with a fuel_async_yield_interval of 1. I do not currently have the up-to-date version of main running on 32-bit RISC-V, so I was only able to test this fix with an older version of Wasmtime. The stackswitching implementation has only been changed by commit f3156fe since then, those changes do not appear relevant to this fix.

I suspect this bug to be present in other stack switching implementations as well but do not have the hardware available to test a fix. For this reason, I have started a Zulip topic about this.

<!--
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 (Jul 15 2026 at 15:15):

:thumbs_up: alexcrichton submitted PR review:

Thanks for this! I'll file issues for the other implementations.

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

alexcrichton added PR #13883 Reserve stack space before writing in riscv32imac stackswitching implementation to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 15 2026 at 15:40):

:check: alexcrichton merged PR #13883.

view this post on Zulip Wasmtime GitHub notifications bot (Jul 15 2026 at 15:40):

alexcrichton removed PR #13883 Reserve stack space before writing in riscv32imac stackswitching implementation from the merge queue.


Last updated: Jul 29 2026 at 05:03 UTC