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

winch: Sync registers and locals before fuel check #9554

Merged

Conversation

saulecabrera
Copy link
Member

This commit fixes a fuzz bug in which the stack was misaligned when calling the out-of-fuel builtin function.

The misalignment was introduced by a erroneous handling of the the control flow merge introduced by the fuel check conditional. In general, prior to every branch emission, a spill to memory is needed to avoid issues at the control flow merge.

Note that we don't have many cases like this one in Winch's codebase (3 in total), however as a follow-up, it's probably worth considering introducing a stronger abstraction around branching to ensure that this case is handled whenever an arbitrary branch needs to be introduced. This change solely focuses on the fix and does not introduce any refactoring. I plan to follow-up with investigating a better branching strategy, since we would need to introduce a similar pattern for epoch handling.

I used wasm-tools shink to shrink the original program, which I decided to add as part of an integration test.

This commit fixes a fuzz bug in which the stack was misaligned when
calling the out-of-fuel builtin function.

The misalignment was introduced by a erroneous handling of the the
control flow merge introduced by the fuel check conditional. In general,
prior to every branch emission, a spill to memory is needed to avoid
issues at the control flow merge.

Note that we don't have many cases like this one in Winch's codebase (3
in total), however as a follow-up, it's probably worth considering
introducing a stronger abstraction around branching to ensure that this
case is handled whenever an arbitrary branch needs to be introduced.
This change solely focuses on the fix and does not introduce any
refactoring. I plan to follow-up with investigating a better branching
strategy, since we would need to introduce a similar pattern for epoch
handling.

I used `wasm-tools shink` to shrink the original program, which
I decided to add as part of an integration test.
@saulecabrera saulecabrera requested review from a team as code owners November 5, 2024 14:07
@saulecabrera saulecabrera requested review from cfallin and alexcrichton and removed request for a team November 5, 2024 14:07
tests/all/fuel_stack_alignment.wat Outdated Show resolved Hide resolved
@github-actions github-actions bot added the winch Winch issues or pull requests label Nov 5, 2024
Copy link

github-actions bot commented Nov 5, 2024

Subscribe to Label Action

cc @saulecabrera

This issue or pull request has been labeled: "winch"

Thus the following users have been cc'd because of the following labels:

  • saulecabrera: winch

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@saulecabrera saulecabrera added this pull request to the merge queue Nov 5, 2024
@alexcrichton
Copy link
Member

@saulecabrera would you be ok backporting this to the release-27 branch? If you're busy I'm happy to take that on myself

Merged via the queue into bytecodealliance:main with commit b5627a8 Nov 5, 2024
40 checks passed
@saulecabrera saulecabrera deleted the winch-unaligned-stack-fuel branch November 5, 2024 18:19
@saulecabrera saulecabrera restored the winch-unaligned-stack-fuel branch November 5, 2024 18:28
@saulecabrera
Copy link
Member Author

@alexcrichton I've opened #9564. Just to confirm, since 27 is not released yet, there's nothing to follow-up on after the backport lands, right?

@alexcrichton
Copy link
Member

Indeed, and thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
winch Winch issues or pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants