Skip to content

Commit b51bc2b

Browse files
committed
security(wasm): bound WASM output reads to prevent OOM from malicious modules
Add MAX_ROUTE_OUTPUT_SIZE (16MB) and MAX_TASK_OUTPUT_SIZE (16MB) limits to validate out_len before reading WASM memory in execute_get_routes, execute_handle_route, and execute_get_tasks. Without these bounds, a malicious WASM module could return an arbitrarily large out_len value, causing the host to attempt allocation of a huge buffer and potentially trigger an OOM condition.
1 parent 38a2e14 commit b51bc2b

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

bins/validator-node/src/wasm_executor.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use wasm_runtime_interface::{
1414
};
1515

1616
const MAX_EVALUATION_OUTPUT_SIZE: u64 = 64 * 1024 * 1024;
17+
const MAX_ROUTE_OUTPUT_SIZE: u64 = 16 * 1024 * 1024;
18+
const MAX_TASK_OUTPUT_SIZE: u64 = 16 * 1024 * 1024;
1719

1820
#[derive(Clone, Debug, Serialize, Deserialize)]
1921
pub struct EvaluationInput {
@@ -470,6 +472,14 @@ impl WasmChallengeExecutor {
470472
let out_len = (result >> 32) as i32;
471473
let out_ptr = (result & 0xFFFF_FFFF) as i32;
472474

475+
if out_len > 0 && out_len as u64 > MAX_TASK_OUTPUT_SIZE {
476+
return Err(anyhow::anyhow!(
477+
"WASM get_tasks output size {} exceeds maximum allowed {}",
478+
out_len,
479+
MAX_TASK_OUTPUT_SIZE
480+
));
481+
}
482+
473483
let result_data = if out_ptr > 0 && out_len > 0 {
474484
instance
475485
.read_memory(out_ptr as usize, out_len as usize)
@@ -632,6 +642,14 @@ impl WasmChallengeExecutor {
632642
let out_len = (result >> 32) as i32;
633643
let out_ptr = (result & 0xFFFF_FFFF) as i32;
634644

645+
if out_len > 0 && out_len as u64 > MAX_ROUTE_OUTPUT_SIZE {
646+
return Err(anyhow::anyhow!(
647+
"WASM get_routes output size {} exceeds maximum allowed {}",
648+
out_len,
649+
MAX_ROUTE_OUTPUT_SIZE
650+
));
651+
}
652+
635653
let result_data = if out_ptr > 0 && out_len > 0 {
636654
instance
637655
.read_memory(out_ptr as usize, out_len as usize)
@@ -735,6 +753,14 @@ impl WasmChallengeExecutor {
735753
let out_len = (result >> 32) as i32;
736754
let out_ptr = (result & 0xFFFF_FFFF) as i32;
737755

756+
if out_len > 0 && out_len as u64 > MAX_ROUTE_OUTPUT_SIZE {
757+
return Err(anyhow::anyhow!(
758+
"WASM handle_route output size {} exceeds maximum allowed {}",
759+
out_len,
760+
MAX_ROUTE_OUTPUT_SIZE
761+
));
762+
}
763+
738764
let result_data = if out_ptr > 0 && out_len > 0 {
739765
instance
740766
.read_memory(out_ptr as usize, out_len as usize)

0 commit comments

Comments
 (0)