From owner-freebsd-hackers@freebsd.org Sat Feb 23 11:32:55 2019 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 565C81511D3E for ; Sat, 23 Feb 2019 11:32:55 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5E06686A10 for ; Sat, 23 Feb 2019 11:32:54 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id x1NBWk5K035938 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 23 Feb 2019 13:32:49 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua x1NBWk5K035938 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id x1NBWkEt035937; Sat, 23 Feb 2019 13:32:46 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 23 Feb 2019 13:32:46 +0200 From: Konstantin Belousov To: Robert Ayrapetyan Cc: FreeBSD Subject: Re: ptrace: SIGTRAP and EXIT race Message-ID: <20190223113246.GH2420@kib.kiev.ua> References: <20190222101026.GX2420@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.2 (2019-01-07) X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on tom.home X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 23 Feb 2019 11:32:55 -0000 On Fri, Feb 22, 2019 at 03:57:49PM -0800, Robert Ayrapetyan wrote: > Hi, thanks for a prompt reply. Here are the instructions of how to > reproduce (sorry for inconvenient way of specifying BP address when running > app): > > uname -a > FreeBSD XXX 12.0-RELEASE-p3 FreeBSD 12.0-RELEASE-p3 GENERIC amd64 > > cd /tmp > git clone https://github.com/rayrapetyan/ptrace_bug_poc.git > cd ptrace_bug_poc > mkdir build > cd build > cmake .. > make > > Run ~20 times: > > /tmp/ptrace_bug_poc/build/src/ptrace_test/ptrace_test > /tmp/ptrace_bug_poc/build/src/mt_example/mt_example 0x201385 > > ------- > Note: make sure 0x201385 is a call to in > "/tmp/ptrace_bug_poc/build/src/mt_example/mt_example": > gdb /tmp/ptrace_bug_poc/build/src/mt_example/mt_example > disassemble foo > ------- > > Wait fo appearance of: > "BOOM! Invalid BP hits counter (hits: 1, tid: XXXX)" > at the end of the output (most of the times it will be "SUCCESS") > ~700 lines of C++ code definitely do not fall under the 'minimal repro' spec. I do not to read all of it. >From looking at Debugger::Launch(), it seems that you missed the required debugger/child synchronization for PT_TRACE_ME. Typically child does raise(SIGSTOP); immediately after PT_TRACE_ME, and the tracer must consume this signal. Otherwise the child continues the execution and might just execute the place where you intend to set a breakpoint. I may missed the sync (or it might be done by other means in your code), because as I said, I do not want to read 700 lines of C++.