Skip to content

Hardware bounds checking fails for multi-memory + multi-module #4703

@sbird-kick

Description

@sbird-kick

Describe the bug
Using two modules in which one calls the other, I can reproduce a scenario in out of bounds memory accesses are ignored if done by the second module. This does not happen if you disable hardware bounds checks.

Version
I am using iwasm-2.4.3. The commit is 7898af9.

To Reproduce

  1. Compile iwasm with these flags -DWAMR_BUILD_MULTI_MODULE=1 -DWAMR_BUILD_MULTI_MEMORY=1 -DWAMR_DISABLE_HW_BOUND_CHECK=0
  2. Compile these two wat files using wat2wasm --enable-multi-memory
    single_page_memory.wat -> simple_page_memory.wasm:
(module
  (func $other_main (import "double_page_memory" "main_2") (result i32))
  (memory (export "memory") 1)
  (func $main (export "main") (result i32)
      i32.const 0
      i32.load 
      call $other_main
      drop
  )
)

double_page_memory.wat -> double_page_memory.wasm:

(module 
  (memory $first_memory (export "memory_2") 100)
  (memory $second_memory (export "memory_3") 200)
  (func $main_2 (export "main_2") (result i32)
      
      i32.const 10213
      
      i32.const 6553400
      i32.load 
      
      i32.div_s 
      drop

      i32.const 10213
      
      i32.const 1055340000
      i32.load $second_memory
      
      i32.div_s 
      
  )
  (data 0 (i32.const 6553400) "12345678" )
  (data 1 (i32.const 10553400) "12345678" )
)
  1. Run them using iwasm-2.4.3 single_page_memory.wasm --module-path=$(pwd)

  2. Compile iwasm again using -DWAMR_BUILD_MULTI_MODULE=1 -DWAMR_BUILD_MULTI_MEMORY=1 -DWAMR_DISABLE_HW_BOUND_CHECK=1 and run it again

Expected behavior
I should see an out of bounds memory access in both.

humzai@humzai-2313D:~/bug_report_iwasm$ iwasm-2.4.3 single_page_memory.wasm --module-path=$(pwd)
Exception: out of bounds memory access

Actual Result
I only see an out of bounds memory access when iwasm is compiled with -DWAMR_DISABLE_HW_BOUND_CHECK=1

Desktop

  • Arch x86
  • Board B650M AORUS ELITE AX
  • OS Ubuntu
  • 24.03

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmulti-moduleWAMR_BUILD_MULTI_MODULE/WASM_ENABLE_MULTI_MODULE

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions