Skip to content

wasm2c: fix to check address + offset addition for memory64 - #2785

Merged
shravanrn merged 1 commit into
WebAssembly:mainfrom
UT-Security:mem64-codegen-fixes
Jul 3, 2026
Merged

shravanrn merged 1 commit into
WebAssembly:mainfrom
UT-Security:mem64-codegen-fixes

Conversation

@shravanrn

@shravanrn shravanrn commented Jul 3, 2026 •

Copy link
Copy Markdown
Collaborator

As part of routine audit we found a bugs in the wasm2c code-generation for modules supporting memory64. Memory32 is not affected.

The wasm2c code generator for LoadExpr and StoreExpr emits (u64)(addr) + offset as uint64_t addition. This is fine for memory32 due to the uint64_t promotion but hides an overflow for memory64 load/store that will violate Wasm semantics (but not break security).

When the addr and offset addition overflow in Memory64 (e.g., addr=1 + offset=0xFFFFFFFFFFFFFFFF wraps to 0), the wrapped value is passed to i32_store/i32_load, where MEMCHECK_GENERAL -> RANGE_CHECK only checks the already-wrapped (small) value against mem->size. The overflow is undetected and the access succeeds at the wrong address instead of trapping.

@shravanrn
shravanrn requested review from keithw and sbc100 July 3, 2026 03:01
@shravanrn shravanrn changed the title wasm2c: (Security) fix to check address + offset addition for memory64 wasm2c: fix to check address + offset addition for memory64 Jul 3, 2026
@shravanrn
shravanrn enabled auto-merge (rebase) July 3, 2026 21:52
@shravanrn
shravanrn force-pushed the mem64-codegen-fixes branch from cefc50e to 770e756 Compare July 3, 2026 21:52
@shravanrn
shravanrn merged commit 4bedf7c into WebAssembly:main Jul 3, 2026
17 checks passed
@shravanrn

Copy link
Copy Markdown
Collaborator Author

Just an fyi, looks like I accidentally made the commit title include a (Security) prefix. To clarify, this is not a security issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants