Fix double-free of cached WASM module in fizzy vm_manager - #862
Open
pgarciagon wants to merge 1 commit into
Open
Fix double-free of cached WASM module in fizzy vm_manager#862pgarciagon wants to merge 1 commit into
pgarciagon wants to merge 1 commit into
Conversation
fizzy_vm_backend::run() caches a parsed module in a module_guard, whose destructor frees it with fizzy_free_module. The same module pointer was then passed to fizzy_resolve_instantiate, which per fizzy's API takes ownership of the module and frees it via fizzy_free_instance. The same FizzyModule was therefore freed twice. A double free is undefined behavior that manifests only under a strict allocator: it is caught immediately by AddressSanitizer and crashes on the macOS 26 SDK toolchain (EXC_BAD_ACCESS in fizzy::Module::~Module during module_cache teardown, surfacing as the read_contract_tests failure and any full block execution), while older/other allocators tolerate it silently. Instantiate a fizzy_clone_module() copy so the FizzyInstance owns its own module and the cache keeps the original. Also make module_guard non-copyable and non-movable: it is the sole owner of a raw FizzyModule and copying it would reintroduce the double free. Verified with an AddressSanitizer build: read_contract_tests and the full chain suite pass with zero ASan errors. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
fizzy_vm_backend::run()caches a parsed WASM module in amodule_guard, whose destructor frees it withfizzy_free_module. The same module pointer is then passed tofizzy_resolve_instantiate, which per fizzy's C API takes ownership of the module and frees it viafizzy_free_instance:So the same
FizzyModuleis freed twice.A double free is undefined behavior that surfaces only under a strict allocator. It is caught immediately by AddressSanitizer, and crashes deterministically on the macOS 26 SDK toolchain —
EXC_BAD_ACCESSinfizzy::Module::~Moduleduringmodule_cacheteardown, showing up as thecontroller_tests/read_contract_testsfailure and in any full block execution. Older/other allocators (older macOS, Linux) tolerate it silently, which is why it has gone unnoticed.AddressSanitizer
Fix
fizzy_clone_module()copy, so theFizzyInstanceowns its own module and the cache keeps the original.module_guardnon-copyable and non-movable — it is the sole owner of a rawFizzyModuleand copying it would reintroduce the double free.Testing
AddressSanitizer build (Debug,
-fsanitize=address):read_contract_testsand the full chain suite pass with zero ASan errors. Release full suite also green.Note: this is independent of the state-delta replay work (#860 / #861); it is a pre-existing vm_manager bug. The same vendored vm_manager exists in the Teleno monolith and should get the same fix.