Skip to content

Commit

Permalink
Fix out of bounds check in runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-fink committed Jul 19, 2023
1 parent 7cc9114 commit 755c901
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion crates/runtime/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,19 @@ impl Instance {
}

fn validate_inbounds(&self, max: usize, ptr: u64, len: u64) -> Result<usize, Trap> {
#[cfg(all(target_arch = "aarch64", target_os = "linux", target_feature = "mte"))]
fn strip_mte_tag(ptr: u64) -> u64 {
ptr & 0xF0FF_FFFF_FFFF_FFFF
}

#[cfg(not(all(target_arch = "aarch64", target_os = "linux", target_feature = "mte")))]
fn strip_mte_tag(ptr: u64) -> u64 {
ptr
}

let oob = || Trap::MemoryOutOfBounds;
let end = ptr

let end = strip_mte_tag(ptr)
.checked_add(len)
.and_then(|i| usize::try_from(i).ok())
.ok_or_else(oob)?;
Expand Down

0 comments on commit 755c901

Please sign in to comment.