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: 1407198 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=KDna62wb; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CjFbv09rlz9sSn for ; Sat, 28 Nov 2020 00:20:10 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 777393972C28; Fri, 27 Nov 2020 13:20:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 777393972C28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606483208; bh=9A7jyF9nJCx5qjd6mb9MA3ZfKz/fr2f9ttL3ctZTfxQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=KDna62wbgka6fYs1jRzuhk4G5U386MZ+IrxM1K4ItjKO6CoNziIuG+YeN4vCfOGj8 +eJp5hz+hADdN2mCr+gzfpvw+c9GCWegYlhElC9aB7NM34tyEU3yEx7SWSkXNkXH2z cCfVIBzczF/O8hzKgle/qudJpgFcfOTcuvFXDBaw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2078.outbound.protection.outlook.com [40.107.21.78]) by sourceware.org (Postfix) with ESMTPS id 9C656396E463 for ; Fri, 27 Nov 2020 13:20:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9C656396E463 Received: from DB6PR0801CA0056.eurprd08.prod.outlook.com (2603:10a6:4:2b::24) by AM6PR08MB4627.eurprd08.prod.outlook.com (2603:10a6:20b:d1::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:03 +0000 Received: from DB5EUR03FT043.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:2b:cafe::2d) by DB6PR0801CA0056.outlook.office365.com (2603:10a6:4:2b::24) 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:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;sourceware.org; dmarc=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 DB5EUR03FT043.mail.protection.outlook.com (10.152.20.236) 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 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 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: 6f4faeb8-f2fc-4f0d-1929-08d892d7269b X-MS-TrafficTypeDiagnostic: PA4PR08MB6014:|AM6PR08MB4627: 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: DB5EUR03FT043.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: ZPHv2RYoTPb1ZDNSmUOWmeI3AnHVoZt3Jg299cc16pubXnIOZ8PsLGPLgBlPLLTpbra+rBvdenlpsGhiWtsNsv8NPYrDykAyC6NG9yCfVy7YCnI72/h9+Mf4BR49+fKvrGf6jDZLs5zfa8PFHu51bNzBg/mA9PS53jsr8qyq8YRPSYwRr2GvOQhBqq8TUjUU6sHnBQ3jBZ+GnlpY+QPUXCxU6voO2tbH8nTNjLSC5/0M5+AENsi5x8lwalvPUEFKFEUZxcLKOaYsvoc9zuNPtuOitBMGtpAcU7oP6zj0sQ/773iciIE4jXhnIz+XTwY75OypnbocuqlGW8HF1USlWnUREVobQTBj4rol1ZSEedYHrYcCfeC92IhckElNO9FGy0HG1SKLwQI5ab96UMWzcznzq9B9cWr6xr5h7MEhm99V42aZyRL3BWE+XbSKcHLV 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)(136003)(39860400002)(346002)(46966005)(6666004)(26005)(16526019)(336012)(4326008)(82310400003)(69590400008)(186003)(478600001)(36756003)(6506007)(70586007)(5660300002)(356005)(44832011)(2906002)(6486002)(83380400001)(86362001)(8676002)(6916009)(81166007)(82740400003)(8936002)(107886003)(2616005)(70206006)(316002)(47076004)(956004)(6512007)(54906003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2020 13:20:03.6177 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6f4faeb8-f2fc-4f0d-1929-08d892d7269b 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: DB5EUR03FT043.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4627 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy 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 Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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: 1407199 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=pCV+mAtf; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CjFcJ6XWjz9sSf for ; Sat, 28 Nov 2020 00:20:32 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8EF5A3972C2D; Fri, 27 Nov 2020 13:20:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8EF5A3972C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606483230; bh=slIbyxS48hCYiEWuhWEE/Oa6nVJ/gAblbWHjFFkv6s8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=pCV+mAtfnesefDn1u+3BE/EL+uktJezAR4BLqRo1uBAU0fRbtdIvaHcVxT2fbe/yT JsHRcARu3w5lmfeLEKPQ8jTjKHsLx5srAYOr9thMcDJTjqasvjr5GeY3t2tPrcVp1c VejXS8VTu/BJ9RjbaI8vnDRDrKw355q1F/t5sBP0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2082.outbound.protection.outlook.com [40.107.20.82]) by sourceware.org (Postfix) with ESMTPS id 46941396E463 for ; Fri, 27 Nov 2020 13:20:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 46941396E463 Received: from DB9PR05CA0008.eurprd05.prod.outlook.com (2603:10a6:10:1da::13) by AM6PR08MB4471.eurprd08.prod.outlook.com (2603:10a6:20b:b9::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20; Fri, 27 Nov 2020 13:20:25 +0000 Received: from DB5EUR03FT022.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:1da:cafe::7f) by DB9PR05CA0008.outlook.office365.com (2603:10a6:10:1da::13) 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; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;sourceware.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 DB5EUR03FT022.mail.protection.outlook.com (10.152.20.171) 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 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 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: e1455747-24f2-4061-cccb-08d892d733a3 X-MS-TrafficTypeDiagnostic: PA4PR08MB5982:|AM6PR08MB4471: 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: DB5EUR03FT022.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: dYu4lpKcaZMTh+qtyq22L3ksL/dwx8k5CHp4o0RwGRRH+BpytJ29YgsFcX2yNkywMiximYf/5lbJ2KasQD62QRPsSmLwoWOqhEntmkYNAvMWruOW59tEPsTy1lFVCm+OWqocYne+gK3Q5YOhDnbbDI8Lb8rmJjzJczCprBT/DiTWTEOAyjHTUmMW8jqNDXwTOt//m4WxnyjnruktXeRJv9q4bxFpASo3hQTPJtaA/1wS/YoZdLLtjpnQ1Iy/0bNBjCOZ6FKtSxF7DTGbpqLne71URbJAPccNcbCxxuFAejEAbvZwAP/RT/Dp1K/a0qI/nRX2GI2orCPi3QdseVu4UovuoNc+cUq5XJhqpI+fnf1gVyP9rkxLXIn6PHnqY4A3zOS1M/m23WV+H1CbL7itHpRTUHEo0x/WjgjJJ4Yk13eMkXcflpEkvS+FhUhhlX6R 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)(376002)(346002)(396003)(46966005)(86362001)(6486002)(356005)(8676002)(70206006)(316002)(478600001)(83380400001)(2906002)(81166007)(36756003)(44832011)(70586007)(6916009)(69590400008)(82740400003)(8936002)(6512007)(47076004)(2616005)(336012)(82310400003)(956004)(16526019)(4326008)(6666004)(26005)(186003)(54906003)(107886003)(6506007)(5660300002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2020 13:20:25.4851 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e1455747-24f2-4061-cccb-08d892d733a3 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: DB5EUR03FT022.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4471 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy 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 Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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: 1407200 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=F//d0oML; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CjFcn2r4kz9sVK for ; Sat, 28 Nov 2020 00:20:57 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A454A3972C33; Fri, 27 Nov 2020 13:20:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A454A3972C33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606483254; bh=c4W8h42KC+tuve8tPTBuxxqbSUaADFodArmw0B4sZp4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=F//d0oML2RmHRoQETlJzA3Fk4wzYbz3lNs0OYDgLHFyABcAnP6Xwxx+oWkdUR6vTq 25u44oh1TwWE5Gf0O2lj8DcwdpuvJ2nZoHrLyq+U6ezSep6AXqv5mTI1scpDhh5uEh OuI0wEpR6XqUB5aawxoSSV0QzZaTs9wKUtLFRmgc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70082.outbound.protection.outlook.com [40.107.7.82]) by sourceware.org (Postfix) with ESMTPS id 815B3396E463 for ; Fri, 27 Nov 2020 13:20:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 815B3396E463 Received: from DB6PR07CA0055.eurprd07.prod.outlook.com (2603:10a6:6:2a::17) by AM0PR08MB4193.eurprd08.prod.outlook.com (2603:10a6:208:125::28) 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:49 +0000 Received: from DB5EUR03FT011.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:2a:cafe::19) by DB6PR07CA0055.outlook.office365.com (2603:10a6:6:2a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.6 via Frontend Transport; Fri, 27 Nov 2020 13:20:49 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;sourceware.org; dmarc=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 DB5EUR03FT011.mail.protection.outlook.com (10.152.20.95) 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 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 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: c3a55d37-2368-4e3e-1d69-08d892d74218 X-MS-TrafficTypeDiagnostic: PA4PR08MB6014:|AM0PR08MB4193: 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: DB5EUR03FT011.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: By5kjK7w+mTEt1e8zm8uZXqjdrKmA4Ez4Vk0oWtIrAjQtM1iginioGeq2dW0zES+78TkgvpZTLhT5ZMa+CToBfAM+qmJmR/ejv5kHMjL8lb+TgSoqensvWILRNuPJ47tzothjTUdVJE/kokwLjVmTcRZ27GOwkmYw4OyTixxtrRbdsSZljru6HBMfQXITmf6Twtl9dPt++u/7o88v9ou47LTonTQYmdeWPET4abjh9z2heDK/fgu8exruwK0oehq5aqhTidVNX+gySSo3V/gtLWdQmxb8jMEG0OGLxx9CvPMBUg7Imqwhe1tQTb/m5x62Nqxafu1e9+4QRZ6+g1aedBad8MQNmpicr2D7PV+7Ft5vTT99zaQ8VLZ4o6pg39yo3uc16Cw2Cqqr3BH0fKvgnm4iGEhYNVn4Wqr5PS64DGLKiCisLs3mk9DttvQKU0J 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)(376002)(39860400002)(46966005)(2906002)(336012)(70206006)(6666004)(5660300002)(16526019)(36756003)(6512007)(956004)(82310400003)(81166007)(26005)(356005)(4326008)(6506007)(107886003)(83380400001)(2616005)(69590400008)(316002)(82740400003)(6486002)(8676002)(70586007)(186003)(54906003)(86362001)(8936002)(6916009)(44832011)(478600001)(47076004); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2020 13:20:49.7365 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c3a55d37-2368-4e3e-1d69-08d892d74218 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: DB5EUR03FT011.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB4193 X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy 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 Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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: 1407201 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=vBTqdgjo; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CjFdB5mL4z9sVK for ; Sat, 28 Nov 2020 00:21:18 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 465E7396E463; Fri, 27 Nov 2020 13:21:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 465E7396E463 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606483275; bh=Q1jU0aMUj4QfK8EyRD8DvcTi5AwkXzK9UGUF9Nf79/g=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=vBTqdgjoCA6gjcbkmTR5kbopGqCXIdgBNsF643F7xb7+ljgza7krLVfHIkfc8+imL J0tT7UMhuDQMRIHSPPXZGXqXAIOa6rddeExgY4LdBOxsHEyTSfLJVIuv5+ph+fxFpN Ym2VaSbRMI1oA17ANWI7h3uSUBIzOk78tbHEPbJQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-eopbgr120085.outbound.protection.outlook.com [40.107.12.85]) by sourceware.org (Postfix) with ESMTPS id 3842C396E463 for ; Fri, 27 Nov 2020 13:21:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3842C396E463 Received: from AM5PR0502CA0006.eurprd05.prod.outlook.com (2603:10a6:203:91::16) by PR2PR08MB4841.eurprd08.prod.outlook.com (2603:10a6:101:27::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3589.29; Fri, 27 Nov 2020 13:21:09 +0000 Received: from AM5EUR03FT032.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:91:cafe::ce) by AM5PR0502CA0006.outlook.office365.com (2603:10a6:203:91::16) 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:21:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;sourceware.org; dmarc=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 AM5EUR03FT032.mail.protection.outlook.com (10.152.16.84) 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 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 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: 6aeb1a58-8d86-452c-0d66-08d892d74df6 X-MS-TrafficTypeDiagnostic: PA4PR08MB6014:|PR2PR08MB4841: 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: AM5EUR03FT032.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: KV4ByULy0A5Cp+dqf+/l/8h/M6NgYUbgwXrXhRjg7H0GRuCIhVySi1wnQEjz1BcUKplyjJQDBZJzgUqZzTUSsDy8QMiYUrT34vuiUyX8jcmoTPoV6GSMc04ZgRUlsF3o950nIL49BZTjNj6RU7yOHdmjY4k1Qdp460N6+yC7mxiscaUbuEAsELTbh64lG68pbFLvDCnC0OO3Uu7g+ZA9ZcuFyx8e5xePlKxMtnU0c7pIWURPkPdu3cjuMG+sYIdnHrjEhTEQPxnFaY8S6WTCUL8KNjkycv60Pa/KnQsMyy+WPEsC5kwllqTVSNYkJKGh0mS6iuyhzuB7clN1M3aRrtZAJ/2KEvwV0BHwvjZQ0Jx1+sKsns/ZN2avMe8/0nqOX6241NMO/Ddhth2Cft/D+XhUS0zlgmwy2/d3PU/rCgr0WD/58ryiacx//JTJh78s 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)(376002)(346002)(39860400002)(46966005)(81166007)(6506007)(356005)(5660300002)(6486002)(54906003)(86362001)(316002)(2616005)(36756003)(44832011)(6916009)(8676002)(69590400008)(956004)(82310400003)(6512007)(8936002)(70206006)(26005)(6666004)(336012)(16526019)(478600001)(47076004)(186003)(83380400001)(82740400003)(107886003)(70586007)(36906005)(4326008)(2906002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2020 13:21:09.5960 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6aeb1a58-8d86-452c-0d66-08d892d74df6 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: AM5EUR03FT032.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR2PR08MB4841 X-Spam-Status: No, score=-14.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy 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 Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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. Reviewed-by: Adhemerval Zanella --- 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: 1407202 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=EoUfinzM; dkim-atps=neutral Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CjFdk5J6Nz9sSn for ; Sat, 28 Nov 2020 00:21:46 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 51F553972C37; Fri, 27 Nov 2020 13:21:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 51F553972C37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606483304; bh=nBpOGzKrR218CsAMW7ki/EWPc6Uz5KXS+PBRk1M3+bg=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=EoUfinzMt/VEOv3oZ2z3FVEm9eGIQKip03bATVI5dYoHF/R9XWPKKYS/6sE6brTwk fyuILB/BhGV+wvbTMFsdlqbthnQCDcRCta/vthnOJ+AKiyCXd8VTM3yuReSBKNXZq5 0vjtQBnkUDRzyqMJApQVOi2/FuVs4qUpzjwEYF6Y= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2043.outbound.protection.outlook.com [40.107.22.43]) by sourceware.org (Postfix) with ESMTPS id 7D2E2397282A for ; Fri, 27 Nov 2020 13:21:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7D2E2397282A Received: from AM5PR0601CA0038.eurprd06.prod.outlook.com (2603:10a6:203:68::24) by VE1PR08MB4670.eurprd08.prod.outlook.com (2603:10a6:802:ac::16) 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:21:37 +0000 Received: from VE1EUR03FT021.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:68:cafe::e2) by AM5PR0601CA0038.outlook.office365.com (2603:10a6:203:68::24) 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; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;sourceware.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 VE1EUR03FT021.mail.protection.outlook.com (10.152.18.117) 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 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 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: cf91ba1d-9917-4b5e-3606-08d892d75e13 X-MS-TrafficTypeDiagnostic: PA4PR08MB6014:|VE1PR08MB4670: 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: VE1EUR03FT021.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: Qt2PSuFD7CwhSGOOmP6UT/g/lmzSnmZ95562700whobDw3Pv2cu9pTLjIAp9nnwib8p9TMR6HgJwKL6HQqArCV77DtYxEIuf7NjrFHktygmNLttUId9RN1lmdlLfASy7T4vvKhEfaU94heihhQYBZcQY/vCLjJJ5u6aGVq2M6CCgqutGNq8cxSHvKjVXdH+a2NW4F5VzYfyEYyBjR315RIjy+w+9b9k53W9L0CsLZg9Vo/Y3cKDOT1L4W02aXjrGhyXhQoWFUYb+1e84TVwF27FlmNdg9Ddshp+DzQpGEr0A7G3gJMmoXn6s3FJSpANFmPBvj8Bc1I8hJBShWeSsfMzWG2y9WhxWkGjuCgPN4RsC7f2KnY6nBhNHztGepq4nZZX5RTYNFu29+wbROaYhViC2FubKcduGwZFqgwDa9yuhEhMGTxZiTz7yBLMTd93C 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)(39860400002)(136003)(376002)(346002)(396003)(46966005)(6486002)(54906003)(83380400001)(316002)(6512007)(44832011)(16526019)(2616005)(6506007)(26005)(186003)(6916009)(69590400008)(336012)(956004)(82310400003)(81166007)(86362001)(356005)(107886003)(8676002)(6666004)(2906002)(4326008)(8936002)(70206006)(70586007)(82740400003)(47076004)(5660300002)(36756003)(478600001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2020 13:21:36.5537 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cf91ba1d-9917-4b5e-3606-08d892d75e13 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: VE1EUR03FT021.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB4670 X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy 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 Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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: 1407203 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=vgz9aAdK; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CjFf91ZyXz9sSn for ; Sat, 28 Nov 2020 00:22:09 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E06A43972C3C; Fri, 27 Nov 2020 13:22:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E06A43972C3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606483326; bh=wNhDXoIacsU34w/3BvmYpkHf4Z/z/9IrNSX8sg3eJMw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=vgz9aAdKDoBTwHx1FXMyRdxamVU2p2MO8VtVNwxVhl9bsj+BDd7dq5QBYFxGUh699 bwaQtYl1h7Ois0RnXc0jja9P+Dlrf/bo1tBU14yj1fzBoQVxKDXkV3k799XNyBmA+n Nbc4iQcyQ6YWBv3CJ4+8+rIsl8RFRYhDjqnWCDKU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60046.outbound.protection.outlook.com [40.107.6.46]) by sourceware.org (Postfix) with ESMTPS id AA1363972C3B for ; Fri, 27 Nov 2020 13:22:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AA1363972C3B Received: from DB6PR0301CA0085.eurprd03.prod.outlook.com (2603:10a6:6:30::32) by HE1PR0801MB1689.eurprd08.prod.outlook.com (2603:10a6:3:87::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3589.20; Fri, 27 Nov 2020 13:22:01 +0000 Received: from DB5EUR03FT038.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:30:cafe::a7) by DB6PR0301CA0085.outlook.office365.com (2603:10a6:6:30::32) 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:01 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;sourceware.org; dmarc=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 DB5EUR03FT038.mail.protection.outlook.com (10.152.21.84) 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:01 +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 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 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: f706a4c8-3de6-46fa-2f1d-08d892d76cfe X-MS-TrafficTypeDiagnostic: PA4PR08MB6014:|HE1PR0801MB1689: 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: DB5EUR03FT038.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: aJTp0uK6WgGKEWc0ajoBs9FT3/Q4xjZB2Arq7k4uhQD9wvzZy4tN/ST8itj+92zOthjqXtiYAGSjv3H9lpvZgKq3Yfi2Imab0fhS7xr/tbbnnGkGzs8EJAP+uSxDInOw0S+CKAKBZ6Rjl8bLjWnM00eihzDRLu4RA+HkaAX6n4c8XZnzJ25hzIg+JDtMjYDsa4+EV549UL6aDhTpKv8zB9OZtQplfWQLFBEgVTYK92srl2J4Yud6gnyPNJX8r1rzsDsh9Wc7IzFHaGP0lW4U4FUVTRA5K8joDo/dwrtVvjuSltmQs74zQjJyG5MqLp5UKMCnD026sZJpSB5N8AsYnswnrnIvRmzs3INczVaWwwmVNPQL1dygpAP5EYZFQemER8D0czS2D/pV8A4Xuq6HjArdavjF77+yNC/JeL+GeglFTlPhQtauT29s7n79js8i 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)(39860400002)(136003)(396003)(346002)(376002)(46966005)(47076004)(356005)(54906003)(6506007)(336012)(6916009)(4326008)(107886003)(6512007)(81166007)(16526019)(82740400003)(6666004)(186003)(26005)(478600001)(36756003)(316002)(86362001)(8936002)(70206006)(8676002)(6486002)(83380400001)(956004)(70586007)(82310400003)(2616005)(2906002)(44832011)(5660300002)(69590400008); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2020 13:22:01.7086 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f706a4c8-3de6-46fa-2f1d-08d892d76cfe 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: DB5EUR03FT038.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0801MB1689 X-Spam-Status: No, score=-14.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy 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 Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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. */ };