Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow values to cross stores #1016

Merged

Conversation

alexcrichton
Copy link
Member

Lots of internals in the wasmtime-{jit,runtime} crates are highly
unsafe, so it's up to the wasmtime API crate to figure out how to make
it safe. One guarantee we need to provide is that values never cross
between stores. For example you can't take a function in one store and
move it over into a different instance in a different store. This
dynamic check can't be performed at compile time and it's up to
wasmtime to do the check itself.

This adds a number of checks, but not all of them, to the codebase for
now. This primarily adds checks around instantiation, globals, and
tables. The main hole in this is functions, where you can pass in
arguments or return values that are not from the right store. For now
though we can't compile modules with anyref parameters/returns anyway,
so we should be good. Eventually when that is supported we'll need to
put the guards in place.

Closes #958

pub(crate) fn comes_from_same_store(&self, store: &Store) -> bool {
match self {
Val::FuncRef(f) => Store::same(store, f.store()),
_ => true,
Copy link
Member

Choose a reason for hiding this comment

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

It'd be helpful to have a brief comment here, mentioning that none of the numeric value types inherently depend on a store.

Copy link
Member Author

Choose a reason for hiding this comment

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

I went ahead and opted to switch this to an exhaustive match and added a comment for integers

pub(crate) fn comes_from_same_store(&self, store: &Store) -> bool {
match self {
Val::FuncRef(f) => Store::same(store, f.store()),
_ => true,
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to handle AnyRef here too, for the InternalRef case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently it technically doesn't need to because we don't really support anyref in wasmtime at the moment. I went ahead and explicitly matched it to always return false with a TODO comment about how to fix it in the future.

Lots of internals in the wasmtime-{jit,runtime} crates are highly
unsafe, so it's up to the `wasmtime` API crate to figure out how to make
it safe. One guarantee we need to provide is that values never cross
between stores. For example you can't take a function in one store and
move it over into a different instance in a different store. This
dynamic check can't be performed at compile time and it's up to
`wasmtime` to do the check itself.

This adds a number of checks, but not all of them, to the codebase for
now. This primarily adds checks around instantiation, globals, and
tables. The main hole in this is functions, where you can pass in
arguments or return values that are not from the right store. For now
though we can't compile modules with `anyref` parameters/returns anyway,
so we should be good. Eventually when that is supported we'll need to
put the guards in place.

Closes bytecodealliance#958
@alexcrichton alexcrichton force-pushed the require-same-instance branch from 008a3f6 to 5051295 Compare March 2, 2020 14:54
arkpar pushed a commit to paritytech/wasmtime that referenced this pull request Mar 4, 2020
@alexcrichton alexcrichton merged commit 11510ec into bytecodealliance:master Mar 10, 2020
@alexcrichton alexcrichton deleted the require-same-instance branch March 10, 2020 14:28
alexcrichton added a commit to alexcrichton/wasmtime that referenced this pull request May 4, 2020
alexcrichton added a commit that referenced this pull request May 4, 2020
Turns out this was a typo from #1016!
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.

What to do about cross-Store calls?
2 participants