From: Tomoyuki Chikanaga Date: 2011-08-02T13:11:52+09:00 Subject: [ruby-dev:44322] [Ruby 1.9 - Bug #5139] sigsegv のスタックオーバフロー Issue #5139 has been updated by Tomoyuki Chikanaga. Target version changed from 1.9.4 to 1.9.3 試した環境は 2つあります。 A) Ubuntu 10.04.03 $ uname -srvm Linux 2.6.32-33-generic #70-Ubuntu SMP Thu Jul 7 21:09:46 UTC 2011 i686 $ gcc --version gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3 Copyright (C) 2009 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ /lib/libc.so.6 --version GNU C Library (Ubuntu EGLIBC 2.11.1-0ubuntu7.8) stable release version 2.11.1, by Roland McGrath et al. Copyright (C) 2009 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Compiled by GNU CC version 4.4.3. Compiled on a Linux >>2.6.24-27-server<< system on 2011-01-21. Available extensions: crypt add-on version 2.1 by Michael Glad and others GNU Libidn by Simon Josefsson Native POSIX Threads Library by Ulrich Drepper et al BIND-8.2.3-T5B For bug reporting instructions, please see: . B) Red Hat Enterprise Linux ES release 4 (Nahant Update 8) $ uname -srvmp Linux 2.6.9-89.ELlargesmp #1 SMP Mon Apr 20 10:43:12 EDT 2009 x86_64 x86_64 $ gcc-4.5 --version # configure --with-gcc で gcc-4.5 を指定 gcc-4.5 (GCC) 4.5.1 Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ /lib/libc.so.6 --version GNU C Library stable release version 2.3.4, by Roland McGrath et al. Copyright (C) 2005 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Compiled by GNU CC version 3.4.6 20060404 (Red Hat 3.4.6-10). Compiled on a Linux 2.4.20 system on 2009-01-09. Available extensions: GNU libio by Per Bothner crypt add-on version 2.1 by Michael Glad and others linuxthreads-0.10 by Xavier Leroy The C stubs add-on version 2.1.2. BIND-8.2.3-T5B NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk Glibc-2.0 compatibility add-on by Cristian Gafton GNU Libidn by Simon Josefsson libthread_db work sponsored by Alpha Processor Inc Thread-local storage support included. For bug reporting instructions, please see: . それぞれについて -O0 と -O3 でビルドしたもので -e 'Process.kill :SEGV, $$' を実行すると (A)/-O0 => "[BUG]" まで表示して SEGV (A)/-O3 => "[BUG]" まで表示して SEGV (B)/-O0 => 再現せず(最後まで表示して abort で終了) (B)/-O3 => "C level backtrace information" のバナーまで表示して SEGV また (B) で ruby_1_9_3 のブランチの HEAD を -O3 でビルドしてみたところ (B)/-O3, 1.9.3 => "C level backtrace information" のバナーまで表示して SEGV でした。 やはりスタックサイズだけが原因ではないみたいで 1.9.3 でも発生するのでバージョン 1.9.3 にしておきます。 手が空いたらもうちょっと条件を整理したいですが、とりあえず以上です。 ---------------------------------------- Bug #5139: sigsegv のスタックオーバフロー http://redmine.ruby-lang.org/issues/5139 Author: Tomoyuki Chikanaga Status: Assigned Priority: Normal Assignee: Motohiro KOSAKI Category: core Target version: 1.9.3 ruby -v: ruby 1.9.4dev (2011-08-01 trunk 32793) [i686-linux] 現在の trunk が Linux で test_segv_test(TestRubyOptions) が Failure になります。 $ ruby -e 'Process.kill :SEGV, $$' のように実行すると表示されるはずのバックトレースや LOADED FEATURES の情報が表示されないためです。 おそらく r32751 からだと思うのですが、手元の環境(Ubuntu 10.4, Kernel 2.6.32-33-generic, gcc 4.4.3) では どうやら sigsegv() から呼ばれている rb_vm_bugreport() で sigaltstack で設定したシグナルハンドラ用スタックを オーバフローして、シグナルハンドラ内で再度 SEGV していると思います。 以下 gdb での実行の抜粋 (gdb) run -e 'Process.kill 11, $$' Program received signal SIGSEGV, Segmentation fault. 0x0012d422 in __kernel_vsyscall () (gdb) c Continuing. -e:1: [BUG] Segmentation fault ruby 1.9.4dev (2011-08-01 trunk 32793) [i686-linux] ------------ snip ----------- * Loaded features: Program received signal SIGSEGV, Segmentation fault. 0x08150864 in rb_vm_bugreport () at ../ruby/vm_dump.c:834 834 for (i=0; iloaded_features); i++) { (gdb) p ruby_current_thread->altstack $5 = (void *) 0x8221ab8 (gdb) p $esp $6 = (void *) 0x8220560 (gdb) p $esp - ruby_current_thread->altstack $7 = -5464 (gdb) up #1 0x08187095 in report_bug (file=0x82480b0 "-e", line=1, fmt=0x81c3bcb "Segmentation fault", args=0x8222714 "\263\063") at ../ruby/error.c:265 265 rb_vm_bugreport(); (gdb) p (char *)$esp - (char *)ruby_current_thread->altstack $15 = -5144 (gdb) up #2 0x08187121 in rb_bug (fmt=0x81c3bcb "Segmentation fault") at ../ruby/error.c:284 284 report_bug(file, line, fmt, args); (gdb) p (char *)$esp - (char *)ruby_current_thread->altstack $16 = 3112 $esp と ruby_current_thread->altstack の関係をみてオーバフローではないかと思ったのですがどうでしょう。 なお sigaltstack に渡しているスタックサイズは 4096 です。 -- http://redmine.ruby-lang.org