JSPI shadow stack management

未关闭
#27,364 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
冷清
技术栈
javascript, rust, wasm
领域
compilers

调研方向

从 emscripten_stack_get_current() 入口点以及 issue 中描述的 WebAssembly.promising 影子栈行为开始。比较两种提议的方法——由编译器/toolchain 处理,或新增 emscripten_stack_get_promising_top() 原语——以及相关的 Pyodide 和 wasm-bindgen 工作。完成的标准是为 Rust JSPI 影子栈的挂起和恢复建立一个可互操作且健全的约定。

由索引模型根据 Issue 内容生成。

描述

Pyodide implemented JSPI shadow stack suspend/resume semantics quite comprehensively in https://blog.pyodide.org/posts/jspi-with-c-runtime/.

I'm now seeing similar issues for Rust and JSPI, and have been prototyping some (unfinished) ideas in https://github.com/guybedford/jspi - where as far as I can tell Emscripten is not automatically handling the shadow stack save and restore operations, so that JSPI will lead to stack corruption in Rust per Hood's blog post scenario.

In addition, wasm-bindgen is about to land support for JSPI with it's own shadow stack handling in https://github.com/wasm-bindgen/wasm-bindgen/pull/5193 and to get these approaches to interoperate well requires falling on strong conventions.

All conventions come down to needing a stack top though for the shadow stack suspension range. And the stack top is not easy to get since by the time you call emscripten_stack_get_current() you're always deep into the entry point Rust wrapper code.

We can't use the stack base, because WebAssembly.promising functions can be called with arbitrary non-JSPI stack depth, so this core feature missing to integrate this well into Rust seems to me to be a emsripten_stack_get_promising_top() for the current WebAssembly.promising which Emscripten in theory would know about.

Unless I'm missing something, as far as I can tell this leaves us with two options for Rust JSPI soundness:

  1. Either fully implement the shadow stack save/restore work at the compiler / toolchain level (instead of as a library)
  2. Expose a new JSPI-specific emscripten_stack_get_promising_top() primitive

I'd be interested to hear what others think about how to handle the problems here.

主要语言
C++
星标
27.8k
派生
3.6k
平均合并
1 天 10 小时
30 天内合并 PR
177

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

emscripten-core/emscripten 的其他 Issue

查看 emscripten-core/emscripten 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。