Add more checks to enhance security (#446)

add more checks to enhance security
clear "wasi proc exit" exception before return to caller in wasm/aot call functions
fix memory profiling issue
change movdqa to movdqu in simd invokeNative asm codes to fix issue of unaligned address access
move setjmp/longjmp from libc-builtin to libc-emcc
fix zephyr platform compilation issue in latest zephyr version
This commit is contained in:
Wenyong Huang
2020-11-24 14:00:09 +08:00
committed by GitHub
parent f4770ae8c8
commit 74be7a0b7c
24 changed files with 397 additions and 216 deletions

View File

@ -41,14 +41,14 @@ push_args:
loop push_args
push_args_end:
/* fill all fp args */
movdqa 0x00(%rsi), %xmm0
movdqa 0x10(%rsi), %xmm1
movdqa 0x20(%rsi), %xmm2
movdqa 0x30(%rsi), %xmm3
movdqa 0x40(%rsi), %xmm4
movdqa 0x50(%rsi), %xmm5
movdqa 0x60(%rsi), %xmm6
movdqa 0x70(%rsi), %xmm7
movdqu 0x00(%rsi), %xmm0
movdqu 0x10(%rsi), %xmm1
movdqu 0x20(%rsi), %xmm2
movdqu 0x30(%rsi), %xmm3
movdqu 0x40(%rsi), %xmm4
movdqu 0x50(%rsi), %xmm5
movdqu 0x60(%rsi), %xmm6
movdqu 0x70(%rsi), %xmm7
/* fill all int args */
movq 0x80(%rsi), %rdi

View File

@ -579,8 +579,10 @@ wasm_functype_new(wasm_valtype_vec_t *params, wasm_valtype_vec_t *results)
failed:
LOG_DEBUG("%s failed", __FUNCTION__);
FREEIF(func_type->params);
FREEIF(func_type->results);
if (func_type)
FREEIF(func_type->params);
if (func_type)
FREEIF(func_type->results);
FREEIF(func_type);
return NULL;
}
@ -1151,10 +1153,15 @@ native_func_trampoline(wasm_exec_env_t exec_env, uint64 *argv)
}
if (trap) {
wasm_name_t *message = NULL;
wasm_trap_message(trap, message);
LOG_WARNING("got a trap %s", message->data);
wasm_name_delete(message);
wasm_name_t *message = malloc_internal(sizeof(wasm_name_t));
if (message) {
wasm_trap_message(trap, message);
if (message->data) {
LOG_WARNING("got a trap %s", message->data);
wasm_name_delete(message);
}
FREEIF(message);
}
}
/* there is no result or there is an exception */
@ -2188,7 +2195,7 @@ interp_process_export(wasm_store_t *store,
uint32 export_cnt = 0;
uint32 i = 0;
bh_assert(store && inst_interp && externals);
bh_assert(store && inst_interp && inst_interp->module && externals);
exports = inst_interp->module->exports;
export_cnt = inst_interp->module->export_count;

View File

@ -2094,6 +2094,11 @@ wasm_application_execute_main(WASMModuleInstanceCommon *module_inst,
func_type = ((AOTFunctionInstance*)func)->u.func.func_type;
#endif
if (!func_type) {
LOG_ERROR("invalid module instance type");
return false;
}
if (!check_main_func_type(func_type)) {
wasm_runtime_set_exception(module_inst,
"invalid function type of main function");
@ -2318,7 +2323,7 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
{
WASMFunctionInstanceCommon *func;
WASMType *type = NULL;
uint32 argc1, *argv1 = NULL, cell_num, j, k = 0;
uint32 argc1, *argv1 = NULL, cell_num = 0, j, k = 0;
int32 i, p;
uint64 total_size;
const char *exception;
@ -2362,6 +2367,11 @@ wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
}
#endif
if (!type) {
LOG_ERROR("invalid module instance type");
return false;
}
if (type->param_count != (uint32)argc) {
wasm_runtime_set_exception(module_inst,
"invalid input argument count");

View File

@ -200,8 +200,10 @@ notify_wait_list(bh_list *wait_list, uint32 count)
notify_count = wait_list->len;
node = bh_list_first_elem(wait_list);
if (!node)
return 0;
for (i = 0; i < count; i++) {
for (i = 0; i < notify_count; i++) {
bh_assert(node);
next = bh_list_elem_next(node);