From patchwork Wed Jul 1 14:40:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 39871 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 20CD7386188A; Wed, 1 Jul 2020 14:40:39 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2076.outbound.protection.outlook.com [40.107.22.76]) by sourceware.org (Postfix) with ESMTPS id 7BD353857007 for ; Wed, 1 Jul 2020 14:40:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7BD353857007 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=nUtjZ8MxE/HoT2ciyvCRhauxY1gID6XJ0NF2gGk+He8=; b=lfNlOeXY70v457SkLHOAJYGZreNEuiokf1EfOuTpZngYV4zQnKTWApZszvWt6ms0fcQ/v8HR2trPG0OmH/ZF2PBps8fK+ukRoxVzsRk2s+uR/agq9LgkLRSCzsq61EuZcT2muAHbXkoKq7UKEgJTNQp24BgfZ5mulCuXvdAwcic= Received: from DB6PR07CA0013.eurprd07.prod.outlook.com (2603:10a6:6:2d::23) by DB7PR08MB3852.eurprd08.prod.outlook.com (2603:10a6:10:7f::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.21; Wed, 1 Jul 2020 14:40:34 +0000 Received: from DB5EUR03FT008.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:2d:cafe::c) by DB6PR07CA0013.outlook.office365.com (2603:10a6:6:2d::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.10 via Frontend Transport; Wed, 1 Jul 2020 14:40:34 +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 DB5EUR03FT008.mail.protection.outlook.com (10.152.20.98) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.22 via Frontend Transport; Wed, 1 Jul 2020 14:40:34 +0000 Received: ("Tessian outbound e44de778b77e:v62"); Wed, 01 Jul 2020 14:40:34 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: c6b44b415fbead13 X-CR-MTA-TID: 64aa7808 Received: from d940d0b0b32c.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id A9A7A718-FAA8-4A62-9ACA-995A402198C2.1; Wed, 01 Jul 2020 14:40:28 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id d940d0b0b32c.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 01 Jul 2020 14:40:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jf5YRFOZND7F0fHwvXGmo8FJjPsEbShGbe3kxRWHpk2pCuGj+exInqp0Gvr7WeMkw3Dt5zrrIfwz1X4a0Vq9mJoYr9bdLg7jLG8EnYJJr0SGeT109md1BkqIKz6qgLqCbfcHndtF98725//R5xHYTDgUuSxWf5hy1nJ/p0cnlwrtT+7YZZK+aRsdFiPE30pDQpEWqZjKt8xxUoWkFxSIXsb7Unik1s3Tgch9NSEHvcctgJzdOQ5gy+YQUKfHY7axCTdGQP8aB9KQBKTTfFLWbzdPZl6BaS3eMfLF/b3Ss4WmXYBEEDQygHiaLXh2VKzDED3p7Sz8dc5rIrXU9sygRQ== 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=nUtjZ8MxE/HoT2ciyvCRhauxY1gID6XJ0NF2gGk+He8=; b=K7gPtqw0mH1JylRMi1Go9RebPggwOOl44lUpw2L32HdwhiNOXNs3yv89t+KzpiOH1mxrfq60R+9+4FmXtlSVwsIO5IqfChPKQhMlrBUrluZ5U6s/Znin9V4Uypifyl/DlCAwR5oo26K5zeSUlx4KGL8WglTbDPoVuR9YF6pmF6phNXaVYiPcwWuVhG0v6PH+BZ6Pu/vhwD7hDt02PeVEkRK9VasVmwbV6iSFwSevtmoM9X67SV8nNh0XwTC1AiHK5FzG64N4f66FpEeXdy4+sMG4Qc5ULneAkbQcziVjTCdxYhiq/0zruaQYaIigiydeZ31udpO7l2VxbCbd+q1RIA== 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=nUtjZ8MxE/HoT2ciyvCRhauxY1gID6XJ0NF2gGk+He8=; b=lfNlOeXY70v457SkLHOAJYGZreNEuiokf1EfOuTpZngYV4zQnKTWApZszvWt6ms0fcQ/v8HR2trPG0OmH/ZF2PBps8fK+ukRoxVzsRk2s+uR/agq9LgkLRSCzsq61EuZcT2muAHbXkoKq7UKEgJTNQp24BgfZ5mulCuXvdAwcic= 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 AM6PR08MB3879.eurprd08.prod.outlook.com (2603:10a6:20b:8c::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.24; Wed, 1 Jul 2020 14:40:27 +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.3131.033; Wed, 1 Jul 2020 14:40:27 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v6 11/14] aarch64: Add pac-ret support to assembly files Date: Wed, 1 Jul 2020 15:40:21 +0100 Message-Id: <1b0ad642e8d7b6aeb4481c834e857cbe0d4a5934.1593612309.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0265.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a1::13) 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 LO2P265CA0265.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a1::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.22 via Frontend Transport; Wed, 1 Jul 2020 14:40:27 +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: f075879a-a1de-413d-7e11-08d81dccb68a X-MS-TrafficTypeDiagnostic: AM6PR08MB3879:|DB7PR08MB3852: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8882;OLM:8882; X-Forefront-PRVS: 04519BA941 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: vv5i7L0gUCNbUGvQZunsjThktu95FHBCsTvjD4P0UA2PUymAOtGc7RpO6P1JoVXh7mWW0uHdks9E/m1qX1Z8rsCKXZPBH1PKodhQKVqS6cyDZOptzRcJrYv/A3yVp6i2RwhnmyVvArGvv+uOliJp3xaFz9YSpFkM3o88vPaVV2hX2EQJMn6nyAKAjAN3kzT1SVv6uFihRpK6nTvweeMmLfDX2rZVu3Zrrl5l0+FGp+1S4b/tK7OiIhDzmHY+HY62gtU0ql1YSL7aMXO1vrrCZ1EQuHuCHiVuBkha8dnXJQVi1qMgFB3pEGDCtOZ5HGbt1DNFpxl1iGXR8UGvukw2J/QY2FXIi+NpKtl7MQfTSCUnqAeNZ2fxlO9mcJ48qe0dOJkPIYHTW85/0jVVx+BPnmD+cDuJR5vQ5Op8xjlYMvs= 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)(39860400002)(366004)(136003)(346002)(376002)(396003)(186003)(2906002)(52116002)(478600001)(36756003)(956004)(2616005)(6916009)(6512007)(66946007)(66476007)(44832011)(6666004)(66556008)(6486002)(69590400007)(83380400001)(5660300002)(26005)(6506007)(16526019)(86362001)(8936002)(316002)(8676002)(136400200001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: vRStoAcAMtvVyph5u7HPDH1vm40hJo2N9TBdQGKb55w4sdXv1wVctj6MiJj/MXH2Mvocf+OBN/kqLhXuXwskyQknlgQR4okb2pGLodLFAzXbUPZs58fIm5IspeOzy4onaxNm3rsdIlN6ifoeWHskXPFpurS5BZmZ4/XNEpythlV4hajA46IW9YqmzdSpDkkMlOTbRewFAlqlqAK1YPpAz/sCC5luevdKs1b/h6AMSLLTYGdxeNqzrrtMc1z/mixaqZ1+f0KcxiDGG8vmYYrm3XpLSQ0CINJCvA8v773gYHbrWD7nXSkahLKb76Cgk75nZBpBwPmHiHDC3v/TgyunR3mijVSBWDiS8RTELv+I+szwPVLB0USYLZC6C5J/M9Xym5CvtbZtyAwx4PyO7h0KpiKjeLoeCw15/rKzubW4A4pZjUAwiMRoMYvmXg8jDeavmBzxLENOA5cxXgksmmdM4jdo8TG5jkilWyD10IdaS/Y= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3879 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: DB5EUR03FT008.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)(346002)(376002)(396003)(39860400002)(136003)(46966005)(16526019)(6506007)(81166007)(82310400002)(83380400001)(8936002)(86362001)(82740400003)(47076004)(8676002)(478600001)(69590400007)(356005)(316002)(6512007)(2906002)(6916009)(26005)(186003)(36756003)(6486002)(336012)(2616005)(6666004)(956004)(70586007)(44832011)(70206006)(5660300002)(136400200001); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: a286c353-85bf-4951-6c69-08d81dccb253 X-Forefront-PRVS: 04519BA941 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /udCl027Ot7Xkkp7m2+Vk2aQOQQbSl4PSjGQth2oJGbg+tm4YGcXXQ+1wQloFaiiZ9MSaTbVqAQJq73x8GQ4bh7HZ1DQtKEfhcIM2oGQsejIjJpcATzsvbOmkO9xYpCnFWd9w2nVnE19E3BlJ7Gko3xRGcGWlXn+HhKiz1RiIj7iArHEWh6nQu8nyuaH+oLmy+tUtdqSNXXsevbK2lIyhIh5/pc0tO3PSuwRa99k681+asViaZxjyJGZzCuO9xB6sndV33JYHKTjrpKKCPHwKnBPwYNo+c3fgWYiXBGMCdXaIdaYwlya+EJ24QJ1YlWslpTwZE2tSM0t++rxnfgEMjy17fTBaHYW1QFZfJXNBffaq9Ca1ENkxYx5IrBwxz81CKcVaXZdPFqctJWRXXkolj+FGZG3WVj2ILAwR82vBfG/wpXSlumyt2weehr2stfLP+nIRr5qdkkgqWx46axkLQ== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jul 2020 14:40:34.5928 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f075879a-a1de-413d-7e11-08d81dccb68a 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: DB5EUR03FT008.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR08MB3852 X-Spam-Status: No, score=-16.3 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 4664329d3a..500c272745 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