-
Notifications
You must be signed in to change notification settings - Fork 70
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
addAfterVmCallAction
may cause unexpected problems
#326
Comments
cc @PiotrSikora |
@johnlanni thank you for digging into it! I agree that under no circumstances Wasm should be able to crash the host, so this is definitely a serious issues, but I don't think it's caused by There are at least two issues here:
Unfortunately, both of those are breaking changes (although, the first one shouldn't be noticeable), but we should address them sooner than later. cc @mpwarres |
@PiotrSikora Maybe we should add the stage of the function in |
addAfterVmCallAction
anddoAfterVmCallActions
are used by the context to execute functions after vm calls, such asonRequestHeaders
:proxy-wasm-cpp-host/src/context.cc
Lines 312 to 324 in 72ce32f
If
sendLocalReply
has been added toafter_vm_call_actions_
viaaddAfterVmCallAction
:https://github.com/envoyproxy/envoy/blob/main/source/extensions/common/wasm/context.cc#L1635-L1645
Here
f()
will executesendLocalReply
:proxy-wasm-cpp-host/include/proxy-wasm/wasm.h
Line 154 in 72ce32f
It will call encodeHeaders() which triggers the vm to call
onResponseHeaders
as follows:proxy-wasm-cpp-host/src/context.cc
Lines 374 to 384 in 72ce32f
Then call
doAfterVmCallActions
again, that is, the function is re-entered, and the functions inafter_vm_call_actions_
left in theonRequestHeaders
stage will be executed in theonResonseHeaders
stage, which may cause unexpected problems.The following code compiled to wasm crashes Envoy:
ResumeHttpRequest
will callcontinueStream
and add thedecoder_callbacks_->continueDecoding()
function toafter_vm_call_actions_
, which will be executed during theonResonseHeaders
stage triggered bysendLocalReply
.https://github.com/envoyproxy/envoy/blob/a77335a730f567502721319b20c4b0fab10e09bc/source/extensions/common/wasm/context.cc#L1497-L1501
This resolved issue was also caused by this mechanism.
The text was updated successfully, but these errors were encountered: