From patchwork Wed Jul 8 12:13:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 39975 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E94B738618EB; Wed, 8 Jul 2020 12:13:54 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-eopbgr20080.outbound.protection.outlook.com [40.107.2.80]) by sourceware.org (Postfix) with ESMTPS id 8C156386186A for ; Wed, 8 Jul 2020 12:13:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8C156386186A 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=Ou0mr1ZYvIjpsVVHc+jlGLoVyKIaBhqKOr6JSzu27RA=; b=x2t2oJJ7dBgb/CKABm0er3/g5LTuCYF9RevIL4lSsqa+NKtPcIefojjWCkwLkRv7unQ8zsvE3SGbykTq8ooSBV10YivnA7JlcnxKUG81kZKYlI/CAD4+NW+iRFq6hXL7SNdZID6jwpmadTF1ksxajT/jp3PS+DzQkQbTNiQEEYs= Received: from AM5PR1001CA0060.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:206:15::37) by DBBPR08MB4252.eurprd08.prod.outlook.com (2603:10a6:10:c2::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.24; Wed, 8 Jul 2020 12:13:50 +0000 Received: from AM5EUR03FT008.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:15::4) by AM5PR1001CA0060.outlook.office365.com (2603:10a6:206:15::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.23 via Frontend Transport; Wed, 8 Jul 2020 12:13:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; sourceware.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 AM5EUR03FT008.mail.protection.outlook.com (10.152.16.123) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Wed, 8 Jul 2020 12:13:50 +0000 Received: ("Tessian outbound e44de778b77e:v62"); Wed, 08 Jul 2020 12:13:50 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 52bbcd2e22a8a343 X-CR-MTA-TID: 64aa7808 Received: from cc2cc8e447f3.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 3F505574-D45F-4356-959C-C2EBEC685D18.1; Wed, 08 Jul 2020 12:13:44 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id cc2cc8e447f3.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 08 Jul 2020 12:13:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KovOAVJeX7ijNY6acpUim0AkT6x8JUHKgGUsd/HvLZJU2MBhk7f8xieYfaHHgBlJfGvoTKrjIbiq79KqHEeiNzWZ20pxKJDeEvJeMQsZcW3miP+o8ANSkbwtyMA4G4opqD1TvzOSNhyfBwb90e3N+DFxEhm/pR/9Pb6+/x/a5ZMSYDgaUmZFFhGseNc3iNFUXY6+AcYdY7gEdBxJk3J9qHTgPgaQQtW3wvKjuViPCr4mHvsSLTaFGoOxlpZfawvccKyEUkQsz5ENmXbPRnDFGMOaoCW61mPPKVPTHuIzvOs7g3XVI5u/MpMIOscHQysoREhjxEcAGOYuj3/uLZKWig== 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=Ou0mr1ZYvIjpsVVHc+jlGLoVyKIaBhqKOr6JSzu27RA=; b=ThWh0ykyBEk4WnV3HskLoL2aAwF8SMgQKj5B3mmQY4ZKnOAJ41UB9ZnT0LqfEGCfz9pWVZILIFL8GuOz8hJDJdmxQ9rqJhZNOdlx5y4hZw3W2FxIoB6RllJbOt/aqaxhttVF+Wu9ZcZ8jSWw4773x+JDS+Wlcxav78UEMkx2DMHa5TK/TJYlXp1bswOjEqxy0oItKGq++FeayieTE59/YBpxyGAzPSNhT9KF55u3bKISPeTE53j6agLo1P7M9AOfDDLw9lWGnHBG3F7nsnEZKY8AD5ymp+RSm+Ecgq7hEaFufkQIfrSrZQHAepiRVEWCZ1Ei36fdxmmzpj5eWn37rQ== 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=Ou0mr1ZYvIjpsVVHc+jlGLoVyKIaBhqKOr6JSzu27RA=; b=x2t2oJJ7dBgb/CKABm0er3/g5LTuCYF9RevIL4lSsqa+NKtPcIefojjWCkwLkRv7unQ8zsvE3SGbykTq8ooSBV10YivnA7JlcnxKUG81kZKYlI/CAD4+NW+iRFq6hXL7SNdZID6jwpmadTF1ksxajT/jp3PS+DzQkQbTNiQEEYs= Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) by AM7PR08MB5527.eurprd08.prod.outlook.com (2603:10a6:20b:de::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.28; Wed, 8 Jul 2020 12:13:43 +0000 Received: from AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::2404:de9f:78c0:313c]) by AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::2404:de9f:78c0:313c%6]) with mapi id 15.20.3153.031; Wed, 8 Jul 2020 12:13:43 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v7 11/14] aarch64: Add pac-ret support to assembly files Date: Wed, 8 Jul 2020 13:13:37 +0100 Message-Id: <3439111b473697ec4f146bee1ace22759b8bad47.1594209990.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: LO2P123CA0072.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1::36) To AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.53) by LO2P123CA0072.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.24 via Frontend Transport; Wed, 8 Jul 2020 12:13:43 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [217.140.106.53] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 03ace36f-6816-4c95-ebcb-08d823385f8f X-MS-TrafficTypeDiagnostic: AM7PR08MB5527:|DBBPR08MB4252: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8882;OLM:8882; X-Forefront-PRVS: 04583CED1A X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 6aTuWjG3A0D8C0EpYV+btMmWW5whVvr9TH1Y/V5KnLqPFxiUANUthLAZoh+5wOOiJmsiYVcAV7UiEy78JR5UMx0pPgfFJckbf89fz9QUQ0jesN2NbsIvDWxZ0+73bONzeNhTNXLaj70TkzAI8S0V9t5KW0ajGBBpcmyy67FhvWa7iOSEA8lnajji2e5UXAI8Cq3q7RvwM9S4YCUk94LE+GHi/kmbR36KfkF4DPJ/U0KB8jDoN40IkMrWId+XV3DpYiGOUrtqA343lp/1PpZBjfRNfLwRJm2PM746q/mihfs3iUXnGp99nk5AXC3nbADaLKmSUnwAQjhf4sdYw6X/dh7OHkyXl3Fc/edCJC6wqDeK985xNOqqtNIC8JXGmd3ofesHteJVD+2dvPCnBAw9gw5pKi37Ca3TvcUpQsMqp68= 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:(4636009)(136003)(39860400002)(396003)(376002)(346002)(366004)(8676002)(478600001)(6506007)(2616005)(956004)(8936002)(44832011)(16526019)(2906002)(186003)(26005)(36756003)(66476007)(66556008)(6916009)(316002)(66946007)(6666004)(5660300002)(83380400001)(86362001)(69590400007)(6512007)(6486002)(52116002)(136400200001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: jaP/onArge/y8UL17bvB0ycdLR3GhUXztSLSkqYuqdFFoqJtF9TyYIuyv/Ggo4iVznPRoM9VtfRwKlSbzv770g9V+ubQog6HWh1DfGszV3fFhIzfwkaAZFirISvRbx/D9vN1wypOvQiu/fkP9IW1j7tVwYlP70rhvsCel/MwamnPoS0WDsYlcVpxiza3xmfN820GQKjLj6h41JxMYyupMqAc5v2T6+vujlcfMQjfet24smP7zQDq59/T+i4x2rx0W3wLbxhCQJ1bmHhZXa41MZ9im5fj3Y6lrF5CK9/DWK1PCcqRGregzaXavtG4DGnYN9VCkS1CO2wiVUVRf+j+nA8igzWgSXmjJKRYkFGElI3RzhYmFNQHCjIe8JsNQJ9SJQ+Tiqw8vL1iy+Qh610qnxkQVNxNcMLEhhSJvI3WX8/vIyFQPwXI2pkSclffNWPGhYz1nNnldwGrmMINo/2+ihBI/XKcptSSzTmQ7TxWiJU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5527 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT008.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:(4636009)(396003)(376002)(346002)(39860400002)(136003)(46966005)(356005)(2616005)(478600001)(336012)(316002)(81166007)(956004)(82310400002)(36906005)(8676002)(82740400003)(6486002)(69590400007)(70586007)(8936002)(70206006)(6506007)(6666004)(36756003)(47076004)(186003)(16526019)(26005)(5660300002)(86362001)(6512007)(2906002)(6916009)(44832011)(83380400001)(136400200001); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: c34e7aed-8133-490b-49de-08d823385b6d X-Forefront-PRVS: 04583CED1A X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rQNBekVuRARihGFlpvSkdhS8NBAq5KESQaxdp60HaXWUw62dzBj/N43ypxlJAz146AaK6X+Xyw0pEa47G0S6yp3L0PEeXx5gFAaA4PMJzzSzjljWigrO2rMYlvWw5AagHUWGFzVufgrTPZpNrhvcpU85r0bvB8m30ivQmCa1wVjot9nfMSkU9hxe9COYmR1o+ZTBUxKZCWe2xU6ZMFAKOteej2o/hUx6uWXkum3g+KniPevqN8mDgeJYNtR90NdposIgZ3ps/tPluKMHGrKXexSLbH8rvKkGehyLjbvUwB0BS0ujQ+nKOBzWnvB3WkY6NJEou3wuxttj6QXfGw21x4xYSk3BHdEsE/lRA+QtwG5Chyh9dqReVU2U95S61n18Cb8KEYX0Z0oHGNgb29wwdH8I6B2vjC/UvywDS7s3KI3GJr1nKQGTIe4keu7jvDIv5kNDKN4DyriH2LPSAqfO+Q== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2020 12:13:50.0684 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 03ace36f-6816-4c95-ebcb-08d823385f8f 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-AuthSource: AM5EUR03FT008.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB4252 X-Spam-Status: No, score=-16.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Use return address signing in assembly files for functions that save LR when pac-ret is enabled in the compiler. The GNU property note for PAC-RET is not meaningful to the dynamic linker so it is not strictly required, but it may be used to track the security property of binaries. (The PAC-RET property is only set if BTI is set too because BTI implies working GNU property support.) Reviewed-by: Adhemerval Zanella --- sysdeps/aarch64/crti.S | 8 ++++++++ sysdeps/aarch64/crtn.S | 6 ++++++ sysdeps/aarch64/dl-tlsdesc.S | 8 ++++++++ sysdeps/aarch64/dl-trampoline.S | 18 ++++++++++++++++++ sysdeps/aarch64/sysdep.h | 8 +++++++- 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/sysdeps/aarch64/crti.S b/sysdeps/aarch64/crti.S index c346bcad72..c486e9ca44 100644 --- a/sysdeps/aarch64/crti.S +++ b/sysdeps/aarch64/crti.S @@ -75,7 +75,11 @@ call_weak_fn: .hidden _init .type _init, %function _init: +#if HAVE_AARCH64_PAC_RET + PACIASP +#else BTI_C +#endif stp x29, x30, [sp, -16]! mov x29, sp #if PREINIT_FUNCTION_WEAK @@ -90,6 +94,10 @@ _init: .hidden _fini .type _fini, %function _fini: +#if HAVE_AARCH64_PAC_RET + PACIASP +#else BTI_C +#endif stp x29, x30, [sp, -16]! mov x29, sp diff --git a/sysdeps/aarch64/crtn.S b/sysdeps/aarch64/crtn.S index 0c1ef112c2..d21c21c203 100644 --- a/sysdeps/aarch64/crtn.S +++ b/sysdeps/aarch64/crtn.S @@ -41,8 +41,14 @@ .section .init,"ax",%progbits ldp x29, x30, [sp], 16 +#if HAVE_AARCH64_PAC_RET + AUTIASP +#endif RET .section .fini,"ax",%progbits ldp x29, x30, [sp], 16 +#if HAVE_AARCH64_PAC_RET + AUTIASP +#endif RET diff --git a/sysdeps/aarch64/dl-tlsdesc.S b/sysdeps/aarch64/dl-tlsdesc.S index 9d96c8632a..db8a064322 100644 --- a/sysdeps/aarch64/dl-tlsdesc.S +++ b/sysdeps/aarch64/dl-tlsdesc.S @@ -183,6 +183,10 @@ _dl_tlsdesc_dynamic: callee will trash. */ /* Save the remaining registers that we must treat as caller save. */ +# if HAVE_AARCH64_PAC_RET + PACIASP + cfi_window_save +# endif # define NSAVEXREGPAIRS 8 stp x29, x30, [sp,#-16*NSAVEXREGPAIRS]! cfi_adjust_cfa_offset (16*NSAVEXREGPAIRS) @@ -233,6 +237,10 @@ _dl_tlsdesc_dynamic: cfi_adjust_cfa_offset (-16*NSAVEXREGPAIRS) cfi_restore (x29) cfi_restore (x30) +# if HAVE_AARCH64_PAC_RET + AUTIASP + cfi_window_save +# endif b 1b cfi_endproc .size _dl_tlsdesc_dynamic, .-_dl_tlsdesc_dynamic diff --git a/sysdeps/aarch64/dl-trampoline.S b/sysdeps/aarch64/dl-trampoline.S index 2cbfa81434..794876fffa 100644 --- a/sysdeps/aarch64/dl-trampoline.S +++ b/sysdeps/aarch64/dl-trampoline.S @@ -127,7 +127,12 @@ _dl_runtime_resolve: cfi_startproc .align 2 _dl_runtime_profile: +# if HAVE_AARCH64_PAC_RET + PACIASP + cfi_window_save +# else BTI_C +# endif /* AArch64 we get called with: ip0 &PLTGOT[2] ip1 temp(dl resolver entry point) @@ -239,8 +244,17 @@ _dl_runtime_profile: cfi_restore(x29) cfi_restore(x30) +# if HAVE_AARCH64_PAC_RET + add sp, sp, SF_SIZE + cfi_adjust_cfa_offset (-SF_SIZE) + AUTIASP + cfi_window_save + add sp, sp, 16 + cfi_adjust_cfa_offset (-16) +# else add sp, sp, SF_SIZE + 16 cfi_adjust_cfa_offset (- SF_SIZE - 16) +# endif /* Jump to the newly found address. */ br ip0 @@ -287,6 +301,10 @@ _dl_runtime_profile: /* LR from within La_aarch64_reg */ ldr lr, [x29, #OFFSET_RG + DL_OFFSET_RG_LR] cfi_restore(lr) +# if HAVE_AARCH64_PAC_RET + /* Note: LR restored from La_aarch64_reg has no PAC. */ + cfi_window_save +# endif mov sp, x29 cfi_def_cfa_register (sp) ldr x29, [x29, #0] diff --git a/sysdeps/aarch64/sysdep.h b/sysdeps/aarch64/sysdep.h index 0eeb0bb2f1..cd88023163 100644 --- a/sysdeps/aarch64/sysdep.h +++ b/sysdeps/aarch64/sysdep.h @@ -45,6 +45,10 @@ #define BTI_C hint 34 #define BTI_J hint 36 +/* Return address signing support (pac-ret). */ +#define PACIASP hint 25 +#define AUTIASP hint 29 + /* GNU_PROPERTY_AARCH64_* macros from elf.h for use in asm code. */ #define FEATURE_1_AND 0xc0000000 #define FEATURE_1_BTI 1 @@ -66,7 +70,9 @@ /* Add GNU property note with the supported features to all asm code where sysdep.h is included. */ -#if HAVE_AARCH64_BTI +#if HAVE_AARCH64_BTI && HAVE_AARCH64_PAC_RET +GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_PAC) +#elif HAVE_AARCH64_BTI GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI) #endif