From 31fa95b708daba7508c3d44e9aa1a5fc0e7b1b75 Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Tue, 20 Aug 2024 10:01:28 +0000 Subject: [PATCH 1/5] update wamser; mem.grow compile time limits checks --- vm-executor-wasmer/Cargo.toml | 6 +++--- vm-executor-wasmer/src/wasmer_instance.rs | 1 + vm-executor-wasmer/src/wasmer_opcode_control.rs | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/vm-executor-wasmer/Cargo.toml b/vm-executor-wasmer/Cargo.toml index b4ad51f..6b8815c 100644 --- a/vm-executor-wasmer/Cargo.toml +++ b/vm-executor-wasmer/Cargo.toml @@ -11,15 +11,15 @@ version = "0.2.0" path = "../vm-executor" [dependencies] -wasmer = { git = "https://github.com/multiversx/wasmer", rev = "cdd1550", default-features = false, features = [ +wasmer = { git = "https://github.com/multiversx/wasmer", rev = "090ad17927fd1cbecb253a7b123d21e453fa13df", default-features = false, features = [ "singlepass", "sys", "universal", "wat", ] } -wasmer-vm = { git = "https://github.com/multiversx/wasmer", rev = "cdd1550" } -wasmer-types = { git = "https://github.com/multiversx/wasmer", rev = "cdd1550" } +wasmer-vm = { git = "https://github.com/multiversx/wasmer", rev = "090ad17927fd1cbecb253a7b123d21e453fa13df" } +wasmer-types = { git = "https://github.com/multiversx/wasmer", rev = "090ad17927fd1cbecb253a7b123d21e453fa13df" } chrono = "0.4.23" log = "0.4.17" diff --git a/vm-executor-wasmer/src/wasmer_instance.rs b/vm-executor-wasmer/src/wasmer_instance.rs index 385e947..e5629c9 100644 --- a/vm-executor-wasmer/src/wasmer_instance.rs +++ b/vm-executor-wasmer/src/wasmer_instance.rs @@ -180,6 +180,7 @@ fn push_middlewares( // Create opcode_control middleware let opcode_control_middleware = Arc::new(OpcodeControl::new( + 100, // TODO: should be compilation_options.max_memory_grow_count, compilation_options.max_memory_grow, compilation_options.max_memory_grow_delta, breakpoints_middleware.clone(), diff --git a/vm-executor-wasmer/src/wasmer_opcode_control.rs b/vm-executor-wasmer/src/wasmer_opcode_control.rs index 195bca4..7c1cbe8 100644 --- a/vm-executor-wasmer/src/wasmer_opcode_control.rs +++ b/vm-executor-wasmer/src/wasmer_opcode_control.rs @@ -26,6 +26,8 @@ struct OpcodeControlGlobalIndexes { #[derive(Debug)] pub(crate) struct OpcodeControl { + total_memory_grow_count: Arc>, + max_memory_grow_count: usize, max_memory_grow: usize, max_memory_grow_delta: usize, breakpoints_middleware: Arc, @@ -34,11 +36,14 @@ pub(crate) struct OpcodeControl { impl OpcodeControl { pub(crate) fn new( + max_memory_grow_count: usize, max_memory_grow: usize, max_memory_grow_delta: usize, breakpoints_middleware: Arc, ) -> Self { Self { + total_memory_grow_count: Arc::new(Mutex::new(0)), + max_memory_grow_count, max_memory_grow, max_memory_grow_delta, breakpoints_middleware, @@ -81,6 +86,8 @@ impl ModuleMiddleware for OpcodeControl { _local_function_index: LocalFunctionIndex, ) -> Box { Box::new(FunctionOpcodeControl { + total_memory_grow_count: self.total_memory_grow_count.clone(), + max_memory_grow_count: self.max_memory_grow_count, max_memory_grow: self.max_memory_grow, max_memory_grow_delta: self.max_memory_grow_delta, breakpoints_middleware: self.breakpoints_middleware.clone(), @@ -117,6 +124,8 @@ impl MiddlewareWithProtectedGlobals for OpcodeControl { #[derive(Debug)] struct FunctionOpcodeControl { + total_memory_grow_count: Arc>, + max_memory_grow_count: usize, max_memory_grow: usize, max_memory_grow_delta: usize, breakpoints_middleware: Arc, @@ -193,6 +202,12 @@ impl FunctionMiddleware for FunctionOpcodeControl { state: &mut MiddlewareReaderState<'b>, ) -> Result<(), MiddlewareError> { if matches!(operator, Operator::MemoryGrow { .. }) { + let mut grow_count = self.total_memory_grow_count.lock().map_err(|_| MiddlewareError::new("MemoryGrowLimit", "failed to lock counter"))?; + *grow_count += 1; + if *grow_count > self.max_memory_grow_count { + return Err(MiddlewareError::new("MemoryGrowLimit", "memory.grow limit exceeded")); + } + self.inject_memory_grow_check(state); } From 367198e7547e0d7cfbb40923f762b3d3fb00e935 Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Tue, 20 Aug 2024 11:04:37 +0000 Subject: [PATCH 2/5] remove deprecated build os in actions --- .github/workflows/libvmexeccapi-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/libvmexeccapi-build.yml b/.github/workflows/libvmexeccapi-build.yml index 6e57182..44c58a8 100644 --- a/.github/workflows/libvmexeccapi-build.yml +++ b/.github/workflows/libvmexeccapi-build.yml @@ -19,7 +19,7 @@ jobs: - os: ubuntu-20.04 artifact_name: libvmexeccapi.so make_target: capi-linux-amd64 - - os: macos-11 + - os: macos-13 artifact_name: libvmexeccapi.dylib make_target: capi-osx-amd64 - os: macos-13-xlarge From e06a51f56eb269444a64ba90b6d5b9cda3b9a15c Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Tue, 20 Aug 2024 15:33:12 +0000 Subject: [PATCH 3/5] fix rust version in actions --- .github/workflows/libvmexeccapi-build.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/libvmexeccapi-build.yml b/.github/workflows/libvmexeccapi-build.yml index 44c58a8..74d8a02 100644 --- a/.github/workflows/libvmexeccapi-build.yml +++ b/.github/workflows/libvmexeccapi-build.yml @@ -26,6 +26,11 @@ jobs: artifact_name: libvmexeccapi_arm make_target: capi-osx-arm steps: + - name: Install rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: "1.77" + - name: Checkout uses: actions/checkout@v4 From 6eaad7d65b66e58bf8e552e02669b34aee212be0 Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Tue, 20 Aug 2024 15:36:29 +0000 Subject: [PATCH 4/5] fix rust version in actions --- .github/workflows/rust-ci.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/rust-ci.yml b/.github/workflows/rust-ci.yml index fa8a949..acf9e00 100644 --- a/.github/workflows/rust-ci.yml +++ b/.github/workflows/rust-ci.yml @@ -11,6 +11,10 @@ jobs: name: Rust tests runs-on: ubuntu-latest steps: + - name: Install rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: "1.77" - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: @@ -23,6 +27,10 @@ jobs: name: Clippy linter check runs-on: ubuntu-latest steps: + - name: Install rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: "1.77" - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: From 54448cdd391731aded65a37078d44aacecbbb374 Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Tue, 20 Aug 2024 15:38:37 +0000 Subject: [PATCH 5/5] fix rust version in actions --- .github/workflows/rust-ci.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/rust-ci.yml b/.github/workflows/rust-ci.yml index acf9e00..5a88d1d 100644 --- a/.github/workflows/rust-ci.yml +++ b/.github/workflows/rust-ci.yml @@ -11,15 +11,11 @@ jobs: name: Rust tests runs-on: ubuntu-latest steps: - - name: Install rust - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - toolchain: "1.77" - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: default: true - toolchain: stable + toolchain: "1.77" - name: Run rust tests run: cargo test clippy_check: @@ -27,10 +23,6 @@ jobs: name: Clippy linter check runs-on: ubuntu-latest steps: - - name: Install rust - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - toolchain: "1.77" - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: