-
Notifications
You must be signed in to change notification settings - Fork 60
Add WASM SEGV handler and test. #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: If they are not already assigned, you can assign the PR to them by writing The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Continuing discussion from the previous PR, this Exception
it isn't caught, see:
[2019-02-21 01:05:30.146][2704][error][wasm] [source/extensions/common/wasm/wasm.cc:796] wasm log: before badptr
[2019-02-21 01:05:30.146][2704][critical][main] [source/exe/terminate_handler.cc:13] std::terminate called! (possible uncaught exception, see trace)
[2019-02-21 01:05:30.146][2704][critical][backtrace] [bazel-out/k8-dbg/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:67] Backtrace (use tools/stack_decode.py to get line numbers):
[2019-02-21 01:05:30.173][2704][critical][backtrace] [bazel-out/k8-dbg/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:73] #0: Envoy::TerminateHandler::logOnTerminate()::$_0::operator()() [0x27464ef]
[2019-02-21 01:05:30.190][2704][critical][backtrace] [bazel-out/k8-dbg/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:73] #1: Envoy::TerminateHandler::logOnTerminate()::$_0::__invoke() [0x2746489]
[2019-02-21 01:05:30.207][2704][critical][backtrace] [bazel-out/k8-dbg/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:73] #2: __cxxabiv1::__terminate() [0x27ea0c6]
[2019-02-21 01:05:30.207][2704][critical][backtrace] [bazel-out/k8-dbg/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:81] Caught Aborted, suspect faulting address 0x3e800000a89
[2019-02-21 01:05:30.207][2704][critical][backtrace] [bazel-out/k8-dbg/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:67] Backtrace (use tools/stack_decode.py to get line numbers):
[2019-02-21 01:05:30.224][2704][critical][backtrace] [bazel-out/k8-dbg/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:73] #0: Envoy::SignalAction::sigHandler() [0x2743cfc]
[2019-02-21 01:05:30.224][2704][critical][backtrace] [bazel-out/k8-dbg/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:73] #1: __restore_rt [0x7f246a03e0c0]
[2019-02-21 01:05:30.224][2704][critical][backtrace] [bazel-out/k8-dbg/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:73] #2: Envoy::TerminateHandler::logOnTerminate()::$_0::__invoke() [0x2746489]
[2019-02-21 01:05:30.224][2704][critical][backtrace] [bazel-out/k8-dbg/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:73] #3: __cxxabiv1::__terminate() [0x27ea0c6]
Also, I believe that using Runtime::catchRuntimeExceptions()
will produce in-module stacktrace vs in-host stacktrace (when using Exceptions), but my memory is a bit fuzzy at this point, so I might be misremembering things.
@@ -0,0 +1,12 @@ | |||
// NOLINT(namespace-envoy) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add segv.wasm
and segv.wat
to this commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can I reproduce the failure you are seeing? When I run bazel test wasm_test in envoy/test/extensions/wasm I get:
//test/extensions/wasm:wasm_test PASSED in 2.4s
Which is to say I am seeing the Exception caught.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it works fine in mocked tests (since you're explicitly catching Exception using EXPECT_THROW_WITH_MESSAGE
), but that has nothing to do with "normal" usage.
To reproduce that stacktrace, you can add badptr
code to any WASM HTTP filter (e.g. headers.cc
), recompile it, and start Envoy with it. Envoy should crash when executing badptr
code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes, from the unhandled Exception. I was thinking that generally we would convert all errors of this type to Exceptions so that we can catch them and signal the controller (istio) then unload/disable the filter but I haven't completed that code yet. I was expecting to do it in a later PR. I can capture the stack pointer/trace when I throw the Exception as well. That should generalize to this case as well as those covered by Runtime::catchRuntimeExceptions(). Do you have another design in mind. Let's talk offline.
While there, re-enable make/free accounting, since it was broken for the same reason (implementation was leaked into headers). Fixes envoyproxy/envoy-wasm#18. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
Add WASM SEGV handler and test.
When llvm detects that an trap is inevitable it calls the function llvm_trap.
This provides a handler which converts the crash into an Exception which can be caught.