From patchwork Fri Nov 27 13:19: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: 11936319 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=-11.7 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 71E39C2D0E4 for ; Fri, 27 Nov 2020 13:21:40 +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 7EE832222C for ; Fri, 27 Nov 2020 13:21:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="EwQkiO4W"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="lk8vgOFl"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="lk8vgOFl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7EE832222C 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=RoFudy7XBSbGnUcjmkpck0msfDi8GD7paamYUJRvJGk=; b=EwQkiO4WuTpRze/yFG0qM0pqS 6pO2+W9WnpKMN5YqUkRTl0Pq2lEfavVpkM9ATjAPadB7W85tMHY9vlpV+1+BLB1xwYdeqe0HQ73u6 QTrx/Pmeil1rwnxTAuPpXuq0KLhJRrAqzrjFHgCePeBuAbHwoIbDGiqrywUjeeZ/AT8b16WnTE4mP 9PqY3q2V1baXI1/ZJuqBLsHudtiiCh/easinw1n+sgCx7+HFpsOenxfhjxqeNMJwElZTSPLxmW0sR BE54FJOjYETM/9d+ba24ZAqnlg0cc6ifFt/9PMgpY6c/KckNIwiQgWcOASOpIACQREdYw+GFfnhxP J1U1aEVLg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kidfW-0001Bm-07; Fri, 27 Nov 2020 13:20:10 +0000 Received: from mail-vi1eur05on2041.outbound.protection.outlook.com ([40.107.21.41] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kidfS-0001AS-Qb for linux-arm-kernel@lists.infradead.org; Fri, 27 Nov 2020 13:20:07 +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=9A7jyF9nJCx5qjd6mb9MA3ZfKz/fr2f9ttL3ctZTfxQ=; b=lk8vgOFl6kVbdcta8kFUtSd1hJYDp9QCkl6batXCJkSbVOeryHM11FJ2iLumDR33dDjlg6GjArUcebLdZhB+6wBPqZjy5yHXyhNLeL8tO0vga3c/MGhLzcyQ9JUn9ZhATsfrIxPumljWkKnoB4KSiAgMp0VVTwKUTKRCQ8FD82Q= Received: from AS8PR04CA0019.eurprd04.prod.outlook.com (2603:10a6:20b:310::24) by VI1PR08MB4557.eurprd08.prod.outlook.com (2603:10a6:803:f5::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3589.21; Fri, 27 Nov 2020 13:20:03 +0000 Received: from AM5EUR03FT021.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:310:cafe::8f) by AS8PR04CA0019.outlook.office365.com (2603:10a6:20b:310::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.22 via Frontend Transport; Fri, 27 Nov 2020 13:20:03 +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 AM5EUR03FT021.mail.protection.outlook.com (10.152.16.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.26 via Frontend Transport; Fri, 27 Nov 2020 13:20:03 +0000 Received: ("Tessian outbound 39167997cde8:v71"); Fri, 27 Nov 2020 13:20:03 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: ed2580a6f81f2e3b X-CR-MTA-TID: 64aa7808 Received: from 101fef75b2b3.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 3020D548-B854-468E-AD38-42394A12F666.1; Fri, 27 Nov 2020 13:19:58 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 101fef75b2b3.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 27 Nov 2020 13:19:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SthThQMQPbTk/YiRyPCygY0nI/tM7T5S87cxpXX7GyX/UZQWuj28wYJ9QK/LyDVe7VoApn5QfnF8zIuZae/LQODqeAUcDq7D7LJHwmGhybgKvp6ziz757l35iGQ/Il04Eocw2G7+iImCzbna0BX7WvbaU2/afbJLuOLT3A3f1p5qaxbfa8DozM7hqqW7G1+4hKf+5QeCk1eW0L4KdnuJQGq8BmW5o/nI3lpFL5zNH/rPpYSkfHjBnvcpSSz6GGm5/ruYTe69c/MO+4fsD9Fi9k0pBhpOF1xvQpI2k3rQ6Wy84kG0ZUn/hLEOCsFCk6ij2Zsamg2/tPu+X5kcH0spxQ== 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=9A7jyF9nJCx5qjd6mb9MA3ZfKz/fr2f9ttL3ctZTfxQ=; b=GpGiTrR6ZE0P7wuT59kguCB0pkOIA+UwvPRo1nrjo5+Cp6qr5Au6g31nzVZ6C9+vRwpf6yZj8slOcZdj7PZzEJsK2iglPx7jNfYbK4ZPTV8XPz/kT66duwaTDRdGQ/12aZyAsduvReAZXFtbVYPsqQryPJnLzP+/z3GVRB2UBJyGRj6j4ks9WWHWkVvz9dj+JO0gq71mH0MOrLtdeVHMb3/ByQaxdipTLl3v3CUmFJIe0ATq1hOu/omJMW3ealy+pjeIxclz/OxXhMOvoE5DE1/Dksnpn8BpahIXl9UuyPGXljbpBPTBNwiDf7b9Hj8eP5o53ijrIjmeWt3TGHlRig== 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=9A7jyF9nJCx5qjd6mb9MA3ZfKz/fr2f9ttL3ctZTfxQ=; b=lk8vgOFl6kVbdcta8kFUtSd1hJYDp9QCkl6batXCJkSbVOeryHM11FJ2iLumDR33dDjlg6GjArUcebLdZhB+6wBPqZjy5yHXyhNLeL8tO0vga3c/MGhLzcyQ9JUn9ZhATsfrIxPumljWkKnoB4KSiAgMp0VVTwKUTKRCQ8FD82Q= 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 PA4PR08MB6014.eurprd08.prod.outlook.com (2603:10a6:102:ee::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.25; Fri, 27 Nov 2020 13:19:57 +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; Fri, 27 Nov 2020 13:19:57 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v2 1/6] aarch64: Fix missing BTI protection from dependencies [BZ #26926] Date: Fri, 27 Nov 2020 13:19:43 +0000 Message-Id: <8756cc1083eb4cd93d3766cd39b2f34b6623bbcb.1606319495.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: DM6PR11CA0031.namprd11.prod.outlook.com (2603:10b6:5:190::44) 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 DM6PR11CA0031.namprd11.prod.outlook.com (2603:10b6:5:190::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20 via Frontend Transport; Fri, 27 Nov 2020 13:19:54 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 2616cbd0-ac5a-4775-babc-08d892d726ba X-MS-TrafficTypeDiagnostic: PA4PR08MB6014:|VI1PR08MB4557: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:6790;OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: uSOwfWKWO7RxbVFSGdFP/D5GTUPDuWc6xJHr7c2rKOJx6XtCt45M03i7MD4PK3VtDRWG0coWsJjud9+eS9NV1vvzyY+na74m5ImrbrJJBkyUb3StlEcpihIkClCgAr7UEcRNF+apCI/27rWWsJOR6cYafjGzw1odfcoWw+aWv6MYNYh9bT0WAFqczem3BfDdQjLiOtt5tIC+VY2BID/p/gerYuv+UBUuuzPZRToaBaVIM8rO4iyhqSj87Ijy+2eV8YlyhohWNRObi/zNTYl/+gNCYbr7+IeBVNgKZILxTMq4jiu9RTrIM1eTTY47c4bIieKNBivTlRRoxeorr7Q8xZNHPDAJ8vMZ3WxmCaXMVxOKSlq2LhRwptAZOWVlNJhk 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)(136003)(39860400002)(346002)(376002)(366004)(396003)(4326008)(54906003)(69590400008)(6916009)(6512007)(36756003)(6486002)(6666004)(316002)(478600001)(5660300002)(2616005)(86362001)(44832011)(2906002)(956004)(8936002)(16526019)(186003)(26005)(8676002)(66476007)(66946007)(6506007)(66556008)(52116002)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: mE0W7bVcxrzcoVIn/VsONJxpsphrN/LkSiNomsqtOsOC3e0N1nrc341aqCU4R2J+YZKxtOPrETF6gwx1S0FRj8qq7NB1X29cF5vsWJVHw5dv6/2D7bzmjzPhm42EGMzdCEJz/1MKzqONSC/TtsD00YDY7Gx2semgeWEHgS1oWrmE6kBFo9J2snqrjThRD346+X1Gadu0TuAdugaA0eVrdlkakrPdwqgWsh+CXn3PlHxoSApq1NmR9dFHNIzqMJeH04rfZeo9mP3t5p2mm8K77dVyVJzGiKj1l/TMkadaatwfVfQgCQiDC5Kk4AF2B8XMeVppDtG+LDXmbcnWRISGcOAN3hwEay0WZL4d+myfOENIkyQ0clcbamNWybUU5kGCgeaMVBXqPQGVphwkveIuiRqgZRgUNPD6W5Z9ZlJYB3OdOH4RouMLHK7JnaZd1IzupglxEv1AAGQ9FaHt01etzZhL/cGuATAngROoNINu53r4m9MA6aH/rNc3qTrA16cs7ukEem04sEk5/psQ0SNnJHbD9/iUZKioyxsHRSIPTiJo6E3b63jmfMsqxhKHTSZ2Uo3oXkboo87BERejQaGbjbc64P6gyno7uRytQ5rx4OwKOM9qHVED4U4An42sLpwcN1fCZMUe0GZXpOFpZ5UgKvTavmAKmqP5NLaqWg88ssisgj0c+3XK26Pn0ryxbJSQm9s7GQssys/QgRW+i9Jo7+tcf2y0Bf/jiwdMBh9f2yJ7KIQpAaJrPS7LwfPCyip4wxx74XLdeJw1tZLKaq5+VeAhEhtLQEbJS4+Vb0I2ytXihAWQs9rtzYzJl/+aJd50c0tM32DllryjnKFdNEmIjiJ520/0h6diOFw+DXPLRCBDLcwinAvPxhyEOyoLlYGESM8zEOs1mGWKN/FEjRJqSmjt0Pk5QX8eHJzRo9iPGLbd81273R06CyVXqFLxct2zdQvUQ8vrw1Su9Jc33BuQHzLig4nRpzpPZWV3TW40Q+Pajmw4UkctetstoG3jCOzK X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6014 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: AM5EUR03FT021.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 452f73ad-b22f-4e13-96b2-08d892d722a2 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PMbqhQhyJS4sQdCEDh1WRhDhYI3Z/pBRFf/QY5YmQvD2i9p2ULuWc/gD0CulsjiGh/+p8lrC9ApS0J7AkKsQvg4yC1ZqiaXcgOxzcgVLwvptDj36q+Tma5NW2sYBSxssf0vX8+OVgS89wz+NAiw5Nkf0WC3OkjUP15Y/mQ3tI3XZ3/ua+9/XMQwfOaQKh2vkN4RqO0Ql/oZ8eFm7XZU4d3xtNlA+LwoLZpOJ0h+w7k0EqldF/n1Cxw9Jrqirwf2n9a0LDaPsqq9f1avHVlaYvSGHFLsVunr6HqV56KjpYCrkJyrSuowlWH4Vb/O3P4Hx3FHJaZH6fMJhtTP0YnMCJRKY7YKJ1drgec9XpragjzaEPpyVsAp8+tU/LTxLisLHk4wAKtUEwwVGgvqd/Kh5H43osalSW+yb1w1ROD7hwNJpPfQN7PVG81hkhJJUp4dD 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)(136003)(346002)(39860400002)(396003)(376002)(46966005)(70206006)(316002)(16526019)(956004)(8936002)(186003)(2616005)(70586007)(69590400008)(82310400003)(54906003)(36906005)(86362001)(44832011)(36756003)(2906002)(336012)(82740400003)(4326008)(47076004)(6486002)(81166007)(6506007)(356005)(6512007)(34206002)(6666004)(8676002)(26005)(5660300002)(478600001)(83380400001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2020 13:20:03.7561 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2616cbd0-ac5a-4775-babc-08d892d726ba 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: AM5EUR03FT021.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB4557 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201127_082006_887868_6B632617 X-CRM114-Status: GOOD ( 14.97 ) 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 The _dl_open_check and _rtld_main_check hooks are not called on the dependencies of a loaded module, so BTI protection was missed on every module other than the main executable and directly dlopened libraries. The fix just iterates over dependencies to enable BTI. Fixes bug 26926. --- sysdeps/aarch64/dl-bti.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/sysdeps/aarch64/dl-bti.c b/sysdeps/aarch64/dl-bti.c index 196e462520..8f4728adce 100644 --- a/sysdeps/aarch64/dl-bti.c +++ b/sysdeps/aarch64/dl-bti.c @@ -51,11 +51,24 @@ enable_bti (struct link_map *map, const char *program) return 0; } -/* Enable BTI for L if required. */ +/* Enable BTI for MAP and its dependencies. */ void -_dl_bti_check (struct link_map *l, const char *program) +_dl_bti_check (struct link_map *map, const char *program) { - if (GLRO(dl_aarch64_cpu_features).bti && l->l_mach.bti) - enable_bti (l, program); + if (!GLRO(dl_aarch64_cpu_features).bti) + return; + + if (map->l_mach.bti) + enable_bti (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); + } } From patchwork Fri Nov 27 13:20:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 11936321 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=-11.7 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 C7504C2D0E4 for ; Fri, 27 Nov 2020 13:22:04 +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 4260A22242 for ; Fri, 27 Nov 2020 13:22:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="V9KGZQ78"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="taFM8hUg"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="taFM8hUg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4260A22242 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=TLdz6s9rguoKiMvaWrIY9zp5GQ4abSnBnBIzzzGXVq8=; b=V9KGZQ78X0n6ZRfY2Laq9Pl6E xD0B4kdHH238ZowcUOWtxg9VvZ9CZKJFAC2KPA7C1ZnrD9fLy/gOsFE4PF+VSxY/c3VjCi6UXhGfu jXTelbjDrBP55sFQOuW2edV2KWGm5V8hk/23cUELKQciv9wsFJS4n6ie0nYkQMYOwdFksXoNFrLtm B/GnNAGaiUfvqKSuVp5YOUTjfO5XU5zLG/RzNnvNbPYU82VYOxUbSTV8NQDyRWWV8GudL/F845y87 l6sC1lNAvH2cFidXUh0P0ImQ0XnelWTW2Jk0MoEi5eC3GkvQbCpHOqa9ucNG9rS+P9qmhqp8NJNI3 BMzWDvgyg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kidft-0001Lb-HH; Fri, 27 Nov 2020 13:20:33 +0000 Received: from mail-eopbgr70051.outbound.protection.outlook.com ([40.107.7.51] helo=EUR04-HE1-obe.outbound.protection.outlook.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kidfq-0001KH-KU for linux-arm-kernel@lists.infradead.org; Fri, 27 Nov 2020 13:20:31 +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=slIbyxS48hCYiEWuhWEE/Oa6nVJ/gAblbWHjFFkv6s8=; b=taFM8hUgOnIBKEaVp+Zor4s+41Ip+tHCUhiyztCmtIpD5YeVOJjq9A/pwCFBx0QQXUqMm9ia5ucqRPGYJJmGiEAhY7wxNUfx5mBWX01Uw46fd4KjdsU/OyX5YfYnbOfgdAQJAtQCHU7HeMY3DKk1sZkgabT53BGpQpYouBuYNI4= Received: from AM0PR04CA0032.eurprd04.prod.outlook.com (2603:10a6:208:122::45) by DBBPR08MB4757.eurprd08.prod.outlook.com (2603:10a6:10:f0::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.21; Fri, 27 Nov 2020 13:20:25 +0000 Received: from AM5EUR03FT015.eop-EUR03.prod.protection.outlook.com (2603:10a6:208:122:cafe::6a) by AM0PR04CA0032.outlook.office365.com (2603:10a6:208:122::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20 via Frontend Transport; Fri, 27 Nov 2020 13:20:25 +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 AM5EUR03FT015.mail.protection.outlook.com (10.152.16.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.26 via Frontend Transport; Fri, 27 Nov 2020 13:20:25 +0000 Received: ("Tessian outbound 13ed5f5344c0:v71"); Fri, 27 Nov 2020 13:20:25 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: bfa20ae54c0ca7b5 X-CR-MTA-TID: 64aa7808 Received: from f4644680f99d.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id F327C572-4EB9-4F9D-8108-BC04F72577C4.1; Fri, 27 Nov 2020 13:20:17 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id f4644680f99d.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 27 Nov 2020 13:20:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Uk5XPL8mkiafvct1eaKa4RBqBatDaQwqTzHoEy14pGTxqT7al/UhhKS6DHdkUPQhVebf42At1tIlRFh2Ug3mi5bXQEbq+xa+rn2lVVk5U8AtpbFWwn9zPMoYt2hiaHsship0Eb4OThqYQRZDHrOlWsioGNXXmrY5vJpI9CkAAlL1xiZti42O0reT91jngtyNWujUGrRMrUAGQhpNQ9pgKG+0JrlgWOIb+Dd0KJB+eFbD2Z/sxTPSoyfUmwlqAzf+r3YExhAWB5d8hmgXHudbjz7zIA0M3gJ3KrMkOviSfAwFkexDOBijlhXFizEtjBD/WTLJYHAhMQZnWLZZrA8mWg== 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=slIbyxS48hCYiEWuhWEE/Oa6nVJ/gAblbWHjFFkv6s8=; b=jmLMu9SpaLUbY2sWMul9koJYiQdpwb719i2LbKrOWWk0UR6RgrfLj4diYVpolmSbPiWqkIOwBQSxAvu29+VDdC2Fl/tAOqV3CYYLLR+bQLxy6a4AivgJNIj3ElIs0YrWGncuJwDW+j+WGdbpjKzq16Jy6lnkUaUZL2zcHvX8ZYL3Fogdof8SDu10LTXD7RhSOdxviRcIMZo3gEuoKrK82ztauuzOONsAJXL6gQs9GmqJLBkBDaxCD7Rmr1eucOS3S09UF8OGUdSlt8kaYvrD4QyxZA6vlZTwpuMBh9cICnZmdN9e6wZ2oEMjc8JWWCAqjIYKkTZKtZyQGjIzNskgow== 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=slIbyxS48hCYiEWuhWEE/Oa6nVJ/gAblbWHjFFkv6s8=; b=taFM8hUgOnIBKEaVp+Zor4s+41Ip+tHCUhiyztCmtIpD5YeVOJjq9A/pwCFBx0QQXUqMm9ia5ucqRPGYJJmGiEAhY7wxNUfx5mBWX01Uw46fd4KjdsU/OyX5YfYnbOfgdAQJAtQCHU7HeMY3DKk1sZkgabT53BGpQpYouBuYNI4= 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 PA4PR08MB5982.eurprd08.prod.outlook.com (2603:10a6:102:eb::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.23; Fri, 27 Nov 2020 13:20:16 +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; Fri, 27 Nov 2020 13:20:16 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v2 2/6] elf: lose is closely tied to _dl_map_object_from_fd Date: Fri, 27 Nov 2020 13:20:10 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.54] X-ClientProxiedBy: LO2P265CA0137.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9f::29) 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 LO2P265CA0137.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9f::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20 via Frontend Transport; Fri, 27 Nov 2020 13:20:15 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8160f1d2-949e-44ef-a814-08d892d733c1 X-MS-TrafficTypeDiagnostic: PA4PR08MB5982:|DBBPR08MB4757: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:7219;OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 169udulgEyFULlkhHnw9txM9ywDvuQI1qogOg8kzYBLTuVIZMNwvjq/5jeZsWfHFgUmZVL+pujYlNsGm4Wwf7qZXYDBAv6bOjgLUYIru1o11Ac9qaGMGDmScQSkTfChPoN4d+sd/xZ5Qe1V9XYPlMdVNsyP25yICtJDuJbzUFRqjc+sUWP6KixQqs7cJVlJwBPUokMPZDtG2oE7OjL0iOQ71Hau7F0VMdZ6+98AqbgQtPpNM9Odf/paRcKEeeCJjwhpd5IA/q3VURKAvtF6P6qHDHVEXTUPkzMI7pDPH/rr1nk0q5TrXoitgHglPXiDuaqSnQBcbpvXAXmPwatEmmGLmsz5DOYLCl9FVbYw+rvmmpk2wkLaq0ZM8zitIFkmh 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)(396003)(366004)(39860400002)(136003)(376002)(2906002)(6666004)(186003)(5660300002)(83380400001)(52116002)(69590400008)(956004)(2616005)(16526019)(6506007)(26005)(8936002)(6512007)(36756003)(44832011)(86362001)(4326008)(6916009)(6486002)(66946007)(316002)(8676002)(66556008)(66476007)(54906003)(478600001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 0fhxp9laLub2DCy5zx1lYWE1z6n0cGagE1A9atqcBUIigILKRbT+qcZ5yZbK3u0kVwhpI6ywDbPLue19tomPJowHjJPfTpbQ6H4yIjQf0nyBqRudJr56DWocKSZ7Aw0xIPDEEzZlcUUU2x/FANgJevdCc3IWCQnkHPPAw1cEebcVLV5d7sutQlJLO++nfvUd2aaaobNVkzERaDn/ckxzEIzRD+pPkg1JcQWZ9xwhsa2rNyNw6iLmWCiQzp+KRB6Zt0QnnT22aPA3wYZn/GHKtbGhZNBsWL5UJgudUPGGHyev47oej8moeU2k0FiZQPcqBU+YBxD05U3OxSNPvXAQqt4ZzTZwoHOeKSdZWIS3+BMvMT54Y21vHibjhd1DXU9A50or8spsMPF/FLoeWe7pEkF9Vl/a7yFdqkAWa/u2dcX6sXjRWyw1IejASGgBDVDj7e0QR2LpkyGEF2homKf61G7gXu0AWSswk81p/wlfKb7Ck04ZOonupU4f5/CtukVER2YFXkuttUiNdNCAOEcGrIrsojFsrSPU67/04EhlYo4dXbO4cMUpheGZQeiGysRMsNahwHtUABYCP6DUBlVWAH1Y50AtWUexZBUGfgfvs4jon8ubmdH716K8jX/PEDPDN8+ekhYroxM+VJYXpYfZ2zKAaoC0nHR4Uypt8oeFrC+boi/bzPUgNguAzvxh4wonJX5GeThM7R9AiJRKjpUtzKLfTpvvp9BMXN0CwSr/dAcw3DzYVRy276/UkJZ6IzfO0V1nwpcPg7u7DeN3+fn8lqYsUCEfCxJRUfx6+xcD9BWbrPnyb/3nYbcpm9XlHUrcsQxEsgXCybRA2z1iozjQZYtBPXBgWhTRlexoAgjMFg9rORWAfIAuNuWw4i7+EgIhw4ZeUJo9MAjnxlE3u0r6TpUDhNyUFeaDUjLDyp4NGW6LAef8NjYyWMwRQw1hAu5sDjuAwsZTIientqHx+YegBgJ9q9P1i1pWrgT1maLhP/9Ed3BzrPjTIYZoHNM+i8ZP X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB5982 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: AM5EUR03FT015.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 1cccce31-6dca-4b23-c130-08d892d72e0b X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: opkCsHob8LyMJNlkW4dtdiI3sH/egwR14pwaLvJuzNd4+/mX8Biyf2vSMEDgk/rWPUC8P9PmmgQCKXlcGWqjryP53bok3gmxmYlBErjW3IwBAQ+vG570C9O9SClWPjQLUoXkoT74D+qzm1TJ41loFUDtRixon3GfwY4SzJAqNBSQFpuscn7yYtl55w1+buR4R++StcaNOueeXIRuX8H9CA4QkEdWpMbBEEKnUCPloa3p/efVImDiVAd1KTuN9TiHKAm8miDCgUvveD6vT3eOvr1YGbuzU8UMFT+5Uk/MN0ehd24YwNE3wg+vBwgTUvyIwQVFdxU1gZDiXVe/H4eg7aV6ZCbw3P/fgtiJi2JkFWM+m6TojVqsB35Jp/p4ah3rmewyY6YRgRN16gYZXjSG5ezmIBblVADknQFqguiKCHqjJUmn7mPYmKRKq340cHId 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)(39860400002)(346002)(396003)(136003)(46966005)(83380400001)(54906003)(356005)(34206002)(36906005)(8936002)(478600001)(316002)(6666004)(2906002)(44832011)(8676002)(81166007)(82740400003)(47076004)(4326008)(186003)(6486002)(26005)(70206006)(70586007)(16526019)(5660300002)(82310400003)(336012)(6512007)(69590400008)(956004)(2616005)(36756003)(6506007)(86362001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2020 13:20:25.6258 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8160f1d2-949e-44ef-a814-08d892d733c1 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: AM5EUR03FT015.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB4757 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201127_082030_713380_1EE485BB X-CRM114-Status: GOOD ( 15.92 ) 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 Simple refactoring to keep failure handling next to _dl_map_object_from_fd. --- elf/dl-load.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index f3201e7c14..21e55deb19 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -835,30 +835,6 @@ _dl_init_paths (const char *llp, const char *source) } -static void -__attribute__ ((noreturn, noinline)) -lose (int code, int fd, const char *name, char *realname, struct link_map *l, - const char *msg, struct r_debug *r, Lmid_t nsid) -{ - /* The file might already be closed. */ - if (fd != -1) - (void) __close_nocancel (fd); - if (l != NULL && l->l_origin != (char *) -1l) - free ((char *) l->l_origin); - free (l); - free (realname); - - if (r != NULL) - { - r->r_state = RT_CONSISTENT; - _dl_debug_state (); - LIBC_PROBE (map_failed, 2, nsid, r); - } - - _dl_signal_error (code, name, NULL, msg); -} - - /* Process PT_GNU_PROPERTY program header PH in module L after PT_LOAD segments are mapped. Only one NT_GNU_PROPERTY_TYPE_0 note is handled which contains processor specific properties. */ @@ -930,6 +906,30 @@ _dl_process_pt_gnu_property (struct link_map *l, const ElfW(Phdr) *ph) } +static void +__attribute__ ((noreturn, noinline)) +lose (int code, int fd, const char *name, char *realname, struct link_map *l, + const char *msg, struct r_debug *r, Lmid_t nsid) +{ + /* The file might already be closed. */ + if (fd != -1) + (void) __close_nocancel (fd); + if (l != NULL && l->l_origin != (char *) -1l) + free ((char *) l->l_origin); + free (l); + free (realname); + + if (r != NULL) + { + r->r_state = RT_CONSISTENT; + _dl_debug_state (); + LIBC_PROBE (map_failed, 2, nsid, r); + } + + _dl_signal_error (code, name, NULL, msg); +} + + /* Map in the shared object NAME, actually located in REALNAME, and already opened on FD. */ From patchwork Fri Nov 27 13:20:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 11936323 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=-11.7 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 EF158C63798 for ; Fri, 27 Nov 2020 13:22:22 +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 5FDB922254 for ; Fri, 27 Nov 2020 13:22:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gOK+IGIn"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="ccRhqIZi"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="ccRhqIZi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5FDB922254 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=3hyDinl8d/DdHVJfnplH5u0ZAayowINIWMx+GlKWRj4=; b=gOK+IGInBjgJ7mfQuF3xDsHM5 r7rm3bYyUU/8Ped8ElMiFWjw0qivRBjzyyPblQAsMSSVjDMThOMQ1kX7yQnb/hwMpytjpL77BM24k VH1GWjQBO7FdF52chCXeqDjGpLXwHFBPUcV88C6l6ikA1HOdbyAw9H8Po4O4ZpRZyoq85EXvuGeGy 3XsAlipfYbPzjsTEe2pAoUW6fDzRITgMb2SQ+dxDlOmSgNOw6k7Ciq27lZkTCIThTP6xFDVN6VSdV 0/+AIxCr47/mvGME3+FuXXTX4Hc9SMrbNQ18pXUwpqkTWiG5rZQ5WfnQxl/jZMZ5vW2ItXoD3JxdF IA8lXXR3w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kidgG-0001U3-O5; Fri, 27 Nov 2020 13:20:56 +0000 Received: from mail-vi1eur05on2081.outbound.protection.outlook.com ([40.107.21.81] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kidgD-0001SN-8F for linux-arm-kernel@lists.infradead.org; Fri, 27 Nov 2020 13:20:54 +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=c4W8h42KC+tuve8tPTBuxxqbSUaADFodArmw0B4sZp4=; b=ccRhqIZi9UVo4l0UYwQ5++Is4eHPOXlA+3b5poxqiHO5dd512DUC7UgMEB0CS9ODpUfhavp4vpt3AVsWZXBBRGFBU524xIvgHVW5faL3ZzceRZjGzpe50Mtd5yRwwVG6dMqunCnWs0TONgafGaEPjLR6IMo8dMPN5oM3uJMXKDg= Received: from AM6P195CA0018.EURP195.PROD.OUTLOOK.COM (2603:10a6:209:81::31) by AM0PR08MB3924.eurprd08.prod.outlook.com (2603:10a6:208:131::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.25; Fri, 27 Nov 2020 13:20:50 +0000 Received: from AM5EUR03FT063.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:81:cafe::50) by AM6P195CA0018.outlook.office365.com (2603:10a6:209:81::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20 via Frontend Transport; Fri, 27 Nov 2020 13:20:50 +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 AM5EUR03FT063.mail.protection.outlook.com (10.152.16.226) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.26 via Frontend Transport; Fri, 27 Nov 2020 13:20:49 +0000 Received: ("Tessian outbound 082214a64d39:v71"); Fri, 27 Nov 2020 13:20:49 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: c722bb8456fde5d2 X-CR-MTA-TID: 64aa7808 Received: from 7d851b936626.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 7F3099A4-5F71-4A5B-B361-4FD5C8893D90.1; Fri, 27 Nov 2020 13:20:44 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 7d851b936626.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 27 Nov 2020 13:20:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RdLqBmhKUuS1hsf5G5Ghty0uZZBkyD8vxTF22waWWH4hEkVvL/QFzWxyBh/LliRhK3ZF1wtrABqszxrhplkT3EFQxZPr/onlsHC1nX/aehBCuvAeEKSZcHH3omXTjDtUiA0uahbPG2JfhPaoGFQGMZAYpM3L/Grlh/e1PMW4oQV0wkSuTBM2ajn4ZE8yQNnpWRHf2/iFjb7SFGEq1SysvTQUQYBPw4/ZvReQhBwQTe8rlt3yX8V4gCf7o+X6aJO97gbCCMFMdcM90N86xzcnHE7nhw1WIl3ehcG6EFO5X46Kkl+ShPkzz8u3wMHgWIslBvXYJFGivEH3yeDk/79oHQ== 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=c4W8h42KC+tuve8tPTBuxxqbSUaADFodArmw0B4sZp4=; b=oQpWL0c5CrPlCUrwIZBCyM3WCFHFfOEpHEfbM5Roxsk7i51yzNDT2dfGKUjebf68dcglj3oiW7kbxXH/QccpJ4Qf+FR5NXmCVhX+TmOhIUwhUqI7eqmcue/IaSr+iY7CmpW9ZKi9z3oEfmtTqeMfqpOR7DGIJy52MArNtXMRSSrvhabOy6BnIxZKShAXq8kPkbnL5BBZm+agtYOudfXnL9vtdjoBgy9/Ch9KbAsJ937jlZHESqto4NBP7GZQ9/uftzwamBv4tDQkcofJLkOlFfdee80xLclSS7uuVUET4UaO0UBT9Lxfw+rTU94KRqvX0AMhN17FP4YMlrDDu7dA/g== 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=c4W8h42KC+tuve8tPTBuxxqbSUaADFodArmw0B4sZp4=; b=ccRhqIZi9UVo4l0UYwQ5++Is4eHPOXlA+3b5poxqiHO5dd512DUC7UgMEB0CS9ODpUfhavp4vpt3AVsWZXBBRGFBU524xIvgHVW5faL3ZzceRZjGzpe50Mtd5yRwwVG6dMqunCnWs0TONgafGaEPjLR6IMo8dMPN5oM3uJMXKDg= 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 PA4PR08MB6014.eurprd08.prod.outlook.com (2603:10a6:102:ee::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.25; Fri, 27 Nov 2020 13:20:43 +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; Fri, 27 Nov 2020 13:20:43 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v2 3/6] elf: Fix failure handling in _dl_map_object_from_fd Date: Fri, 27 Nov 2020 13:20:29 +0000 Message-Id: <8ebf571196dd499c61983dbf53c94c68ebd458cc.1606319495.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: SA0PR11CA0023.namprd11.prod.outlook.com (2603:10b6:806:d3::28) 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 SA0PR11CA0023.namprd11.prod.outlook.com (2603:10b6:806:d3::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20 via Frontend Transport; Fri, 27 Nov 2020 13:20:39 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 000af66d-054c-4d0a-e9d3-08d892d74234 X-MS-TrafficTypeDiagnostic: PA4PR08MB6014:|AM0PR08MB3924: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: wckCYhRrptvH2hDAGN//RAyND2YoofEg/92zhQ7sYK0lOQ2Jjb5usPsQRDTvlD1L0saDq+prR+YySojIqIr+tTiZEPeZKvmXEsE1B7WFt7aAjwMz4k+kV0Y+Wx9F1r3Mk4SO2lqXP4EC/Ogp8NkyYT1bpPl7wEEaQG2HyY0oOxubZRtUmPFEkHaNxFafO2s4JTf02neahrLDyE63g6LvUl6jx1Dvs8NfKdOOfqRBgZQOA5LBzTCZo/X4YmilR7WQr5WHZEhbG1I3XTZYTbL6rJKZsevwOdtL+LnMnDiOwtj/Jn1gGKlIoWh0FJYintTr/isrH0WYvyCPHgQZCGoO/qAEOAlPZxGqsHAwG9Xu2eE23FH0gc4VVW+3e1H9Xb5G 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)(136003)(39860400002)(346002)(376002)(366004)(396003)(4326008)(54906003)(69590400008)(6916009)(6512007)(36756003)(6486002)(6666004)(316002)(478600001)(5660300002)(2616005)(86362001)(44832011)(2906002)(956004)(8936002)(16526019)(186003)(26005)(8676002)(66476007)(66946007)(6506007)(66556008)(52116002)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: R4Yu4qh4lbx4/u1KQNldVSznsB/U3fxexII6Bdbq50gSBJj+Kk425A6yfbiD7uVhGsOcpP7kTTcKZTCDGPrv//KbpyXCgAlC93yzju1Yhqw8TlZ4rkDIk+UgEW8D/bCCaQl+lgmhPd3R2DZKk9Ux2+kpi1PhYrY6jP2KzKU9iEwP7dC53lWpzi4eEUyO7HJVcdaRTtumnevelG/0UqayNnKmH7FqMM+42j+UbXfT1dEHb2DWv+XoyYmhaUgulzLwSvGLZOM1nQshQs+WdESnewIMM9bfWbWz6QosE8er4a3bZMxdvAtQBHdhnUfAC1VprnE0iKrfrvJPTfTNZafm6dJF+31yleBTmpPaX5xlVyZQL5Dor2SmhaE4HtFs2xu34CfrvCZ2KaSikbI4C4HAyKkDQw3BFwJfj2Q7NHBlXaR60WLkR/gMxYRM47AQJ+AntTVl70F4OAHHpStu/yh6XlyNl3z6rmjdeQgSMExqifH/uerZiIOz3C6W6IDl9fty5pmB62vjOyDdac1vmcp75laBYkY2e7N5lUNKxdiVXn1zQY9AGqJPpIWNjPrn9qWtkfOpkmiAC3a3e/b0Hla+bSIlwD4fZYe810GDKyTBomcJCObuKqYZL8MvhErlo1RL5SKRef8GH0eGZmfxoKi13E6CGTbyMXrEV4DsKGlYiHOJOqK/0dMFNz0cdWxTATcVsPgI+zqrikft0WmTRtT20PtSSwU5Fa74+cekZiY1Uz8rLBlDv9WDA3OY4IhomgzZhRyGD84H3az89Y6cYMvBj/CZgfgWTZnauVgH1mlqvjzgvT7hz+jqa4aIN9A+PGzVZuzfHp1QehFSsasWhFYBjO8+mMW13Y/SV5ChI5586gVeTWamTbCznCrZzGdLOi0iMtbU0emQ2SmOuAnGuEibN839vY+Sa+VOS2LvvUiOlhE+jxDC9dH0CCc9W8H5xpLy6KuKcaCQfmt+RpvUT/BGG/0AFh6Y92eIk0PZ/fU237yCfWucCNvb8xuq84cO5NQn X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6014 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: AM5EUR03FT063.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 9dc536e2-20e4-4c3a-86a4-08d892d73e03 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Bgwp6xDPnN4JRR44lBfinM4V5pYsdbYaGzXNOm7qc0ds8hLSvS13GFfPQxEKLxWuv7iS8IrdRqIc5SQPTHddMFxzlFNNxhWUbLbqdCXF047akOwP/+CCJHjAKBiGqlwLXDWwqtqt4b4/ZNKyss6314OgsQgHXe3bhzowNXr0mgPCWmz3X+0Vd3XLryWXRULOZUQ7s/Oo3Ydey5noxcQ7y6rwjZGqiyVmM0vFTZNVmf+AQp9lSHlg2+qolJKMGLZEm+1yBbVH4RQYnQ2Nu3lzmITgiNS54r9qen7I7fqtP9OQWk4n8NPF7CFvCew/0UsW8pvRiCx6hJf4FmbAMbGPlBMx2U0w05G256AipxL7n6pjaMjthZyjYpN7nPFuPRO67m3JPBXc2aFAquSGRPc55IgNf7XUjmdUVD/0ThlOotZ4YAeJEQ9tsllayUCjB+RY 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)(136003)(396003)(346002)(39860400002)(376002)(46966005)(336012)(36906005)(6512007)(44832011)(54906003)(2616005)(34206002)(956004)(316002)(4326008)(2906002)(8936002)(8676002)(26005)(186003)(16526019)(478600001)(6486002)(6506007)(86362001)(83380400001)(70586007)(70206006)(36756003)(82310400003)(81166007)(82740400003)(356005)(47076004)(69590400008)(5660300002)(6666004); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2020 13:20:49.8753 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 000af66d-054c-4d0a-e9d3-08d892d74234 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: AM5EUR03FT063.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3924 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201127_082053_331096_B737E26C X-CRM114-Status: GOOD ( 17.48 ) 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 There are many failure paths that call lose to do local cleanups in _dl_map_object_from_fd, but it did not clean everything. Handle l_phdr, l_libname and mapped segments in the common failure handling code. There are various bits that may not be cleaned properly on failure (e.g. executable stack, tlsid, incomplete dl_map_segments). --- elf/dl-load.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 21e55deb19..9c71b7562c 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -914,8 +914,15 @@ lose (int code, int fd, const char *name, char *realname, struct link_map *l, /* The file might already be closed. */ if (fd != -1) (void) __close_nocancel (fd); + if (l != NULL && l->l_map_start != 0) + _dl_unmap_segments (l); if (l != NULL && l->l_origin != (char *) -1l) free ((char *) l->l_origin); + if (l != NULL && !l->l_libname->dont_free) + free (l->l_libname); + if (l != NULL && l->l_phdr_allocated) + free ((void *) l->l_phdr); + free (l); free (realname); @@ -1256,7 +1263,11 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, errstring = _dl_map_segments (l, fd, header, type, loadcmds, nloadcmds, maplength, has_holes, loader); if (__glibc_unlikely (errstring != NULL)) - goto call_lose; + { + /* Mappings can be in an inconsistent state: avoid unmap. */ + l->l_map_start = l->l_map_end = 0; + goto call_lose; + } /* Process program headers again after load segments are mapped in case processing requires accessing those segments. Scan program @@ -1294,14 +1305,6 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, || (__glibc_unlikely (l->l_flags_1 & DF_1_PIE) && __glibc_unlikely ((mode & __RTLD_OPENEXEC) == 0))) { - /* We are not supposed to load this object. Free all resources. */ - _dl_unmap_segments (l); - - if (!l->l_libname->dont_free) - free (l->l_libname); - - if (l->l_phdr_allocated) - free ((void *) l->l_phdr); if (l->l_flags_1 & DF_1_PIE) errstring @@ -1392,6 +1395,9 @@ cannot enable executable stack as shared object requires"); /* Signal that we closed the file. */ fd = -1; + /* Failures before this point are handled locally via lose. + No more failures are allowed in this function until return. */ + /* If this is ET_EXEC, we should have loaded it as lt_executable. */ assert (type != ET_EXEC || l->l_type == lt_executable); From patchwork Fri Nov 27 13:20:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 11936325 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=-11.7 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 03675C63798 for ; Fri, 27 Nov 2020 13:22:54 +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 7FC492224D for ; Fri, 27 Nov 2020 13:22:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="dqTrQOdV"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="v2zbgEDQ"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="v2zbgEDQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7FC492224D 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=rkV2bBCe6VazAaBKvLp0HLV+TYiKk4X93BD+TdR6VEQ=; b=dqTrQOdVNAVcsrNMVua2kCUR1 cwFybz67+EzTGRNAS1BntN56BljaVejI8yz+seWy4hDiQtUa8NqPPLtELC2zbczOpXkC4VZwdHddw ndd7ptYNuWhc625W323TSAM1DlhI3TMWL/EZl5hcXM6UJsndVOg/covN06arxwUgL8ZOoRm9G5YC2 YijDhLWlihUQR0lIaHYT1Is1gZnBYl7lHIj7sZmF2JWT46TftbXO9pZ7NQlY90ojoOcKXjXgsoPW6 cazFkcwwI5MzT5C0ZlUAckzlzI6ObbNy7JEq3L/Haau2Db8ptwCzP/xBgDy9nxb+1HphhQBnQt4au 0Bh2YjbXQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kidgd-0001e3-P3; Fri, 27 Nov 2020 13:21:19 +0000 Received: from mail-eopbgr140054.outbound.protection.outlook.com ([40.107.14.54] helo=EUR01-VE1-obe.outbound.protection.outlook.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kidgZ-0001aw-LD for linux-arm-kernel@lists.infradead.org; Fri, 27 Nov 2020 13:21:17 +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=Q1jU0aMUj4QfK8EyRD8DvcTi5AwkXzK9UGUF9Nf79/g=; b=v2zbgEDQfnkZznT5ohEdE1fg1znGlFpYrUJMX6R5umj5T5vE1qTEZnPP+1Ki84gp4RFQ3XcppV0jtzfjnfegC4FpfiIUUlDnLB5FVCuYG0k41GFqPNpiC2D390y13h+gQQhLpR8f5/IpzzJQGI8R2ttVv6rmmJAYIcIDTc5eqRY= Received: from AM5PR0602CA0012.eurprd06.prod.outlook.com (2603:10a6:203:a3::22) by VI1PR08MB3598.eurprd08.prod.outlook.com (2603:10a6:803:7a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3589.22; Fri, 27 Nov 2020 13:21:10 +0000 Received: from VE1EUR03FT041.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:a3:cafe::c) by AM5PR0602CA0012.outlook.office365.com (2603:10a6:203:a3::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20 via Frontend Transport; Fri, 27 Nov 2020 13:21:10 +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 VE1EUR03FT041.mail.protection.outlook.com (10.152.19.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.26 via Frontend Transport; Fri, 27 Nov 2020 13:21:09 +0000 Received: ("Tessian outbound 797fb8e1da56:v71"); Fri, 27 Nov 2020 13:21:09 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: ae0120a5a66a482b X-CR-MTA-TID: 64aa7808 Received: from 887aa895777a.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id FAD0C319-BE1F-407C-ACE8-AE6C84572118.1; Fri, 27 Nov 2020 13:21:03 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 887aa895777a.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 27 Nov 2020 13:21:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Epwm4JhQr0QvK1ShXqOrTtIVSSpyD2ikjdRanp1E5C5+eAAfvfgkmXxSD6I477wSRYryU153ejgUrAa0d42RJHH5A5wprF9wLpPAIAM43yfBQgC5Ezc3MpWMRjKhcM7iHm3ubcGymYbrLGZS7DnsoLmjl98MivistEqG+lzA2geX/V/QRxE3oSJpaZwqcNFU57Opa2wC2zNjeFOKVuaCiYzppFevFQaXLytzSc01wfmhPoLNlHpvGJiYHX3ZEJfe0f7TQIJA6eGtVnQNsuAi7u7AuQCeP2uUAeG/hu93vOQwFNMzrnG2tLRiaQypIBf82ogfUqFQlq/2ilFn9kcHFQ== 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=Q1jU0aMUj4QfK8EyRD8DvcTi5AwkXzK9UGUF9Nf79/g=; b=n+Vrzwe2Iu52oJVldbv0ZPmgzJwxVYSocxzTKXfhMsfnB3ypsGjsjirkLfNMCbNtWeQfxVddRk73vhKRzg7XIKmvk1XCVBiSR4SyqvyZ4JdBjZvEG3Mo+dU4wC1FZNG0q3VUMDIXqa0rRE+PJfpLcKFXbPTuccAyDzaJeuSlD+UKm0d7DN5pU5agtPaMDRNHtzQbX7f+/UCnUEI1hqp0drdDsNfEzC432teEpABXOdg6nMPNzP9TWC4zPpKD4Pg5eL7IcZhDH7rv97fUvL/CSlPl48CmWjbiDlQA/2u8zyoS1e58Yb649vXyezH5J+KrvJQCHKxO8rGd9P1QTV+M3w== 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=Q1jU0aMUj4QfK8EyRD8DvcTi5AwkXzK9UGUF9Nf79/g=; b=v2zbgEDQfnkZznT5ohEdE1fg1znGlFpYrUJMX6R5umj5T5vE1qTEZnPP+1Ki84gp4RFQ3XcppV0jtzfjnfegC4FpfiIUUlDnLB5FVCuYG0k41GFqPNpiC2D390y13h+gQQhLpR8f5/IpzzJQGI8R2ttVv6rmmJAYIcIDTc5eqRY= 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 PA4PR08MB6014.eurprd08.prod.outlook.com (2603:10a6:102:ee::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.25; Fri, 27 Nov 2020 13:21:02 +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; Fri, 27 Nov 2020 13:21:02 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v2 4/6] elf: Move note processing after l_phdr is updated Date: Fri, 27 Nov 2020 13:20:56 +0000 Message-Id: <36d457074f389740b45afc4f9c6d124046f8352b.1606319495.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: LO2P265CA0434.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:e::14) 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 LO2P265CA0434.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20 via Frontend Transport; Fri, 27 Nov 2020 13:21:02 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 611f540a-4c1e-477e-a572-08d892d74e28 X-MS-TrafficTypeDiagnostic: PA4PR08MB6014:|VI1PR08MB3598: 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-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 4qFAq0tSahHcXScZ4dLCssSeJ3HuLehp2jF9u+cjWLCThQAxXvzNPSngtA+/7v7a4a/J6BgRmdPM3NSIRb5AaxbmFaZ+1eovTNMriswmoCO4RqooiK9C8KhlFpK22eoeD9TtMiOig2/H8gYyxB0J5HKzLXUCctteSrX4agThhYQ8Qd6a9+veyqePM58aY8t0DJyIg4KYL60WPdlsEdZLL+pRCmNlgoIkau3Ob9I8OB2DMRNe0+SjDheqwnKDteeYICA6jCYrxxYc0Jz+BxV/c/Gefvs40l9gwEjyUZ9KmHjv2iTE4aaVF18qCouJOf5ChJaogi/AcTZ/r9AqK2wgCW/KZxUw8aYWnYk9Hd0yyNzE1TNJTVWqtPRkOSLM2nsu 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)(136003)(39860400002)(346002)(376002)(366004)(396003)(4326008)(54906003)(69590400008)(6916009)(6512007)(36756003)(6486002)(6666004)(316002)(478600001)(5660300002)(2616005)(86362001)(44832011)(2906002)(956004)(8936002)(16526019)(186003)(26005)(8676002)(66476007)(66946007)(6506007)(66556008)(52116002)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 2sAd3LJe8SPRFyw/KkmDjGjzl+CVO6DqB15QnRoLKp+B8oLgCXE/y3WAWB2QPfOgm+O8O02cDjhpNAQWYjJfJYLOgNg5NqNGL3by1INuogOPF+r2UciVEa6qbdWISfHx5++E6AzFrQSjJPnWKcwEvTiH5NKGwUqkAgkuI+bt7bsmR1DJbCohE1lwlEq1dKyT7sV7BqCDAvO7muFBK2YEo4OYc/NxMkYeCqhWqvG6ES3KHRRexShDqLitDJjYsaBlMXpWMnQ4DoB663yYfBl8XL5H6/jLEVCWDggl1h1bSzl3D+S4rTl/P0PjE/tn0X2eONP0ZYzRCxuvHTeMGvxt02+m8xciaP2e+Ps/OldlEZrDy3bB6++vZH2IAG2en8FPOkuew0xitatSwyTswjb0BKgq5QE+ZE/ldzZinKWgVefliS6THEKvZgO4Pyr8+Odgiff+7LauNj3Nv/CmW8EmaCQuKMKDlSZtGopT9cY0ij5KSHL1UWBPJ5lhez7nob93ekRg2/HZ1nUKcYCEbfCtS1SK0cS/3WoL+q1aHcU3gZQYknNU+NJ/OPPooM/+V7poaZy+YKUmxnFICQ1AFOlvpSkyTNAI5vKO+iQPXbjczo9KcdkI5fMkrpkOC4tSufGBb+WHIEtLLz/a+Ilohz3wiFo9nOX+3WheY6W49l3ULfVJTXH9wXBrbJE7s/Gj1HD/T+zqKlq1G/3lHevV4iYmCmX3lRh8nIEBASmUcc1E3GzOLh9xEOHQF8Qj0rXqU/Y2cnXnfyPpw/sX2pKkL8RCKxn/38qpy+cihaYE5aMrLqeycHy+pwI99h5B3vKo9Z5svCT4/2MI9CCOyMtBowlwptQFlVNDXhECNk+LdlkMh9ykzuDbSPtAzY7IUFqWMLD/eSfiEg8RDjxlWvhuzP+hSTNLbJuwAtBWeV1CrLgowH7kwz0hd1Au0PnaqPc3XJNWdxhpqzXd3mrb5/aWvJR1T0ePG+2hhCtNCvaFEqwtVyJFu6tW81jAXyIM2AfIIm5q X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6014 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: VE1EUR03FT041.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: e10275c7-e43e-4b10-7585-08d892d749e5 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WFjsuw11hOJO+ICEh2DE2M5YrPFM5KpxZgh1RBJNV+CIEEc5IzshkV0Yq9QUCk4/3B1jE6wnLYXylpIEuKT7cY/6grpOoEw0fiYB7QjvCnMyg92JawnprlrXCu3yO4AnhItgGOdk2UEnQZ9sdN9HQxSXzw9SSonfV68+DrryNdr7+wiIk43CoHo6V0GR9KLcCImP5nRE7mZMERRiJ2PAIcgqBI5coZ6Lnvgj2VI5C6BgHF16UK52i8DktWZvEcXCCRlRzk2ps3BsEcgFe+x2W6ZJyHZEpnxSacRYGQBXg9/fXCK0MWU46yTYEvPJJhaAnFW0PH/A32Ka4sqNfQv9J9xOEqgHcbm443vHHqxvxUuFDaioeajs0O0teOxe8vzX3IAtSWOWXcEZHX/HqwbpC9Lg+TqJzz3E3XcxWA8CkrhzpEuJDDDAJH3aa32X3w8w 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)(396003)(136003)(376002)(346002)(39860400002)(46966005)(6512007)(8676002)(82310400003)(478600001)(8936002)(5660300002)(6486002)(70206006)(70586007)(16526019)(81166007)(83380400001)(44832011)(47076004)(316002)(6666004)(356005)(69590400008)(82740400003)(54906003)(26005)(336012)(4326008)(2906002)(36756003)(186003)(6506007)(2616005)(34206002)(956004)(86362001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2020 13:21:09.8066 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 611f540a-4c1e-477e-a572-08d892d74e28 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: VE1EUR03FT041.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB3598 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201127_082115_793975_172BF4CB X-CRM114-Status: GOOD ( 17.98 ) 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 Program headers are processed in two pass: after the first pass load segments are mmapped so in the second pass target specific note processing logic can access the notes. The second pass is moved later so various link_map fields are set up that may be useful for note processing such as l_phdr. The second pass should be before the fd is closed so that is available. --- elf/dl-load.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 9c71b7562c..b0d65f32cc 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1268,21 +1268,6 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, l->l_map_start = l->l_map_end = 0; goto call_lose; } - - /* Process program headers again after load segments are mapped in - case processing requires accessing those segments. Scan program - headers backward so that PT_NOTE can be skipped if PT_GNU_PROPERTY - exits. */ - for (ph = &phdr[l->l_phnum]; ph != phdr; --ph) - switch (ph[-1].p_type) - { - case PT_NOTE: - _dl_process_pt_note (l, &ph[-1]); - break; - case PT_GNU_PROPERTY: - _dl_process_pt_gnu_property (l, &ph[-1]); - break; - } } if (l->l_ld == 0) @@ -1386,6 +1371,21 @@ cannot enable executable stack as shared object requires"); if (l->l_tls_initimage != NULL) l->l_tls_initimage = (char *) l->l_tls_initimage + l->l_addr; + /* Process program headers again after load segments are mapped in + case processing requires accessing those segments. Scan program + headers backward so that PT_NOTE can be skipped if PT_GNU_PROPERTY + exits. */ + for (ph = &l->l_phdr[l->l_phnum]; ph != l->l_phdr; --ph) + switch (ph[-1].p_type) + { + case PT_NOTE: + _dl_process_pt_note (l, &ph[-1]); + break; + case PT_GNU_PROPERTY: + _dl_process_pt_gnu_property (l, &ph[-1]); + break; + } + /* We are done mapping in the file. We no longer need the descriptor. */ if (__glibc_unlikely (__close_nocancel (fd) != 0)) { From patchwork Fri Nov 27 13:21:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 11936327 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=-11.7 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 6DEF1C2D0E4 for ; Fri, 27 Nov 2020 13:23:24 +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 E5FDD2224D for ; Fri, 27 Nov 2020 13:23:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="uQjtmKB5"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="rki/Ir58"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="rki/Ir58" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E5FDD2224D 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=U/eY8z+FajIGlNIslpPX/XRtel1B3Myy9lJ3UUM+nRE=; b=uQjtmKB5Ax3X38MBJZvP3iFoE AiHoPRfmOvpsv+AzPOT22hnRBpQbcFr8Me0OWrcUaG+SY2XMeVrRFIWWVCyiegercwaPiTcAgekXY 6xvnyZEdV5wZ4FdgkCRhQGfZ3f07GzHGJL63aI/cU1GVzV36S1bt6yGn1MfUHMSCndL9Cfv/628N9 cmYoCX1h0oOyZTgiF6HPLz/NTrdgY/3O8bJEiULfJLBRGTgpA+mh3BujfpOOTh/2Qv9K+4GOKEidJ p4Ky+IQQZmQ2JLW9Py//x0ptNUXjC4+m6Sb19sVRsKkxkkoJVvEEJzgzurc470GcwFeGhZ8kll/Ma snApPWx1Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kidh2-0001oT-UN; Fri, 27 Nov 2020 13:21:45 +0000 Received: from mail-eopbgr40063.outbound.protection.outlook.com ([40.107.4.63] helo=EUR03-DB5-obe.outbound.protection.outlook.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kidgx-0001lN-N7 for linux-arm-kernel@lists.infradead.org; Fri, 27 Nov 2020 13:21:41 +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=nBpOGzKrR218CsAMW7ki/EWPc6Uz5KXS+PBRk1M3+bg=; b=rki/Ir581+lLxNNmGwUMQO05FbHBw8o/NToB3tbMUOuOcnWLlQSZ4QKTtEmstxI4iel3dsaqo74fSa5t0RXgYJWq51fmxDCOIKKLisCResqS2jgR5w6rMJVarLA7ZdqT7MAcDgruswaYiIDeDHhO6b3YPe8cCRQfN+ZHw6TWH9M= Received: from AM5PR0301CA0029.eurprd03.prod.outlook.com (2603:10a6:206:14::42) by AM4PR0802MB2356.eurprd08.prod.outlook.com (2603:10a6:200:65::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.21; Fri, 27 Nov 2020 13:21:36 +0000 Received: from AM5EUR03FT043.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:14:cafe::4b) by AM5PR0301CA0029.outlook.office365.com (2603:10a6:206:14::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20 via Frontend Transport; Fri, 27 Nov 2020 13:21:36 +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 AM5EUR03FT043.mail.protection.outlook.com (10.152.17.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.26 via Frontend Transport; Fri, 27 Nov 2020 13:21:36 +0000 Received: ("Tessian outbound 13ed5f5344c0:v71"); Fri, 27 Nov 2020 13:21:36 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: af772a76cb38de87 X-CR-MTA-TID: 64aa7808 Received: from 92429340f285.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 3E18FB1D-F007-44AB-BFDB-1FB03EC9DDF6.1; Fri, 27 Nov 2020 13:21:29 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 92429340f285.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 27 Nov 2020 13:21:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ceuY7EflCuKkhAHmQ8DiMeZurh2vyKW7l8xQNd7dvFLnIKaRMZk50LQn5VfWJJRiNgcWt+owWYKQ1iOLuji5KM69XqjRSPZustAl5K60aP0YB5M4Ocmu9wgkrnX2EDJDDqy9xtpqUtAAtwBbF5CPeEM4MeeuQOIuCeWkPitz/yVQ07FzrgtqHlNxgCd3YNTQNf/pgHQsJzIEugNFWKZPT7xBpnLKcqt13ITkpOBjK8bnV752g3suasXbmq2sYILsR+pd68d1zZLT468srgUY48kOzymNHGU2r2v45eJ7KsWvRER1hgzKlkzqW8vfcAgUWsUdE9lb65dbS93JhaaLnQ== 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=nBpOGzKrR218CsAMW7ki/EWPc6Uz5KXS+PBRk1M3+bg=; b=hkzJ0so75df+2c/JlJMDolm0XKcgW5A6uZl14v19RWx9+g6n2gPXwa1gukMky8JonTPGyU2DBQEeIAUHnnb92PrSlrvkTumrq2Oh2DivdmwiM1jIvyUl+6/f4YWVzkqqJY6WI0GmBJeBD8R77VBD4OOTmKdSP1U8Nn25r6zzxHbXRuHCifn/ruArMwA6DHcAWj/MWGeSztTqXJ9T27qNh6rjGOuRUuT7LEqaqMFZenbWEp7y1Wdr9S124S8OXFb9/2I6OxDN6c/jfpM5+6K7FGG2wTYbQnQ9PPquv16jCDDdsnV90prQ4bnf4fdu4fF6x6uLYvhls0iQYNassSxFnA== 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=nBpOGzKrR218CsAMW7ki/EWPc6Uz5KXS+PBRk1M3+bg=; b=rki/Ir581+lLxNNmGwUMQO05FbHBw8o/NToB3tbMUOuOcnWLlQSZ4QKTtEmstxI4iel3dsaqo74fSa5t0RXgYJWq51fmxDCOIKKLisCResqS2jgR5w6rMJVarLA7ZdqT7MAcDgruswaYiIDeDHhO6b3YPe8cCRQfN+ZHw6TWH9M= 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 PA4PR08MB6014.eurprd08.prod.outlook.com (2603:10a6:102:ee::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.25; Fri, 27 Nov 2020 13:21: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; Fri, 27 Nov 2020 13:21:28 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v2 5/6] elf: Pass the fd to note processing Date: Fri, 27 Nov 2020 13:21:15 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.54] X-ClientProxiedBy: DM6PR01CA0018.prod.exchangelabs.com (2603:10b6:5:296::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 DM6PR01CA0018.prod.exchangelabs.com (2603:10b6:5:296::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20 via Frontend Transport; Fri, 27 Nov 2020 13:21:25 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 95f9e346-1182-447e-1d8c-08d892d75e1e X-MS-TrafficTypeDiagnostic: PA4PR08MB6014:|AM4PR0802MB2356: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:9508;OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: ChnA9nbTd6Ke9iN2cUb1YDhb9FUR1mjCFjQo3SZXjPaQExKKsKXoQnw0j5zSx7ZRnh69YWuNXagC7yHRgxntr7OO3Vnqe0IpYuspE/taovZrHF2mu+5LrTG6hbX4ilYbLHj1vGQyJsMhpENFCxEiI7enAjdqaHRJCRlIgZPHjD8jqHZha75U7oM7esNBGKzP4aFpD5jVqM1e5ciQehGvo5Rbxe+ZudVcPsBRuRo515daX3VLNyOQIXfYNDEhM1RwBD+gpIPx/Vt5U1jSPaBRE4UloHjswgnagLywQRFvw/DMQnyLnse0KUK/cmL3MT1J76mHOZYPWUxFGlDFWdoEIkJ8Z8Xd/xjH2LkxHPtX5woCQSJJSHjolaApGUKPVHER 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)(136003)(39860400002)(346002)(376002)(366004)(396003)(4326008)(54906003)(69590400008)(6916009)(6512007)(36756003)(6486002)(6666004)(316002)(478600001)(5660300002)(2616005)(86362001)(44832011)(2906002)(956004)(8936002)(16526019)(186003)(26005)(8676002)(66476007)(66946007)(6506007)(66556008)(52116002)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: steav44q3620kaxrbs7+gVB1Li8QDGoSj0u+0lUpKXbPdZZLw7+t5LGgjwG4o5OuE70GeRGTPiXu1tU8EezZ4/o34e889NLc1Pc/8vJ1dJXULPz3fJoi6tWDM2BbTpCjNgdMOvwkVs7Mg/kFc1bIiJLmeKmY57bwiftoJRSj3dnoPIOtwHzFr8V6uIzDZ+FQP/6/1tvOMt8/UcGuI96CQj6mfrH5FCvIhLWRXWesDRWvWXdXVG6Zsefugaf03AcmRXDoDiWSyOJUeqFfxSLeAxk4wWuFQNpTN/IXAQWESN32opiGfomSxjUdAtgyic3ABpEgFQ2NXw95aSj0WDZHHlHmcPqLNeHoNaVPUeeGV8M+4RDjjQvndaikNiGFsFbQ8VOSckFq3owOoyqgY5BZ14ZuHfdrN7wl0o8EOoj7rS8KVacVDFq6U/C3QJUm80ljfn+fUkpCNxeiKITXiwrXbbsj+q18fyus1RBUiiHoTmfPMIY4MK/GQXVZi0JoqVU/KnS5If9KeDE/JKugeD5ph9tTwqgmVdiQM8tQ1W5DdZxzDoh0WHsR8qPYe9kMYHr5Uh1q11U27+cl8QcCMS5zMjz7+reW14tI28ruOTNTi3g9R7ZT49hkE11+5QtSrdB4gPniUnu4QmMcZvFABJ9EVRtLK8Z2KEFQPesLZ12R42w3I+uI+9cAm4Vb6ESwE/ARCGDpXuXR7XYNfu44LCCnqLsN1GW4zvo4G8f1ekoFN9Owlt8LX6m7rC7act9JZRtqPUAYIZP0FMqDmH3Gi0iCqrLAb9a9qC1V34zLuOFcQdmz0XNh3ppTIVUPOoiXzJNRQZtUc3TzR5kkL3cuJEyCUBR0NhNOEnz0OaE4/9m33rkpjxp+/qiefhIGD6TwG9ovoGUa3HUB60jrLgmeDbTFLr7wP5fFYuxEd0hMaAGyW5Pam1uSTRBoEeWDbvqGIclFHoLSJ2ICHjaEZv8K4sR0FaWwUN2eQzoHRZ0okrd8xor3YQ6A4t5NBnE8B2KCft5a X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6014 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: AM5EUR03FT043.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 7714e35c-d348-4d9f-6b08-08d892d7592f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FqKuZTEWNyyKlcCbVAYNuJvMYklhsPTQDO2i5qkxxi3jwfhJzwvHButuRs4T3bOTAOahJ/rsKylD1scUkMjmGD1c8CC5d0QXB953Qa8c4xUJIbAXXvWTzeM2Xs69BZeM8M+XJuHDikkY0jxKx79L67af4bAo2LAPxNr37dPOrpsoDe7Jbkk2KPFoXRgDHGNduZDd2H/pkxbzmqhD/XsL01kr9qgdHnaByfmu7rTaUa/krqY4RZ8pfCM4H1oEsjvENA/xDwpEAJATfGS+mzZkobRRaGVXZwktn+R8AuBMBVq2X/hJXyaTp1MGcbwEomwqEnglD3qrI216gHK1QpexPTp0YjyQe5QH/QuWprIXqOsCfTvUcHhL5V1Cm59p4q6xZrf32OfBs2eUq0goTU59uRu0k6JIgQMsO2IqDyzZRZ5XS75CEnSICOpgNCZXeofh 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)(136003)(39860400002)(396003)(376002)(346002)(46966005)(8676002)(70206006)(70586007)(6666004)(5660300002)(82310400003)(8936002)(356005)(83380400001)(82740400003)(69590400008)(81166007)(86362001)(36756003)(2616005)(47076004)(956004)(186003)(4326008)(16526019)(336012)(6486002)(34206002)(6506007)(26005)(44832011)(2906002)(36906005)(478600001)(316002)(6512007)(54906003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2020 13:21:36.6921 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 95f9e346-1182-447e-1d8c-08d892d75e1e 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: AM5EUR03FT043.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0802MB2356 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201127_082139_905601_A4C94119 X-CRM114-Status: GOOD ( 16.52 ) 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 To handle GNU property notes on aarch64 some segments need to be mmaped again, so the fd of the loaded ELF module is needed. When the fd is not available (kernel loaded modules), then -1 is passed. The fd is passed to both _dl_process_pt_gnu_property and _dl_process_pt_note for consistency. Target specific note processing functions are updated accordingly. Reviewed-by: Adhemerval Zanella --- elf/dl-load.c | 12 +++++++----- elf/rtld.c | 4 ++-- sysdeps/aarch64/dl-prop.h | 6 +++--- sysdeps/generic/dl-prop.h | 6 +++--- sysdeps/generic/ldsodefs.h | 5 +++-- sysdeps/x86/dl-prop.h | 6 +++--- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index b0d65f32cc..74039f22a6 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -837,10 +837,12 @@ _dl_init_paths (const char *llp, const char *source) /* Process PT_GNU_PROPERTY program header PH in module L after PT_LOAD segments are mapped. Only one NT_GNU_PROPERTY_TYPE_0 - note is handled which contains processor specific properties. */ + note is handled which contains processor specific properties. + FD is -1 for the kernel mapped main executable otherwise it is + the fd used for loading module L. */ void -_dl_process_pt_gnu_property (struct link_map *l, const ElfW(Phdr) *ph) +_dl_process_pt_gnu_property (struct link_map *l, int fd, const ElfW(Phdr) *ph) { const ElfW(Nhdr) *note = (const void *) (ph->p_vaddr + l->l_addr); const ElfW(Addr) size = ph->p_memsz; @@ -887,7 +889,7 @@ _dl_process_pt_gnu_property (struct link_map *l, const ElfW(Phdr) *ph) last_type = type; /* Target specific property processing. */ - if (_dl_process_gnu_property (l, type, datasz, ptr) == 0) + if (_dl_process_gnu_property (l, fd, type, datasz, ptr) == 0) return; /* Check the next property item. */ @@ -1379,10 +1381,10 @@ cannot enable executable stack as shared object requires"); switch (ph[-1].p_type) { case PT_NOTE: - _dl_process_pt_note (l, &ph[-1]); + _dl_process_pt_note (l, fd, &ph[-1]); break; case PT_GNU_PROPERTY: - _dl_process_pt_gnu_property (l, &ph[-1]); + _dl_process_pt_gnu_property (l, fd, &ph[-1]); break; } diff --git a/elf/rtld.c b/elf/rtld.c index c4ffc8d4b7..ec62567580 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -1540,10 +1540,10 @@ dl_main (const ElfW(Phdr) *phdr, switch (ph[-1].p_type) { case PT_NOTE: - _dl_process_pt_note (main_map, &ph[-1]); + _dl_process_pt_note (main_map, -1, &ph[-1]); break; case PT_GNU_PROPERTY: - _dl_process_pt_gnu_property (main_map, &ph[-1]); + _dl_process_pt_gnu_property (main_map, -1, &ph[-1]); break; } diff --git a/sysdeps/aarch64/dl-prop.h b/sysdeps/aarch64/dl-prop.h index b0785bda83..2016d1472e 100644 --- a/sysdeps/aarch64/dl-prop.h +++ b/sysdeps/aarch64/dl-prop.h @@ -35,13 +35,13 @@ _dl_open_check (struct link_map *m) } static inline void __attribute__ ((always_inline)) -_dl_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph) +_dl_process_pt_note (struct link_map *l, int fd, const ElfW(Phdr) *ph) { } static inline int -_dl_process_gnu_property (struct link_map *l, uint32_t type, uint32_t datasz, - void *data) +_dl_process_gnu_property (struct link_map *l, int fd, uint32_t type, + uint32_t datasz, void *data) { if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) { diff --git a/sysdeps/generic/dl-prop.h b/sysdeps/generic/dl-prop.h index f1cf576fe3..df27ff8e6a 100644 --- a/sysdeps/generic/dl-prop.h +++ b/sysdeps/generic/dl-prop.h @@ -37,15 +37,15 @@ _dl_open_check (struct link_map *m) } static inline void __attribute__ ((always_inline)) -_dl_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph) +_dl_process_pt_note (struct link_map *l, int fd, const ElfW(Phdr) *ph) { } /* Called for each property in the NT_GNU_PROPERTY_TYPE_0 note of L, processing of the properties continues until this returns 0. */ static inline int __attribute__ ((always_inline)) -_dl_process_gnu_property (struct link_map *l, uint32_t type, uint32_t datasz, - void *data) +_dl_process_gnu_property (struct link_map *l, int fd, uint32_t type, + uint32_t datasz, void *data) { return 0; } diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index b1da03cafe..89eab4719d 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -933,8 +933,9 @@ extern void _dl_rtld_di_serinfo (struct link_map *loader, Dl_serinfo *si, bool counting); /* Process PT_GNU_PROPERTY program header PH in module L after - PT_LOAD segments are mapped. */ -void _dl_process_pt_gnu_property (struct link_map *l, const ElfW(Phdr) *ph); + PT_LOAD segments are mapped from file FD. */ +void _dl_process_pt_gnu_property (struct link_map *l, int fd, + const ElfW(Phdr) *ph); /* Search loaded objects' symbol tables for a definition of the symbol diff --git a/sysdeps/x86/dl-prop.h b/sysdeps/x86/dl-prop.h index 89911e19e2..4eb3b85a7b 100644 --- a/sysdeps/x86/dl-prop.h +++ b/sysdeps/x86/dl-prop.h @@ -145,15 +145,15 @@ _dl_process_cet_property_note (struct link_map *l, } static inline void __attribute__ ((unused)) -_dl_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph) +_dl_process_pt_note (struct link_map *l, int fd, const ElfW(Phdr) *ph) { const ElfW(Nhdr) *note = (const void *) (ph->p_vaddr + l->l_addr); _dl_process_cet_property_note (l, note, ph->p_memsz, ph->p_align); } static inline int __attribute__ ((always_inline)) -_dl_process_gnu_property (struct link_map *l, uint32_t type, uint32_t datasz, - void *data) +_dl_process_gnu_property (struct link_map *l, int fd, uint32_t type, + uint32_t datasz, void *data) { return 0; } From patchwork Fri Nov 27 13:21:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 11936329 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=-11.7 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 D6D0FC2D0E4 for ; Fri, 27 Nov 2020 13:24: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 719822224D for ; Fri, 27 Nov 2020 13:24:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="TRCuVyTO"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="Ai4rrVEb"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="Ai4rrVEb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 719822224D 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=JkX/h8dUXZFGc92qM+8eBs9ty0q4wK594s9nQ73jF0Q=; b=TRCuVyTO0T1XVqc4miALeeAJF rDAO4rS6VZswK1Vd5+9Bn1y2jgVwzzAAm2wqjlTZYBpZ4dFttD5MGXPvD61+amEJGPm3wYUkxJy6c D7WshdotTcU/hEF3+WuL4yM0g3hPRirFv8elEfIF2Y0Bsw3DlnSv25SXuXEO3rD+6XEcqHcXwFdvU NTZSJmPgvIRJ64vyPZdOb2tavPgWC6ycGlP1sdxewd77SG7o3V0IzbOrav4EAYU/f+AF7cJXEclCk FsuD5ntQX8AcorOZQzRdlMRYaWRbs2OEUpUiNdc0+HicPWMxvQOYnD7J71LyhgwHPplfbDHbZWv0d i01EJ3X7Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kidi2-0002GD-Ph; Fri, 27 Nov 2020 13:22:46 +0000 Received: from mail-eopbgr00060.outbound.protection.outlook.com ([40.107.0.60] helo=EUR02-AM5-obe.outbound.protection.outlook.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kidhR-0001zV-Ob for linux-arm-kernel@lists.infradead.org; Fri, 27 Nov 2020 13:22:14 +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=wNhDXoIacsU34w/3BvmYpkHf4Z/z/9IrNSX8sg3eJMw=; b=Ai4rrVEbR5P0boFd6cuSuVZHXHC7jIWIr6j0VrY4gsiI97au396Biv7U6so79xRLz4cui4tD7kDBwPo8v0suW6XFUMY80pTE9N0n/XpZjCHp5H4LtTrNXp2iXcdsz99xKT/pnwunMuSVo6nQVnFUSlDvoECLSO6zZ5NW8d35igg= Received: from AM6PR0202CA0059.eurprd02.prod.outlook.com (2603:10a6:20b:3a::36) by PA4PR08MB6032.eurprd08.prod.outlook.com (2603:10a6:102:e4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.22; Fri, 27 Nov 2020 13:22:02 +0000 Received: from VE1EUR03FT046.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:3a:cafe::83) by AM6PR0202CA0059.outlook.office365.com (2603:10a6:20b:3a::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20 via Frontend Transport; Fri, 27 Nov 2020 13:22:02 +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 VE1EUR03FT046.mail.protection.outlook.com (10.152.19.226) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.26 via Frontend Transport; Fri, 27 Nov 2020 13:22:02 +0000 Received: ("Tessian outbound d6c201accd3c:v71"); Fri, 27 Nov 2020 13:22:01 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 40dd52e927242136 X-CR-MTA-TID: 64aa7808 Received: from 7260ca125c44.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 34BDB80F-9248-4D34-B61D-26C210692084.1; Fri, 27 Nov 2020 13:21:56 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 7260ca125c44.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 27 Nov 2020 13:21:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nKJ1A4jFkTZwRzjEfloDbnaFiZR1YOxRrPK4rz8Aoh9K2AtBdUvPmhQ6HFSv7y44ddmfXki1tIuIY7I48zuzC90xP/8nKtHqaCCyYpyIJydhf0CilyxPzd+JY0dRCF1LR/nfqN/OWEHuU+31t+ffFv7Zgl+V2RM5WIL+6ms4I79bISfi11TRw1TBj1LaquLlTEgOZzc6LCaDCkAPbdjjn121Wb4ZZGpMcbQvYtmSBwgiF12u/Jyd4mmKWqrHpihGJ6/WRA9DQDEGW0PASYKqPy6YW+RACJRjmH+GePZZQyGjtgg6Rhi0lU0iTvlLH1fKQOjsWMUpuQGTeFUmWqVPTA== 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=wNhDXoIacsU34w/3BvmYpkHf4Z/z/9IrNSX8sg3eJMw=; b=BvWP7tGZSOZNttkIXg6IQYanOXe+Hk0NPXmuBKvXUIg47mXMosfqFD6d5CfJQztYf0ghJizBH0fxXiW12fEAUB9KKHVfZ0ZddeRg8EyBm6S+koZZuidvdyLzh/0E0l3FLxPhT9ITEXp7k0cMWZbG/ppUnNw0tsJZ5Ba75CkBMZFukHoWaVOvAK48Gk6053q9MReSfA7pH55GnW9wuT1PljO50WnURnWNtygEGFDZGZSIrxDiJx51utLyjiZ6iOgq7UeQolj5tS2n+ubtJsOYjhNXQlLuhkSC5JVSWafrkw/U7NtXNIC7RiOHfqH8lhQPbRDL3pwmbcqVWP34quyJtA== 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=wNhDXoIacsU34w/3BvmYpkHf4Z/z/9IrNSX8sg3eJMw=; b=Ai4rrVEbR5P0boFd6cuSuVZHXHC7jIWIr6j0VrY4gsiI97au396Biv7U6so79xRLz4cui4tD7kDBwPo8v0suW6XFUMY80pTE9N0n/XpZjCHp5H4LtTrNXp2iXcdsz99xKT/pnwunMuSVo6nQVnFUSlDvoECLSO6zZ5NW8d35igg= 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 PA4PR08MB6014.eurprd08.prod.outlook.com (2603:10a6:102:ee::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.25; Fri, 27 Nov 2020 13:21:55 +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; Fri, 27 Nov 2020 13:21:55 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v2 6/6] aarch64: Use mmap to add PROT_BTI instead of mprotect [BZ #26831] Date: Fri, 27 Nov 2020 13:21:41 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [217.140.106.54] X-ClientProxiedBy: SN6PR04CA0108.namprd04.prod.outlook.com (2603:10b6:805:f2::49) 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 SN6PR04CA0108.namprd04.prod.outlook.com (2603:10b6:805:f2::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20 via Frontend Transport; Fri, 27 Nov 2020 13:21:52 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f878791f-66f8-41a0-23be-08d892d76d44 X-MS-TrafficTypeDiagnostic: PA4PR08MB6014:|PA4PR08MB6032: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:497;OLM:497; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: BaBuPb9/YuYaqm6UJpQ+WP7akESjJp71I8Ow31uIMF1TpHrI2zvDRmlKv0AP4BLZGzpv+LS1h3GAR2sbXBMfIkim12QEmMtK4mZQV4jomdjZMkCiDKpKn3enGdI/Jzq+eYMaFWvGpPwyVrIi6NqCso8nydIiw0a/3ZWuVc4U0G6jYxKDCOdp5oo5yHHHRHZgr88CDSNxvzyny3xnZ6iYwqCSCHDQua0+t5hRuM+t5qFCJyEmrdaG5cYPNpuJSL+Qv255ei6omgWn9uUWeuPi6pj07Ezd2JhTmCIvIw+bKkNV9t3H1fIGm7F3BIrvKtYEwh3IFdSvsQ2O7mTHkKq5OzYhtR5VbhVMgwuanoWxUKm0dgZrL2ZBoO66TlGBAGmn 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)(136003)(39860400002)(346002)(376002)(366004)(396003)(4326008)(54906003)(69590400008)(6916009)(6512007)(36756003)(6486002)(6666004)(316002)(478600001)(5660300002)(2616005)(86362001)(44832011)(2906002)(956004)(8936002)(16526019)(186003)(26005)(8676002)(66476007)(66946007)(6506007)(66556008)(52116002)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: aBkv4e8QhDD/Lzlh8V/SyjUP8T5/lAC12SFWNYWmYVo5bKLLwRESK3gDvWTsY59yzqsNcMchEywEBLfj8NLUbKcNAcCPOvf4AyabEpV7XFjfGshbcuH8XxgXGN6xGcwwFF78GFLxn9Ico3Ngh0hVDNEeaB2i8fusthlwqnIw4uYReM9+mCxsKe3qTHNIpalCN683Nhx6tAN40Ik5cFzBMgVdRp1lQOzFhteTnJ8okdrlfgJ5TCSDD0V+oedtUKfDXDYgxk766oAJo8/XTxPLV49GKQT3S6Je2EStM+uG8w0OSUpZ0lB52M1qb6Pc4EmOutbD93ipjgB2JOFpMFnWwo1W90xCv8Ge8tBfxEMbq6Om/oXyYhli8u7bbX2FXJPlpFMFE1wH0zgG9UATUGqJuNEPu1nf1Rqj7Vh38X4UdrmlRFk7ExWSn6v/qijBNHhhRboPyJbqMW2hVF7slSbaWRIlDiW+umAv90+9Z/5FWraNObzrhv3WYQwE/x7IkcflGLye/b1J63wePBufw8OqbxdZly9c0Y2xNzJC70bsGUvstrpJY6xa7E0gsEJKkg0915tbbFTXhLKVMrIsEhfv+e8V94woZjoKeZ2tsHoGOghExm+tmKvCpES9Bdyi7vJdxfYNj554Eh5k7gifKlEgpNSSjLWk+8tELIAD6dYKYLXrvzxUd13waXvYu9nkjxWJe5b9VYoCkmEDL/tH/Qd+srAmfIn+4/Had0HRKagUxL2KSk6tPwiKHU0inEjtJ8l8iUMb2ZdEFsg2IeuHdYiUXoUhkUmEoe4w/xM5j93qwXkh6u0cz7Cyuo8fhfTGApNpRmQeheurkndBTlJtl6X1Rd9fTfEunWkkWDzBoU+pNQHqLHf1MOoh8K3B7OPRxmA206TCWuhu+0arIQOH6MdPs/3ta0JtrDNEMOMkRnnWYZ2EspXNNUnKspZ5OkMalj7sYuYn9452aHr+y3+UdHMisLslGgfUNoJN4dWS+xwpLiZzvJV6ZtlwQa4428w+hWuZ X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6014 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: VE1EUR03FT046.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: f345003f-ce57-4f90-ab51-08d892d768ff X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LCBxOmLXZ7bpMaAeavfIrU/0UCyc6qbShtMwxrKJXSHH/KPHO6ldyHPGScFqyrh6sqFLB2nUYESKgMz/S6XoZjzvqlt0Z3KUdKqkJgEtJKn1k8OrUqol+jEdnGlpAzNx83HG+wMx6VWlHMtIYzR6FXkabbXt+htA7IQ6jurobzcWocGH5/2upzEca8M2++9ateQinKyRn0doL1c3Kgegpj71vS9Im0QnT3j09ZQhe4/sIq6rCEcxH6hy/3uyhfvBFl8kzhvAmHzQIJ5/uEDjlyGWoJRKvcO6ZlJ+oFDRrFCeeeY/yc0Gpi/vaRfciKyy0yo7Rb+yoUp5HsNRtMrNBnuaZLf/ioxtnWZW9phXgNiVO45dUcGX6vmctXsW33ixInQBrXtQaQDiVQ7ErSUF0CRhycosi1/ASZvA8iKZlX6MEaZCbM/Jk0iNKjvxX5o3 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)(396003)(376002)(39860400002)(346002)(136003)(46966005)(16526019)(36756003)(8676002)(186003)(5660300002)(356005)(956004)(6666004)(4326008)(6486002)(6512007)(81166007)(2616005)(44832011)(83380400001)(8936002)(34206002)(336012)(316002)(70206006)(82310400003)(86362001)(54906003)(70586007)(2906002)(26005)(47076004)(69590400008)(82740400003)(478600001)(6506007); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2020 13:22:02.0461 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f878791f-66f8-41a0-23be-08d892d76d44 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: VE1EUR03FT046.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6032 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201127_082209_998924_9B923069 X-CRM114-Status: GOOD ( 22.81 ) 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. Computing the mapping bounds follows _dl_map_object_from_fd more closely now. 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. --- sysdeps/aarch64/dl-bti.c | 67 +++++++++++++++++++++++++-------------- sysdeps/aarch64/dl-prop.h | 8 ++++- sysdeps/aarch64/linkmap.h | 2 +- 3 files changed, 52 insertions(+), 25 deletions(-) diff --git a/sysdeps/aarch64/dl-bti.c b/sysdeps/aarch64/dl-bti.c index 8f4728adce..34b5294f92 100644 --- a/sysdeps/aarch64/dl-bti.c +++ b/sysdeps/aarch64/dl-bti.c @@ -19,39 +19,62 @@ #include #include #include +#include -static int -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; - 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; + /* Add PROT_BTI. */ + unsigned prot = PROT_EXEC | PROT_BTI; if (phdr->p_flags & PF_R) prot |= PROT_READ; 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; } - return 0; } -/* 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) @@ -59,16 +82,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. */ };