Repository navigation
wasm: fix potential crash of extensions for failed remote code fetch - #20843
Conversation
|
Hi @johnlanni, welcome and thank you for your contribution. We will try to review your Pull Request as quickly as possible. In the meantime, please take a look at the contribution guidelines if you have not done so already. |
Signed-off-by: johnlanni <[email protected]>
|
envoy/source/extensions/common/wasm/wasm.cc Line 477 in ff13ff6 The reason is this line may return a nullptr since wasm configure failed here: This crash definitely occurs when two wasm filters use the same vm configuration, the first is configured correctly and the second is wrong. The logic here only checks the plugin config of the first one: and the logic here will make the second one reuse the This crash also occurs in dynamic filter config scenarios such as ECDS is used to discover the config. |
|
test config: admin:
address:
socket_address:
protocol: TCP
address: 0.0.0.0
port_value: 9901
static_resources:
listeners:
- name: listener_0
# enable_reuse_port: true
connection_balance_config:
exact_balance: {}
address:
socket_address:
protocol: TCP
address: 0.0.0.0
port_value: 10000
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
scheme_header_transformation:
scheme_to_overwrite: https
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match:
prefix: "/"
direct_response:
status: 200
body:
inline_string: "hello world"
http_filters:
- name: basic-auth-1
typed_config:
"@type": type.googleapis.com/udpa.type.v1.TypedStruct
type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm
value:
config:
name: basic-auth
vm_config:
runtime: envoy.wasm.runtime.v8
code:
local:
filename: ./basic-auth.wasm
configuration:
"@type": "type.googleapis.com/google.protobuf.StringValue"
value: |
{
"credentials":[ "ok:test2"]
}
- name: basic-auth-2
typed_config:
"@type": type.googleapis.com/udpa.type.v1.TypedStruct
type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm
value:
config:
name: basic-auth
vm_config:
runtime: envoy.wasm.runtime.v8
code:
local:
filename: ./basic-auth.wasm
configuration:
"@type": "type.googleapis.com/google.protobuf.StringValue"
value: |
{
"credentials":[ "ok:test2"
}
- name: envoy.filters.http.routerstart envoy, and execute the |
Signed-off-by: johnlanni <[email protected]>
|
cc @PiotrSikora |
PiotrSikora
left a comment
There was a problem hiding this comment.
Thanks! Could you make similar changes in other Wasm extensions?
|
|
||
| std::shared_ptr<Context> createFilter() { | ||
| Wasm* wasm = nullptr; | ||
| if (!tls_slot_->currentThreadRegistered()) { |
There was a problem hiding this comment.
When can this happen? cc @jmarantz for TLS bits.
There was a problem hiding this comment.
When using remote wasm code, createWasm here will return without calling this callback, which makes the tls_slot not yet registered when it starts serving the request:
envoy/source/extensions/filters/http/wasm/wasm_filter.cc
Lines 15 to 29 in ff13ff6
the createWasm logic of using remote wasm code:
envoy/source/extensions/common/wasm/wasm.cc
Lines 409 to 457 in ff13ff6
Signed-off-by: johnlanni <[email protected]>
The same changes have been made to the access_logger and network filter extensions, and bootstrap extension doesn't seem to have this problem. |
Signed-off-by: johnlanni <[email protected]>
Signed-off-by: johnlanni <[email protected]>
Signed-off-by: johnlanni <[email protected]>
Signed-off-by: johnlanni <[email protected]>
Signed-off-by: johnlanni <[email protected]>
|
@PiotrSikora @lizan All checks have passed, could you help me review it? Thanks! |
|
/assign @kyessenov |
|
Have you tried the latest version of Envoy? |
@kyessenov I tried the latest version and the problem persists. Did you execute the command |
|
Sorry for the delay, and yes, indeed this is a crash. I am quite confused by the sequence of events. Is this the right way to interpret it:
I think this whole sequence is confusing. I'd expect the second instance of the plugin to behave the same whether or not there is another plugin somewhere. With this change, I think it silently accepts it (can you confirm?), but if i remove the first instance, LDS is rejected. That's not very consistent. So I think we have two choices here:
WDYT? |
@kyessenov I think having the second filter do config canarying is a better opion, since plugins may need to share rootContext over the shared VM, and shared VM can also reduce the memory usage. |
|
@kyessenov There is another problem that causes envoy to crash: when using remote wasm code, envoy/source/extensions/filters/http/wasm/wasm_filter.cc Lines 15 to 29 in ff13ff6 This UT would also crash without this code: |
kyessenov
left a comment
There was a problem hiding this comment.
This is definitely an improvement, so thank you for the fix! I think it's fair to handle failed remote code load by not crashing, even though it's potentially risky to load authorization filters this way (because xDS is accepted but filter is not applied when fetching fails). We should probably add a note somewhere explaining the risk.
Could you file an issue upstream in proxy-wasm requesting canarying for duplicate filter configs?
…nvoyproxy#20843) Signed-off-by: johnlanni [email protected] Commit Message: Handle null plugins handle when skipping config canarying for duplicate filters and also when the remote code fetch is in progress or fails. Risk Level: low Testing: ok
…nvoyproxy#20843) Signed-off-by: johnlanni [email protected] Commit Message: Handle null plugins handle when skipping config canarying for duplicate filters and also when the remote code fetch is in progress or fails. Risk Level: low Testing: ok Signed-off-by: 澄潭 <[email protected]> Signed-off-by: Ryan Northey <[email protected]>
…20843) Signed-off-by: johnlanni [email protected] Commit Message: Handle null plugins handle when skipping config canarying for duplicate filters and also when the remote code fetch is in progress or fails. Risk Level: low Testing: ok Signed-off-by: 澄潭 <[email protected]> Signed-off-by: Ryan Northey <[email protected]>


Commit Message:
Additional Description:
Risk Level: low
Testing: ok
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]
this
PluginHandleSharedPtr handlemaybe null.