go-interpreter / wagon

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

Context-awareness #62

Open Xe opened 6 years ago

Xe commented 6 years ago

It would be interesting to provide context-awareness to the exec.VM type. This would check the context Done every so often during execution, and if it is done then a new "took too long" error would be returned to the callee. This would make it possible for users to submit arbitrary untrusted webassembly code for a backend server to run and return the results without as much fear of users submitting code that blocks infinitely.

ghost commented 6 years ago

Great idea ! Was wondering about how to solve that corner case too

On Fri, 22 Jun 2018, 02:45 Christine Dodrill, notifications@github.com wrote:

It would be interesting to provide context https://godoc.org/context-awareness to the exec.VM type. This would check the context Done every so often during execution, and if it is done then a new "took too long" error would be returned to the callee. This would make it possible for users to submit arbitrary untrusted webassembly code for a backend server to run and return the results without as much fear of users submitting code that blocks infinitely.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/go-interpreter/wagon/issues/62, or mute the thread https://github.com/notifications/unsubscribe-auth/ATuCwqZsL6YWjlbZHjV5Q8M24PGZkSKxks5t_D4OgaJpZM4Uy-j9 .

sbinet commented 6 years ago

apologies for the belated answer.

yes, having a context aware exec.VM type would definitely be interesting.

now, the also interesting thing would be to decide until what "depth" we want to weave it through:

Xe commented 6 years ago
  • down to each VM operation? (e.g. pushInt64, i32Load8s, ...)

This would be beyond overkill and would be super performance impactful.

  • only at VM.ExecCode ?

Probably check here too.

  • somewhere in the middle?

I was thinking every n operations or on function/loop/block barriers.

sbinet commented 6 years ago

down to each VM operation? (e.g. pushInt64, i32Load8s, ...)

This would be beyond overkill and would be super performance impactful.

I agree, I was just being facetious :)

I was thinking every n operations or on function/loop/block barriers.

every n operation is probably simplest to explain and implement, while not being too intrusive.

Xe commented 6 years ago

How about every 65536 instructions? That constant is already used as the size of a memory page and it's a very nice, even number.

sbinet commented 6 years ago

SGTM