From patchwork Wed Dec 2 08:55:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 11945215 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C474C64E7C for ; Wed, 2 Dec 2020 08:57:28 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E7D57221E9 for ; Wed, 2 Dec 2020 08:57:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E7D57221E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=AHR1snbcXtpakafZoB1GInpFNb7SuM+I2Fa8RvyReRo=; b=IomFGdqMK7NzI0fVyuVeJwlFy O/KGkdRURVB1VPKXeJtms1+mJJXLm2y/GEfPY1NJVUlJa2TLyXjLS0xojkZQjmEOwV/+WHJp2Kb95 UChVvCmA1/zTF9sG+5zFI+E3aOLYb9Eub8qlr+rJINiWYmRY+CBVv+YmT0F9BVp79ixohQT0uUgqL /A3Psivh9HO0Xo7wC1Q5BkfrhbEEHkK9dZKSoQ0aIyxiEcCivnx85LT9UfAguqcM1PBKwTrPWDJQR oR1WUGd2aaK0WPZA08+s0WYJro2pDwpAsXEKWtyxb3/ysIpOhHlwCLSvxwnk70Gb/8XKty0Rxs302 SufS3gL/A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kkNvm-0006Ux-O3; Wed, 02 Dec 2020 08:56:10 +0000 Received: from mail-am6eur05on2057.outbound.protection.outlook.com ([40.107.22.57] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kkNvj-0006UD-Ps for linux-arm-kernel@lists.infradead.org; Wed, 02 Dec 2020 08:56:08 +0000 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=bo4g1VjjeNpD+m+0h54bDJSCv5eSt52W6wWRAK1/PYM=; b=uR0yYnVyuukvEXdXt9RpyTgABejcTt3QG6finUapNKgOUmOHa8nz0Tg6QBtcbYi9lNzMPBmLls8jN9J7veME++VXl4vnoze73i20vK0wvFfWdymFR3eZkdWvDUdJPj0Oe5+gHJFDCU4qn4Kifl1Uq2FADgd4GaMr9bp2GpXG3Uk= Received: from DB9PR01CA0013.eurprd01.prod.exchangelabs.com (2603:10a6:10:1d8::18) by AM6PR08MB5173.eurprd08.prod.outlook.com (2603:10a6:20b:e5::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17; Wed, 2 Dec 2020 08:56:04 +0000 Received: from DB5EUR03FT048.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:1d8:cafe::47) by DB9PR01CA0013.outlook.office365.com (2603:10a6:10:1d8::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17 via Frontend Transport; Wed, 2 Dec 2020 08:56:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; lists.infradead.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;lists.infradead.org; dmarc=pass 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 DB5EUR03FT048.mail.protection.outlook.com (10.152.21.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17 via Frontend Transport; Wed, 2 Dec 2020 08:56:04 +0000 Received: ("Tessian outbound eeda57fffe7b:v71"); Wed, 02 Dec 2020 08:56:04 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: cc848dc2bf9ee73f X-CR-MTA-TID: 64aa7808 Received: from 0fa8f2697906.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 37FA4EAB-0DB6-468C-BFA6-02371FBAA784.1; Wed, 02 Dec 2020 08:55:47 +0000 Received: from EUR03-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 0fa8f2697906.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 02 Dec 2020 08:55:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F1/1/+BFQhLpclKryv/5T9Sqn2L1R9HY1wAPVRAxi8kcy1JI6QIOpY3Thq4jqB6JxAjn78UodcJq9wEaNlCMq+a5wrgK4J2dBTANCTdc5Mg51z4InKoyIUHa2ckirN9FhJw/GTabp+MU0SUiUol8yxvw/pnQNBMs4oRUGgVca/FLhW+msWhBK0nSBioEEEHkSU/a37HCKKP8Bkopj/DvQ02jzsRiL0GEnRjDaNdI91Nj8fPk13yzSk7roy5kjDPikG4eScSmoYaOQtOCZ+NL4v3Oy5PapvQzh2x3OvulxvcScl70KhuG7x40fAuRKg7oWYjn8eOPdXX3s+xtC7C1sA== 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=bo4g1VjjeNpD+m+0h54bDJSCv5eSt52W6wWRAK1/PYM=; b=aiszp8W6+gV9pf6VFMGKYbHYJZvH56b+uhhSJQTvrF9KJnnd6vzrBHf6rj3m0Lb1Ob7uy93M3e/9qjWBOQv6URfu/DO3bb9sY8oc2Ifz27Q8ZXfW+XUw/9PZ2Vcc+w/ndDH9H+Fz+EvvLa5R6+8qn4gPVa2v/Wl4gXr+b/PdshWYTU6lcUrL8RtVODUYrJW/4Te09S9TGArIh0iKN9qUbJGqxO8DbrlX4ijPzltPpRMGFAIopP9Tq8PK+tGloh/MN6F5JkMZ0OVeUUCJ4JyecbYXdCRhMgAK+hpN9PX4xJwp0VvQGNQ4L2gwbHN5lTVtrFTM/fPkQFtYct7dt1kBtg== 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=bo4g1VjjeNpD+m+0h54bDJSCv5eSt52W6wWRAK1/PYM=; b=uR0yYnVyuukvEXdXt9RpyTgABejcTt3QG6finUapNKgOUmOHa8nz0Tg6QBtcbYi9lNzMPBmLls8jN9J7veME++VXl4vnoze73i20vK0wvFfWdymFR3eZkdWvDUdJPj0Oe5+gHJFDCU4qn4Kifl1Uq2FADgd4GaMr9bp2GpXG3Uk= 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 PR3PR08MB5564.eurprd08.prod.outlook.com (2603:10a6:102:87::18) by PR3PR08MB5644.eurprd08.prod.outlook.com (2603:10a6:102:86::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17; Wed, 2 Dec 2020 08:55:46 +0000 Received: from PR3PR08MB5564.eurprd08.prod.outlook.com ([fe80::ac13:db5:ef4:2dd2]) by PR3PR08MB5564.eurprd08.prod.outlook.com ([fe80::ac13:db5:ef4:2dd2%4]) with mapi id 15.20.3611.025; Wed, 2 Dec 2020 08:55:46 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v3 2/2] aarch64: Use mmap to add PROT_BTI instead of mprotect [BZ #26831] Date: Wed, 2 Dec 2020 08:55:40 +0000 Message-Id: <7e800caa0485fec67b21ebab1e27bb23b2f0d971.1606898457.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.54] X-ClientProxiedBy: LO2P265CA0345.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:d::21) To PR3PR08MB5564.eurprd08.prod.outlook.com (2603:10a6:102:87::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.54) by LO2P265CA0345.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:d::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17 via Frontend Transport; Wed, 2 Dec 2020 08:55:45 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7e83803b-964e-4313-bef2-08d896a019bf X-MS-TrafficTypeDiagnostic: PR3PR08MB5644:|AM6PR08MB5173: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:1824;OLM:1824; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: teIoYpkYojRI/jYUYuTkWXQf5GOXRSS2bpllNpYsSAsPClOX3OVjyCp2Uh32oooSxOCi77vFkN2xWjE5gSz8vlBd6gP85FObE6EmXyqhetwurUxpoUV1mK9wEmDniAxbxh2eHfkwON9nsCTI2fjeXryyUgT5CJgl1IsU7mI6ygF2ChXqmsHyChtHj4g/qpsLdTsETxlhBpA3KbP/0dqKAlnfcybwfXcZ1O5JC45tRvjdcoIztdKuzS66o/YC+mijWZluwsmxDn8VDpR3LL2gTC1jLNu/fEkilj69lDKj+1evtS46O9w3j1UorztSMsyrRxYCZ74NnfDMm+zrhfaTZxdL9/k8K4A7P2ol1r3ruW/UYkp6mBSAplhra/0v8d92 X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PR3PR08MB5564.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(366004)(396003)(39850400004)(346002)(136003)(44832011)(956004)(2906002)(316002)(86362001)(8676002)(8936002)(54906003)(6666004)(36756003)(478600001)(66946007)(66476007)(66556008)(5660300002)(69590400008)(2616005)(52116002)(6512007)(4326008)(186003)(6486002)(16526019)(6506007)(6916009)(26005)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: jWjZJ7jpYgfUVyQ90oifYa0y+saFIDNkgH2AZFtIuJg4GU19GLDb1HHGKm3r0WFWH5auFkkLgXYSZKNRjsdmES3r+ltfzUobUxl9PLkaqxCEEjNi1+dT1eENK8P+1MaWg2Lchmz+vRp4ERFM0V5OFQ39q7RBfACr6nNl0LAIjMv/idohamA/O/P0LQ0p9hVvAYfofrum0X7cx1ENvSuVWI0o0sCpZOEnB8mWIVFbYWjAJaXG7rG1WRDSGQCy+q6BownUtb/6an3nbNzIHzJrmihjwdSBW+KR7AVu5N/JKJz5rmXS1/VyrLoznqXd7rbj6CjnEZqGqYfQLDoTGfuZXz/XyNAtK4RmNsSQq28/M2MM/AM63r01EWz4kXAIRr8+E9htuxfHMu2BTQRGZ5NjEawojZ/FOsQGAxzZFcZw2OlRvom9qtmodJEk4eA1C5wtjhn+FGZ8P6xdd+JpIC5+e08dh+5BAxPKYVjsD8uIM5tpcA2mR8LDHlLcgVfPVw9q0sVz7r009/GD5eI1kBep5Snm+7orPb2Q2As+RAAz76N7WaaCXoYWQDEAadhT6I8lCiJMilKU/nmq3PvzpiByfR9TC2jO2gZtq6KACYixmyCYALDQKKfWlTXQLZ50krQNfsAQ3zfn0B3sWI/+W2mzKXYKlvEYZmzebZb8Igpiyc3QJ6TmCmsomMSTlwmZDgAaBcntdNuGB7UU8dosE0jz9qlDFgLsjnEPKBt4mYHiGVJOiSiAmBwiVS4nrytRXBzXPSnaSoH65JjN4GImTmHG4FumUtV7fALtOudtUyRncOn+heFjgpm1LmnY734IbD4qtzGwgYy9XbnGmlFkV7x+FxWtSMwtz4VRqq+IKm+Iam5WngxbYKpP13Ks+T5tVuQVgXJAWFs4qWfgYULnwfn/bHTuIxPPezEXMmFKtBlBZ14nfxAtXgRae23uWbCkeVALJexpcRaqOOqs/tjK9kn0gD3V8jb/muhDZXxd3zEvcWkwdRuEg0U5sXaDT7cNv0Gd X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR08MB5644 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: DB5EUR03FT048.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: d0817323-7a2e-48b1-7f54-08d896a00ed4 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Isv2MwvC+Dj8u+U+Uj9PBR0IY6u3pi0atPpRUuiiwn/lBGQOvgt8Z+qTImzSXi/bFcNYTxrldOZSWSx85pPSdn10uQKCk4ViFcb2Eow7jceqOk574g2QXHDj8LO8bJywPfoGDU9w+uw8cCWPrp+ToawDOcej8eukX3Dn7VkVtlKA/TuC/jywq5oOAaffVFp/AKE57orphb46Ef/JvKsPU+ZTgOaOhrKu1EnenPCV5pWIaJ5qddo9FgEl4SpMDTdXAeSPKhdD70KKeq1jWApNny8XY4jwvRL2/izpzyqR4irKecH7ykwRpz71Z5mARut/RD1SYOF0R/wC7ZzxgLe2xmFw3d7wkgW4PoDZ6kqSPPLP4GqBQkB0b+lBypAo9bw7/6JhS+keS+wbjRg1MJwQW7NBxndKlHuCOkxPKyOJuEg/fbwneoysioxaD0qyFPle 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; SFS:(4636009)(346002)(396003)(376002)(39850400004)(136003)(46966005)(956004)(70206006)(336012)(34206002)(6512007)(6666004)(82310400003)(5660300002)(2906002)(44832011)(81166007)(70586007)(356005)(2616005)(4326008)(82740400003)(16526019)(26005)(186003)(47076004)(83380400001)(6506007)(69590400008)(8676002)(478600001)(316002)(8936002)(36756003)(86362001)(6486002)(54906003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2020 08:56:04.3785 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7e83803b-964e-4313-bef2-08d896a019bf 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: DB5EUR03FT048.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB5173 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201202_035607_976717_9E05107C X-CRM114-Status: GOOD ( 24.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , kernel-hardening@lists.openwall.com, Catalin Marinas , linux-kernel@vger.kernel.org, Jeremy Linton , Mark Brown , Topi Miettinen , Will Deacon , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Re-mmap executable segments if possible instead of using mprotect to add PROT_BTI. This allows using BTI protection with security policies that prevent mprotect with PROT_EXEC. If the fd of the ELF module is not available because it was kernel mapped then mprotect is used and failures are ignored. To protect the main executable even when mprotect is filtered the linux kernel will have to be changed to add PROT_BTI to it. The delayed failure reporting is mainly needed because currently _dl_process_gnu_properties does not propagate failures such that the required cleanups happen. Using the link_map_machine struct for error propagation is not ideal, but this seemed to be the least intrusive solution. Fixes bug 26831. Reviewed-by: Adhemerval Zanella --- v3: - split the last patch in two. - pushed to nsz/btifix-v3 branch. sysdeps/aarch64/dl-bti.c | 54 ++++++++++++++++++++++++++------------- sysdeps/aarch64/dl-prop.h | 8 +++++- sysdeps/aarch64/linkmap.h | 2 +- 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/sysdeps/aarch64/dl-bti.c b/sysdeps/aarch64/dl-bti.c index 67d63c8a73..ff26c98ccf 100644 --- a/sysdeps/aarch64/dl-bti.c +++ b/sysdeps/aarch64/dl-bti.c @@ -19,9 +19,17 @@ #include #include #include +#include -static void -enable_bti (struct link_map *map, const char *program) +/* See elf/dl-load.h. */ +#ifndef MAP_COPY +# define MAP_COPY (MAP_PRIVATE | MAP_DENYWRITE) +#endif + +/* Enable BTI protection for MAP. */ + +void +_dl_bti_protect (struct link_map *map, int fd) { const size_t pagesz = GLRO(dl_pagesize); const ElfW(Phdr) *phdr; @@ -41,19 +49,31 @@ enable_bti (struct link_map *map, const char *program) if (phdr->p_flags & PF_W) prot |= PROT_WRITE; - 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")); - } + if (fd == -1) + /* Ignore failures for kernel mapped binaries. */ + __mprotect (start, len, prot); + else + map->l_mach.bti_fail = __mmap (start, len, prot, + MAP_FIXED|MAP_COPY|MAP_FILE, + fd, off) == MAP_FAILED; } } -/* Enable BTI for MAP and its dependencies. */ + +static void +bti_failed (struct link_map *l, const char *program) +{ + if (program) + _dl_fatal_printf ("%s: %s: failed to turn on BTI protection\n", + program, l->l_name); + else + /* Note: the errno value is not available any more. */ + _dl_signal_error (0, l->l_name, "dlopen", + N_("failed to turn on BTI protection")); +} + + +/* Report BTI protection failures for MAP and its dependencies. */ void _dl_bti_check (struct link_map *map, const char *program) @@ -61,16 +81,14 @@ _dl_bti_check (struct link_map *map, const char *program) if (!GLRO(dl_aarch64_cpu_features).bti) return; - if (map->l_mach.bti) - enable_bti (map, program); + if (map->l_mach.bti_fail) + bti_failed (map, program); unsigned int i = map->l_searchlist.r_nlist; while (i-- > 0) { struct link_map *l = map->l_initfini[i]; - if (l->l_init_called) - continue; - if (l->l_mach.bti) - enable_bti (l, program); + if (l->l_mach.bti_fail) + bti_failed (l, program); } } diff --git a/sysdeps/aarch64/dl-prop.h b/sysdeps/aarch64/dl-prop.h index 2016d1472e..e926e54984 100644 --- a/sysdeps/aarch64/dl-prop.h +++ b/sysdeps/aarch64/dl-prop.h @@ -19,6 +19,8 @@ #ifndef _DL_PROP_H #define _DL_PROP_H +extern void _dl_bti_protect (struct link_map *, int) attribute_hidden; + extern void _dl_bti_check (struct link_map *, const char *) attribute_hidden; @@ -43,6 +45,10 @@ static inline int _dl_process_gnu_property (struct link_map *l, int fd, uint32_t type, uint32_t datasz, void *data) { + if (!GLRO(dl_aarch64_cpu_features).bti) + /* Skip note processing. */ + return 0; + if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) { /* Stop if the property note is ill-formed. */ @@ -51,7 +57,7 @@ _dl_process_gnu_property (struct link_map *l, int fd, uint32_t type, unsigned int feature_1 = *(unsigned int *) data; if (feature_1 & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) - l->l_mach.bti = true; + _dl_bti_protect (l, fd); /* Stop if we processed the property note. */ return 0; diff --git a/sysdeps/aarch64/linkmap.h b/sysdeps/aarch64/linkmap.h index 847a03ace2..b3f7663b07 100644 --- a/sysdeps/aarch64/linkmap.h +++ b/sysdeps/aarch64/linkmap.h @@ -22,5 +22,5 @@ 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. */ + bool bti_fail; /* Failed to enable Branch Target Identification. */ };