From patchwork Wed Dec 2 08:55:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 11945213 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=ham 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 4807CC64E7C for ; Wed, 2 Dec 2020 08:57:16 +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 547BC221E9 for ; Wed, 2 Dec 2020 08:57:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 547BC221E9 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=f3Ks3oZGILl4KiL++cP28sGr0yKjAzhXxRBUXh5QnmM=; b=RbaQWHdy5mKM5Q1VWAuVKz98/ qPAoipGMh7/ZPcffGB79yJurQLfxwcc6aAuSrhTf7fsSGEq0//0GtdvHYdJ7iQWbzGTJ1niJzV3k2 Al1I6ocX1rjtGHf9V9eC2vlL+ZXidck7PS0ONu64FLEHQKDTIrM0vmmESV4pjD5AtYPwtD/Gusu/M 9HNdE1YL9tQb4otdMgFm9zSwJ50d/MJSvI4eukHIp6UNk6KrCMH/v7cfyQZeofJDB0gZwqTHwBkVF RJqY3Ml7HTsovVqaxm25vwf9RM0VGl1QW6CZy/GGlGNuiN0vxvOHXcL+6D8wGfn3+ZA+OoX6IGVlD e7AYv8bzw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kkNvW-0006Sp-Ft; Wed, 02 Dec 2020 08:55:54 +0000 Received: from mail-am6eur05on2074.outbound.protection.outlook.com ([40.107.22.74] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kkNvT-0006SA-Ng for linux-arm-kernel@lists.infradead.org; Wed, 02 Dec 2020 08:55:53 +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=NXffKCVdJsUjKE9yUrpY+buHuATx7T0FPdE9nZs50nw=; b=vSMTNbXrQU5lwa5eZUsj8zsbVBkCsrSg4o9mnBiB0hyEeAZRDUWimd+2CenBqpwq8XpmL6f0wvcRKveRBBVEEMFoFue4/XI73ekbfeyZwMCHC0w5JAbEBwED8WTrkLeuqLJVnL70cs/vzESWQ2H9ZjUxfKqJSXcV6xfMvyu5+GU= Received: from MR2P264CA0169.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501::8) by HE1PR0802MB2587.eurprd08.prod.outlook.com (2603:10a6:3:de::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20; Wed, 2 Dec 2020 08:55:45 +0000 Received: from VE1EUR03FT019.eop-EUR03.prod.protection.outlook.com (2603:10a6:501:0:cafe::43) by MR2P264CA0169.outlook.office365.com (2603:10a6:501::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20 via Frontend Transport; Wed, 2 Dec 2020 08:55:45 +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 VE1EUR03FT019.mail.protection.outlook.com (10.152.18.153) 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 Received: ("Tessian outbound 665ba7fbdfd9:v71"); Wed, 02 Dec 2020 08:55:44 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: cc6684c77939eb35 X-CR-MTA-TID: 64aa7808 Received: from 18861434d5cb.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 82D6A3AF-2B19-4BE3-829F-D7F3941207C0.1; Wed, 02 Dec 2020 08:55:29 +0000 Received: from FRA01-PR2-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 18861434d5cb.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 02 Dec 2020 08:55:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E12fujD0czzKZF+/mnx/FUkpEgw6pnYl4yx77VuCXJQIWv/0hD1JLGepDHBN6iRd13QSPrCiv+rjt92W6xR0ruKqmlWvLBNKnQ1j+3t5d30B3lxLVnrzG0aYqGBsE3cWwX2A9DVIliVwfsykyVg6M58IQf6Zxt90g2Hg5kKadYtEx9GCv3DXfIg+uwHx8Dhmmt2PDnEaiV6c/4Bo3AoHtI51+86RXPh7XfjAr8vCkb/3mxR0gb7Ki1OA3zB5JV5xWx7QuZ3aE/boknhPOT1MKj0OcwFZtAsAhBlNOEpokc9N15I733Kzv9LNAX39m40wE6PinyZhaHa+ZZnFxoUGjw== 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=NXffKCVdJsUjKE9yUrpY+buHuATx7T0FPdE9nZs50nw=; b=Z4eSfQchURAByrWGoERGguHqXjUcbJV/AVExA+U3XTWM+86JEWE8osrzxHezhvL5EWdvYVqTSYzHBjvbiCFzPXCI/6kNQgij3krKVSfB/zjgwo8y8zxFaBHf8WSto7rCyEy7Oh3SjyyfdYpu2OSjdnBQf+hEVjkIhDHLNEudvEX0a0n3h2QqCN/EnxOngHbJEMwkpiyOEOVUOmNJ6uBDeh78pDbVuCfhnrAiTYqWrS0vPZgQ+AgzvM1oyKCJzlV5YF/ApGHWEap5Z6lcisO+0XIRqjq+dz8qFMddI8tcTnLWRBsvfoPuKWFz/jj5yefvOzP5CFUI7TivJRpPw1c8Sw== 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=NXffKCVdJsUjKE9yUrpY+buHuATx7T0FPdE9nZs50nw=; b=vSMTNbXrQU5lwa5eZUsj8zsbVBkCsrSg4o9mnBiB0hyEeAZRDUWimd+2CenBqpwq8XpmL6f0wvcRKveRBBVEEMFoFue4/XI73ekbfeyZwMCHC0w5JAbEBwED8WTrkLeuqLJVnL70cs/vzESWQ2H9ZjUxfKqJSXcV6xfMvyu5+GU= 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 PR2PR08MB5225.eurprd08.prod.outlook.com (2603:10a6:101:1c::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.31; Wed, 2 Dec 2020 08:55:28 +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:27 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v3 1/2] aarch64: align address for BTI protection [BZ #26988] Date: Wed, 2 Dec 2020 08:55:14 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.54] X-ClientProxiedBy: SA9PR13CA0048.namprd13.prod.outlook.com (2603:10b6:806:22::23) 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 SA9PR13CA0048.namprd13.prod.outlook.com (2603:10b6:806:22::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.5 via Frontend Transport; Wed, 2 Dec 2020 08:55:24 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f8d68dc2-0a18-41db-6725-08d896a00e69 X-MS-TrafficTypeDiagnostic: PR2PR08MB5225:|HE1PR0802MB2587: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:2958;OLM:2958; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: XQm/MD2nC9jVAqH51R5remRXNMVEC+ZEC8vuP0FPtPiCjKDYxT4QJtW9W6xRWtUGwXiSBCjFPVgKw3kjSwHWeLeMVieRew979/C4K4+VzaDKfxN7rGstWPMzrUR95VP9qlVztwGR9E7+d9HNirN1YuXK1UmcR4WCRfGs2VtgiP2csdDOmNJ3wngbHEWDqogmIjAqLr+9zFALTCjVdYcLX7Cz4IkYjTOh0S0XkperrBQWCQe+ftzD2Q9zPe8azjoP5OwGyh4upVI7Bc6pBYxX45DSe+GyXPk7hUU8squfCQiUpKEUn8TIGMkyDFKrKPB4wQF5jEA9415q8fTA6jXhJPX2nE87pWMwJsJZz7Qtjb2ORxc3Q9p1jb5Grom5vzdn 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)(346002)(136003)(376002)(366004)(39850400004)(396003)(6506007)(6512007)(2616005)(6916009)(2906002)(4326008)(86362001)(36756003)(44832011)(5660300002)(16526019)(316002)(956004)(83380400001)(26005)(52116002)(6666004)(8936002)(186003)(66476007)(478600001)(66946007)(69590400008)(66556008)(6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5Jt4n4ttnYO X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR2PR08MB5225 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: VE1EUR03FT019.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: a1bf3ed6-a11e-46b9-875a-08d896a003ba X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XeeQnN60H/CmqJGgpqix8vGCQAfDJLM8WqaiMkNiY6iwnvouwIB99kUsSs4WvaieexOhlaV62ryfV3bhTR0qcTdBR3wt+NKs2Y0bU4O2CkQxccUnYvm5PLfAJaNiNukfq/Krqq5BJDEId5eISd2eoYJOwDxYh5yiGn/3W1rgFG7gq+LCYlTx9IbfHKqSbwjQRCgtYWco+f1U6V+rBUtDo692Dd0Arp2S87/19h9NDU++x283mQgkaYwT6ISaJrLyThEyaJ94QQiW5Sykii6rYrbA+wwjnyT8XsacjkiC0MQulKK3ZCqzclJa8RLEu3lR5WQg95Yvh0S2NzfAxT3YX3ZJZNn+n+iq54O4GAKb0oxFCwKfzKAM/x6MXRfebp8zF9NtuWh2/j7pygpfEuspG+bhqlINCG6wcPncFJDBcnUFfNqo5UhrvjA0gXr79sRn 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)(376002)(396003)(136003)(39850400004)(346002)(46966005)(81166007)(2906002)(44832011)(956004)(6512007)(83380400001)(2616005)(478600001)(6486002)(70206006)(70586007)(5660300002)(8936002)(34206002)(82310400003)(47076004)(36756003)(82740400003)(69590400008)(8676002)(16526019)(6666004)(86362001)(316002)(4326008)(186003)(54906003)(26005)(356005)(6506007)(336012); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2020 08:55:45.1928 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f8d68dc2-0a18-41db-6725-08d896a00e69 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: VE1EUR03FT019.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0802MB2587 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201202_035551_827067_4AB2F727 X-CRM114-Status: GOOD ( 15.79 ) 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 Handle unaligned executable load segments (the bfd linker is not expected to produce such binaries, but other linkers may). Computing the mapping bounds follows _dl_map_object_from_fd more closely now. Fixes bug 26988. Reviewed-by: Adhemerval Zanella --- v3: - split the last patch in two so this bug is fixed separately. - pushed to nsz/btifix-v3 branch. sysdeps/aarch64/dl-bti.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sysdeps/aarch64/dl-bti.c b/sysdeps/aarch64/dl-bti.c index 8f4728adce..67d63c8a73 100644 --- a/sysdeps/aarch64/dl-bti.c +++ b/sysdeps/aarch64/dl-bti.c @@ -20,19 +20,22 @@ #include #include -static int +static void enable_bti (struct link_map *map, const char *program) { + const size_t pagesz = GLRO(dl_pagesize); const ElfW(Phdr) *phdr; - unsigned prot; 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; + size_t vstart = ALIGN_DOWN (phdr->p_vaddr, pagesz); + size_t vend = ALIGN_UP (phdr->p_vaddr + phdr->p_filesz, pagesz); + off_t off = ALIGN_DOWN (phdr->p_offset, pagesz); + void *start = (void *) (vstart + map->l_addr); + size_t len = vend - vstart; - prot = PROT_EXEC | PROT_BTI; + unsigned prot = PROT_EXEC | PROT_BTI; if (phdr->p_flags & PF_R) prot |= PROT_READ; if (phdr->p_flags & PF_W) @@ -48,7 +51,6 @@ enable_bti (struct link_map *map, const char *program) N_("mprotect failed to turn on BTI")); } } - return 0; } /* Enable BTI for MAP and its dependencies. */