From patchwork Thu Jan 6 18:57:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1576260 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=o/vSZTJH; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JVFyT4cpBz9sSs for ; Fri, 7 Jan 2022 05:59:29 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3FE95385800A for ; Thu, 6 Jan 2022 18:59:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3FE95385800A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641495567; bh=5KAxdzI1JZdsNafhi0kPFxAXJEJ0vNqd3REZHtj1xGY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=o/vSZTJHmLjByR0mG8LodRp9wxdJ/4WLOEUySYEcX4VHidEr1ZizJtt5nVmJ2dCCD nhlo1DIx8Yh5OH65YZH1mNZ+hEdqun5XZdpWh/cWFdWNrRL8+Upk+brPpNYEekXMha LRlJg2OYmiIxyWGZeGTdIsbgPGbucrEmshd/3+z4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by sourceware.org (Postfix) with ESMTPS id 5964C3858034 for ; Thu, 6 Jan 2022 18:58:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5964C3858034 Received: by mail-pj1-x1030.google.com with SMTP id iy13so3235615pjb.5 for ; Thu, 06 Jan 2022 10:58:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5KAxdzI1JZdsNafhi0kPFxAXJEJ0vNqd3REZHtj1xGY=; b=iR8VtbNQx8BN6X1tQh7GUOmlq+1cOduwjRBQw9uwGjovtHa1Kev1DDBa6AfivwL6Sh 6ld7tytVKOkye+EHHOSfY1UK0I5XVsRc+cu4x3DAI4KI3TtDDUtJ3uQFRavkFEuFtdpR 44LKPl8R8OrPraKsBISs65ie+y8Un2fLwyF2l/m97nmBrPLiFkbgg97fWN6swa9NHdUJ /izk/dfILrHbZYRfebiaQKCznnMe+gb4XeE0qvPLCQk3VnduGfClSQH7gDewU8AvOt/h f5cK4q3Zhodrv4j1vkh10ZBdgJTJzaVSvFBGzudf/Gnj0gq6EOifieEa1vu1pDwhGKzC 1FYQ== X-Gm-Message-State: AOAM533guomTbBBH0aTiU+WXZRnr8IUiyn5a+Dnh8l775SVmXHsY4j01 F7aDWzXjqGzcpGFPzIuxk7yACxf6EFk= X-Google-Smtp-Source: ABdhPJy51bVWEXCIOVyvomPAITcGN34PjXPIvyBaPGdwp9lqpsBK7/cQtF/sBGR5gqj2W+TAVsrOkQ== X-Received: by 2002:a17:90a:520e:: with SMTP id v14mr11501527pjh.221.1641495482292; Thu, 06 Jan 2022 10:58:02 -0800 (PST) Received: from gnu-tgl-3.localdomain ([172.58.35.133]) by smtp.gmail.com with ESMTPSA id z13sm3189178pjq.0.2022.01.06.10.58.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 10:58:02 -0800 (PST) Received: from gnu-tgl-2.localdomain (gnu-tgl-2 [192.168.1.42]) by gnu-tgl-3.localdomain (Postfix) with ESMTPS id 0EE44C0284; Thu, 6 Jan 2022 10:58:01 -0800 (PST) Received: from gnu-tgl-2.. (localhost [IPv6:::1]) by gnu-tgl-2.localdomain (Postfix) with ESMTP id 6339E3003B1; Thu, 6 Jan 2022 10:57:57 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] x86: Generate INT3 for __builtin_eh_return Date: Thu, 6 Jan 2022 10:57:57 -0800 Message-Id: <20220106185757.1561582-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3028.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Gcc-patches" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Generate INT3 after indirect jmp in exception return for -fcf-protection with -mharden-sls=indirect-jmp. gcc/ PR target/103925 * config/i386/i386.c (ix86_output_indirect_function_return): Generate INT3 after indirect jmp for -mharden-sls=indirect-jmp. gcc/testsuite/ PR target/103925 * gcc.target/i386/harden-sls-6.c: New test. --- gcc/config/i386/i386.c | 9 ++++++--- gcc/testsuite/gcc.target/i386/harden-sls-6.c | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/harden-sls-6.c diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 835ec2cafcb..35fb5adf2ef 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -16367,11 +16367,14 @@ ix86_output_indirect_function_return (rtx ret_op) } else output_indirect_thunk (regno); - - return ""; } else - return "%!jmp\t%A0"; + { + output_asm_insn ("%!jmp\t%A0", &ret_op); + if (ix86_harden_sls & harden_sls_indirect_jmp) + fputs ("\tint3\n", asm_out_file); + } + return ""; } /* Output the assembly for a call instruction. */ diff --git a/gcc/testsuite/gcc.target/i386/harden-sls-6.c b/gcc/testsuite/gcc.target/i386/harden-sls-6.c new file mode 100644 index 00000000000..9068eb64008 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/harden-sls-6.c @@ -0,0 +1,18 @@ +/* { dg-do compile { target { ! ia32 } } } */ +/* { dg-options "-O2 -fcf-protection -mharden-sls=indirect-jmp" } */ + +struct _Unwind_Context _Unwind_Resume_or_Rethrow_this_context; + +void offset (int); + +struct _Unwind_Context { + void *reg[7]; +} _Unwind_Resume_or_Rethrow() { + struct _Unwind_Context cur_contextcur_context = + _Unwind_Resume_or_Rethrow_this_context; + offset(0); + __builtin_eh_return ((long) offset, 0); +} + +/* { dg-final { scan-assembler "jmp\[ \t\]+\\*%rcx" } } */ +/* { dg-final { scan-assembler-times "int3" 1 } } */