From patchwork Wed Jul 1 14:39:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1320551 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=nquZO9Ru; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=nquZO9Ru; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49xkQk2262z9sTT for ; Thu, 2 Jul 2020 00:39:58 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 310D5386184F; Wed, 1 Jul 2020 14:39:56 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10056.outbound.protection.outlook.com [40.107.1.56]) by sourceware.org (Postfix) with ESMTPS id 6E8213857007 for ; Wed, 1 Jul 2020 14:39:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6E8213857007 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=iYgn7j8nOcVKzNfjwSz/8jsWOtsZnZBHqMEDfi+iKLs=; b=nquZO9Ru9hvbGx56pbwG4FkhQWk8/EgVK6/Ew/KL4m5GGKp/d2L7Q6rSTr+iVM4QnMCxey1HssF6F5GmALLgfGlhjLKzr6TSqSVqo+psx6AcahTe6F8FSGBABDCH1qZxkHV+qOmxglmx4Z4xT1n7UAbTORBXF4EhvvK+iWBjuJY= Received: from DB8PR03CA0019.eurprd03.prod.outlook.com (2603:10a6:10:be::32) by DB6PR0802MB2264.eurprd08.prod.outlook.com (2603:10a6:4:85::21) 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:39:49 +0000 Received: from DB5EUR03FT051.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:be:cafe::cb) by DB8PR03CA0019.outlook.office365.com (2603:10a6:10:be::32) 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:39:49 +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 DB5EUR03FT051.mail.protection.outlook.com (10.152.21.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.20 via Frontend Transport; Wed, 1 Jul 2020 14:39:49 +0000 Received: ("Tessian outbound 4e683f4039d5:v62"); Wed, 01 Jul 2020 14:39:49 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: ce107bd1c748112a X-CR-MTA-TID: 64aa7808 Received: from 574d6e514545.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id D9BA8230-3120-4A0C-AAC3-91245CA41512.1; Wed, 01 Jul 2020 14:39:44 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 574d6e514545.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 01 Jul 2020 14:39:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NfR6WIDvr9sfQACNYiwDhn8jW0d7DIas5OMafBYxswxEiO4F1K5/cKFR+86+M/wV519m/JUCQ5sv3Kwa0r+H4v4wC8pvNv+MSMglo/NRqYWh7D1nT1/eSFpG9FEni97Evu0WVtKqhbFH3zN9Q2eN9eXi7/c2QNxHEs8tM7rL6KJFm6AbtdMXUGaOY55sMMFc4MkueL9hRnPs2WxjVJcN6o0VDHg5rfiM9FVcvV24I+0/Tk/FLIYJJcHxO8fKJW2PsPAexngn2+wiJ+nSttCKsFhgCaLdIAO5HIKsMGkAyMKnkkyC2jkaIOBJviQh76+SpHEu4s7lSsyj1sJTRCLE7A== 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=iYgn7j8nOcVKzNfjwSz/8jsWOtsZnZBHqMEDfi+iKLs=; b=lsT6EPOpbif7/JhibAjPu/avq2VhDTMmIRHk+SdRxtfnFqgoKZKE9uCoqD7wGw7gzyw6ZasA+q9FLWV2bn6jz9oIaWgIX5L84qyr2rZyYOvM0dq6JYJPv9wsc++YPYw5AB1+WK8Gf0GJG1BcG1GVtIgtSxs0bOYOObedkoDPaVTOfRpSD1C9MXuBGx/nAJYUSkgjU0NHzBeI5UdwtPtDySxKLS4IYWoD7krxIKY1XE/04oAQz0fb3rzU5MbMG26DFkHjVrPJoFZNNTwTL3uUePEpmagLHKgN3dBp/6VNY5/hqTSSycnxAdZasGf6uN2J6/Y8SNEILa/cRsK27UfrWA== 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=iYgn7j8nOcVKzNfjwSz/8jsWOtsZnZBHqMEDfi+iKLs=; b=nquZO9Ru9hvbGx56pbwG4FkhQWk8/EgVK6/Ew/KL4m5GGKp/d2L7Q6rSTr+iVM4QnMCxey1HssF6F5GmALLgfGlhjLKzr6TSqSVqo+psx6AcahTe6F8FSGBABDCH1qZxkHV+qOmxglmx4Z4xT1n7UAbTORBXF4EhvvK+iWBjuJY= 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:39: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.3131.033; Wed, 1 Jul 2020 14:39:43 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v6 08/14] aarch64: enable BTI at runtime Date: Wed, 1 Jul 2020 15:39:32 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0113.namprd05.prod.outlook.com (2603:10b6:803:42::30) 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 SN4PR0501CA0113.namprd05.prod.outlook.com (2603:10b6:803:42::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.12 via Frontend Transport; Wed, 1 Jul 2020 14:39:41 +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: 58072a01-fb8f-4641-04b2-08d81dcc9be8 X-MS-TrafficTypeDiagnostic: AM6PR08MB3879:|DB6PR0802MB2264: 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: 04519BA941 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: GfuncmYYfARL8ORtvrlYPv7/J10qBJmnwhqOMNl9Hmcr2lDgkHQowAaKUa30hqdpwJMH6b52rgF1iA6TlRaB3BSzbeJlmpfDAik29q5pkVMlhSIDVxXgIzK217onScszw7WSSo8wbMIoD7tPwWe+MkQDA8kcjxE8qlStxQW5sRrgjmx4DJ2biGWZzXDZrX0hFLevAGUMEg3HcYdM/fTSpB4hVRMN14R18GWcbFnDXBjO5/ODPzpVAw6hHng5/WtH41Wy/ZwvXXl5WhqfKtARE1JFEdiK1/7DGPcj+Kb8mDRVj2SYaal8lEPTAi7uxFKdlvUe4VsrEHsLqmDa58O1orGJbFVeUxyIqc8WX1EN9RMVL8uleqmYlC1zTyGHtMXs0ZtfBHkWP/RriZPbaaiMKZ8S1VCPPdH+kvHfwLTiIPVWvV51b5xul/PrOg+9IrqCn7OX7ABnPlUykZsQt5Vq5xRl8sQ+IEcysNKGqWrDCC3CMjD1z1/Evh56eWlQFUD3rBCqhbC2fSJP/X6blx2Owg== 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)(4326008)(66476007)(44832011)(6666004)(66556008)(6486002)(69590400007)(5660300002)(26005)(6506007)(16526019)(86362001)(8936002)(316002)(8676002)(2004002)(136400200001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: lkF9uTyHCqznFWl4qWMexPtykGSpwRg1kV/V2ottZYLJIgHOc7dt+/QyS50KR1D6wOH+K3NdG0SIX2oyFufJ9d+LMvq4aeP8cqTMEJAwDA8yNrTUK0HXL0tTFVdF24qldm2M7inEAOYoKUtGJK74V0XtESWWqrGn3B4PDcr3uwfiQfEQnIn8N6y7ILD2DCMnpzRG7TYQnR6U952v1QrdFb2/dhlD+ipaL3EW+VHbXxsNC88mFCX44WCg0nTzYhnVQ1Oj/eS9eBSCqoCUXxtMRWE088bz8cjwR5mKsBjNJAjZTYnAvZZHtXHFWbaU/6OthhJzbtu5KtU1q9yDbmpZar0XKHEB+u8zKGyYw9rZ+hC1Tr0/bfkURtL56RUJgN/af7ZgrofoXX8JtVvHB7yOUBjiJoy/W2pQATPDWJdPzhAQ+dEVJgHlhYGkREP4k+B8ORbL6rFOoTVFQiDyZ8PPbnHeQ1o4atay6VRWRdcicb6/uI+f8g/4BJik5NErysdF 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: DB5EUR03FT051.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)(46966005)(69590400007)(70206006)(956004)(6506007)(44832011)(70586007)(6512007)(2616005)(336012)(4326008)(86362001)(6486002)(16526019)(8936002)(2906002)(82310400002)(6916009)(186003)(498600001)(26005)(6666004)(81166007)(36756003)(8676002)(47076004)(5660300002)(356005)(2004002)(136400200001); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: ecf0a2f8-2257-4398-332f-08d81dcc9784 X-Forefront-PRVS: 04519BA941 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DwtkriqYGeBCC+vVVkPI9RFi2lsEecVzoVb2IdmZKWJAKIbN62jw2T1ncaY3EphSx7LeNZ8/9PYi3rVVHLg0eno6v/gioZkvf7wpu0vIApc1uMxxE0H8kW0WjXeEw2SkZir+JC+r28R4Du2nmAeebK7XAGZMi1lkJqvVhR3VnEt0HYe9YXudxOOQkbarOLlRk5RRoi6ONcbIC5K2S4I3Q9T3WiI7rffthSOwDX9UrrJqfY38Px+jzEKuIWGyT423Dbu1d0aRsvmt8wYxJ+yC4b5K3ctI/au/sZuFsnTlDN41bqW3LVNhwoJ/27jrV1Gmm385xRRwcS27haPbCBU64A1+NDHq1KkWYlOmWZmfw4YvzXN3qVegQmv2IjyEK/YI6i4UheQpFy1Q0ZXnyzzJY/SBVFJ7t4Lp0lkJfiYnQxyqrepLFzrxX7ZeRT9rz9ECiQlvR39xDpJ1G3q+IQwIsEuby5e5hhGRCGp7YHEuLA7iEuJSGgwGfvpC9Jm1dx33OTaQKIRb2uJOnoRNQ4IlGrh3cV5UPd81us3QYS4Wa4IsQe0tKH6mCjoevo6EcsW2 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jul 2020 14:39:49.9043 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 58072a01-fb8f-4641-04b2-08d81dcc9be8 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: DB5EUR03FT051.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0802MB2264 X-Spam-Status: No, score=-16.3 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..3c92377cc8 --- /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)) + { + ElfW(Addr) start = phdr->p_vaddr + map->l_addr; + ElfW(Addr) len = phdr->p_memsz; + if (__mprotect ((void *) 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 */