[前][次][番号順一覧][スレッド一覧]

ruby-changes:50648

From: usa <ko1@a...>
Date: Sun, 18 Mar 2018 23:25:07 +0900 (JST)
Subject: [ruby-changes:50648] usa:r62810 (ruby_2_3): merge revision(s) 58769, 59710, 59712: [Backport #13566]

usa	2018-03-18 23:25:01 +0900 (Sun, 18 Mar 2018)

  New Revision: 62810

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62810

  Log:
    merge revision(s) 58769,59710,59712: [Backport #13566]
    
    Treat NULL reference case [Bug #13566]
    
    Fix C level backtrace on Darwin
    
    SEGV caused by invalid instruction call.
    
    skip unless PLATFORM is darwin.

  Added files:
    branches/ruby_2_3/test/ruby/test_vm_dump.rb
  Modified directories:
    branches/ruby_2_3/
  Modified files:
    branches/ruby_2_3/ChangeLog
    branches/ruby_2_3/version.h
    branches/ruby_2_3/vm_dump.c
Index: ruby_2_3/version.h
===================================================================
--- ruby_2_3/version.h	(revision 62809)
+++ ruby_2_3/version.h	(revision 62810)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1
 #define RUBY_VERSION "2.3.7"
 #define RUBY_RELEASE_DATE "2018-03-18"
-#define RUBY_PATCHLEVEL 411
+#define RUBY_PATCHLEVEL 412
 
 #define RUBY_RELEASE_YEAR 2018
 #define RUBY_RELEASE_MONTH 3
Index: ruby_2_3/test/ruby/test_vm_dump.rb
===================================================================
--- ruby_2_3/test/ruby/test_vm_dump.rb	(nonexistent)
+++ ruby_2_3/test/ruby/test_vm_dump.rb	(revision 62810)
@@ -0,0 +1,21 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/ruby/test_vm_dump.rb#L1
+# frozen_string_literal: true
+require 'test/unit'
+
+class TestVMDump < Test::Unit::TestCase
+  def assert_darwin_vm_dump_works(args)
+    skip if RUBY_PLATFORM !~ /darwin/
+    assert_in_out_err(args, "", [], [:*, /^.* main \+ \d+$/, :*, /^\[IMPORTANT\]/, :*])
+  end
+
+  def test_darwin_invalid_call
+    assert_darwin_vm_dump_works(['-rfiddle', '-eFiddle::Function.new(Fiddle::Pointer.new(1), [], Fiddle::TYPE_VOID).call'])
+  end
+
+  def test_darwin_segv_in_syscall
+    assert_darwin_vm_dump_works('-e1.times{Process.kill :SEGV,$$}')
+  end
+
+  def test_darwin_invalid_access
+    assert_darwin_vm_dump_works(['-rfiddle', '-eFiddle.dlunwrap(100).class'])
+  end
+end
Index: ruby_2_3/vm_dump.c
===================================================================
--- ruby_2_3/vm_dump.c	(revision 62809)
+++ ruby_2_3/vm_dump.c	(revision 62810)
@@ -434,6 +434,7 @@ rb_vmdebug_thread_dump_state(VALUE self) https://github.com/ruby/ruby/blob/trunk/ruby_2_3/vm_dump.c#L434
 # elif defined(__APPLE__) && defined(__x86_64__) && defined(HAVE_LIBUNWIND_H)
 #  define UNW_LOCAL_ONLY
 #  include <libunwind.h>
+#  include <sys/mman.h>
 #  undef backtrace
 int
 backtrace(void **trace, int size)
@@ -460,6 +461,8 @@ darwin_sigtramp: https://github.com/ruby/ruby/blob/trunk/ruby_2_3/vm_dump.c#L461
     /* darwin's bundled libunwind doesn't support signal trampoline */
     {
 	ucontext_t *uctx;
+	char vec[1];
+	int r;
 	/* get _sigtramp's ucontext_t and set values to cursor
 	 * http://www.opensource.apple.com/source/Libc/Libc-825.25/i386/sys/_sigtramp.s
 	 * http://www.opensource.apple.com/source/libunwind/libunwind-35.1/src/unw_getcontext.s
@@ -483,8 +486,10 @@ darwin_sigtramp: https://github.com/ruby/ruby/blob/trunk/ruby_2_3/vm_dump.c#L486
 	unw_set_reg(&cursor, UNW_X86_64_R14, uctx->uc_mcontext->__ss.__r14);
 	unw_set_reg(&cursor, UNW_X86_64_R15, uctx->uc_mcontext->__ss.__r15);
 	ip = uctx->uc_mcontext->__ss.__rip;
-	if (((char*)ip)[-2] == 0x0f && ((char*)ip)[-1] == 5) {
-	    /* signal received in syscall */
+	r = mincore((const void *)ip, 1, vec);
+	if (r || !vec[0] || memcmp((const char *)ip-2, "\x0f\x05", 2) == 0) {
+	    /* if segv is caused by invalid call or signal received in syscall */
+	    /* the frame is invalid; skip */
 	    trace[n++] = (void *)ip;
 	    ip = *(unw_word_t*)uctx->uc_mcontext->__ss.__rsp;
 	}
Index: ruby_2_3/ChangeLog
===================================================================
--- ruby_2_3/ChangeLog	(revision 62809)
+++ ruby_2_3/ChangeLog	(revision 62810)
@@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/ChangeLog#L1
+Sun Mar 18 23:23:48 2018  Koichi Sasada  <ko1@a...>
+
+	skip unless PLATFORM is darwin.
+
+Sun Mar 18 23:23:48 2018  NARUSE, Yui  <naruse@r...>
+
+	Treat NULL reference case [Bug #13566]
+
+	Fix C level backtrace on Darwin
+	SEGV caused by invalid instruction call.
+
 Sun Mar 18 23:11:29 2018  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in (ARFLAGS): check if deterministic mode flag is
Index: ruby_2_3
===================================================================
--- ruby_2_3	(revision 62809)
+++ ruby_2_3	(revision 62810)

Property changes on: ruby_2_3
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r58769,59710,59712

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]