Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Disallow fewer instructions in Wizer (#11851)

Alex Crichtonab2486b449d9
diff --git a/crates/wizer/src/lib.rs b/crates/wizer/src/lib.rs
index 613490ca55..d39fe61dc3 100644
--- a/crates/wizer/src/lib.rs
+++ b/crates/wizer/src/lib.rs
@@ -271,48 +271,51 @@ impl Wizer {
};
match payload {
wasmparser::Payload::CodeSectionEntry(code) => {
- let mut ops = code.get_operators_reader().unwrap();
+ let mut ops = code.get_operators_reader()?;
while !ops.eof() {
- match ops.read().unwrap() {
+ match ops.read()? {
+ // Table mutations aren't allowed as wizer has no
+ // way to record a snapshot of a table at this time.
+ // The only table mutations allowed are those from
+ // active element segments which can be
+ // deterministically replayed, so disallow all other
+ // forms of mutating a table.
+ //
+ // Ideally Wizer could take a snapshot of a table
+ // post-instantiation and then ensure that after
+ // running initialization the table didn't get
+ // mutated, allowing these instructions, but that's
+ // also not possible at this time.
wasmparser::Operator::TableCopy { .. } => {
anyhow::bail!("unsupported `table.copy` instruction")
}
wasmparser::Operator::TableInit { .. } => {
anyhow::bail!("unsupported `table.init` instruction")
}
- wasmparser::Operator::ElemDrop { .. } => {
- anyhow::bail!("unsupported `elem.drop` instruction")
- }
- wasmparser::Operator::DataDrop { .. } => {
- anyhow::bail!("unsupported `data.drop` instruction")
- }
wasmparser::Operator::TableSet { .. } => {
anyhow::bail!("unsupported `table.set` instruction")
}
- wasmparser::Operator::TableGet { .. } => {
- anyhow::bail!("unsupported `table.get` instruction")
- }
- wasmparser::Operator::RefNull { .. } => {
- anyhow::bail!("unsupported `ref.null` instruction")
- }
- wasmparser::Operator::RefIsNull => {
- anyhow::bail!("unsupported `ref.is_null` instruction")
- }
- wasmparser::Operator::TypedSelect { .. } => {
- anyhow::bail!("unsupported typed `select` instruction")
- }
- wasmparser::Operator::RefFunc { .. } => {
- anyhow::bail!("unsupported `ref.func` instruction")
- }
- wasmparser::Operator::TableSize { .. } => {
- anyhow::bail!("unsupported `table.size` instruction")
- }
wasmparser::Operator::TableGrow { .. } => {
anyhow::bail!("unsupported `table.grow` instruction")
}
wasmparser::Operator::TableFill { .. } => {
anyhow::bail!("unsupported `table.fill` instruction")
}
+
+ // Wizer has no way of dynamically determining which
+ // element or data segments were dropped during
+ // execution so instead disallow these instructions
+ // entirely. Like above it'd be nice to allow them
+ // but just forbid their execution during the
+ // initialization function, but that can't be done
+ // easily at this time.
+ wasmparser::Operator::ElemDrop { .. } => {
+ anyhow::bail!("unsupported `elem.drop` instruction")
+ }
+ wasmparser::Operator::DataDrop { .. } => {
+ anyhow::bail!("unsupported `data.drop` instruction")
+ }
+
_ => continue,
}
}
diff --git a/crates/wizer/tests/all/tests.rs b/crates/wizer/tests/all/tests.rs
index 07e69e56f4..e71346f676 100644
--- a/crates/wizer/tests/all/tests.rs
+++ b/crates/wizer/tests/all/tests.rs
@@ -266,7 +266,7 @@ fn reject_table_get_set() -> Result<()> {
let err = result.unwrap_err();
assert!(
err.to_string()
- .contains("unsupported `table.get` instruction"),
+ .contains("unsupported `table.set` instruction"),
"bad error: {err}",
);
@@ -300,7 +300,7 @@ fn reject_table_get_set_with_reference_types_enabled() -> Result<()> {
let err = result.unwrap_err();
assert!(
err.to_string()
- .contains("unsupported `table.get` instruction"),
+ .contains("unsupported `table.set` instruction"),
);
Ok(())
@@ -330,7 +330,7 @@ fn reject_table_grow_with_reference_types_enabled() -> anyhow::Result<()> {
let err = result.unwrap_err();
assert!(
err.to_string()
- .contains("unsupported `ref.func` instruction")
+ .contains("unsupported `table.grow` instruction")
);
Ok(())