bytecodealliance / bytecodealliance/wasmtime
Partially out-of-bounds writes on ARM and riscv
- Dominant language
- Rust
- Stars
- 18.6k
- Forks
- 1.8k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 126
Description
Apparently on ARM (edit: and riscv) when
* a store is unaligned
* and crosses a page boundary
* and one page faults but the other doesn't
then there is no guarantee that the part of the store to the page that didn't fault will not succeed, despite the other part raising a signal.
This means that partially out-of-bounds Wasm stores that trigger a trap can potentially mutate memory for the in-bounds portion of the write, which is not spec compliant.
Apparently it is implementation-defined behavior, so it may or may not be an issue on any given ARM machine.
Thus far, @cfallin tested on the ARM machines he has access to and none of the following have failed the attached test case:
* Apple M2
* RPi4
* the BA ARM server ("Neoverse N1 core, I think, in an Ampere Altra CPU")
The test case does fail on the following machines we have tested:
* [JH7110 (SiFive u74 core)](https://github.com/bytecodealliance/wasmtime/issues/7237#issuecomment-1763523982) (riscv)
### Test Case
```wat
(module
(memory 1)
(func (export "i64.store") (param i32 i64)
local.get 0
local.get 1
i64.store)
(func (export "i32.load8_u") (param i32) (result i32)
local.get 0
i32.load8_u))
(assert_trap (invoke "i64.store"
(i32.const 65529)
(i64.const 0xffffffffffffffff))
"out of bounds memory access")
;; Partial bytes were not written.
(assert_return (invoke "i32.load8_u" (i32.const 65529))
(i32.const 0))
(assert_return (invoke "i32.load8_u" (i32.const 65530))
(i32.const 0))
(assert_return (invoke "i32.load8_u" (i32.const 65531))
(i32.const 0))
(assert_return (invoke "i32.load8_u" (i32.const 65532))
(i32.const 0))
(assert_return (invoke "i32.load8_u" (i32.const 65533))
(i32.const 0))
(assert_return (invoke "i32.load8_u" (i32.const 65534))
(i32.const 0))
(assert_return (invoke "i32.load8_u" (i32.const 65535))
(i32.const 0))
```
### See Also
* https://github.com/WebAssembly/design/issues/1490
* https://bugzilla.mozilla.org/show_bug.cgi?id=1666747
Contributor guide
Assessment
This issue has not been assessed yet.