From patchwork Thu Apr 9 14:20:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1268626 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=u23a5rzz; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=u23a5rzz; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 48yjwd0c11z9sT6 for ; Fri, 10 Apr 2020 00:20:32 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D4BC0385E02A; Thu, 9 Apr 2020 14:20:26 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30043.outbound.protection.outlook.com [40.107.3.43]) by sourceware.org (Postfix) with ESMTPS id 54206385DC1E for ; Thu, 9 Apr 2020 14:20:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 54206385DC1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Szabolcs.Nagy@arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GXcpJvklqqIUxtyaciNoyI5SE8cNFvuwuZ47t0lg3cM=; b=u23a5rzzUl1fzlC8IHmSh/0udHWXCwUoXjCY9fp1ysQZgpyJNSr+n68uVKdcLOK78GyL+S6YWbiyjxhEaku2uSNRwUZTF9K/7IGQ6fTdQREKxizpshFmDcsrGKsm/WIg61d9+NMHxH9As0JKcSJrk+bOUODcB8rQ0/7xFEmlMrk= Received: from AM6P194CA0016.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:90::29) by AM4PR0802MB2179.eurprd08.prod.outlook.com (2603:10a6:200:5c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2878.20; Thu, 9 Apr 2020 14:20:22 +0000 Received: from VE1EUR03FT031.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:90:cafe::67) by AM6P194CA0016.outlook.office365.com (2603:10a6:209:90::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2900.17 via Frontend Transport; Thu, 9 Apr 2020 14:20:22 +0000 Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; gcc.gnu.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; gcc.gnu.org; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT031.mail.protection.outlook.com (10.152.18.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2900.18 via Frontend Transport; Thu, 9 Apr 2020 14:20:22 +0000 Received: ("Tessian outbound 55454527ea3b:v50"); Thu, 09 Apr 2020 14:20:21 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 589991bdea88d625 X-CR-MTA-TID: 64aa7808 Received: from 6ccfd80e3a05.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 55460302-B19C-404D-8A28-F5D257F85CC0.1; Thu, 09 Apr 2020 14:20:16 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 6ccfd80e3a05.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 09 Apr 2020 14:20:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SpIg3oadg7LlA+Rbpfrb+yAEuv4C0+oD6i06Mj9m+uswMEUKnLdUR1NsT1DRhxpCMUVMKmEBcujtsBqzkRszrDtf3kws6Zt1nIAeYcIOYDtIhe/jzkxFmizVe6Cw20tgAEp/VHD+cBgrUKlZVsUku0iEbv4p7IlLhZfD8nHZKgTbdQ8o/a9tP24evwqFFdhdaZktDLZmpEQEzaSXeVL+BV2nfAEO/xQegnm3ClchH9oTOz42tnXu8YekwU/JgYaWK1WtzDxwtpGScr5H9Oev8Ya+4T6vJf7vBGEXL/C97zcyZaYyBJEaDx5EBPnPisLPXalB5DrAH3igk+hAOKkHcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GXcpJvklqqIUxtyaciNoyI5SE8cNFvuwuZ47t0lg3cM=; b=FWoPRwASAQ3o/Kv7g3/u0JSi0mY7JqSi9Ov4j0Vd4jOhN/1mqmx2urektaWoUZLCJZdXlqc8MIAmGmZKmZQUyXNBDjUkDhox/66c/zrhDAQErC6dI3MW7iyr2Fq4+zengPev39O/IGKClrEaxJvBjPybdh2+cRgN2ZBwrIJ8DV7rakTPSUkYZZ7HK+MWQKG6QwIkuZjUevn0YHId94xZG3/90mOdN3lYDgIac6pgZN6ydeI2g6oLPgT9TD/lQMtYtXXmn8K17vHuwShX+hYlxmAGRMwTrautPZeQADby1pD6ffTmCyvqsN//0qKBY+L4iIlZoyocT5HahuphdNECWQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GXcpJvklqqIUxtyaciNoyI5SE8cNFvuwuZ47t0lg3cM=; b=u23a5rzzUl1fzlC8IHmSh/0udHWXCwUoXjCY9fp1ysQZgpyJNSr+n68uVKdcLOK78GyL+S6YWbiyjxhEaku2uSNRwUZTF9K/7IGQ6fTdQREKxizpshFmDcsrGKsm/WIg61d9+NMHxH9As0JKcSJrk+bOUODcB8rQ0/7xFEmlMrk= Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Szabolcs.Nagy@arm.com; Received: from AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) by AM6PR08MB4279.eurprd08.prod.outlook.com (2603:10a6:20b:bb::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2878.16; Thu, 9 Apr 2020 14:20:15 +0000 Received: from AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::49fd:6ded:4da7:8862]) by AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::49fd:6ded:4da7:8862%7]) with mapi id 15.20.2900.015; Thu, 9 Apr 2020 14:20:15 +0000 Date: Thu, 9 Apr 2020 15:20:13 +0100 From: Szabolcs Nagy To: gcc-patches@gcc.gnu.org Subject: [PATCH] aarch64: Fix .cfi_window_save with pac-ret [PR94515] Message-ID: <20200409142011.GG987@arm.com> Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-ClientProxiedBy: LNXP265CA0050.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5d::14) To AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from arm.com (217.140.106.55) by LNXP265CA0050.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2900.17 via Frontend Transport; Thu, 9 Apr 2020 14:20:14 +0000 X-Originating-IP: [217.140.106.55] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 886e793d-c84e-42b1-abda-08d7dc9123a6 X-MS-TrafficTypeDiagnostic: AM6PR08MB4279:|AM6PR08MB4279:|AM4PR0802MB2179: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-Forefront-PRVS: 0368E78B5B X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3047.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(10009020)(4636009)(39860400002)(136003)(396003)(366004)(346002)(376002)(5660300002)(44832011)(54906003)(36756003)(1076003)(2616005)(478600001)(316002)(86362001)(33656002)(81166007)(4326008)(66946007)(2906002)(6916009)(8676002)(52116002)(26005)(8886007)(55016002)(186003)(16526019)(66556008)(956004)(8936002)(81156014)(66476007)(7696005)(142923001); DIR:OUT; SFP:1101; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: dTFhHZHnqqK0xpsXCqZ2HdbMJ8VAvFAK54FkHEQeqiiEjzjiXCGi0InZAqr2nlR124CpXFyqx134yvQJznRwSjn8R+ZWfDCyWAQsEwcu9BOVET29O82E13mXr86n/xfsZcFA+1oolfBWmAylwemSfr0NZ5ihkfQLo+rnPDOCQ/HpRa2Wy0PVj5iG4eT5Ig3zKnMw8h0CvDSHTeEeXICSg5EQJTJ9Ap352ofCkwc0/uqjpj7W1uYKWOel8WUQA24N5MnlZw8XJlBdv/P1WCkdwy1c3eXvbjODdj33UXBlu8cMazqotvdA7LPR//HkxsDOp07nkXnv6Xv7ScM4HvU3FGO5GoWWNJd/+9KLXdRkNoB6a/7zpdtA3rBR3jJzKKZ9A4OCTfHyGPLE8uGxiWpl/RcUWy7j1x0xYCrF6ToY7i7EJK0ijmX5KG9YWTpSA2r7taxUlEYVUQaPxZQNkQFgA2xV4cJPt0oQqPB3kkcDBRyZgF8AM6jZKwqREaqZsJln X-MS-Exchange-AntiSpam-MessageData: afUJZhyZDBWmgRh+qjPaw9ogrnO21DZvSCJKGrAIlBGBpS8XKTYheOtxuXkb9MrEcd8JV5HrWY4uD5xnAfhwvJAPZ9tKCqqygyjEEQGbnatKUlBmxD6p/k02NRiVIcOLzfbgj8HLSKvZs2tkLfxLAw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4279 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Szabolcs.Nagy@arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT031.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFTY:; SFS:(10009020)(4636009)(376002)(346002)(136003)(396003)(39860400002)(46966005)(33656002)(8936002)(8676002)(956004)(70206006)(47076004)(16526019)(6916009)(8886007)(81166007)(2906002)(7696005)(336012)(478600001)(36906005)(70586007)(2616005)(44832011)(26005)(26826003)(356004)(36756003)(316002)(1076003)(86362001)(186003)(81156014)(5660300002)(4326008)(82740400003)(54906003)(55016002)(142923001); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 7e53e5a5-fd79-408c-956f-08d7dc911f29 X-Forefront-PRVS: 0368E78B5B X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BZXOusUrScNAsu/awDJM1JPCy3NEZCelGtANswUfyNq8T7OCgOia2cJiyMVyqyq5A4sKwZlfpkRrI0b3iEvd0VQc85dkVmcK0sndDFbEBZtjOQzzY30ZQlCgK3gZtkpvRReHF2IimBjJJIKOJfcIn5EOqYOCkJsQ3qERpwlhB5rxMSbzAwa46mRJFCND3QxUhDl8P2wE48LIpR9Cy5rBzNipDrVQgTeMeEVNJgT2nSQntKjP9sseFNCHCp1CKfstrjJEwqhzveqf+zoeQfePTKtyLVR9rp655XhHif7grMHnSTwzpy3raLeQj3HQI2Kk8Y06A4+G52Sc/N2yfol7962btDOkgJVQKLdzf6YXdLpmXwi2Wvv+7IBuP1lZZQTWRw4cf3wscIjECgpCh1UYxvQemF6ixw37UqztaQk1l4qIjJbzPa/UiowbmmbxnNU3/LZH61MjUJoaegYHtMtipj43HQmP1Mrr8y+EIZidVe5DSc0YTeqMOnTHWAGyd3I8ZmxgaXf6rGFgwH733SlY7UwbBnUbIc72ernxnLuftZ0= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2020 14:20:22.1597 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 886e793d-c84e-42b1-abda-08d7dc9123a6 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0802MB2179 X-Spam-Status: No, score=-28.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Cc: Richard Earnshaw Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" On aarch64 -mbranch-protection=pac-ret reuses the dwarf opcode for window_save to mean "toggle the return address mangle state", but in the dwarf2cfi internal logic the state was not properly recorded so the remember/restore logic was broken. This can cause the unwinder not to authenticate return addresses that were signed (or vice versa) which means a runtime crash on a pauth enabled system. Currently only aarch64 pac-ret uses REG_CFA_TOGGLE_RA_MANGLE. gcc/ChangeLog: 2020-04-XX Szabolcs Nagy PR target/94515 * dwarf2cfi.c (dwarf2out_frame_debug): Record RA mangle state in cur_row->window_save. gcc/testsuite/ChangeLog: 2020-04-XX Szabolcs Nagy PR target/94515 * g++.target/aarch64/pr94515.C: New test. --- gcc/dwarf2cfi.c | 3 ++ gcc/testsuite/g++.target/aarch64/pr94515.C | 43 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 gcc/testsuite/g++.target/aarch64/pr94515.C diff --git a/gcc/dwarf2cfi.c b/gcc/dwarf2cfi.c index 229fbfacc30..22989a6c2fb 100644 --- a/gcc/dwarf2cfi.c +++ b/gcc/dwarf2cfi.c @@ -2145,6 +2145,9 @@ dwarf2out_frame_debug (rtx_insn *insn) case REG_CFA_TOGGLE_RA_MANGLE: /* This uses the same DWARF opcode as the next operation. */ dwarf2out_frame_debug_cfa_window_save (true); + /* Keep track of RA mangle state by toggling the window_save bit. + This is needed so .cfi_window_save is emitted correctly. */ + cur_row->window_save = !cur_row->window_save; handled_one = true; break; diff --git a/gcc/testsuite/g++.target/aarch64/pr94515.C b/gcc/testsuite/g++.target/aarch64/pr94515.C new file mode 100644 index 00000000000..7707c773a72 --- /dev/null +++ b/gcc/testsuite/g++.target/aarch64/pr94515.C @@ -0,0 +1,43 @@ +/* PR target/94515. Check .cfi_window_save with multiple return paths. */ +/* { dg-do run } */ +/* { dg-additional-options "-O2 -mbranch-protection=pac-ret --save-temps" } */ + +volatile int zero = 0; + +__attribute__((noinline, target("branch-protection=none"))) +void unwind (void) +{ + if (zero == 0) + throw 42; +} + +__attribute__((noinline, noipa, target("branch-protection=pac-ret"))) +int test (int z) +{ + if (z) { + asm volatile ("":::"x20","x21"); + unwind (); + return 1; + } else { + unwind (); + return 2; + } +} + +__attribute__((target("branch-protection=none"))) +int main () +{ + try { + test (zero); + __builtin_abort (); + } catch (...) { + return 0; + } + __builtin_abort (); +} + +/* This check only works if there are two return paths in test and + cfi_window_save is used for both instead of cfi_remember_state + plus cfi_restore_state. This is currently the case with -O2. */ + +/* { dg-final { scan-assembler-times {\t\.cfi_window_save\n} 4 } } */