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

YJIT: Protect strings from GC on String#<< #7466

Merged
merged 1 commit into from Mar 7, 2023

Conversation

k0kubun
Copy link
Member

@k0kubun k0kubun commented Mar 7, 2023

Fix Shopify/yjit#310

[Bug #19483]

rb_str_buf_append may allocate when a buffer needs to be reallocated. At that point, string objects could be freed and random bytes could be written to the string content. We need gen_save_sp to let GC scan and mark those objects.

Fix Shopify/yjit#310

[Bug #19483]

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
Co-authored-by: Jimmy Miller <jimmy.miller@shopify.com>
@matzbot matzbot requested a review from a team March 7, 2023 19:48
@maximecb maximecb merged commit 33edcc1 into ruby:master Mar 7, 2023
95 of 96 checks passed
@machty
Copy link
Contributor

machty commented Mar 7, 2023

Maybe a noob question but shouldn't a bugfix like this with a somewhat esoteric fix have a breaking test?

@maximecb
Copy link
Contributor

maximecb commented Mar 7, 2023

Maybe a noob question but shouldn't a bugfix like this with a somewhat esoteric fix have a breaking test?

That's a fair point. We'll accept a PR if you can find one :)

It would involve triggering GC during string concat, maybe with a very large string, or lots of repeated concatenation.

@k0kubun
Copy link
Member Author

k0kubun commented Mar 7, 2023

Actually I tried to write one:

original = (('a'..'z').to_a * 100).join

buf0 = ''
buf1 = ''
GC.stress = true
original.size.times do |i|
  buf0 << original[i]
  buf1 << original[i]
end

p(original == buf0)
p(original == buf1)

and failed. You probably need to find an operation that are likely to (not just could) overwrite freed space with random bytes, but I can't think of one right now.

It's possible to copy original code of rubylib even while it's a gem, but it was too rare to reproduce even with the original code in a few iterations. So we need to come up with something else.

@k0kubun k0kubun deleted the yjit-save-buf branch March 7, 2023 21:17
@k0kubun
Copy link
Member Author

k0kubun commented Mar 7, 2023

Hmm, but actually, let me try your code rubyzip/rubyzip#550 first. I've overlooked that PR.

@k0kubun
Copy link
Member Author

k0kubun commented Mar 7, 2023

Ah I thought you meant "non-indeterministic" but it was actually "non-deterministic". I tried it but it doesn't seem to reproduce the issue with a few attempts. We need something else.

@machty
Copy link
Contributor

machty commented Mar 7, 2023

Yes, I failed to provide a repro -- unfortunately i ate through my budget of investigating this but perhaps the reason it happens on my machine / CI is that it's running in a rake task of a large rails app with the Rails environment fully loaded with much higher memory pressure. Not sure the best way to simulate that.

casperisfine pushed a commit to Shopify/ruby that referenced this pull request Mar 9, 2023
Fix Shopify/yjit#310

[Bug #19483]

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
Co-authored-by: Jimmy Miller <jimmy.miller@shopify.com>
casperisfine pushed a commit to Shopify/ruby that referenced this pull request Mar 9, 2023
Fix Shopify/yjit#310

[Bug #19483]

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
Co-authored-by: Jimmy Miller <jimmy.miller@shopify.com>
nurse added a commit to nurse/ruby that referenced this pull request Mar 18, 2023
	YJIT: Protect strings from GC on String#<< (ruby#7466)

	Fix Shopify/yjit#310

	[Bug #19483]

	Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
	Co-authored-by: Jimmy Miller <jimmy.miller@shopify.com>
	---
	 yjit/src/codegen.rs | 3 +++
	 1 file changed, 3 insertions(+)
casperisfine pushed a commit to Shopify/ruby that referenced this pull request Mar 23, 2023
Fix Shopify/yjit#310

[Bug #19483]

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
Co-authored-by: Jimmy Miller <jimmy.miller@shopify.com>
casperisfine pushed a commit to Shopify/ruby that referenced this pull request Mar 31, 2023
Fix Shopify/yjit#310

[Bug #19483]

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
Co-authored-by: Jimmy Miller <jimmy.miller@shopify.com>
croaky added a commit to croaky/laptop that referenced this pull request Apr 21, 2023
I have been seeing non-deterministic failures running `chromedriver`
in GitHub Actions with Ruby 3.2.1 and the YJIT compiler same as:
titusfortner/webdrivers#245

This was caused by an issue in rubyzip here:
Shopify/yjit#310

And fixed in Ruby here:
ruby/ruby#7466
croaky added a commit to croaky/laptop that referenced this pull request Apr 21, 2023
I have been seeing non-deterministic failures running `chromedriver`
in GitHub Actions with Ruby 3.2.1 and the YJIT compiler same as:
titusfortner/webdrivers#245

This was caused by an issue in rubyzip here:
Shopify/yjit#310

And fixed in Ruby here:
ruby/ruby#7466

#209
matzbot pushed a commit that referenced this pull request Jul 16, 2023
…Backport #19483]

	YJIT: Protect strings from GC on String#<< (#7466)

	Fix Shopify/yjit#310

	[Bug #19483]

	Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
	Co-authored-by: Jimmy Miller <jimmy.miller@shopify.com>
	---
	 yjit/src/codegen.rs | 3 +++
	 1 file changed, 3 insertions(+)

	YJIT: Save PC on rb_str_concat (#7586)

	[Bug #19483]

	Co-authored-by: Alan Wu <alansi.xingwu@shopify.com>
	---
	 test/ruby/test_yjit.rb | 19 +++++++++++++++++++
	 yjit/src/codegen.rs    |  6 ++++--
	 2 files changed, 23 insertions(+), 2 deletions(-)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants