Repository navigation
Conversation
Thread::DoCall sizes the results vector to the callee's result count before calling a host function, but Func::Call passes the caller's vector through unchanged, which is empty. A host callback then writes results[i] past the end of an empty vector. Through the wasm C API, wasm_func_new sizes its wasm_val_vec_t from that vector, so the embedder's callback gets results->size == 0 and data == NULL. Resize results to the function type's result count in HostFunc::DoCall so both call paths give the callback a correctly sized vector.
This branch has not been deployed
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.
ASan, wasm C API, calling a re-exported host import with
wasm_func_call:How I found it: I was fuzzing the interpreter by instantiating modules and calling every export. Only exports that were re-exported imports behaved oddly, so I followed that path by hand.
What I saw:
Thread::DoCall. That function buildsValues results(func_type.results.size())before it calls the host.Func::Callis the public entry point. It hands the caller'sresultstoHostFunc::DoCallunchanged, and that vector is normally empty.results[i]using the declared result arity, so it writes past an empty vector.wasm_func_newandwasm_func_new_with_envsize theirwasm_val_vec_tfrom that empty vector. The embedder's callback getsresults->size == 0withdata == NULL.FromWabtValuesthen reads the empty vector using the declared result count.The trigger needs nothing unusual. A module only has to re-export an import,
(import "" "f" (func (result i32))) (export "f" (func 0)). An embedder that calls that export throughwasm_func_callhits the bug.Conclusion: the size belongs to the callee, so it is set in
HostFunc::DoCall. On theThread::DoCallpath the vector is already the right size, so the resize does nothing there. On the direct path, the callback now gets the vector it expects. With the patch the reproducer returns 42, and the newInterpTest.HostFunc_CallReexportpasses. That test fails on main withresults.size()equal to 0, followed by a vector subscript assertion. All 143 unit tests and the interp file tests pass.