Skip to content

Support preserving shadow stack pointer in wasmfx implementation#3

Merged
dhil merged 4 commits intomainfrom
shadow-stack
May 13, 2024
Merged

Support preserving shadow stack pointer in wasmfx implementation#3
dhil merged 4 commits intomainfrom
shadow-stack

Conversation

@frank-emrich
Copy link
Copy Markdown
Contributor

@frank-emrich frank-emrich commented May 13, 2024

This PR adds optional support for preserving the shadow stack when using the wasmfx implementation of the fiber interface.

This is achieved as follows:

  • for each continuation, we malloc a dedicated region of linear memory, to be used as its shadow stack
  • for each continuation, we save 1) the beginning of this region of memory and 2) the current shadow stack pointer (within that region)
  • whenever we resume a continuation, we set the global shadow stack pointer aside and set it to the previous shadow stack pointer saved for the continuation to be resumed
  • once a continuation finishes (via return or suspend), we restore the global stack pointer. Further, unless the continuation has returned, we also update the shadow stack pointer of the suspended continuation using the value of the global shadow stack pointer at the point of the suspend.

Copy link
Copy Markdown
Member

@dhil dhil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

#ifdef FIBER_WASMFX_PRESERVE_SHADOW_STACK
;; The shadow stack pointer, created by clang
(import "main" "__exported_shadow_stack_pointer" (global $sstack_ptr (mut i32)))
(import "main" "__stack_pointer" (global $sstack_ptr (mut i32)))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@dhil dhil merged commit 818dca7 into main May 13, 2024
@dhil dhil deleted the shadow-stack branch May 13, 2024 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants