From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 374FB1F464 for ; Fri, 27 Sep 2019 10:05:50 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 8B62D120BB2; Fri, 27 Sep 2019 19:05:40 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 2A18D120BB3 for ; Fri, 27 Sep 2019 19:05:37 +0900 (JST) Received: by filter0176p3mdw1.sendgrid.net with SMTP id filter0176p3mdw1-8122-5D8DDEF1-4F 2019-09-27 10:05:37.340028454 +0000 UTC m=+308584.401925016 Received: from herokuapp.com (unknown [3.91.96.212]) by ismtpd0096p1iad2.sendgrid.net (SG) with ESMTP id h40Qi3Z5SnyacuuJlzqezA for ; Fri, 27 Sep 2019 10:05:37.305 +0000 (UTC) Date: Fri, 27 Sep 2019 10:05:37 +0000 (UTC) From: iv@altlinux.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70686 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16184 X-Redmine-Issue-Author: iv-m X-Redmine-Sender: iv-m X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?WfYseQ1RardbWxw=2FdWWhetV1CqQcnZYCD6ZOQJG8UaBuYKoVuG5DrauUr8g7BH?= =?us-ascii?Q?=2FM0dkDt49TfITug7rHK4FqH7yjQaH1hjXJ=2Fkf+O?= =?us-ascii?Q?Nx=2FH+On+Q7GiJIKBrFQIYxILnMwvHbs3Ly2qBNX?= =?us-ascii?Q?Z+8QFn9Fj9raMTSVlZhZQMsukyG6i32rodIpo9z?= =?us-ascii?Q?Xu11sKtu+QjVp?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95131 Subject: [ruby-core:95131] [Ruby master Bug#16184] Entry persists in catch table even though its labels were removed, which may cause [BUG] X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #16184 has been updated by iv-m (Ivan Melnikov). > And having `position` field of labels initialized (as in my attached patch) makes crash totally impossible. I think having this field properly initialized is a good idea anyway, so I created a pull request: https://github.com/ruby/ruby/pull/2499 ---------------------------------------- Bug #16184: Entry persists in catch table even though its labels were removed, which may cause [BUG] https://bugs.ruby-lang.org/issues/16184#change-81766 * Author: iv-m (Ivan Melnikov) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.5.5p157 (2019-03-15) [mipsel-linux] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- When `remove_unreachable_chunk` removes the code from within a rescue block, the catch table entry corresponding the block is not removed. Here is a simple reproducer (tested with ruby 2.5.5): ``` ruby puts "BEGIN" if false begin require "some_mad_stuff" rescue LoadError puts "no mad stuff loaded" end end puts "END" ``` Here is the corresponding disasm: ``` == disasm: #@test2.rb:1 (1,0)-(12,10)>====================== == catch table | catch type: rescue st: 11022376 ed: 11022516 sp: -002 cont: 0000 == disasm: #@test2.rb:7 (7,2)-(9,2)>============== local table (size: 1, argc: 0 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) [ 1] "\#$!" 0000 getlocal_OP__WC__0 "\#$!" ( 7) 0002 getinlinecache 9, 0005 getconstant :LoadError 0007 setinlinecache 0009 checkmatch 3 0011 branchunless 20 0013 putself ( 8)[Li] 0014 putstring "no mad stuff loaded" 0016 opt_send_without_block , 0019 leave ( 7) 0020 getlocal_OP__WC__0 "\#$!" 0022 throw 0 | catch type: retry st: 11022516 ed: 0000 sp: -001 cont: 11022376 |------------------------------------------------------------------------ 0000 putself ( 2)[Li] 0001 putstring "BEGIN" 0003 opt_send_without_block , 0006 pop 0007 putself ( 12)[Li] 0008 putstring "END" 0010 opt_send_without_block , 0013 leave ``` The interesting line here is: ``` catch type: rescue st: 11022376 ed: 11022516 sp: -002 cont: 0000 ``` As the instruction corresponding the `begin..rescue` block were optimized away, the `sp` filed of the continue label was still -1 (or -2) and `position`s of start, end and continue labels are never initialized. When any exception happens in the remaining code (requires a bit more complex reproducer, happens in real life), this may cause an interpreter to segfault. I've discovered this issue when building net-scp gem, which has this `if false; require` pattern in its Rakefile: https://github.com/net-ssh/net-scp/blob/v2.0.0/Rakefile . Interpreter reproducibly segfaults when trying to run it on my MIPS32 LE machine. ---Files-------------------------------- ruby-2.5.5-alt-fix-crash-on-mipsel.patch (372 Bytes) crush.log (8.14 KB) -- https://bugs.ruby-lang.org/