design icon indicating copy to clipboard operation
design copied to clipboard

Newtypes for stronger control flow integrity

Open SoniEx2 opened this issue 8 months ago • 31 comments

A newtype is a (mostly) zero-cost wrapper for an existing type. When it comes to the type stack, a newtype and its underlying type are indistinguishable. When it comes to certain interactions, they are very much distinguishable. In particular:

  1. On a call_indirect, newtypes of the expected function (as per type of the call_indirect) and of the passed function (as per type in function table) must match.
  2. Imports must also match newtypes.

So for example, a string-ptr newtype (i32) is just an i32 and can be manipulated and used like an i32, but a function that takes a string-ptr and a function that takes an i32 are not compatible.

Thoughts?

SoniEx2 avatar Mar 18 '25 20:03 SoniEx2