ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "kjtsanaktsidis (KJ Tsanaktsidis)" <noreply@ruby-lang.org>
Subject: [ruby-core:116987] [Ruby master Bug#20310] ASAN fake stacks need to be marked during GC for non-current execution context
Date: Wed, 28 Feb 2024 04:01:37 +0000 (UTC)	[thread overview]
Message-ID: <redmine.issue-20310.20240228040137.10173@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-20310.20240228040137.10173@ruby-lang.org

Issue #20310 has been reported by kjtsanaktsidis (KJ Tsanaktsidis).

----------------------------------------
Bug #20310: ASAN fake stacks need to be marked during GC for non-current execution context
https://bugs.ruby-lang.org/issues/20310

* Author: kjtsanaktsidis (KJ Tsanaktsidis)
* Status: Assigned
* Assignee: kjtsanaktsidis (KJ Tsanaktsidis)
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
When ASAN (address sanitizer) is enabled, the compiler does not necessarily store all local variables on the real machine stack; instead, locals can be stored in per-frame heap allocated memory which ASAN uses to detect things like stack-use-after-return ("fake stacks"). A pointer to the fake stack is left on the real machine stack, so it's possible to discover these fake stacks during GC and mark locals stored there as well.

At the moment, Ruby is currently marking these fake stacks for the current execution context which triggered GC, as part of `mark_current_machine_context`: https://github.com/ruby/ruby/blob/fe0b704df5553bdd59e90650ffbbfac785a2e48a/gc.c#L6411. However, there are other machine stacks which also need to be marked like this:

* Machine stacks for other threads which did not trigger GC are marked in `rb_execution_context_mark` here: https://github.com/ruby/ruby/blob/fe0b704df5553bdd59e90650ffbbfac785a2e48a/vm.c#L3422
* Machine stacks for fibers are marked in `cont_mark` here: https://github.com/ruby/ruby/blob/fe0b704df5553bdd59e90650ffbbfac785a2e48a/cont.c#L1030

We need to make these two kinds of stacks perform the same ASAN fake stack marking as `mark_current_machine_context` does.

(P.S. - `callcc` continuations are another kind of machine stack which get marked, but ASAN is not compatible with callcc, so this doesn't really matter).

(P.S. - it appears to me that the currently-switched-to fiber will have its stack marked _twice_; once in `rb_execution_context_mark` or `mark_current_machine_context, and once in `cont_mark`; if this is true, I will fix this too)





-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

       reply	other threads:[~2024-02-28  4:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-28  4:01 kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core [this message]
2024-02-28  8:12 ` [ruby-core:116989] [Ruby master Bug#20310] ASAN fake stacks need to be marked during GC for non-current execution context kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core
2024-03-14  9:44 ` [ruby-core:117152] " mame (Yusuke Endoh) via ruby-core

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.issue-20310.20240228040137.10173@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    --cc=noreply@ruby-lang.org \
    --cc=ruby-core@ml.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).