go-interpreter / wagon

wagon, a WebAssembly-based Go interpreter, for Go.
BSD 3-Clause "New" or "Revised" License
904 stars 148 forks source link

exec: expose memory size to Process #149

Closed laizy closed 5 years ago

laizy commented 5 years ago

we current has some host function like:

func HostFunc(proc *exec.Process, keyPtr uint32, keylen uint32) {
    keybytes := make([]byte, keylen) 
    _, err := proc.ReadAt(keybytes, int64(keyPtr))
       ...
}

vicious wasm code can provide a large keylen to make the bytes allocation failed. Expose the current memory size can let us prevent this attack by checking keyPtr + keylen <= MemSize

codecov-io commented 5 years ago

Codecov Report

Merging #149 into master will decrease coverage by 0.02%. The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #149      +/-   ##
==========================================
- Coverage   69.47%   69.44%   -0.03%     
==========================================
  Files          43       43              
  Lines        4921     4923       +2     
==========================================
  Hits         3419     3419              
- Misses       1217     1219       +2     
  Partials      285      285
Impacted Files Coverage Δ
exec/vm.go 83.27% <0%> (-0.6%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 0864b86...c8ed6c5. Read the comment docs.