Skip to content

Conversation

jplevyak
Copy link

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.

@istio-testing
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approvers:

If they are not already assigned, you can assign the PR to them by writing /assign in a comment when ready.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

@PiotrSikora PiotrSikora left a 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)

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Author

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.

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.

Copy link
Author

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.

@jplevyak jplevyak closed this Feb 22, 2019
@jplevyak jplevyak deleted the wasm-segv branch February 22, 2019 20:08
PiotrSikora added a commit that referenced this pull request Jun 4, 2019
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants