Skip to content

Disallow values to cross stores#1016

Merged
alexcrichton merged 3 commits into
bytecodealliance:masterfrom
alexcrichton:require-same-instance
Mar 10, 2020
Merged

Disallow values to cross stores#1016
alexcrichton merged 3 commits into
bytecodealliance:masterfrom
alexcrichton:require-same-instance

Conversation

@alexcrichton
Copy link
Copy Markdown
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

Comment thread crates/api/src/values.rs Outdated
pub(crate) fn comes_from_same_store(&self, store: &Store) -> bool {
match self {
Val::FuncRef(f) => Store::same(store, f.store()),
_ => true,
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.

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
Copy Markdown
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

Comment thread crates/api/src/values.rs Outdated
pub(crate) fn comes_from_same_store(&self, store: &Store) -> bool {
match self {
Val::FuncRef(f) => Store::same(store, f.store()),
_ => true,
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.

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

Copy link
Copy Markdown
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