Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasmparser: Fix validation of the return_call family of instructions #1585

Merged

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented May 29, 2024

We need to additionally check that the callee's results are an exact match of the caller's results. We were incorrectly allowing return calls that would push more values on the operand stack than would be returned. That is fine with a call; return sequence, where extra values on the stack are allowed to dangle, but not okay with a return_call. With a return_call it doesn't make sense because the callee might need a return pointer to put all its results into, but the caller can't supply one since its frame is going away, nor can the caller forward a return pointer that it received to the callee, since it might not return enough values to require a return pointer. This commit fixes the validation to match the spec and disallow return_calls that would leave dangling values on the operand stack.

cc bytecodealliance/wasmtime#8704

We need to additionally check that the callee's results are an exact match of
the caller's results. We were incorrectly allowing return calls that would push
more values on the operand stack than would be returned. That is fine with a
`call; return` sequence, where extra values on the stack are allowed to dangle,
but not okay with a `return_call`. With a `return_call` it doesn't make sense
because the callee might need a return pointer to put all its results into, but
the caller can't supply one since its frame is going away, nor can the caller
forward a return pointer that it received to the callee, since it might not
return enough values to require a return pointer. This commit fixes the
validation to match the spec and disallow `return_call`s that would leave
dangling values on the operand stack.

cc bytecodealliance/wasmtime#8704

Co-Authored-By: Trevor Elliott <[email protected]>
@fitzgen fitzgen force-pushed the fix-return-call-validation branch from 6f9b07b to d7eabc4 Compare May 29, 2024 17:36
@alexcrichton alexcrichton added this pull request to the merge queue May 29, 2024
Merged via the queue into bytecodealliance:main with commit 80dc262 May 29, 2024
25 checks passed
@fitzgen fitzgen deleted the fix-return-call-validation branch May 29, 2024 18:30
@fitzgen
Copy link
Member Author

fitzgen commented May 29, 2024

Upstreaming these new tests to the spec testsuite here: WebAssembly/function-references#116

@fitzgen fitzgen restored the fix-return-call-validation branch June 11, 2024 20:13
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