fix: use-after-free in cabi_realloc free_list on repeated export calls#319
Open
chaynabors wants to merge 1 commit intobytecodealliance:mainfrom
Open
fix: use-after-free in cabi_realloc free_list on repeated export calls#319chaynabors wants to merge 1 commit intobytecodealliance:mainfrom
chaynabors wants to merge 1 commit intobytecodealliance:mainfrom
Conversation
cabi_realloc tracked all allocations in Runtime.free_list, which post_call freed after each export invocation. When the host calls cabi_realloc during an import to write a return value into guest memory, those allocations may still be referenced by live JS objects across repeated export calls. post_call would free them, causing use-after-free on the next invocation. Fix: remove indiscriminate tracking from cabi_realloc. Only the retptr allocated explicitly in call() is tracked and freed by post_call. Fixes bytecodealliance#224
Author
|
This is a step closer to the ideal solution, but may be a partial regression in that some buffers may no longer be freed if they were copied during lifting. The lifetimes aren't clear enough to me at this point to validate this holistically. I'm trying to convince my team to adopt WASM. We can stomach a small bounded memory leak, but the current use-after-free makes Componentize unusable for us. A more comprehensive solution might involve some sort of deallocator in the splicer, but this is far more involved and risky for me to implement than the proposed solution. I'm happy to take a stab at it if I can get WASM adopted, but won't have time otherwise. |
Author
|
Accidentally closed #318 while doing some spring cleaning. Sorry for duplicate. |
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.
Fixes #224
cabi_realloctracked all allocations inRuntime.free_list, whichpost_callfreed after each export invocation. When the host callscabi_reallocduring an import to write a return value into guest memory, those allocations may still be referenced by live JS objects across repeated export calls.post_callwould free them, causing use-after-free on the next invocation.This PR removes indiscriminate tracking from
cabi_realloc. Only theretptrallocated explicitly incall()is tracked and freed bypost_call.retptris a temporary buffer that JS never references directly, which is why it needs to be managed explicitly.