Skip to content

Fix double-free of cached WASM module in fizzy vm_manager - #7

Open
pgarciagon wants to merge 1 commit into
mainfrom
fix/vm-manager-module-double-free
Open

Fix double-free of cached WASM module in fizzy vm_manager#7
pgarciagon wants to merge 1 commit into
mainfrom
fix/vm-manager-module-double-free

Conversation

@pgarciagon

Copy link
Copy Markdown
Contributor

Teleno vendors the same koinos vm_manager as koinos-chain and carries the same double-free.

fizzy_vm_backend::run() caches a parsed WASM module in a module_guard (frees it via fizzy_free_module), then passes the same pointer to fizzy_resolve_instantiate, which per fizzy's API takes ownership of the module and frees it via fizzy_free_instance. The same FizzyModule is freed twice.

A double free is UB that surfaces only under a strict allocator: it crashes deterministically on the macOS 26 SDK (EXC_BAD_ACCESS in fizzy::Module::~Module during module_cache teardown) and is tolerated silently on older allocators.

Fix: instantiate a fizzy_clone_module() copy so the instance owns its own module and the cache keeps the original; make module_guard non-copyable/non-movable.

Twin of koinos/koinos-chain#862, where it was root-caused with AddressSanitizer (zero ASan errors after the fix, full suite green).

fizzy_vm_backend::run() caches a parsed module in a module_guard (frees it
via fizzy_free_module), then passes the same pointer to
fizzy_resolve_instantiate, which per fizzy's API takes ownership of the
module and frees it via fizzy_free_instance. The same FizzyModule is freed
twice.

A double free is UB that a strict allocator crashes on (macOS 26 SDK:
EXC_BAD_ACCESS in fizzy::Module::~Module during module_cache teardown) while
older allocators tolerate it silently. Instantiate a fizzy_clone_module()
copy so the FizzyInstance owns its own module and the cache keeps the
original, and make module_guard non-copyable/non-movable.

Verified in the koinos-chain twin (koinos/koinos-chain#862) with an
AddressSanitizer build: zero ASan errors, full suite green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pgarciagon
pgarciagon requested a review from joticajulian July 10, 2026 18:40
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