From 397f6633491052a3d4607039f6a87834b9a8524e Mon Sep 17 00:00:00 2001 From: Fadumina Barre Date: Fri, 8 Nov 2024 08:26:37 +0000 Subject: [PATCH 1/5] fix(uwp): Gate NTSTATUS definition behind WINAPI_PARTITION_DESKTOP for UWP builds --- core/shared/platform/windows/win_clock.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/shared/platform/windows/win_clock.c b/core/shared/platform/windows/win_clock.c index ec0bc85664..c402330aad 100644 --- a/core/shared/platform/windows/win_clock.c +++ b/core/shared/platform/windows/win_clock.c @@ -10,9 +10,11 @@ #define NANOSECONDS_PER_SECOND 1000000000ULL #define NANOSECONDS_PER_TICK 100 +#if WINAPI_PARTITION_DESKTOP extern NTSTATUS NtQueryTimerResolution(PULONG MinimumResolution, PULONG MaximumResolution, PULONG CurrentResolution); +#endif static __wasi_errno_t calculate_monotonic_clock_frequency(uint64 *out_frequency) From fdda259d362b418f1f2a624c10d5a44bcdf81d51 Mon Sep 17 00:00:00 2001 From: James Ring Date: Tue, 12 Nov 2024 22:52:27 -0800 Subject: [PATCH 2/5] Fix linked global initialization in multimodule (#3905) While resolving linked globals in multi-module mode, WAMR tries to copy the linked global's initial value into the destination global in the current module. However, a bug in the implementation causes the copy to be done from the InitializerExpression struct, not from its WASMValue field. This did not come up in WAMR's spec test runner because those are built with WASM_ENABLE_SPEC_TEST, which means these globals are resolved as builtins, not linked globals, which goes through a different (presumably not faulty) path. --- core/iwasm/interpreter/wasm_runtime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index accb403196..0f1ccd9371 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -1209,7 +1209,7 @@ globals_instantiate(WASMModule *module, WASMModuleInstance *module_inst, /* The linked global instance has been initialized, we just need to copy the value. */ bh_memcpy_s(&(global->initial_value), sizeof(WASMValue), - &(global_import->import_global_linked->init_expr), + &(global_import->import_global_linked->init_expr.u), sizeof(WASMValue)); } else From 75f5fa46ab7064951b7f1fa4487c67f01a9762b5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:11:11 +0800 Subject: [PATCH 3/5] build(deps): bump github/codeql-action from 3.27.0 to 3.27.1 (#3902) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.27.0 to 3.27.1. - [Release notes](https://github.com/github/codeql-action/releases) - [Commits](https://github.com/github/codeql-action/compare/v3.27.0...v3.27.1) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/codeql.yml | 6 +++--- .github/workflows/supply_chain.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 62bcd0c311..a3228e20d3 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -53,7 +53,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v3.27.0 + uses: github/codeql-action/init@v3.27.1 with: languages: ${{ matrix.language }} @@ -70,7 +70,7 @@ jobs: - run: | ./.github/scripts/codeql_buildscript.sh - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3.27.0 + uses: github/codeql-action/analyze@v3.27.1 with: category: "/language:${{matrix.language}}" upload: false @@ -99,7 +99,7 @@ jobs: output: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif - name: Upload CodeQL results to code scanning - uses: github/codeql-action/upload-sarif@v3.27.0 + uses: github/codeql-action/upload-sarif@v3.27.1 with: sarif_file: ${{ steps.step1.outputs.sarif-output }} category: "/language:${{matrix.language}}" diff --git a/.github/workflows/supply_chain.yml b/.github/workflows/supply_chain.yml index 5e331c08c6..28efecc477 100644 --- a/.github/workflows/supply_chain.yml +++ b/.github/workflows/supply_chain.yml @@ -60,6 +60,6 @@ jobs: # Upload the results to GitHub's code scanning dashboard. - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@3aa71356c75a8edd8430d54dff2982203a28be45 # v2.2.4 + uses: github/codeql-action/upload-sarif@acb9cb18eec7e3a113ef83cff0be91e75cfd9526 # v2.2.4 with: sarif_file: results.sarif From 226bf22f9e61c33345d831c16e756ec40a90b689 Mon Sep 17 00:00:00 2001 From: James Ring Date: Tue, 12 Nov 2024 23:11:33 -0800 Subject: [PATCH 4/5] GlobalValueSet was moved to IRPartitionLayer recently, but we have a local definition anyway (#3899) --- core/iwasm/compilation/aot_orc_extra.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/iwasm/compilation/aot_orc_extra.cpp b/core/iwasm/compilation/aot_orc_extra.cpp index dad9e04c02..d9cf3e711f 100644 --- a/core/iwasm/compilation/aot_orc_extra.cpp +++ b/core/iwasm/compilation/aot_orc_extra.cpp @@ -177,7 +177,7 @@ LLVMOrcLLLazyJITBuilderSetJITTargetMachineBuilder( LLVMOrcDisposeJITTargetMachineBuilder(JTMP); } -static Optional +static Optional PartitionFunction(GlobalValueSet Requested) { std::vector GVsToAdd; From 0e4dffc47922bb6fcdcaed7de2a6edfe8c48a7cd Mon Sep 17 00:00:00 2001 From: TianlongLiang <111852609+TianlongLiang@users.noreply.github.com> Date: Wed, 13 Nov 2024 15:16:13 +0800 Subject: [PATCH 5/5] Fix a leak in wasm_loader_emit_br_info (#3900) Reference Info: 377955855 wamr:wasm_mutator_fuzz_loader: Direct-leak in wasm_loader_emit_br_info https://issues.oss-fuzz.com/issues/377955855 --- core/iwasm/common/wasm_application.c | 3 ++- core/iwasm/interpreter/wasm_loader.c | 22 +++++++++++++--------- core/iwasm/interpreter/wasm_mini_loader.c | 18 +++++++++--------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/core/iwasm/common/wasm_application.c b/core/iwasm/common/wasm_application.c index 3b3be16c05..b5928d95c1 100644 --- a/core/iwasm/common/wasm_application.c +++ b/core/iwasm/common/wasm_application.c @@ -105,7 +105,8 @@ execute_main(WASMModuleInstanceCommon *module_inst, int32 argc, char *argv[]) bool ret, is_import_func = true, is_memory64 = false; #if WASM_ENABLE_MEMORY64 != 0 WASMModuleInstance *wasm_module_inst = (WASMModuleInstance *)module_inst; - is_memory64 = wasm_module_inst->memories[0]->is_memory64; + if (wasm_module_inst->memory_count > 0) + is_memory64 = wasm_module_inst->memories[0]->is_memory64; #endif exec_env = wasm_runtime_get_exec_env_singleton(module_inst); diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 04fa2473ec..4184562108 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -9885,13 +9885,6 @@ reserve_block_ret(WASMLoaderContext *loader_ctx, uint8 opcode, } #endif /* WASM_ENABLE_FAST_INTERP */ -#define RESERVE_BLOCK_RET() \ - do { \ - if (!reserve_block_ret(loader_ctx, opcode, disable_emit, error_buf, \ - error_buf_size)) \ - goto fail; \ - } while (0) - #define PUSH_TYPE(type) \ do { \ if (!(wasm_loader_push_frame_ref(loader_ctx, type, error_buf, \ @@ -11612,7 +11605,10 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, #if WASM_ENABLE_FAST_INTERP != 0 /* if the result of if branch is in local or const area, add a * copy op */ - RESERVE_BLOCK_RET(); + if (!reserve_block_ret(loader_ctx, opcode, disable_emit, + error_buf, error_buf_size)) { + goto fail; + } emit_empty_label_addr_and_frame_ip(PATCH_END); apply_label_patch(loader_ctx, 1, PATCH_ELSE); @@ -11672,7 +11668,15 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, #if WASM_ENABLE_FAST_INTERP != 0 skip_label(); /* copy the result to the block return address */ - RESERVE_BLOCK_RET(); + if (!reserve_block_ret(loader_ctx, opcode, disable_emit, + error_buf, error_buf_size)) { + /* it could be tmp frame_csp allocated from opcode like + * OP_BR and not counted in loader_ctx->csp_num, it won't + * be freed in wasm_loader_ctx_destroy(loader_ctx) so need + * to free the loader_ctx->frame_csp if fails */ + free_label_patch_list(loader_ctx->frame_csp); + goto fail; + } apply_label_patch(loader_ctx, 0, PATCH_END); free_label_patch_list(loader_ctx->frame_csp); diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index 006a38c1ce..a1fb3102fa 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -5592,13 +5592,6 @@ reserve_block_ret(WASMLoaderContext *loader_ctx, uint8 opcode, #endif /* WASM_ENABLE_FAST_INTERP */ -#define RESERVE_BLOCK_RET() \ - do { \ - if (!reserve_block_ret(loader_ctx, opcode, disable_emit, error_buf, \ - error_buf_size)) \ - goto fail; \ - } while (0) - #define PUSH_TYPE(type) \ do { \ if (!(wasm_loader_push_frame_ref(loader_ctx, type, error_buf, \ @@ -6366,7 +6359,10 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, #if WASM_ENABLE_FAST_INTERP != 0 /* if the result of if branch is in local or const area, add a * copy op */ - RESERVE_BLOCK_RET(); + if (!reserve_block_ret(loader_ctx, opcode, disable_emit, + error_buf, error_buf_size)) { + goto fail; + } emit_empty_label_addr_and_frame_ip(PATCH_END); apply_label_patch(loader_ctx, 1, PATCH_ELSE); @@ -6426,7 +6422,11 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, #if WASM_ENABLE_FAST_INTERP != 0 skip_label(); /* copy the result to the block return address */ - RESERVE_BLOCK_RET(); + if (!reserve_block_ret(loader_ctx, opcode, disable_emit, + error_buf, error_buf_size)) { + free_label_patch_list(loader_ctx->frame_csp); + goto fail; + } apply_label_patch(loader_ctx, 0, PATCH_END); free_label_patch_list(loader_ctx->frame_csp);