-
Notifications
You must be signed in to change notification settings - Fork 624
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
BUGs in WAMR #2252
Comments
@LeoneChen Thanks for pointing out this! I only tested in simulator mode and thought that GS register is available. It is a pity that we cannot use the register to enable the segue optimization for linux-sgx platform, I submitted PR #2255 to fix the issue. |
Writing GS segment register is not allowed on linux-sgx since it is used as the base address of thread data in 64-bit hw mode. Reported in #2252. Disable writing it and disable segue optimization for linux-sgx platform.
My pleasure~ |
Hello~ We find another bug Heap OOB & Null Pointer DereferenceIt's about WAMR run in Enclave In EDL, size of wasm-micro-runtime/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.edl Lines 23 to 25 in 5fb5119
When specify
Thus, in wasm-micro-runtime/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp Lines 601 to 605 in 5fb5119
However, e.g. in wasm-micro-runtime/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp Lines 92 to 101 in 5fb5119
As NoteSame bugs in all |
Hi, the Not sure why "argc can be any number (e.g. 0), and cmd_buf may only have insufficient heap memory space", is there any case to reproduce the issue? Or do you mean that |
Yes, I mean "cmd_buf_size may be modified illegally in the host side", since host and even OS are untrusted (e.g. host is controlled by untrusted cloud manager when user deploys this Enclave at cloud). I think in SGX Enclave development principle, it's necessary to keep interfaces like ECALL/OCALL are as safe as possible, which is different from traditional development. |
I'm happy to help you fix SGX specific BUGs like this, if you need. |
Yes, appreciate! https://github.com/inclavare-containers/inclavare-containers |
Null Pointer Dereference
wasm-micro-runtime/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.edl Lines 23 to 25 in 5fb5119
wasm-micro-runtime/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp Lines 601 to 618 in 5fb5119
wasm-micro-runtime/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp Lines 341 to 355 in 5fb5119
|
OK, I'll try to fix it |
Hi~ I'll list all bugs found in this issue, and help to try to fix them~ Time of Check to Time of Use/Double FetchIn wasm-micro-runtime/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp Lines 657 to 685 in 5fb5119
wasm-micro-runtime/core/iwasm/common/wasm_runtime_common.c Lines 1111 to 1131 in 5fb5119
wasm-micro-runtime/core/iwasm/common/wasm_runtime_common.c Lines 631 to 644 in 5fb5119
But there is a situation that, attack at OS level can replace content of Thus it's better to copy whole buffer into Enclave, and then check and use. This problem is very similar to TOCTOU in linux kernel or other situations which involve security boundary, and is firstly pointed out by CCS'19 paper A Tale of Two Worlds: Assessing the Vulnerability of Enclave Shielding Runtimes. |
Yes, many thanks! |
Arbitrarily Enclave Write/Read/ExecuteNeed to check wasm-micro-runtime/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp Line 413 in 5fb5119
wasm-micro-runtime/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp Line 442 in 5fb5119
Need to check wasm-micro-runtime/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp Line 217 in 5fb5119
wasm-micro-runtime/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp Line 232 in 5fb5119
No check on wasm-micro-runtime/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp Line 702 in 5fb5119
No check on wasm-micro-runtime/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp Line 685 in 5fb5119
wasm-micro-runtime/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp Line 247 in 5fb5119
wasm-micro-runtime/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp Line 243 in 5fb5119
wasm-micro-runtime/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp Line 509 in 5fb5119
No check on wasm-micro-runtime/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp Line 372 in 5fb5119
Null Pointer DereferenceNeed to check wasm-micro-runtime/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp Line 434 in 5fb5119
Lack of check wasm-micro-runtime/product-mini/platforms/linux-sgx/enclave-sample/Enclave/Enclave.cpp Line 493 in 5fb5119
|
@wenyongh Hello, the current interface designed for SGX is too open, but it's due to the requirement of fully supported web assembly runtime, and it seems too hard to fix. How about trying Gramine from Intel or Occlum from Ant Group to seamlessly support non-SGX version WAMR, they are LibOS solutions run in Enclave to support legacy applications and have well-designed Enclave interfaces |
@LeoneChen Yes, it may be very hard to fix, could you fix some simple cases? For Gramine and LibOS, maybe we can try running WAMR based on the platform linux (product-mini/platforms/linux), it should be OK if they supports the libc APIs that platform linux requires. |
Hello! My simple idea is change each handle in switch-case to ecalls, in order to leverage auto generated Tbridge code to memory clone for one-level pointer, but for nested pointer, we may need extra work. This will change interface of Enclave, then host need change code to call these interface. If you think it's ok, I will submit a PR for every to review |
It is good to me, but not sure whether it is OK for other developers, they might be using the current mode in their products. How about adding a macro to control it? By default the new interface is used, and developer can use |
Ok |
UAFMalloc
wasm-micro-runtime/core/iwasm/common/wasm_shared_memory.c Lines 49 to 55 in 81f0371
Free
wasm-micro-runtime/core/iwasm/common/wasm_shared_memory.c Lines 66 to 70 in 81f0371
Use
wasm-micro-runtime/core/shared/utils/bh_hashmap.c Lines 249 to 259 in 81f0371
ConclusionWAMR forget to set |
PR #2357 I'm a little busy recently, so late to fix the above problems One detail is that I use indexes to replace the raw pointers when passing
Since I'm not so familiar with WAMR, you may need further check. The Action on this PR failed on SPEC, but I have no idea about this. I've fuzzed with this Enclave with the new interface, and no above bugs are reported anymore. |
Thanks @LeoneChen! We will check the PR and try to fix the issues reported by GitHub CIs. |
…urity (#2416) Call ecall commands arbitrarily from host when enclave's runtime isn't initialized may cause unexpected behavior, for example, load/instantiate wasm module. Add runtime inited status checks in enclave to improve the security. Also fix `wait_map` issue mentioned in #2252 (comment)
…2255) Writing GS segment register is not allowed on linux-sgx since it is used as the base address of thread data in 64-bit hw mode. Reported in bytecodealliance#2252. Disable writing it and disable segue optimization for linux-sgx platform.
…urity (bytecodealliance#2416) Call ecall commands arbitrarily from host when enclave's runtime isn't initialized may cause unexpected behavior, for example, load/instantiate wasm module. Add runtime inited status checks in enclave to improve the security. Also fix `wait_map` issue mentioned in bytecodealliance#2252 (comment)
Hello~
GS register shouldn't be modified in linux-sgx platform hardware mode (64 bit)
In linux-sgx
get_thread_data
useREAD_TD_DATA
assembly macro here, for Enclave Thread Data/Thread Local Storage usage.And in SGX hardware mode,
READ_TD_DATA
useGS
register in 64bit mode as base address of thread data. here(Note in hardware mode
SE_SIM
is undefined)In wamr
Thus it shouldn't modify
GS
register in Enclave.here for exampleos_writegsbase
macro is at hereThe text was updated successfully, but these errors were encountered: