From patchwork Wed Jul 8 12:12:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 39972 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 4194B386189C; Wed, 8 Jul 2020 12:13:04 +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-eopbgr20075.outbound.protection.outlook.com [40.107.2.75]) by sourceware.org (Postfix) with ESMTPS id 4DA5B386102B for ; Wed, 8 Jul 2020 12:13:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4DA5B386102B 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=8Owb/ai7E15+VDGyV7CdP3zOD2mu5GN+coBzjp5WgHI=; b=Pq/P+9XP0mvRiBfeZiFv5nc2Yiqfy9NA5e6NMopGfJCHetMfYTat5UhPyMeqtX1niPZmT37kEAwQ8m6X/mWFvzkfUUlGWYLLCS0NTMqV+1oROVRzbQNP1f6kznTUbgFctIuXSRwYq3cUfloiST733lVRtzpiMxAQYRJt4w/AThE= Received: from AM6PR04CA0072.eurprd04.prod.outlook.com (2603:10a6:20b:f0::49) by DB8PR08MB5403.eurprd08.prod.outlook.com (2603:10a6:10:116::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.20; Wed, 8 Jul 2020 12:12:58 +0000 Received: from VE1EUR03FT004.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:f0:cafe::b8) by AM6PR04CA0072.outlook.office365.com (2603:10a6:20b:f0::49) 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:12:58 +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 VE1EUR03FT004.mail.protection.outlook.com (10.152.18.106) 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:12:57 +0000 Received: ("Tessian outbound b8ad5ab47c8c:v62"); Wed, 08 Jul 2020 12:12:57 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: d85f6582fe1291e4 X-CR-MTA-TID: 64aa7808 Received: from e4b7635fea74.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 997CFFB0-BD70-46FD-A89F-1626776BCA09.1; Wed, 08 Jul 2020 12:12:52 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id e4b7635fea74.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 08 Jul 2020 12:12:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cdPjoFq9tCDMWMDk9OH5z0nN2ywl4g30LGpYx1sc0S7wKIiwjParF658DHTx785OX98T4pVoknWf79pprlNNGzK1cqHYzgQmkFaxHGNdoxuvbamxsJ0ncWmwL5JJXD52c++ciOiD0sknhreqUXiOVTJTeWcbOCE+xeOfpGAtG+cRuHMyCLAntaY014Btsf1ytOhLlcl98lHfyfKo9EvxMIWQ8ZYa7o7390LS0pvra1xPHpRKQzJ6veIddPyTZdab3Kk+TOSGcizmiM5auBJJ73BEyLg848LyEIWCZAmtVeXpBBwdw+RQb4+UTpnlV+3GHEb+d/CPF3GD7vzEkAF0TQ== 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=8Owb/ai7E15+VDGyV7CdP3zOD2mu5GN+coBzjp5WgHI=; b=ZHTi2NGHrWqfJTOa6q8cfBYjgP4Ph11CgwCD+hEpiRQhVzMPhQ50gnhc04O7OJzDDGNmuCQDXImaZISdmEaLUgAmTpcsL9lLE5U6Ky3LskYAsPO4oDOFFOEa1kiU/dfhA02XAMZqP8jwDYS4FPJQ4GENlw/QIGiRWEcOEF5NsrRPpRwd8FS02K4SJ7GlG329sY5mJTDoYfS1VjGCmA6tmJaKFj/KBcoG9L2pstnmGxqOO8AsszLuf6OgBpc+XE9SOjxeNaB0ndHE+bRqvF8xYRFF8r/6dRLg4N53ua8EodNb2rPVU+iRYs0+F1YZuSAwZYkG8q/1lmx5GMl6YQmDmg== 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=8Owb/ai7E15+VDGyV7CdP3zOD2mu5GN+coBzjp5WgHI=; b=Pq/P+9XP0mvRiBfeZiFv5nc2Yiqfy9NA5e6NMopGfJCHetMfYTat5UhPyMeqtX1niPZmT37kEAwQ8m6X/mWFvzkfUUlGWYLLCS0NTMqV+1oROVRzbQNP1f6kznTUbgFctIuXSRwYq3cUfloiST733lVRtzpiMxAQYRJt4w/AThE= 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:12:49 +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:12:49 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v7 08/14] aarch64: enable BTI at runtime Date: Wed, 8 Jul 2020 13:12:43 +0100 Message-Id: <910a949edf217253d82ceb238479e45c5d1738ff.1594209990.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0111.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:c::27) 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 LO2P265CA0111.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:c::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.29 via Frontend Transport; Wed, 8 Jul 2020 12:12:49 +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: 57b14a31-8f7b-44a7-31a9-08d82338408e X-MS-TrafficTypeDiagnostic: AM7PR08MB5527:|DB8PR08MB5403: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:7691;OLM:7691; X-Forefront-PRVS: 04583CED1A X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: CaIl0FLgqv4ceX8tvRB1vhzyNEYT6S9Q4E29N7U9lx05kRgYFr8VaIO62xn3/1U2NP7SjQ0K0ufqY6DL4i7nOA5O7S44GLO4hh7LNaORWKRZMfnqYbWbUT7qBPP7I3lbwyYBSCpeDsjZD7HgxSu4HW0cwh33f2QZ88F0LWiZjvJ4nXlE9Z4Jdth1gMqph2G+MLoCINvOuHDsoSZ14fqVIg4i3sJzrfn4gFQC3bjGd7lHcZ6sE1kwuK4BL8w4lS9Frzeuwtq73TL5uM2K9FKE9l51ZBpQtOjONYhufsNX0GTZYxqHT+Ah1nfddwkAOKimBCxHil3FiAUBShRr/oXfji8VhdvpRxcZcQ+oYnb6J06SUziQYfdBMTUfs47BVXcW97rpmQv58OEjNfBIUwdt+GDHRoWVsv9fRLIKzM5AcvHfiVEzT6QERq2YPnrfQOVgKhTtixCOvBTYAADY1aEhwqHGZTsL9153sk9idzBlEnuG92wc5fl1pB8BCXrr6DoaW4y720AXElMJzX94rIyPZQ== 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)(4326008)(86362001)(69590400007)(6512007)(6486002)(52116002)(136400200001)(2004002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: IW1jkf8m/tplV6m+mP8rfRvzbmpEEPLS0dranjc3aiJ4C1pWCoq1iAEEc/6fXPcboLvRiMW8bayz2SjpsMtnBSodUJSFwj1DM8sTUxC+wjCvdcnS9bRwyMS00rJh4HWLdb6oDjdaDfaxaZ1B0ou2+4k9GTRuEDHnwBI1HK7FzAW3CFr3W6d3QGy/CQxjyw41I4R6OYbBdDXwt/vSZuIR4ncS09ULcO1WX7eUKUecmWih+zs2MKl+L3X370W/60F+ldxxPq5bx2sZdAIDZ8rSApRNt+VkEgO2cI3bXzUyv6cfgGw37Z4igj7dKFS6AdsfiB8VoJz4Qe1uLwFyFrQODQaAjjY+83z7o1gGLbQVWTM+6aGF95oSptk2iuVhLgLUL+03ADKHKkgAOCK+hFJqKKFU75w2O7zXQuMhVC212/Ycz2svC8z4bsX2Gs8tACN6V2hxh+k9wZjnOKXm/4wto8LfS3IsHXBxjv7f/0LqDng= 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: VE1EUR03FT004.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)(376002)(39860400002)(136003)(346002)(396003)(46966005)(336012)(6506007)(956004)(186003)(26005)(2906002)(6916009)(2616005)(316002)(36906005)(8676002)(478600001)(8936002)(4326008)(70586007)(81166007)(69590400007)(82310400002)(6512007)(5660300002)(16526019)(70206006)(356005)(6666004)(82740400003)(44832011)(6486002)(47076004)(36756003)(86362001)(136400200001)(2004002); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 1d61593b-a675-4493-deb6-08d823383b3f X-Forefront-PRVS: 04583CED1A X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bvBhIdld+KnbWeT2H+nQQ7rgeVDAxI585S9wjHKB9nJEtU2d0quB5pjM8OZY6B2ZIuhP7nc/QeCA1zh5Vbgiy8KOQxW2pf+Im6haUkFV2BmoR6WYIu0Y1s7pLvl0deyBgD8K4ydKv+bPGMA3jd/CAO6PZFOveRgNNpx0Fsi7spMb9s7nQ8bPbRoxyXxSK5DWkju6MNCNx+brA0AljpGO/h31LBFRHLj28Hxgd1Y42FzAj66sNge0REcdmVzzmCYJ/qZ5/PVYhvXk95pBGwfUVOTevyP24YmgHQJ/9m/fycbBLEWIs8JyW3fDmhLc3eU/XH4Rp0GyP4mYnnjTfXsMx+TLbhiWudPgyt90EEcuwCNcBVfgSBSj79aCtOBUTmG9jC/IcV9VuQ9viEWm8sm51pcYxQP9d5zShJ4vQRqehQlzzbnja2hSfBwl+YsR2ztJhJzjVbNFidauv0h5imRKG1mRh3+Wg9pPdeSdC22xdd/PNLuYSK1Mkkg+C+jgVVwZ8ovBvFeA48AzXccQ0LPh/Q== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2020 12:12:57.9617 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 57b14a31-8f7b-44a7-31a9-08d82338408e 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: VE1EUR03FT004.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB5403 X-Spam-Status: No, score=-16.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, 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: , Cc: Sudakshina Das Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" From: Sudakshina Das Binaries can opt-in to using BTI via an ELF object file marking. The dynamic linker has to then mprotect the executable segments with PROT_BTI. In case of static linked executables or in case of the dynamic linker itself, PROT_BTI protection is done by the operating system. On AArch64 glibc uses PT_GNU_PROPERTY instead of PT_NOTE to check the properties of a binary because PT_NOTE can be unreliable with old linkers (old linkers just append the notes of input objects together and add them to the output without checking them for consistency which means multiple incompatible GNU property notes can be present in PT_NOTE). BTI property is handled in the loader even if glibc is not built with BTI support, so in theory user code can be BTI protected independently of glibc. In practice though user binaries are not marked with the BTI property if glibc has no support because the static linked libc objects (crt files, libc_nonshared.a) are unmarked. This patch relies on Linux userspace API that is not yet in a linux release but in v5.8-rc1 so scheduled to be in Linux 5.8. Co-authored-by: Szabolcs Nagy Reviewed-by: Adhemerval Zanella --- sysdeps/aarch64/Makefile | 4 ++ sysdeps/aarch64/dl-bti.c | 54 ++++++++++++++++ sysdeps/aarch64/dl-prop.h | 63 +++++++++++++++++++ sysdeps/aarch64/linkmap.h | 3 + sysdeps/unix/sysv/linux/aarch64/bits/hwcap.h | 1 + sysdeps/unix/sysv/linux/aarch64/bits/mman.h | 31 +++++++++ .../unix/sysv/linux/aarch64/cpu-features.c | 3 + .../unix/sysv/linux/aarch64/cpu-features.h | 2 + 8 files changed, 161 insertions(+) create mode 100644 sysdeps/aarch64/dl-bti.c create mode 100644 sysdeps/aarch64/dl-prop.h create mode 100644 sysdeps/unix/sysv/linux/aarch64/bits/mman.h diff --git a/sysdeps/aarch64/Makefile b/sysdeps/aarch64/Makefile index 9cb141004d..5ae8b082b0 100644 --- a/sysdeps/aarch64/Makefile +++ b/sysdeps/aarch64/Makefile @@ -1,5 +1,9 @@ long-double-fcts = yes +ifeq ($(subdir),elf) +sysdep-dl-routines += dl-bti +endif + ifeq ($(subdir),elf) sysdep-dl-routines += tlsdesc dl-tlsdesc gen-as-const-headers += dl-link.sym diff --git a/sysdeps/aarch64/dl-bti.c b/sysdeps/aarch64/dl-bti.c new file mode 100644 index 0000000000..965ddcc732 --- /dev/null +++ b/sysdeps/aarch64/dl-bti.c @@ -0,0 +1,54 @@ +/* AArch64 BTI functions. + Copyright (C) 2020 Free Software Foundation, Inc. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +static int +enable_bti (struct link_map *map, const char *program) +{ + const ElfW(Phdr) *phdr; + unsigned prot = PROT_READ | PROT_EXEC | PROT_BTI; + + for (phdr = map->l_phdr; phdr < &map->l_phdr[map->l_phnum]; ++phdr) + if (phdr->p_type == PT_LOAD && (phdr->p_flags & PF_X)) + { + void *start = (void *) (phdr->p_vaddr + map->l_addr); + size_t len = phdr->p_memsz; + if (__mprotect (start, len, prot) < 0) + { + if (program) + _dl_fatal_printf ("%s: mprotect failed to turn on BTI\n", + map->l_name); + else + _dl_signal_error (errno, map->l_name, "dlopen", + N_("mprotect failed to turn on BTI")); + } + } + return 0; +} + +/* Enable BTI for L if required. */ + +void +_dl_bti_check (struct link_map *l, const char *program) +{ + if (GLRO(dl_aarch64_cpu_features).bti && l->l_mach.bti) + enable_bti (l, program); +} diff --git a/sysdeps/aarch64/dl-prop.h b/sysdeps/aarch64/dl-prop.h new file mode 100644 index 0000000000..b0785bda83 --- /dev/null +++ b/sysdeps/aarch64/dl-prop.h @@ -0,0 +1,63 @@ +/* Support for GNU properties. AArch64 version. + Copyright (C) 2018-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _DL_PROP_H +#define _DL_PROP_H + +extern void _dl_bti_check (struct link_map *, const char *) + attribute_hidden; + +static inline void __attribute__ ((always_inline)) +_rtld_main_check (struct link_map *m, const char *program) +{ + _dl_bti_check (m, program); +} + +static inline void __attribute__ ((always_inline)) +_dl_open_check (struct link_map *m) +{ + _dl_bti_check (m, NULL); +} + +static inline void __attribute__ ((always_inline)) +_dl_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph) +{ +} + +static inline int +_dl_process_gnu_property (struct link_map *l, uint32_t type, uint32_t datasz, + void *data) +{ + if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) + { + /* Stop if the property note is ill-formed. */ + if (datasz != 4) + return 0; + + unsigned int feature_1 = *(unsigned int *) data; + if (feature_1 & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) + l->l_mach.bti = true; + + /* Stop if we processed the property note. */ + return 0; + } + /* Continue. */ + return 1; +} + +#endif /* _DL_PROP_H */ diff --git a/sysdeps/aarch64/linkmap.h b/sysdeps/aarch64/linkmap.h index 943a9ee9e4..847a03ace2 100644 --- a/sysdeps/aarch64/linkmap.h +++ b/sysdeps/aarch64/linkmap.h @@ -16,8 +16,11 @@ License along with the GNU C Library; if not, see . */ +#include + struct link_map_machine { ElfW(Addr) plt; /* Address of .plt */ void *tlsdesc_table; /* Address of TLS descriptor hash table. */ + bool bti; /* Branch Target Identification is enabled. */ }; diff --git a/sysdeps/unix/sysv/linux/aarch64/bits/hwcap.h b/sysdeps/unix/sysv/linux/aarch64/bits/hwcap.h index 4ee14b4208..af90d8a626 100644 --- a/sysdeps/unix/sysv/linux/aarch64/bits/hwcap.h +++ b/sysdeps/unix/sysv/linux/aarch64/bits/hwcap.h @@ -72,3 +72,4 @@ #define HWCAP2_BF16 (1 << 14) #define HWCAP2_DGH (1 << 15) #define HWCAP2_RNG (1 << 16) +#define HWCAP2_BTI (1 << 17) diff --git a/sysdeps/unix/sysv/linux/aarch64/bits/mman.h b/sysdeps/unix/sysv/linux/aarch64/bits/mman.h new file mode 100644 index 0000000000..ecae046344 --- /dev/null +++ b/sysdeps/unix/sysv/linux/aarch64/bits/mman.h @@ -0,0 +1,31 @@ +/* Definitions for POSIX memory map interface. Linux/AArch64 version. + Copyright (C) 2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _SYS_MMAN_H +# error "Never use directly; include instead." +#endif + +/* AArch64 specific definitions, should be in sync with + arch/arm64/include/uapi/asm/mman.h. */ + +#define PROT_BTI 0x10 + +#include + +/* Include generic Linux declarations. */ +#include diff --git a/sysdeps/unix/sysv/linux/aarch64/cpu-features.c b/sysdeps/unix/sysv/linux/aarch64/cpu-features.c index 896c588fee..b9ab827aca 100644 --- a/sysdeps/unix/sysv/linux/aarch64/cpu-features.c +++ b/sysdeps/unix/sysv/linux/aarch64/cpu-features.c @@ -83,4 +83,7 @@ init_cpu_features (struct cpu_features *cpu_features) if ((dczid & DCZID_DZP_MASK) == 0) cpu_features->zva_size = 4 << (dczid & DCZID_BS_MASK); + + /* Check if BTI is supported. */ + cpu_features->bti = GLRO (dl_hwcap2) & HWCAP2_BTI; } diff --git a/sysdeps/unix/sysv/linux/aarch64/cpu-features.h b/sysdeps/unix/sysv/linux/aarch64/cpu-features.h index 1389cea1b3..a81f186ec2 100644 --- a/sysdeps/unix/sysv/linux/aarch64/cpu-features.h +++ b/sysdeps/unix/sysv/linux/aarch64/cpu-features.h @@ -20,6 +20,7 @@ #define _CPU_FEATURES_AARCH64_H #include +#include #define MIDR_PARTNUM_SHIFT 4 #define MIDR_PARTNUM_MASK (0xfff << MIDR_PARTNUM_SHIFT) @@ -64,6 +65,7 @@ struct cpu_features { uint64_t midr_el1; unsigned zva_size; + bool bti; }; #endif /* _CPU_FEATURES_AARCH64_H */