From patchwork Mon Jun 22 14:01:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 39727 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 AF291388B000; Mon, 22 Jun 2020 14:01:18 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60072.outbound.protection.outlook.com [40.107.6.72]) by sourceware.org (Postfix) with ESMTPS id EDBC9388A83C for ; Mon, 22 Jun 2020 14:01:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EDBC9388A83C 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=4HWCIvRxFM4cpIsgvYeaHc9siVQL33dly/L4gU5eXa87o5MMIcOgOU779fDSal2SJvdbUjCVPqUqEqRIv9FUIAz74W03RXo7iCL8NNk0rRqStErSO6EHMk6+eXzPI+zCbkX4e9dBqJpF0EixScUD/DF7QFFi3L+6Hk0yca/XmBg= Received: from AM6PR04CA0058.eurprd04.prod.outlook.com (2603:10a6:20b:f0::35) by AM7PR08MB5368.eurprd08.prod.outlook.com (2603:10a6:20b:103::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.21; Mon, 22 Jun 2020 14:01:14 +0000 Received: from VE1EUR03FT010.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:f0:cafe::3d) by AM6PR04CA0058.outlook.office365.com (2603:10a6:20b:f0::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.22 via Frontend Transport; Mon, 22 Jun 2020 14:01:14 +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 VE1EUR03FT010.mail.protection.outlook.com (10.152.18.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.22 via Frontend Transport; Mon, 22 Jun 2020 14:01:14 +0000 Received: ("Tessian outbound f44be76249db:v59"); Mon, 22 Jun 2020 14:01:14 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 90ea780cdc376049 X-CR-MTA-TID: 64aa7808 Received: from 4faba6b12a21.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 50464197-71C3-44B7-A993-4697AFEC2A2F.1; Mon, 22 Jun 2020 14:01:09 +0000 Received: from EUR03-AM5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 4faba6b12a21.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 22 Jun 2020 14:01:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XQhyCYXuLtMxIZAdgQPJZcjZDFebaWFMce0G95P4zCo/SYDJD8TB62w+z1jA5NYlofkU20L4TGtuO0WZEkoxxh3WpCqrdPt4eT1ToNmjp7zo5pBHOgS5P0yatRV2lL3kkVyzrw94pe21QykUfkjA66qA8FeopgPDL2D6i0yxmfuCdXpadClDi3kWyZxM5McuquDyG+UIU0F+ijal6YLdwsTcUSOiOcdxheJxpvLlVfDEz0xPDr4LS2UFXbKAiWS6tlFB6s3mIk+jZqn/bIhC5+mwb1Io8QZDvezhlxUX0yTBQOZ7ihs79P73GoYMhQEJOGfd0Z0ZB0xvSYA/BuXyPw== 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=C6uZhtgWL6/rVSU+eWkBAHD0S+0IzhlYZ7QqVdbuDA9qxua1CYL4nrYMONhVjvzdfz02Lf9CZqjnIbY2/a/6B8rg9CKGsfV7DZ/sqgsP0QwiGjnvGqBz/rnlYngPP36X/s//635LU415aPIcwyVm8n7VQwoj9NQz4CoI+em+roYj9yJS3DhRU3bDllvepy90SaWzn3x8VYpe1KXskLEtqmAEj7wM2MddFlTvxAojhgoT6eLiWPL2b2gKIIm/rp2nYrAeRcUBRCc9e7OaTJf42kgkdis9nR0IMhR0B0syqrQepFmxjVAl6tK0ziSLVLXSGXNeflJ9to8Ioatd11pjfQ== 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=4HWCIvRxFM4cpIsgvYeaHc9siVQL33dly/L4gU5eXa87o5MMIcOgOU779fDSal2SJvdbUjCVPqUqEqRIv9FUIAz74W03RXo7iCL8NNk0rRqStErSO6EHMk6+eXzPI+zCbkX4e9dBqJpF0EixScUD/DF7QFFi3L+6Hk0yca/XmBg= 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 AM6PR08MB4341.eurprd08.prod.outlook.com (2603:10a6:20b:b9::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.21; Mon, 22 Jun 2020 14:01:08 +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.3109.027; Mon, 22 Jun 2020 14:01:08 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v5 11/14] aarch64: Add pac-ret support to assembly files Date: Mon, 22 Jun 2020 15:01:01 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: LNXP123CA0003.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:d2::15) 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 LNXP123CA0003.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:d2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.26 via Frontend Transport; Mon, 22 Jun 2020 14:01:07 +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: 3a62234a-54ba-4f77-a6b5-08d816b4ba40 X-MS-TrafficTypeDiagnostic: AM6PR08MB4341:|AM7PR08MB5368: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8882;OLM:8882; X-Forefront-PRVS: 0442E569BC X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: mB3YsIRUqcqtWUPyTvhTvr3jJiOu9PfjtI+pMZpxfFJdVEBJZ2Ox915omH4ScFoGx5ovObmYxCKV6QFbTKzhw9zuk5mhyOT40pXDaI/pai/QfUpO4JlK71IyYgvnPCFMaCBIAAJmF409oRNFqgUscytm2xNz99GI00WuvJh3jGtjH9FebOYEZ74eC0fEobdiOZZbvl7Fomo4wVxCfybU5nkTaFw6JiOfh2lhpC/mcya2hNzcOuv7haSng3RNT7QUoeXdUimqhO8Rz21Svp90cYHLxR2qN78+TY/sCDjIYE/eSJNo8N8x38WN1K3Bl7lJKzLyKLDygccWl2eTuDzYVdVvHMS4HEuNRgh0LJ6gYQ87O5gBlEXdcDLE4Pd4JucbUrWV9D1kX505cY0LISXGj+rj0rV67t1JVuyeEErB3dc= 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)(346002)(39860400002)(136003)(376002)(366004)(396003)(16526019)(186003)(66476007)(66556008)(2906002)(36756003)(6486002)(2616005)(44832011)(956004)(6512007)(316002)(66946007)(6666004)(478600001)(6506007)(69590400007)(52116002)(5660300002)(8936002)(8676002)(26005)(83380400001)(86362001)(6916009)(136400200001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: dBDNp9mcuFzn9bchuRBzG/oCULPJ9F7DV9FK3gqzkiaPNCM69rJEiKnaeyv85dhR3zyje/bE5XBR2WxIpO+ECHAJxTZQsjqPEUyxftt+LOA0lgJs0NvW2cRgnhF4wklrdh7y2jae47UaMdFd1r8QuzA5WOPPDxZRqkpebD62q6Cvroj3Q+c9c6vWYvUiQ2PG3A6yLzQKJMyv2yOL5AWD5Y7m/qlVtR8eRBtIUa6zA2T3PgBJ8D71H4xeqGQwvL5YIUjmH4c9DH5Y3NMyReCsb2tBlzlGIKz5PW3f0R/GbsWY2jgSSO+KC7UAV4Qr/iBKtMu+HE1rLUUIROhyk4ExQ0lWU355AY7MPWy4/cm0lntaRdwwVZJuCETk5gfFkN8oAeTMomC/+DCoY1xdrlL6ZxP8T/6YQ1W/k2R1qjiBeDYPv+pDzc7hS7K7MLfO5QcUkz2UbGOgsFc0NhfXz89P62jjJe18sTlnHzR7+2f5AHw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4341 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: VE1EUR03FT010.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)(376002)(136003)(346002)(46966005)(36906005)(70586007)(356005)(81166007)(336012)(5660300002)(478600001)(82740400003)(70206006)(6916009)(2616005)(44832011)(69590400007)(956004)(47076004)(8936002)(36756003)(86362001)(8676002)(26005)(6666004)(6486002)(6506007)(83380400001)(16526019)(6512007)(186003)(316002)(2906002)(82310400002)(136400200001); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 5281d195-1b1d-4017-da99-08d816b4b60b X-Forefront-PRVS: 0442E569BC X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fqgOaFbTclnquAGU89uj5Xr+4lK4FNQ6zuKehD/e1Bi3CJAHn8XmFJsJTluIrFhdXnnPlzISLDDSHnU+vCw/jqTT/xgNI88F/MCvPtJbNTcYxXRR4jNYohAKZbgR3xSWZGRdwNTAKLNqL7AHlkM3sjk5B8Yv1VTv/AP/076n5ECin6vKnHbtMPZ69Z0HUQpzuxmDjIfL+PhInIxc3tpNYKTbMZ+GLhYqGBiDNXmvp/vte8rqYko18Y73+8/J6tNfkGBK5WHnTnLv/4ozC5VH0D6LddEfMAHvI0a8eu3EDTdUVvCxaiSnmqPcm+Im69mA0lZj4mqtHOcnRrpc2tnIhCu87ZAnN4JXagORYYxxDlgPWrsJ4MBxQT5V4saaPHKcq8G3m4VZUt/EMSrzKzSPCvFO7k/HywcWCNTMpYIA+WVccnxNVg9+aP3o+ix2lxlivxR3GglriCvzz/gVGwlqDg== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jun 2020 14:01:14.6520 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3a62234a-54ba-4f77-a6b5-08d816b4ba40 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: AM7PR08MB5368 X-Spam-Status: No, score=-16.8 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