From patchwork Wed Apr 11 10:37:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 897132 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-476199-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=intel.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="RuofIchd"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40LgTf1hHkz9s35 for ; Wed, 11 Apr 2018 20:37:25 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=UJ7uLZti1sZdL5oM7m8G4nWz/K0zI sS4HpMVidJUs1sggFT64WlsSP0Iv/qovC1gc9YzNnqvmsgT3tIk5tTmD/8y5KXer JkXqZqM7Xz6sU6TcvXJsHTPEvYPBRPHdw4Yo37y4XIf3Hp7iJbLQAdj1M8hvGyPS 5DXSWt/JIFpsbo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=hVSLdEnsIG929g/Jw+e4VYbK3NA=; b=Ruo fIchdSi1jVv4xes+YVGuicWcQe6lLnosnCF2//bG0mcxeMFMv0qLz6NOinf5Iws2 OdEAvqUntMdsV7M1NnSKAFcD+w/CE/N1IPgdY/AHikv5Nacx2ErGWKu8jtQlXJUK LRR99HFxJqO+lg1MC4CrBX9ud5rK0l/7qJfskrro= Received: (qmail 39837 invoked by alias); 11 Apr 2018 10:37:19 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 39823 invoked by uid 89); 11 Apr 2018 10:37:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, NO_DNS_FOR_FROM autolearn=ham version=3.3.2 spammy= X-HELO: mga17.intel.com Received: from mga17.intel.com (HELO mga17.intel.com) (192.55.52.151) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Apr 2018 10:37:17 +0000 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Apr 2018 03:37:15 -0700 X-ExtLoop1: 1 Received: from gnu-4.sc.intel.com ([172.25.70.238]) by fmsmga005.fm.intel.com with ESMTP; 11 Apr 2018 03:37:15 -0700 Received: by gnu-4.sc.intel.com (Postfix, from userid 1000) id 9926E1C0658; Wed, 11 Apr 2018 03:37:15 -0700 (PDT) Date: Wed, 11 Apr 2018 03:37:15 -0700 From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: Uros Bizjak , Jeff Law Subject: [PATCH] libgcc/CET: Skip signal frames when unwinding shadow stack Message-ID: <20180411103715.GA33748@intel.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) When -fcf-protection -mcet is used, I got FAIL: g++.dg/eh/sighandle.C (gdb) bt #0 _Unwind_RaiseException (exc=exc@entry=0x416ed0) at /export/gnu/import/git/sources/gcc/libgcc/unwind.inc:140 #1 0x00007ffff7d9936b in __cxxabiv1::__cxa_throw (obj=, tinfo=0x403dd0 , dest=0x0) at /export/gnu/import/git/sources/gcc/libstdc++-v3/libsupc++/eh_throw.cc:90 #2 0x0000000000401255 in sighandler (signo=11, si=0x7fffffffd6f8, uc=0x7fffffffd5c0) at /export/gnu/import/git/sources/gcc/gcc/testsuite/g++.dg/eh/sighandle.C:9 #3 <<<< Signal frame which isn't on shadow stack #4 dosegv () at /export/gnu/import/git/sources/gcc/gcc/testsuite/g++.dg/eh/sighandle.C:14 #5 0x00000000004012e3 in main () at /export/gnu/import/git/sources/gcc/gcc/testsuite/g++.dg/eh/sighandle.C:30 (gdb) p frames $6 = 5 (gdb) frame count should be 4, not 5. This patch skips signal frames when unwinding shadow stack. Tested on i686 and x86-64. OK for trunk? H.J. ---- PR libgcc/85334 * unwind-generic.h (_Unwind_Frames_Increment): New. * config/i386/shadow-stack-unwind.h (_Unwind_Frames_Increment): Likewise. * unwind.inc (_Unwind_RaiseException_Phase2): Increment frame count with _Unwind_Frames_Increment. (_Unwind_ForcedUnwind_Phase2): Likewise. --- libgcc/config/i386/shadow-stack-unwind.h | 5 +++++ libgcc/unwind-generic.h | 3 +++ libgcc/unwind.inc | 6 ++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libgcc/config/i386/shadow-stack-unwind.h b/libgcc/config/i386/shadow-stack-unwind.h index 40f48df2aec..a32f3e74b52 100644 --- a/libgcc/config/i386/shadow-stack-unwind.h +++ b/libgcc/config/i386/shadow-stack-unwind.h @@ -49,3 +49,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see } \ } \ while (0) + +/* Increment frame count. Skip signal frames. */ +#undef _Unwind_Frames_Increment +#define _Unwind_Frames_Increment(context, frames) \ + if (!_Unwind_IsSignalFrame (context)) frames++ diff --git a/libgcc/unwind-generic.h b/libgcc/unwind-generic.h index b5e3568e1bc..639c96f438e 100644 --- a/libgcc/unwind-generic.h +++ b/libgcc/unwind-generic.h @@ -291,4 +291,7 @@ EXCEPTION_DISPOSITION _GCC_specific_handler (PEXCEPTION_RECORD, void *, /* Additional actions to unwind number of stack frames. */ #define _Unwind_Frames_Extra(frames) +/* Increment frame count. */ +#define _Unwind_Frames_Increment(context, frames) frames++ + #endif /* unwind.h */ diff --git a/libgcc/unwind.inc b/libgcc/unwind.inc index 68c08964d30..b49f8797009 100644 --- a/libgcc/unwind.inc +++ b/libgcc/unwind.inc @@ -72,8 +72,9 @@ _Unwind_RaiseException_Phase2(struct _Unwind_Exception *exc, /* Don't let us unwind past the handler context. */ gcc_assert (!match_handler); + _Unwind_Frames_Increment (context, frames); + uw_update_context (context, &fs); - frames++; } *frames_p = frames; @@ -187,10 +188,11 @@ _Unwind_ForcedUnwind_Phase2 (struct _Unwind_Exception *exc, return _URC_FATAL_PHASE2_ERROR; } + _Unwind_Frames_Increment (context, frames); + /* Update cur_context to describe the same frame as fs, and discard the previous context if necessary. */ uw_advance_context (context, &fs); - frames++; } *frames_p = frames;