From patchwork Fri May 15 14:40:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 39267 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 738AC3985C2E; Fri, 15 May 2020 14:41:37 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-eopbgr120087.outbound.protection.outlook.com [40.107.12.87]) by sourceware.org (Postfix) with ESMTPS id B51F2398582C for ; Fri, 15 May 2020 14:41:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B51F2398582C 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=ceDMrw0x+/h7N55nCBLeHJa9UyRADlyr6KTY3OOW8Co=; b=s8+qRBYhSEyspuE8UqCNvtBlxvWtxSJEKSDg9REkw8uolkdef/IAw5/q42TESCrXHqTR+jNRrzLJ7Ehbk/prQfFrfPAw1euewPNUaJaIP6Y3Vk+KzRZTwk0JJFsg1eYAoqrW+GVF5PNk86LPXIKzlxs4Ufdk6Wb4nfQULG87YMU= Received: from DBBPR09CA0017.eurprd09.prod.outlook.com (2603:10a6:10:c0::29) by PR2PR08MB4684.eurprd08.prod.outlook.com (2603:10a6:101:22::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.33; Fri, 15 May 2020 14:41:14 +0000 Received: from DB5EUR03FT027.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:c0:cafe::ea) by DBBPR09CA0017.outlook.office365.com (2603:10a6:10:c0::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20 via Frontend Transport; Fri, 15 May 2020 14:41:14 +0000 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 DB5EUR03FT027.mail.protection.outlook.com (10.152.20.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.19 via Frontend Transport; Fri, 15 May 2020 14:41:13 +0000 Received: ("Tessian outbound ff098c684b24:v54"); Fri, 15 May 2020 14:41:13 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: ecd6f6f607434c33 X-CR-MTA-TID: 64aa7808 Received: from 1ddb15158a9d.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 2EE40992-E3E9-4074-8A52-F8DE75F6E147.1; Fri, 15 May 2020 14:41:08 +0000 Received: from EUR03-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 1ddb15158a9d.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 15 May 2020 14:41:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SD+fq+r5SdAS1OS18xfpp5DlF9JBnYcXPoqr+kHqhOfcNvNGBvjV8AhTTs+AsQSm4HztBg/uEoZJY5IXBvPP07hIgCLX35B4zqCiP1OHHa002k+bVpMymWiyXHI5jkDccNiO7KuCW8KFZFp5sPWA737Du2dEnikEB4fUDlxeFxOkTJ5jr0sK3CBa2y5jK1ASwobtKzbBDIeCkNb6Vdh2QDhrRqJ7LobgJB7FkIN95VVvE1kp0zmKzT/shCOWltKmQ/oeUOzpdSFVT7oCHmnOgGh1QQ21vUMf6gU4XRFbf8wBvT2ztEInNFpgAkk66OeOqZpyG/67vcluazHwDMTKNw== 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=ceDMrw0x+/h7N55nCBLeHJa9UyRADlyr6KTY3OOW8Co=; b=jRQkfiEQCoznWvA40t98IMOAwUv7bJ+E6h6NcOCNpuJ96xYITzqAjanEpRkCfsaC3eyYqPTiNJKKvWRs6uPY06kdJYJEUeLMUnSSomtx5M6pq2uIzEjWaM9prTaWgKjV1JDY9dffJQWm4HeSz+Zczj+D0O0Pi5sFA8u/zfT71y127a1RK9XILy3ZD71jr9zImPAZBNA5n/EoZR3Z2Fk5ABTyvA3825SgqfVjcK2gqdxgBT2TN09roINuvY9+wDgVhxVNFI8E3CCI9UqBHygNc4lWMHcxJxNstuEVM4m2M5hvsjq98aaqHu05rjMGNXXRfmso5y/iujjbjtNriKhIQA== 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=ceDMrw0x+/h7N55nCBLeHJa9UyRADlyr6KTY3OOW8Co=; b=s8+qRBYhSEyspuE8UqCNvtBlxvWtxSJEKSDg9REkw8uolkdef/IAw5/q42TESCrXHqTR+jNRrzLJ7Ehbk/prQfFrfPAw1euewPNUaJaIP6Y3Vk+KzRZTwk0JJFsg1eYAoqrW+GVF5PNk86LPXIKzlxs4Ufdk6Wb4nfQULG87YMU= 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 AM6PR08MB3528.eurprd08.prod.outlook.com (2603:10a6:20b:4b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.34; Fri, 15 May 2020 14:41:07 +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.2979.033; Fri, 15 May 2020 14:41:07 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v3 11/13] aarch64: Add pac-ret support to assembly files Date: Fri, 15 May 2020 15:40:55 +0100 Message-Id: <55c2f030bcb0c66c855e823b60bbd624d7d5bff9.1589552055.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0309.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a5::33) 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.55) by LO2P265CA0309.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a5::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.24 via Frontend Transport; Fri, 15 May 2020 14:41:07 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [217.140.106.55] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9528cb1a-aa01-4a31-ab9b-08d7f8de0491 X-MS-TrafficTypeDiagnostic: AM6PR08MB3528:|PR2PR08MB4684: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8882;OLM:8882; X-Forefront-PRVS: 04041A2886 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: dFBO5gfHkljHaOJgGBnC9JwOZUkk0Yf7blVK5XHuRu3l6O+AseITR5vkzQkdc4qAhrOnt4g8xrECnI2WqiqleArw5VIFHUv2/BSaK//Vr0kKE/hVtc0j3QGITax1T90Wy92HmboeIEwFcGNQRQyocEWTCymLCcNfJlPuMHQqvXKi0tC6vvFajLmvYZKvte09qpGsSNrNVqHY74cbokak2kk/p7NdY7uVk9ONrQ9FVWAg6oCkKXsVxFhl592nUQU7D1R3A/invQr+IhskgtFx/3LUuC96nJqHIDnPA0X0PXLkpqwnC/Kj+Vq6WU/1wXZ9ymE9V/l2dVuxg0KXFrIdVvXM56sMCte35CDNTTyJJvH50X2vKS+YFhHlTOrsYEj/V752vYP/PVcefm+wnMTuL9JbUJ/g9t7PO/mztcr50yfJdoA5uKsAULKJybEHb1EEEUXju1//kg1CootBADRFdCVegQS6LNtuTYXdAemnDU1aRG9gFkLjx6ZxCFWHxkFuVMaVpodTPz1B4xbhhOT+dFM1lCf9/REyMG++RQsuwds= 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)(376002)(39860400002)(346002)(366004)(396003)(86362001)(6506007)(69590400007)(52116002)(478600001)(316002)(6666004)(6916009)(6486002)(66556008)(44832011)(6512007)(5660300002)(2906002)(956004)(66476007)(8936002)(66946007)(36756003)(186003)(26005)(2616005)(8676002)(16526019)(136400200001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 8oQqO2IOXnpbpRhFhscdX16ag7y3UIF/7fLouufohaKbth3xq8oQrewC0Oipl2dtDDj4GYiNhmBtCOkOZac99zkkxfgg1Y1tJGmT69mcFjRfvpW61Pl8bTvR94E8LR6sLdp7sLOq4IeO0b9pp+XyJWnQVoG3J7iDwP+VqAyrq9CFRrt1w2JCYkP4pcVVoL0ta0/NIwmAIaAzL0klD0ZxGFR7yeskAAI8P+NaiHNPfAYJZYtD83xwVBSnwoab+C60Jzx5mwr6TLKgp+J8igvexO1RxEV+HSHM4yN/RrXADhN3SX8uDZ9LhlAXnpdWAjEjgEr7bld+Pcx5HsRZSkXzcyD4SJbtmhQVUKQPPThI5ok5tVbfm6NCwlx8OaVNEmyAt6qX7iQmyM2/QHDtV2/7CmXqPKUgKhvVZPQLB89aplrG8jRPFoZSHw07BUMP4sXfkNtC2iphoqzIQ8ho73GaMlonE8eq2SyZM/mLCxyfuuI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3528 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: DB5EUR03FT027.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)(39860400002)(396003)(136003)(376002)(346002)(46966005)(8676002)(6512007)(8936002)(44832011)(16526019)(69590400007)(6506007)(86362001)(5660300002)(336012)(26005)(2906002)(2616005)(47076004)(956004)(316002)(186003)(36756003)(356005)(6486002)(81166007)(6916009)(70586007)(70206006)(6666004)(82740400003)(82310400002)(478600001)(136400200001); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 5f816a17-4acc-4281-2ec3-08d7f8de00bb X-Forefront-PRVS: 04041A2886 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Il8LL7Wjb0Kh9zB4G1bdfOut4fI/7DYNNNh/qI87Hee35L9kHka2tppgAL5cbv+mI8BY3UijoWAkjPUhUGoPdVV0lSEq9WlzNRk3uP6q+g3HO/G8VJYl4XVMtj4bBDw628P6aaGsnzGa9DV8CgcX9CGtG1XDhoofwyn/qBrH9NeLm9j4mNAK1bDU8WfOEL+POC7RptlUdQnTNcsZliv2UhJrkW76MnzczMTAZwvQ2q4egk+kBpttFVY9Pl6qvi28ZyGDz7dgWQjRgFDuu3s91NKeIM/JX7xdhJeHrhtxkE2ueJGzq/nZPGqiDkKs6q6U++22ALizcD+arbA0A7f1A2ZobiT2OUuRzEdYgf3fBDPwwdIsMhF3TKTySogoEgCZFelKyhi3E/mQxYEFjkzxlxLjUhZ4KLSWfyGUTA+P3mALhkJmlw1jtojYTWcjYtw/gwjA7x6ARuiv5Hvqd+eLhE3Tz6gQp9SNB31sJ3zEQur0o24Nmn6INBTAU7jRGvxgCS1qaaeWLbfdhJ6uwduF9R9VHctDh2eognbl0wmuTAqYz2ljaHipte9cD/3Wr89R/aeKPognZ5ke7pg6ZIbFNg== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 May 2020 14:41:13.9228 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9528cb1a-aa01-4a31-ab9b-08d7f8de0491 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: PR2PR08MB4684 X-Spam-Status: No, score=-19.5 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..02ec7d015e 100644 --- a/sysdeps/aarch64/crti.S +++ b/sysdeps/aarch64/crti.S @@ -75,7 +75,11 @@ call_weak_fn: .hidden _init .type _init, %function _init: +#ifdef 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: +#ifdef 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..4b93b90411 100644 --- a/sysdeps/aarch64/crtn.S +++ b/sysdeps/aarch64/crtn.S @@ -41,8 +41,14 @@ .section .init,"ax",%progbits ldp x29, x30, [sp], 16 +#ifdef HAVE_AARCH64_PAC_RET + AUTIASP +#endif RET .section .fini,"ax",%progbits ldp x29, x30, [sp], 16 +#ifdef HAVE_AARCH64_PAC_RET + AUTIASP +#endif RET diff --git a/sysdeps/aarch64/dl-tlsdesc.S b/sysdeps/aarch64/dl-tlsdesc.S index 9d96c8632a..3746dbec17 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. */ +# ifdef 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) +# ifdef 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..53f92d68bf 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: +# ifdef 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) +# ifdef 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) +# ifdef 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 086fc84b53..c51572a690 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 defined HAVE_AARCH64_BTI +#if defined HAVE_AARCH64_BTI && defined HAVE_AARCH64_PAC_RET +GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI|FEATURE_1_PAC) +#elif defined HAVE_AARCH64_BTI GNU_PROPERTY (FEATURE_1_AND, FEATURE_1_BTI) #endif