-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Avoid use-after-free when disabling local tracepoint #5862
Closed
Closed
Conversation
This file contains 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
Disabling a local tracepoint while handling a different tracepoint can cause a use-after-free in exec_hooks_body in certain cases, because exec_hooks_body accessed local_hooks freed earlier in iseq_remove_local_tracepoint. Fix this by changing local_hooks in rb_iseq_struct from struct rb_hook_list_struct * to struct rb_hook_list_struct **. This allows us to set *local_hooks to NULL after freeing *local_hooks. Functions now check both local_hooks and *local_hooks, and only run hooks if both are non-NULL. Addresses use-after-free crash found while in investigating #18730.
XrXr
added a commit
to XrXr/ruby
that referenced
this pull request
Apr 29, 2022
`vm_trace_hook()` runs global hooks before running local hooks. Previously, we read the local hook list before running the global hooks which led to use-after-free when the global hook frees the local hook list, for example by disabling a local TracePoint. Delay local hook list loading until after running the global hooks. Issue discovered by Jeremy Evans in rubyGH-5862.
XrXr
added a commit
to XrXr/ruby
that referenced
this pull request
Apr 29, 2022
`vm_trace_hook()` runs global hooks before running local hooks. Previously, we read the local hook list before running the global hooks which led to use-after-free when the global hook frees the local hook list, for example by disabling a local TracePoint. Delay local hook list loading until after running the global hooks. Issue discovered by Jeremy Evans in rubyGH-5862.
It seemed weird to me that adding another allocation is necessary and I debugged this down to an ordering problem in |
XrXr
added a commit
to XrXr/ruby
that referenced
this pull request
May 28, 2022
`vm_trace_hook()` runs global hooks before running local hooks. Previously, we read the local hook list before running the global hooks which led to use-after-free when a global hook frees the local hook list. A global hook can do this by disabling a local TracePoint, for example. Delay local hook list loading until after running the global hooks. Issue discovered by Jeremy Evans in rubyGH-5862. [Bug #18730]
XrXr
added a commit
to XrXr/ruby
that referenced
this pull request
May 28, 2022
`vm_trace_hook()` runs global hooks before running local hooks. Previously, we read the local hook list before running the global hooks which led to use-after-free when a global hook frees the local hook list. A global hook can do this by disabling a local TracePoint, for example. Delay local hook list loading until after running the global hooks. Issue discovered by Jeremy Evans in rubyGH-5862. [Bug #18730]
XrXr
added a commit
to XrXr/ruby
that referenced
this pull request
May 28, 2022
`vm_trace_hook()` runs global hooks before running local hooks. Previously, we read the local hook list before running the global hooks which led to use-after-free when a global hook frees the local hook list. A global hook can do this by disabling a local TracePoint, for example. Delay local hook list loading until after running the global hooks. Issue discovered by Jeremy Evans in rubyGH-5862. [Bug #18730]
XrXr
added a commit
that referenced
this pull request
May 30, 2022
`vm_trace_hook()` runs global hooks before running local hooks. Previously, we read the local hook list before running the global hooks which led to use-after-free when a global hook frees the local hook list. A global hook can do this by disabling a local TracePoint, for example. Delay local hook list loading until after running the global hooks. Issue discovered by Jeremy Evans in GH-5862. [Bug #18730]
schneems
pushed a commit
to schneems/ruby
that referenced
this pull request
Jul 26, 2022
`vm_trace_hook()` runs global hooks before running local hooks. Previously, we read the local hook list before running the global hooks which led to use-after-free when a global hook frees the local hook list. A global hook can do this by disabling a local TracePoint, for example. Delay local hook list loading until after running the global hooks. Issue discovered by Jeremy Evans in rubyGH-5862. [Bug #18730]
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.
Disabling a local tracepoint while handling a different tracepoint
can cause a use-after-free in exec_hooks_body in certain cases,
because exec_hooks_body accessed local_hooks freed earlier in
iseq_remove_local_tracepoint.
Fix this by changing local_hooks in rb_iseq_struct from
struct rb_hook_list_struct * to struct rb_hook_list_struct **.
This allows us to set *local_hooks to NULL after freeing
*local_hooks. Functions now check both local_hooks and
*local_hooks, and only run hooks if both are non-NULL.
Addresses use-after-free crash found while investigating #18730.