From: shyouhei@ruby-lang.org
To: ruby-core@ruby-lang.org
Subject: [ruby-core:87453] [Ruby trunk Bug#14834][Assigned] rb_profile_frames SEGV when PC adjusted on IFUNC
Date: Fri, 08 Jun 2018 08:13:05 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-72445.20180608081304.821355cf3bd1694f@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-14834.20180608050715@ruby-lang.org
Issue #14834 has been updated by shyouhei (Shyouhei Urabe).
Status changed from Open to Assigned
Assignee set to shyouhei (Shyouhei Urabe)
Thanks reporting! Will handle it.
----------------------------------------
Bug #14834: rb_profile_frames SEGV when PC adjusted on IFUNC
https://bugs.ruby-lang.org/issues/14834#change-72445
* Author: kivikakk (Ashe Connor)
* Status: Assigned
* Priority: Normal
* Assignee: shyouhei (Shyouhei Urabe)
* Target version:
* ruby -v: ruby 2.6.0dev (2018-06-08 trunk 63606) [x86_64-linux]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
Since r62052, we increment `ec->cfp->pc` by one pointer width (e.g. 8 bytes) in `gc_event_hook_body` around the `EXEC_EVENT_HOOK` call.
This becomes a problem when the hook is on an IFUNC: in this case, `pc == 0x0`, meaning we increment it to a non-zero value during that call.
`rb_profile_frames` uses the following check to determine if frame info should be recorded:
~~~ c
if (cfp->iseq && cfp->pc) {
~~~
The example here is [`stackprof`](https://github.com/tmm1/stackprof/blob/58d65ffa801ed27f013d573148783694526c7426/ext/stackprof/stackprof.c#L486), which calls `rb_profile_frames` in a gc event hook. This will segfault currently, as the above check will pass.
`calc_lineno` then attempts to calculate the line number:
~~~ c
size_t pos = (size_t)(pc - iseq->body->iseq_encoded);
~~~
This fails for a variety of reasons: `iseq_encoded` isn't valid because `iseq` isn't an `rb_iseq_t` underneath, producing an essentially random value, and `pc` is 0x8, so we underflow and eventually cause an overrun in `succ_index_lookup` with a huge `pos` argument.
We instead only adjust PC if it appears to be a valid pointer in the first place.
---Files--------------------------------
pc-treatment.diff (777 Bytes)
--
https://bugs.ruby-lang.org/
next prev parent reply other threads:[~2018-06-08 8:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-14834.20180608050715@ruby-lang.org>
2018-06-08 5:07 ` [ruby-core:87449] [Ruby trunk Bug#14834] rb_profile_frames SEGV when PC adjusted on IFUNC ashe
2018-06-08 5:13 ` [ruby-core:87450] " ashe
2018-06-08 5:44 ` [ruby-core:87451] " ashe
2018-06-08 8:13 ` shyouhei [this message]
2018-06-25 5:47 ` [ruby-core:87628] " ashe
2018-06-27 0:16 ` [ruby-core:87648] " shyouhei
2019-07-30 16:04 ` [ruby-core:94057] [Ruby master " john
2019-08-01 7:09 ` [ruby-core:94091] " shyouhei
2019-08-01 17:30 ` [ruby-core:94099] " tenderlove
2019-08-02 19:41 ` [ruby-core:94117] " XrXr
2019-08-18 6:10 ` [ruby-core:94411] " nagachika00
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-72445.20180608081304.821355cf3bd1694f@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).