WasmEdge: segfault when checkAccessBound

Description

I am trying to integrate WasmEdge into wasm-nginx-module. When I tried to use WasmEdge as the Wasm VM, I got a segfault:

(gdb) bt
#0  WasmEdge::AST::Limit::getMin (this=0x0) at /home/lzx/git/WasmEdge/include/ast/type.h:47
#1  0x00007fc0bf1d9fbd in WasmEdge::Runtime::Instance::MemoryInstance::checkAccessBound (this=0x0, Offset=92, Length=4)
    at /home/lzx/git/WasmEdge/include/runtime/instance/memory.h:77
#2  0x00007fc0bf27ab5b in WasmEdge::Runtime::Instance::MemoryInstance::storeValue<unsigned int> (this=0x0, Value=@0x7ffd1e231908: 0, Offset=92, Length=4)
    at /home/lzx/git/WasmEdge/include/runtime/instance/memory.h:311
#3  0x00007fc0bf25ddee in WasmEdge::Executor::Executor::runStoreOp<unsigned int> (this=0x1813930, MemInst=..., Instr=..., BitWidth=32)
    at /home/lzx/git/WasmEdge/include/executor/engine/memory.ipp:60
#4  0x00007fc0bf250684 in WasmEdge::Executor::Executor::execute(WasmEdge::Runtime::StoreManager&, WasmEdge::AST::Instruction const*, WasmEdge::AST::Instruction const*)::$_0::operator()() const (this=0x7ffd1e233290) at /home/lzx/git/WasmEdge/lib/executor/engine/engine.cpp:242
#5  0x00007fc0bf24ec3a in WasmEdge::Executor::Executor::execute (this=0x1813930, StoreMgr=..., Start=0x304f950, End=0x304fa10)
    at /home/lzx/git/WasmEdge/lib/executor/engine/engine.cpp:1606
#6  0x00007fc0bf24eed6 in WasmEdge::Executor::Executor::runFunction(WasmEdge::Runtime::StoreManager&, WasmEdge::Runtime::Instance::FunctionInstance const&, cxx20::span<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::UnknownRef, WasmEdge::FuncRef, WasmEdge::ExternRef> const, 18446744073709551615ul>) (this=0x1813930, StoreMgr=..., Func=..., Params=...) at /home/lzx/git/WasmEdge/lib/executor/engine/engine.cpp:44
#7  0x00007fc0bf288a88 in WasmEdge::Executor::Executor::invoke(WasmEdge::Runtime::StoreManager&, unsigned int, cxx20::span<WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::UnknownRef, WasmEdge::FuncRef, WasmEdge::ExternRef> const, 18446744073709551615ul>, cxx20::span<WasmEdge::ValType const, 18446744073709551615ul>) (this=0x1813930, StoreMgr=..., FuncAddr=2766, Params=..., ParamTypes=...)
    at /home/lzx/git/WasmEdge/lib/executor/executor.cpp:108
#8  0x00007fc0bf171c51 in WasmEdge_ExecutorInvoke::$_9::operator() (this=0x7ffd1e2338a0) at /home/lzx/git/WasmEdge/lib/api/wasmedge.cpp:1528
#9  0x00007fc0bf16af0f in (anonymous namespace)::wrap<WasmEdge_ExecutorInvoke::$_9, WasmEdge_ExecutorInvoke::$_10, WasmEdge_ExecutorContext, WasmEdge_StoreContext> (Proc=...,
    Then=..., Cxts=0x1859ff0, Cxts=0x1859ff0) at /home/lzx/git/WasmEdge/lib/api/wasmedge.cpp:265
#10 0x00007fc0bf16a828 in WasmEdge_ExecutorInvoke (Cxt=0x1813930, StoreCxt=0x1859ff0, FuncName=..., Params=0x7ffd1e233b80, ParamLen=2, Returns=0x7ffd1e233b60, ReturnLen=1)
    at /home/lzx/git/WasmEdge/lib/api/wasmedge.cpp:1506
#11 0x0000000000699c30 in ngx_wasm_wasmedge_call (data=0x3053ca0, name=0x72bd60 <proxy_on_configure>, has_result=true, param_type=3)
    at /home/lzx/git/wasm-nginx-module/src/vm/wasmedge.c:325
#12 0x00000000006915db in ngx_http_wasm_on_configure (hw_plugin=0x23d97d0, conf=0x7fc0be967e20 "{\"http_status\": 401, \"percentage\": 0}", size=37)
    at /home/lzx/git/wasm-nginx-module/src/http/ngx_http_wasm_module.c:422

The code can be found in https://github.com/api7/wasm-nginx-module/pull/93/files#diff-29a3e0c7bd2fd8b0d13dd0490a28522f81448eecc538703e39429410ee424ea8R260

I could send you the .wasm file if needed.

Environment

  • Hardware Architecture: (e.g. x86_64 or aarch64) x86_64
  • Operating system: (e.g. Ubuntu 20.04 or CentOS 7.6) Ubuntu 20.04

The following information is optional. Please provide them only if you have built from source.

  • C++ Compiler version:
  • CMake version:
  • CMake flags: (e.g. -DCMAKE_BUILD_TYPE=Release -DWASMEDGE_BUILD_AOT_RUNTIME=ON)
  • Boost version:

Steps to Reproduce

Run the https://github.com/api7/wasm-nginx-module/blob/main/t/rust.t test with the code in https://github.com/api7/wasm-nginx-module/pull/93

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 25 (12 by maintainers)

Most upvoted comments

Thanks a lot. I’ll try to add some log in WasmEdge to find out the reason. The WasmEdge 0.10.0 has breaking changes in C API. You can try to update if you want with the Guideline. Thanks.

The lua-resty-http is installed.

I tried again and got another error:

root@3e3eb490a166:/wasm-nginx-module# WASM_VM=wasmedge prove -I. -Itest-nginx/lib -r t/rust.t
t/rust.t .. 1/?
#   Failed test 'TEST 1: fault injection - status code ok'
#   at /wasm-nginx-module/test-nginx/lib/Test/Nginx/Socket.pm line 935.
#          got: ''
#     expected: '403'

#   Failed test 'TEST 1: fault injection - response_body - response is expected (repeated req 0, req 0)'
#   at /wasm-nginx-module/test-nginx/lib/Test/Nginx/Socket.pm line 1589.
#          got: ''
#     expected: 'body'

#   Failed test 'TEST 2: fault injection (without body) - status code ok'
#   at /wasm-nginx-module/test-nginx/lib/Test/Nginx/Socket.pm line 935.
#          got: ''
#     expected: '401'

#   Failed test 'TEST 2: fault injection (without body) - response_body_like - response is expected ()'
#   at /wasm-nginx-module/test-nginx/lib/Test/Nginx/Socket.pm line 1635.
#                   ''
#     doesn't match '(?^:<title>401 Authorization Required</title>)'
t/rust.t .. 8/?
#   Failed test 'TEST 3: fault injection (0 percentage) - status code ok'
#   at /wasm-nginx-module/test-nginx/lib/Test/Nginx/Socket.pm line 948.
#          got: ''
#     expected: '200'
# Looks like you failed 5 tests of 14.
t/rust.t .. Dubious, test returned 5 (wstat 1280, 0x500)
Failed 5/14 subtests

Test Summary Report
-------------------
t/rust.t (Wstat: 1280 Tests: 14 Failed: 5)
  Failed tests:  1-2, 6-7, 11
  Non-zero exit status: 5
Files=1, Tests=14,  1 wallclock secs ( 0.01 usr  0.00 sys +  0.24 cusr  0.10 csys =  0.35 CPU)
Result: FAIL

Yes, the got: '' means the Nginx crashed in the middle, so it doesn’t reply to any expected response.

Congratulation, now we should be able to reproduce it. We can check the error log in t/servroot/logs/error.log.

By running nginx -p $dir_of_wasm_nginx_module/t/servroot/ -c $dir_of_wasm_nginx_module/t/servroot/conf/nginx.conf, we can start the Nginx, and then we can run curl http://127.0.0.1:1984/t -i to reproduce it.

Maybe you have another Nginx installed in the environment?

If I didn’t apt install nginx, I will get:

root@9f66f03f2cfb:/wasm-nginx-module# WASM_VM=wasmedge prove -I. -Itest-nginx/lib -r t/rust.t
t/rust.t .. Bailout called.  Further testing stopped:  Failed to get the version of the Nginx in PATH:
FAILED--Further testing stopped: Failed to get the version of the Nginx in PATH:

Let’s add the built Nginx binary to the $PATH, like https://github.com/api7/wasm-nginx-module/blob/08f1424826004ffd000afddbff91c1181960293d/.github/workflows/test.yml#L70

Let’s add

rustup target add wasm32-wasi

after

curl https://sh.rustup.rs/ -sSf | sh
source $HOME/.cargo/env

rust compile failed here

What is the error message? Maybe it can be solved with the missing rustup target add wasm32-wasi.