ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: nagachika00@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:70574] [Ruby trunk - Bug #10871] Sclass thread unsafe due to CREF sharing
Date: Mon, 24 Aug 2015 16:26:44 +0000	[thread overview]
Message-ID: <redmine.journal-53982.20150824162643.110f6f6ab51d1196@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-10871.20150219215323@ruby-lang.org

Issue #10871 has been updated by Tomoyuki Chikanaga.

Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: DONE

Hello,

I've applied ko1's workaround patch for this issue to `ruby_2_2` branch at r51673.
I'm worried about the wrong side effects of this patch.
Please test on `ruby_2_2` branch HEAD.
If you use rbenv/ruby-build, you can install `ruby_2_2` HEAD via

    rbenv install 2.2.0-dev

Regards,

----------------------------------------
Bug #10871: Sclass thread unsafe due to CREF sharing
https://bugs.ruby-lang.org/issues/10871#change-53982

* Author: Evan Phoenix
* Status: Closed
* Priority: Normal
* Assignee: Koichi Sasada
* ruby -v: 2.2.0p0, trunk
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: DONE
----------------------------------------
When entering an sclass, the context is tracked via the same cref mechanism used for class and module, specifically on the iseq->cref_stack. The bug is that the cref_stack is the wrong place to put the new cref because the scope is specific only to that sclass body. Mutating and using the iseq->cref_stack causes any code that reads the cref via this cref_stack to incorrectly pick up the sclass instance instead of the proper scope!

This is major thread safety bug because it means that all uses of `class << obj` are thread-unsafe and can cause random code to fail.

Here is a simple reproduction of the bug: https://gist.github.com/evanphx/6eef92f2c40662a4171b

I attempted to fix the bug by treating an sclass body the same as an eval, which already has special handling for cref's but I don't understand the code enough to make that change quickly.

I believe this is a major bug and hope that ruby-core can address it soon.

Thank you!



-- 
https://bugs.ruby-lang.org/

      parent reply	other threads:[~2015-08-24 15:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-10871.20150219215323@ruby-lang.org>
2015-02-19 21:53 ` [ruby-core:68191] [Ruby trunk - Bug #10871] [Open] Sclass thread unsafe due to CREF sharing evan
2015-02-23  0:18 ` [ruby-core:68233] [Ruby trunk - Bug #10871] " tenderlove
2015-02-23 10:41 ` [ruby-core:68248] " ko1
2015-03-30 16:57 ` [ruby-core:68696] " clay
2015-03-30 19:27 ` [ruby-core:68697] " ko1
2015-04-27 21:34 ` [ruby-core:69003] " evan
2015-05-12 18:41 ` [ruby-core:69152] " wildgriffin45
2015-05-14 18:18 ` [ruby-core:69198] " redmine
2015-06-16  8:45 ` [ruby-core:69602] " ko1
2015-06-16  9:23 ` [ruby-core:69603] " ko1
2015-06-17 21:11 ` [ruby-core:69636] " nagachika00
2015-06-17 23:16 ` [ruby-core:69640] " ko1
2015-06-30 18:55 ` [ruby-core:69818] " nagachika00
2015-07-11 20:43 ` [ruby-core:69948] " nagachika00
2015-08-24 16:26 ` nagachika00 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-53982.20150824162643.110f6f6ab51d1196@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).