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

Backport bug #20493 to Ruby 3.3 #10798

Conversation

KJTsanaktsidis
Copy link
Contributor

Backports https://bugs.ruby-lang.org/issues/20493 (#10795) to Ruby 3.3

[Bug #20493]

There's an exhaustive explanation of this in the linked redmine bug, but
the short version is as follows:

blocking_region_begin can spill callee-saved registers to the stack for
its own use. That means they're not saved to ec->machine by the call to
setjmp, since by that point they're already on the stack and new,
different values are in the real registers. ec->machine's end-of-stack
pointer is also bumped to accomodate this, BUT, after
blocking_region_begin returns, that points past the end of the stack!

As far as C is concerned, that's fine; the callee-saved registers are
restored when blocking_region_begin returns. But, if another thread
triggers GC, it is relying on finding references to Ruby objects by
walking the stack region pointed to by ec->machine.

If the C code in exec; subsequently does things that use that stack
memory, then the value will be overwritten and the GC might prematurely
collect something it shouldn't.

[Bug #20493]
bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request May 21, 2024
https://build.opensuse.org/request/show/1175260
by user darix + anag+factory
- Backport for fix segfault caused by stack pointers not
  saved/restored properly when yielding execution from Ruby to C.
  https://bugs.ruby-lang.org/issues/20493
  ruby/ruby#10798
  Adds fix-gvl-save-restore.patch

- fix typo in the macros file. this only affected people building
  without the OBS as this macro was shadowed by the macro that is
  in the prjconf
@k0kubun k0kubun merged commit b6c07ac into ruby:ruby_3_3 May 28, 2024
97 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 participants