From owner-freebsd-bugs@FreeBSD.ORG Fri Feb 3 02:10:13 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1A1591065689 for ; Fri, 3 Feb 2012 02:10:13 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 670488FC17 for ; Fri, 3 Feb 2012 02:10:12 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q132ACx5032118 for ; Fri, 3 Feb 2012 02:10:12 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q132ACsG032117; Fri, 3 Feb 2012 02:10:12 GMT (envelope-from gnats) Resent-Date: Fri, 3 Feb 2012 02:10:12 GMT Resent-Message-Id: <201202030210.q132ACsG032117@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Pedro Giffuni Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 45BCA1065673 for ; Fri, 3 Feb 2012 02:09:11 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 29DD38FC1B for ; Fri, 3 Feb 2012 02:09:11 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q1329AOF031537 for ; Fri, 3 Feb 2012 02:09:10 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id q1329AZC031536; Fri, 3 Feb 2012 02:09:10 GMT (envelope-from nobody) Message-Id: <201202030209.q1329AZC031536@red.freebsd.org> Date: Fri, 3 Feb 2012 02:09:10 GMT From: Pedro Giffuni To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: kern/164724: Signal bug in Dtrace X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Feb 2012 02:10:13 -0000 >Number: 164724 >Category: kern >Synopsis: Signal bug in Dtrace >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri Feb 03 02:10:12 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Pedro Giffuni >Release: 9.0-release >Organization: >Environment: FreeBSD pcbsd-8714 9.0-RELEASE FreeBSD 9.0-RELEASE #3: Tue Dec 27 14:14:29 PST 2011 root@build9x64.pcbsd.org:/usr/obj/builds/amd64/pcbsd-build90/fbsd-source/9.0/sys/GENERIC amd64 >Description: Last year Bryan Cantrill found a nasty bug in Dtrace: http://dtrace.org/blogs/bmc/2011/03/09/when-magic-collides/ He warns "you are not expected to understand this", and not really being used to Dtrace I haven't really reproduced it. The fix, however, was relatively easy so I adapted the patch here: http://dtrace.org/resources/bmc/dtrace-signal.patch to work on FreeBSD's port. >How-To-Repeat: >Fix: Patch attached Patch attached with submission follows: Index: cddl/dev/dtrace/i386/dtrace_subr.c =================================================================== --- cddl/dev/dtrace/i386/dtrace_subr.c (revision 230923) +++ cddl/dev/dtrace/i386/dtrace_subr.c (working copy) @@ -27,6 +27,10 @@ * Use is subject to license terms. */ +/* + * Copyright (c) 2011, Joyent, Inc. All rights reserved. + */ + #include #include #include @@ -298,14 +302,15 @@ } /* - * If we've executed the original instruction, but haven't performed - * the jmp back to t->t_dtrace_npc or the clean up of any registers - * used to emulate %rip-relative instructions in 64-bit mode, do that - * here and take the signal right away. We detect this condition by - * seeing if the program counter is the range [scrpc + isz, astpc). + * If we have executed the original instruction, but we have performed + * neither the jmp back to t->t_dtrace_npc nor the clean up of any + * registers used to emulate %rip-relative instructions in 64-bit mode, + * we'll save ourselves some effort by doing that here and taking the + * signal right away. We detect this condition by seeing if the program + * counter is the range [scrpc + isz, astpc). */ - if (t->t_dtrace_astpc - rp->r_pc < - t->t_dtrace_astpc - t->t_dtrace_scrpc - isz) { + if (rp->r_pc >= t->t_dtrace_scrpc + isz && + rp->r_pc < t->t_dtrace_astpc) { #ifdef __amd64 /* * If there is a scratch register and we're on the Index: cddl/dev/dtrace/amd64/dtrace_subr.c =================================================================== --- cddl/dev/dtrace/amd64/dtrace_subr.c (revision 230923) +++ cddl/dev/dtrace/amd64/dtrace_subr.c (working copy) @@ -27,6 +27,10 @@ * Use is subject to license terms. */ +/* + * Copyright (c) 2011, Joyent, Inc. All rights reserved. + */ + #include #include #include @@ -297,14 +301,15 @@ } /* - * If we've executed the original instruction, but haven't performed - * the jmp back to t->t_dtrace_npc or the clean up of any registers - * used to emulate %rip-relative instructions in 64-bit mode, do that - * here and take the signal right away. We detect this condition by - * seeing if the program counter is the range [scrpc + isz, astpc). + * If we have executed the original instruction, but we have performed + * neither the jmp back to t->t_dtrace_npc nor the clean up of any + * registers used to emulate %rip-relative instructions in 64-bit mode, + * we'll save ourselves some effort by doing that here and taking the + * signal right away. We detect this condition by seeing if the program + * counter is the range [scrpc + isz, astpc). */ - if (t->t_dtrace_astpc - rp->r_pc < - t->t_dtrace_astpc - t->t_dtrace_scrpc - isz) { + if (rp->r_pc >= t->t_dtrace_scrpc + isz && + rp->r_pc < t->t_dtrace_astpc) { #ifdef __amd64 /* * If there is a scratch register and we're on the >Release-Note: >Audit-Trail: >Unformatted: