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

Change stack walking to stop at a precise fp #9420

Merged
merged 2 commits into from
Oct 9, 2024

Conversation

alexcrichton
Copy link
Member

Prior to this commit entry trampolines into wasm would record their
stack pointer at the time of the function call to wasm and then this
stack pointer was used to halt the stack walking process. The problem
with this though is that due to the tail ABI it's possible that the
callee will update the caller's stack pointer temporarily. This means
that the recorded stack pointer at the time the trampoline called wasm
may differ from the callee's idea of what the stack pointer is when a
backtrace happens.

To handle this condition when stack walking the frame pointer instead of
the stack pointer is now recorded when wasm is invoked. This frame
pointer is a trusted value as it's managed by Cranelift itself. This
additionally enables the stop condition for frame walking to be a
precise "it must be this value" condition.

Put together this commit fixes an issue where when return_call is used
it's possible for the initial few frames of the stack to get lost in
stack traces. After this the frame pointer chain should always be
precisely walked in its entirety, even in the face of different numbers
of arguments and parameters as return_call instructions are executed.

Prior to this commit entry trampolines into wasm would record their
stack pointer at the time of the function call to wasm and then this
stack pointer was used to halt the stack walking process. The problem
with this though is that due to the `tail` ABI it's possible that the
callee will update the caller's stack pointer temporarily. This means
that the recorded stack pointer at the time the trampoline called wasm
may differ from the callee's idea of what the stack pointer is when a
backtrace happens.

To handle this condition when stack walking the frame pointer instead of
the stack pointer is now recorded when wasm is invoked. This frame
pointer is a trusted value as it's managed by Cranelift itself. This
additionally enables the stop condition for frame walking to be a
precise "it must be this value" condition.

Put together this commit fixes an issue where when `return_call` is used
it's possible for the initial few frames of the stack to get lost in
stack traces. After this the frame pointer chain should always be
precisely walked in its entirety, even in the face of different numbers
of arguments and parameters as `return_call` instructions are executed.
This commit extends the preexisting `stacks` fuzzer with a few new
features:

* `return_call` instructions are now generated
* functions may have both params/results to exercise logic around stack
  adjustments and how that might affect a stack trace
@alexcrichton alexcrichton requested review from a team as code owners October 9, 2024 16:39
@github-actions github-actions bot added fuzzing Issues related to our fuzzing infrastructure wasmtime:api Related to the API of the `wasmtime` crate itself labels Oct 9, 2024
Copy link

github-actions bot commented Oct 9, 2024

Subscribe to Label Action

cc @fitzgen

This issue or pull request has been labeled: "fuzzing", "wasmtime:api"

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

  • fitzgen: fuzzing

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

Learn more.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice clean up

@fitzgen fitzgen added this pull request to the merge queue Oct 9, 2024
Merged via the queue into bytecodealliance:main with commit de469e2 Oct 9, 2024
39 checks passed
@alexcrichton alexcrichton deleted the stop-backtrace-with-fp branch October 9, 2024 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fuzzing Issues related to our fuzzing infrastructure wasmtime:api Related to the API of the `wasmtime` crate itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants