From patchwork Wed May 4 06:26:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1626078 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=JA0y9H8o; dkim-atps=neutral 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+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) 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 (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KtRhq5vZjz9sG6 for ; Wed, 4 May 2022 16:27:55 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A5FAE385840C for ; Wed, 4 May 2022 06:27:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A5FAE385840C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651645673; bh=56PW+SoNFkh1/EkwwyBsTCuaEdftpGtGsgydgEIFGgw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=JA0y9H8oXfVzAJJIfr+8u1jsTXB2FYLt/6s+gKHcFQ+2AcNTAp+fZbrd4/rp9NK4p ijPemRzWblQudEuhJKbbhSS32nEYfyK99G0xKQaoJs3tpRXmRVMCxCzM456+NSxh7q XyPNNhUaUJWBNpQLvepfTKKUFM3libclmakX+RQU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2085.outbound.protection.outlook.com [40.107.20.85]) by sourceware.org (Postfix) with ESMTPS id 1D1A53857825 for ; Wed, 4 May 2022 06:26:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1D1A53857825 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=WcJNgMPUZ4LSzJ/k4BLKW8HUUjwq1YNu26b5pE3p9rmXrzbso+kcH/W9e61TOL1hIosmaXhy507BiGtYNP5n9+pmtJNeRFZhu5yDVhbzkqz6XJzthCdiCIuaWPkoBCqM7tTwRRjViO69os3X1XEYRxtNTo4t60u/kAhYSWBbwhLrllojqm5D0ib2zJ/hN+8ojo/j1aFBapbAFprt166ahn5OuhGcPs+TKrYc60sHj015nAKhNHSPNX/x47DgyQqPXLNngxmqXMhrJjW5OoYv4E4KpaE7cWyhrK3lotEDBzc8IoAmEHStlGro3r+H7t3YX1r5+znfQ6m4YYWR0jW6bQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=56PW+SoNFkh1/EkwwyBsTCuaEdftpGtGsgydgEIFGgw=; b=YBo+Ix7Yxgdo4bFwmlbSMJZ0CqGhT2rZaqzxG7EC5vf3ivDqdG6z1TLvC3Ac5dsgWn/EagSaVELfvwcaILokRoc8nDcZkgO2wLiQ8kgeKEn/8/s6Uw349EPI6ZgNT7jnItwQ5tp/CdCl/+Y7QJVx9DnSsXTIGwHZBGkpsEZGRxL6YCgfBSj0Vp7tjCiSVBrJuU2qTSiabYit96hvdc7S3NEO4wz8k9GArHLxDS9MZw3cVc0ob5hEp5J9wqcB7Kfn//LCdwjfS3voH1g7ADUoKoILwvkLoHx3yJ7ZTdSuYHjAYSd2uEK7yyiUhMJqsQp9eHkt+oNXK9DxBw4RTATS/A== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1, 1, smtp.mailfrom=arm.com] dmarc=[1, 1, header.from=arm.com]) Received: from DB6PR0501CA0043.eurprd05.prod.outlook.com (2603:10a6:4:67::29) by PAXPR08MB6478.eurprd08.prod.outlook.com (2603:10a6:102:159::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Wed, 4 May 2022 06:26:53 +0000 Received: from DB5EUR03FT038.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:67:cafe::30) by DB6PR0501CA0043.outlook.office365.com (2603:10a6:4:67::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.25 via Frontend Transport; Wed, 4 May 2022 06:26:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;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.5227.15 via Frontend Transport; Wed, 4 May 2022 06:26:53 +0000 Received: ("Tessian outbound ab7864ef57f2:v118"); Wed, 04 May 2022 06:26:53 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 88ae5e6b8defc003 X-CR-MTA-TID: 64aa7808 Received: from 985d5fef80c4.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 4196D21F-0781-479D-90CB-92D7016B5E43.1; Wed, 04 May 2022 06:26:47 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 985d5fef80c4.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 04 May 2022 06:26:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UC7037TNCTksW5dZlTEtHE1ZVlpnXucSNAL4eal12+u7LFEMkJTos7urqdtO6SeQfiLU0z7H+j6QjFOnTJWDb+eUMqGXDYU6HGR7A1UysD/p6ZIgIl9ehu97zk98EknrGCKg6q1VlSEEGkAutx8YtEh60jOn/17hfS7lpCOyhliDUdYGjhVAsMebZLNpT0wGCF3iYXKBE/PbOBX2Dv89Lk49ygmUARd6FvwliHd4SOyH5AOZAw3k1pb24BUNJfonl/FGzn1kvWAJkj5UzlKkMXQxhAaj84omwW1DW2KdwZqAAluxE7Y6ZKS9QvL94DVEqEGSVdnjkDqkda+3ZveqKA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=56PW+SoNFkh1/EkwwyBsTCuaEdftpGtGsgydgEIFGgw=; b=Wk1kVb5NkzNiszr2fYOuz2DsKWN8weimJ0k+KK0bPbxnN8v3d+qUbAWSqFYonKdcKDGz7/Ey3UToEujTaXLycYesGbc1rOSQHpaNlUS6CveyFNMx5hJfgcHpzTWCXLC3VjU54ehnSzlEPn+MHcIOOUNvyPuFRjnIwDfIzxHlQrgpj4gevUNdJDwKJOzityFX9bz6TkPp7KSsHgbvrAe1sm9uYpIQ9PEZpiTJDiHi0wzv4jRjvvLQtrRzmlv2+mbcEtleiu8C6RiOHNFufzwLtb9Ccz92RbmA/2T8EGaHzbGyuq+NXf/qwSBkF0t4Og9ixs586HC9wHPUFShUva7Z/A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none Received: from DB9PR05CA0025.eurprd05.prod.outlook.com (2603:10a6:10:1da::30) by AM0PR08MB3555.eurprd08.prod.outlook.com (2603:10a6:208:da::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.12; Wed, 4 May 2022 06:26:45 +0000 Received: from DBAEUR03FT016.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:1da:cafe::69) by DB9PR05CA0025.outlook.office365.com (2603:10a6:10:1da::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24 via Frontend Transport; Wed, 4 May 2022 06:26:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by DBAEUR03FT016.mail.protection.outlook.com (100.127.142.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Wed, 4 May 2022 06:26:44 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Wed, 4 May 2022 06:26:47 +0000 Received: from armchair.cambridge.arm.com (10.2.80.71) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Wed, 4 May 2022 06:26:47 +0000 To: Subject: [PATCH v4 1/4] rtld: Use generic argv adjustment in ld.so [BZ #23293] Date: Wed, 4 May 2022 07:26:43 +0100 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: fe575b9a-a27b-4c16-1b04-08da2d9714b7 X-MS-TrafficTypeDiagnostic: AM0PR08MB3555:EE_|DB5EUR03FT038:EE_|PAXPR08MB6478:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: iEMRXtjZhecuDeqv4al9QXnpD2vqxapMFAoSCcPFn7ZeRRosvvlaxUpyUoPROA65HGAyw54/boInF/6VaWkr4I8ucB4mF5Cyte/2Np1K6hOtDeQ3iEnMJHwDnUwnwUuhpgnh3OopwkMnweUBCdMkzPpnNYlg5fN/+6RfrWibXYYpplR7sW9Qi/yyfxvoCMyPI8KFWWmXbo90JyfZ+f0d29jbyvjAO3AfqfGVwHefkUZ7dFblxKROJutpQ7y0tbkndngke9AJ1DMrLFhPjL41qt0EEmqNYpQ3wTL9psSdeSQ7l8dWvKvLrQal9NY80I1w13rBamLUHoI7+O4u7cTKh0ChjAEKrySt8AAIDrzESFO+fQ6/Rn39An37MlUCCQLafukAns93DrGrBN2/fR3LfyCyuWwwMm2HSZV/LSYnODKzX7JlVij4hhuO+f8+big9/2nMz84x3MbfdvZ1wX3lFRnzTdA1TQ1Vn4N+wVerfVk00zRXuTroynF5Me3gRmPj7e649W8huAxVQsXE9wIIjhdhOpLbRCFvQM3CQcN2OaXldlS2HDXZ2RNK2+lTAvGhIONt+o1ZcpuA/0KFE4QpaH4eyy7Ir0fVmNZR4C4Q4O7OGsStJ07EHWUrtCaMVrhHQtgyuesHGLWN2OtHVvnPIiVxcKJdGju2BEJ4AnlfGMXa40OqQNxvqUtkGXJMH7IJUt3LIiXYp3/5xuJECfNrcojvbrut5h/QiIjJVEIK4c0= X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(186003)(44832011)(6916009)(36860700001)(36756003)(8676002)(81166007)(40460700003)(5660300002)(356005)(316002)(6666004)(70586007)(47076005)(336012)(70206006)(83380400001)(8936002)(426003)(2906002)(508600001)(86362001)(7696005)(2616005)(26005)(82310400005)(41533002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3555 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT038.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 8a9bca68-bb61-4174-7023-08da2d970f65 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UvXlYshcTu0pJJd+x2ivE+H4Amt8WUlL8o3rgM0hsAtv8ZDrj5ey30gje+iUSmEtvANiHXWjzosSlZLcgR8qJHcBDr+meTgZSI25b8xTCjnyunYjw55sPQMqrFgOMiTUeJyKu2/9cJ4+XKmN4GFkKab87qk58emVBpUmWNxY4dl8mbNV67ckq+FOdX5xOie+omqErKGfh4jni7CvHVVLJA6QHaxcXstDMDfri+s8amBRaHqSxk4Kva4MGr3yU2DoflKOhQHRoZJqUqAM6cYn1J0N4USWZ//zhUrYWggLCxXmFy4J9BYdBjXcuGjnyi7PxuNsnhsXS+z91ihGGeb32pEso3z6Eapp5CTt9xzlDzPH1DHywENX0onqa/G93FNNnVAreEid9yuxjgj/aSE69NZD6TE0bZywDadxWrhNcpPd/pp68yszRvtPOiyHKJclVORq4ERWKQ6iRg6rhApeVuH7bENFjVV8oGSnkKow0eoQt/c+bV732aPRaFhv+6NgbpGGkP9uOkZ58WBfVUGyg5l/mJBogEDp2wy4PWFRmlO5g7qwhxiZvCkYqFnTKOuRY239PBHlIvM5Uc3ztPZEZ5pap8CVhmjuUSHLB8fUm3hlH0ngHA0y2zHQA664LmusO3escdeiEJGNqdwcN5S+JllC5Gc/k4IgCkNWwXDw4ukIpCtrB87+5N80JDDJWlS2RsE1E/nNRk8I8sQSvNJr/w== 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:(13230001)(4636009)(40470700004)(36840700001)(46966006)(7696005)(2616005)(8676002)(86362001)(6916009)(6666004)(70206006)(26005)(82310400005)(70586007)(508600001)(316002)(40460700003)(36860700001)(47076005)(186003)(426003)(336012)(81166007)(83380400001)(5660300002)(44832011)(36756003)(2906002)(8936002)(41533002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 May 2022 06:26:53.7117 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fe575b9a-a27b-4c16-1b04-08da2d9714b7 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: PAXPR08MB6478 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" When an executable is invoked as ./ld.so [ld.so-args] ./exe [exe-args] then the argv is adujusted in ld.so before calling the entry point of the executable so ld.so args are not visible to it. On most targets this requires moving argv, env and auxv on the stack to ensure correct stack alignment at the entry point. This had several issues: - The code for this adjustment on the stack is written in asm as part of the target specific ld.so _start code which is hard to maintain. - The adjustment is done after _dl_start returns, where it's too late to update GLRO(dl_auxv), as it is already readonly, so it points to memory that was clobbered by the adjustment. This is bug 23293. - _environ is also wrong in ld.so after the adjustment, but it is likely not used after _dl_start returns so this is not user visible. - _dl_argv was updated, but for this it was moved out of relro, which changes security properties across targets unnecessarily. This patch introduces a generic _dl_start_args_adjust function that handles the argument adjustments after ld.so processed its own args and before relro protection is applied. The initial sp at ld.so entry is passed down to dl_main so it can do the adjustment. The same algorithm is used on all targets, _dl_skip_args is now 0, so existing target specific adjustment code is no longer used. The bug affects aarch64, alpha, arc, arm, csky, ia64, nios2, s390-32 and sparc, other targets don't need the change in principle, but it does not hurt and makes the behaviour more consistent. Follow up patches can remove _dl_skip_args and DL_ARGV_NOT_RELRO. --- v4: - New code is unconditionally used on all targets. - Hide auxv adjustments behind HAVE_AUX_VECTOR. - DL_NEED_START_ARGS_ADJUST macro is removed. - _dl_skip_args is no longer unused. - start_argptr is passed down to dl_main instead of using a global. - moved aarch64 DL_ARGV_NOT_RELRO removal to separate patch. v2: - use p != NULL, and a_type != AT_NULL - remove the confusing paragraph from the commit message. --- elf/rtld.c | 83 +++++++++++++++++++++++------ sysdeps/generic/ldsodefs.h | 3 +- sysdeps/unix/sysv/linux/dl-sysdep.c | 5 +- 3 files changed, 73 insertions(+), 18 deletions(-) diff --git a/elf/rtld.c b/elf/rtld.c index 3b2e05bf4c..d959dab0d0 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -397,7 +397,8 @@ extern struct rtld_global_ro _rtld_local_ro static void dl_main (const ElfW(Phdr) *phdr, ElfW(Word) phnum, - ElfW(Addr) *user_entry, ElfW(auxv_t) *auxv); + ElfW(Addr) *user_entry, ElfW(auxv_t) *auxv, + void **start_argptr); /* These two variables cannot be moved into .data.rel.ro. */ static struct libname_list _dl_rtld_libname; @@ -1306,11 +1307,60 @@ rtld_setup_main_map (struct link_map *main_map) return has_interp; } +static void +_dl_start_args_adjust (void **start_argptr, int skip_args) +{ + void **sp = start_argptr; + void **p; + long argc; + char **argv; + + if (skip_args == 0) + return; + + /* Adjust argc on stack. */ + argc = (long) sp[0] - skip_args; + sp[0] = (void *) argc; + + argv = (char **) (sp + 1); /* Necessary aliasing violation. */ + p = sp + skip_args; + /* Shuffle argv down. */ + do + *++sp = *++p; + while (*p != NULL); + + /* Shuffle envp down. */ + do + *++sp = *++p; + while (*p != NULL); + + /* Update globals in rtld. */ + _dl_argv = argv; + _environ = argv + argc + 1; +#ifdef HAVE_AUX_VECTOR + GLRO(dl_auxv) = (ElfW(auxv_t) *) (sp + 1); /* Aliasing violation. */ + + /* Shuffle auxv down. */ + void *a, *b; /* Use a pair of pointers for an auxv entry. */ + unsigned long a_type; + do + { + a_type = ((ElfW(auxv_t) *) (p + 1))->a_type; + a = *++p; + b = *++p; + *++sp = a; + *++sp = b; + } + while (a_type != AT_NULL); +#endif +} + static void dl_main (const ElfW(Phdr) *phdr, ElfW(Word) phnum, ElfW(Addr) *user_entry, - ElfW(auxv_t) *auxv) + ElfW(auxv_t) *auxv, + void **start_argptr) { struct link_map *main_map; size_t file_size; @@ -1359,6 +1409,7 @@ dl_main (const ElfW(Phdr) *phdr, rtld_is_main = true; char *argv0 = NULL; + int skip_args = 0; /* Note the place where the dynamic linker actually came from. */ GL(dl_rtld_map).l_name = rtld_progname; @@ -1373,7 +1424,7 @@ dl_main (const ElfW(Phdr) *phdr, GLRO(dl_lazy) = -1; } - ++_dl_skip_args; + ++skip_args; --_dl_argc; ++_dl_argv; } @@ -1382,14 +1433,14 @@ dl_main (const ElfW(Phdr) *phdr, if (state.mode != rtld_mode_help) state.mode = rtld_mode_verify; - ++_dl_skip_args; + ++skip_args; --_dl_argc; ++_dl_argv; } else if (! strcmp (_dl_argv[1], "--inhibit-cache")) { GLRO(dl_inhibit_cache) = 1; - ++_dl_skip_args; + ++skip_args; --_dl_argc; ++_dl_argv; } @@ -1399,7 +1450,7 @@ dl_main (const ElfW(Phdr) *phdr, state.library_path = _dl_argv[2]; state.library_path_source = "--library-path"; - _dl_skip_args += 2; + skip_args += 2; _dl_argc -= 2; _dl_argv += 2; } @@ -1408,7 +1459,7 @@ dl_main (const ElfW(Phdr) *phdr, { GLRO(dl_inhibit_rpath) = _dl_argv[2]; - _dl_skip_args += 2; + skip_args += 2; _dl_argc -= 2; _dl_argv += 2; } @@ -1416,14 +1467,14 @@ dl_main (const ElfW(Phdr) *phdr, { audit_list_add_string (&state.audit_list, _dl_argv[2]); - _dl_skip_args += 2; + skip_args += 2; _dl_argc -= 2; _dl_argv += 2; } else if (! strcmp (_dl_argv[1], "--preload") && _dl_argc > 2) { state.preloadarg = _dl_argv[2]; - _dl_skip_args += 2; + skip_args += 2; _dl_argc -= 2; _dl_argv += 2; } @@ -1431,7 +1482,7 @@ dl_main (const ElfW(Phdr) *phdr, { argv0 = _dl_argv[2]; - _dl_skip_args += 2; + skip_args += 2; _dl_argc -= 2; _dl_argv += 2; } @@ -1439,7 +1490,7 @@ dl_main (const ElfW(Phdr) *phdr, && _dl_argc > 2) { state.glibc_hwcaps_prepend = _dl_argv[2]; - _dl_skip_args += 2; + skip_args += 2; _dl_argc -= 2; _dl_argv += 2; } @@ -1447,7 +1498,7 @@ dl_main (const ElfW(Phdr) *phdr, && _dl_argc > 2) { state.glibc_hwcaps_mask = _dl_argv[2]; - _dl_skip_args += 2; + skip_args += 2; _dl_argc -= 2; _dl_argv += 2; } @@ -1456,7 +1507,7 @@ dl_main (const ElfW(Phdr) *phdr, { state.mode = rtld_mode_list_tunables; - ++_dl_skip_args; + ++skip_args; --_dl_argc; ++_dl_argv; } @@ -1465,7 +1516,7 @@ dl_main (const ElfW(Phdr) *phdr, { state.mode = rtld_mode_list_diagnostics; - ++_dl_skip_args; + ++skip_args; --_dl_argc; ++_dl_argv; } @@ -1511,7 +1562,7 @@ dl_main (const ElfW(Phdr) *phdr, _dl_usage (ld_so_name, NULL); } - ++_dl_skip_args; + ++skip_args; --_dl_argc; ++_dl_argv; @@ -1610,6 +1661,8 @@ dl_main (const ElfW(Phdr) *phdr, /* Set the argv[0] string now that we've processed the executable. */ if (argv0 != NULL) _dl_argv[0] = argv0; + /* Adjust arguments for the application entry point. */ + _dl_start_args_adjust (start_argptr, skip_args); } else { diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 4a5e698db2..31de149f23 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -1165,7 +1165,8 @@ extern ElfW(Addr) _dl_sysdep_start (void **start_argptr, void (*dl_main) (const ElfW(Phdr) *phdr, ElfW(Word) phnum, ElfW(Addr) *user_entry, - ElfW(auxv_t) *auxv)) + ElfW(auxv_t) *auxv, + void **start_argptr)) attribute_hidden; extern void _dl_sysdep_start_cleanup (void) attribute_hidden; diff --git a/sysdeps/unix/sysv/linux/dl-sysdep.c b/sysdeps/unix/sysv/linux/dl-sysdep.c index a67c454673..8c4a7e72b9 100644 --- a/sysdeps/unix/sysv/linux/dl-sysdep.c +++ b/sysdeps/unix/sysv/linux/dl-sysdep.c @@ -98,7 +98,8 @@ _dl_sysdep_parse_arguments (void **start_argptr, ElfW(Addr) _dl_sysdep_start (void **start_argptr, void (*dl_main) (const ElfW(Phdr) *phdr, ElfW(Word) phnum, - ElfW(Addr) *user_entry, ElfW(auxv_t) *auxv)) + ElfW(Addr) *user_entry, ElfW(auxv_t) *auxv, + void **start_argptr)) { __libc_stack_end = DL_STACK_END (start_argptr); @@ -138,7 +139,7 @@ _dl_sysdep_start (void **start_argptr, __libc_check_standard_fds (); (*dl_main) (dl_main_args.phdr, dl_main_args.phnum, - &dl_main_args.user_entry, GLRO(dl_auxv)); + &dl_main_args.user_entry, GLRO(dl_auxv), start_argptr); return dl_main_args.user_entry; } From patchwork Wed May 4 06:26:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1626079 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=gnnpnv/W; dkim-atps=neutral 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+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) 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 (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KtRjh04X0z9sG6 for ; Wed, 4 May 2022 16:28:39 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BBBEE3857822 for ; Wed, 4 May 2022 06:28:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBBEE3857822 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651645717; bh=3BIAq4Njp7cM4SYBnx0ZzKR4638cpgAiP7F6RB/K454=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=gnnpnv/WGzNBawZ6epUDkhEhJM9o51rxTq5duLWTOWycJkxUE8aSLvo0U7wrlDqag VOoxArmdVPziVgTBhfEjfGdDoPampPYzrKpVCQCKeQHJ5IVleENFkRt+tFvWj/lN8B vDX79Ha9drDPLg/+0cXl080Zl9SBTrO8MEvZuS6E= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-eopbgr20085.outbound.protection.outlook.com [40.107.2.85]) by sourceware.org (Postfix) with ESMTPS id CEEC63858418 for ; Wed, 4 May 2022 06:27:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CEEC63858418 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=FjT3DPv0CqG4c5yI1lobFWD06pPPispSHvl/WZEuvpoyT0uAvUhhWrdar0RBkc8hf5IU99CFMhGFhgIswb+HG6Jt5SoKV4OwB2+0PjinGDLhExPMr9GbPD5ZDDqezjd6tc0PzoX79T5sC0/KU9/g94GF23a9AZ4Kb5cU3Pa9zibrAL9vUNo06xPmdcN0Brjmw529p1LfCNCHkbDxI4MAiY19fazWzIZX3A/gRZdZ+1utRL+bUeeU1iZ+lNsMFZ/UZ09BYU2xtAPLI4lEy9s9x7EBr5zbWlxUFklU2Uj4EVoViLQY1o0ILei+TRjgdODeaE8IH91fJRbSdCLOqbWMRA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3BIAq4Njp7cM4SYBnx0ZzKR4638cpgAiP7F6RB/K454=; b=jd65LEvld7v0YxwkWaA2t8uGFMP4TYew3AWdgvBVuXfvQc8Tb+T597pit/4qO2tpU/9QLs1PzSMlKeeBIBU8+kOLgnUT5F2gnLOJ8NTcKknwjcNy/xMFvQPMh49bBFi4U3G6LoyQr/8C3d3F/P6RboCXJXKvb9agychQJWqCd0/soGJRBLXYyPPNlI/DV2a+dXQOa/7jqeeNf3GqEMzG584wDZVveaQTpLdyY+5Re9hRl4as7Zq0j0HEnEXR9owiRUI7JNBEvGXJ1kxmOH67iHPXxMGxUJ5HSJ4Ac9R87eLihx702e0X08zogBQ+6fmBnwe6490+XjQpForrxLEkyA== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1, 1, smtp.mailfrom=arm.com] dmarc=[1, 1, header.from=arm.com]) Received: from AM6P195CA0090.EURP195.PROD.OUTLOOK.COM (2603:10a6:209:86::31) by AM5PR0801MB1826.eurprd08.prod.outlook.com (2603:10a6:203:39::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Wed, 4 May 2022 06:27:04 +0000 Received: from VE1EUR03FT055.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:86:cafe::eb) by AM6P195CA0090.outlook.office365.com (2603:10a6:209:86::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24 via Frontend Transport; Wed, 4 May 2022 06:27:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;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 VE1EUR03FT055.mail.protection.outlook.com (10.152.19.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.15 via Frontend Transport; Wed, 4 May 2022 06:27:04 +0000 Received: ("Tessian outbound ab7864ef57f2:v118"); Wed, 04 May 2022 06:27:03 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 08e8598561a37663 X-CR-MTA-TID: 64aa7808 Received: from f5714ee4a5fc.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 833477AF-74E3-4550-BA98-A97BD4A7CA32.1; Wed, 04 May 2022 06:26:58 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id f5714ee4a5fc.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 04 May 2022 06:26:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ws6okuHrVnLOCWeso9x2KXSrbZkXVAWOfIXGr9o8CCyqV9dA2F2EzmrKse56KfVbkClcw1t0V1nUn5Q28Y7daH3yGix1CQrnSp7Gwpr4vlKuJ1uYEWCXQJQwS12no7XuFg4gEAVYNBcrZrLMM+Mog168bZszm1baROXaK3l5A1kaUaUjXNcedLicij0VR/qLmSkrjNMGdPiXqyzGfc5CFKtuk11ysja6Gfrr1xlb13zQlPSjiFvRYoiGEAJqOHfaNB1N0ft+D20N+MLPSW4u3bRlqwl9UaFdGCwachqpwB90U8hBPXooPAOWeDQdczSrTbq/rpJqTIDyWa+aFzShRQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3BIAq4Njp7cM4SYBnx0ZzKR4638cpgAiP7F6RB/K454=; b=JLWl6zbRcUy1fPYhaERf1FmjyJoEB6T8v53EUXmfLIi2pkQTxWf3aA0MTiFf0l1Icdhbvmp8/WTG0sFTuuoeR+knJIwTjFLgkMK2Q52kbMN/OIgiEDFc6WLboZSS3ldtV3/ifTngbJBDyFdmAfxyUKiZ5JBC452Uy3L/sJtEgYdcf3lSvbSgzPbLLrAw8BAR8aqTAVT/BKnqGFK4NQeeXGvFgPU+qGXiJWkGYLvBN6qZIryzIBFqRDNIKD2uXgTJ7vAcYyX9BGhmEvOaYTfUCXP4xyHb8CQgcPIRvFCqWdAQRCeAWI9xChlWt7/eVa7Bxh2HuCn1RpHwW6L981kW5w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none Received: from DB6PR0802CA0042.eurprd08.prod.outlook.com (2603:10a6:4:a3::28) by PAXPR08MB6382.eurprd08.prod.outlook.com (2603:10a6:102:15b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Wed, 4 May 2022 06:26:56 +0000 Received: from DBAEUR03FT052.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:a3:cafe::db) by DB6PR0802CA0042.outlook.office365.com (2603:10a6:4:a3::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24 via Frontend Transport; Wed, 4 May 2022 06:26:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by DBAEUR03FT052.mail.protection.outlook.com (100.127.142.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Wed, 4 May 2022 06:26:55 +0000 Received: from AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.27; Wed, 4 May 2022 06:26:58 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.27; Wed, 4 May 2022 06:26:54 +0000 Received: from armchair.cambridge.arm.com (10.2.80.71) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Wed, 4 May 2022 06:26:58 +0000 To: Subject: [PATCH v4 2/4] rtld: Remove DL_ARGV_NOT_RELRO Date: Wed, 4 May 2022 07:26:54 +0100 Message-ID: <3e12f8fc7eb1050f90fae30b4f20357c638181e6.1651643916.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 4537934f-3b54-4d0a-a2b4-08da2d971af5 X-MS-TrafficTypeDiagnostic: PAXPR08MB6382:EE_|VE1EUR03FT055:EE_|AM5PR0801MB1826:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 6D+8fAWwWqcf2l/wOLNwfgGn15vlRECiTUXCmLUjypz/0PjAvmBA+s2jFGxIIfb3slD5iRLqMuz1VI80QfRViYds56qmpxSRRasa3S6a3fC7sX1XC5iuyseTsrPNWqUVtL7CpU/Yqay1jnmGKIIBymvVRuPO5m3DrhDOHM9ooIUkALBXCjVeJVyYZTO2qtiwQEBOkvTrMmDWB73erPqH2CzwMKTGgXUSslvYy9XP2nVicderiqIKPvr6w08jyLR0XvZagxLf9ZZ6PpxKv4Wmg5tom8bqPGihhDGxiNp7jt68ZehBEfxy9Ow5uLRrsaq1KkX2nmXmq9UZ1xtEgiwuYD3qrzPTH8C/duHmS50I5Y3EYzJtMkv8CfAWcPgDUA/wl2vYBRrrHjV1JXOifXam+ks92YOEAcFfR1bb04g5p9MSZji37pHRvFX8+WmGbuS07UTCMVXoQM9KSqhLilOX8Lb9lxl8w0f5hslOsdj5UjnSud/WSgpsd+UocEp3kBe30r7ukCK6fw7Yp04eXI8ul9zdBQdoQTkLxu4cd37WQ1bmwklD7ct5JUlA5NZHZ8R4DArZLy4DqrId4Tj+6mdZUG32WkiyNirdCDtA4ypbYCn51cxkitmdLpfAvFejhxlF/NX2IZVl/QfmPQcdKSWsG2W/zcYS3m3tt7XYkZ5s92m9OWVhx2n4zrkOTlwiYWufK6E3EzeBOIHtY4O6f0JptSQj3eNoPTid1DyA5VR6PvyL9/ImEpKlV39qMAMvXQepDyuYjBm125e4kj9mLrb12zu3/deu5QgNx186rNNBaZ40FoKVjsS8TCpnlsfkoGXc X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(82310400005)(7696005)(356005)(83380400001)(2616005)(70586007)(8676002)(86362001)(36860700001)(6666004)(70206006)(40460700003)(81166007)(36756003)(2906002)(336012)(47076005)(8936002)(186003)(316002)(5660300002)(426003)(508600001)(44832011)(30864003)(26005)(6916009)(2004002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6382 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT055.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: a7340a9f-631b-4554-980c-08da2d97159f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iTF3N9oadr1u+uPwZFysSZHUHxy7f9pG56SD6iK3cgdFCVPV4pg63oq8zw5eUw3DyPK/WnLtHIBAJUiZkS8EjCU8YwSHw5DHqAHQjbBWUw0x0wrbb+u4FgLFDNLt9j42gCPoGDfguMFJIvqUd5aaRoh51V7hz1WD5zwuzMdnr3eXAVYSCiPwgia4KMOKPdt6Nifsv0BRg5PLs+ZY9AGzFV++aU8eZ/ITzmW7NWdRqZhf4BIUqAs3IJelR46wTeVBnjiJEo/N3064HWogKnO1WBMG+KRsicoEbxY3SI4g2kI/0ciTHxVNe/VEg5+9EI2VHYssEuojJ/VnI4BIZhG8HjyWN1U1EE9q4EzTdjJ/y4OHlyOmIEXAaE45y+fPzzKYjWC5XExGeEF/ygSRDrXUjVmOccBtHohXPbCLHbXPJ921qzyOfyySsUprZRKa36ZjYIMphTPrMjhtcBkozlpTDJCkeesrtdWwOolMgTlRYs2StH4M7jPN0zTk3VAoOdNK6R828pKt5zMbYucca4/SyzYU5zllIr8FXE2noc/OQ3xnwHiZN5+rr1cfULjlvkCcHWpI6Lzy0l+5YJL16ICX3cvb7NiyZOHET3NQK2s5mxo1iMRK84uAd9N4eI6hI0aVcfaFE9y04mu1dflzU1C/c9HW/yGdmaH41lduBFmOY7yzKW3BnrCZSR3ra/oB7nCaCUi2dFBQzBun/Kn1xpgtZ4kyAo4D2EQuM00Bi6KhnhWTVkzLX79dZcimdTe6DCRH1VHvALs2CfzEDHCATSD2Ueyq9u8YqfUIoz6dIMQX3e8= 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:(13230001)(4636009)(36840700001)(40470700004)(46966006)(186003)(44832011)(6916009)(36860700001)(36756003)(8676002)(30864003)(81166007)(40460700003)(5660300002)(316002)(6666004)(70586007)(47076005)(336012)(70206006)(83380400001)(8936002)(426003)(2906002)(508600001)(86362001)(7696005)(2616005)(26005)(82310400005)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 May 2022 06:27:04.0557 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4537934f-3b54-4d0a-a2b4-08da2d971af5 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: VE1EUR03FT055.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1826 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" This is no longer needed because _dl_skip_args is always 0, so the target specific code that modifies argv after relro protection is applied is no longer used. After the patch relro protection is applied to _dl_argv consistently on all targets. Reviewed-by: Florian Weimer Tested-by: Florian Weimer --- v4: - New patch. --- elf/rtld.c | 7 ------- sysdeps/aarch64/dl-sysdep.h | 4 ---- sysdeps/alpha/dl-sysdep.h | 23 ----------------------- sysdeps/arc/dl-sysdep.h | 4 ---- sysdeps/arm/dl-sysdep.h | 4 ---- sysdeps/csky/dl-sysdep.h | 23 ----------------------- sysdeps/generic/ldsodefs.h | 12 ++---------- sysdeps/ia64/dl-sysdep.h | 23 ----------------------- sysdeps/nios2/dl-sysdep.h | 4 ---- sysdeps/s390/s390-32/dl-sysdep.h | 23 ----------------------- sysdeps/sparc/dl-sysdep.h | 23 ----------------------- sysdeps/unix/sysv/linux/ia64/dl-sysdep.h | 4 ---- 12 files changed, 2 insertions(+), 152 deletions(-) delete mode 100644 sysdeps/alpha/dl-sysdep.h delete mode 100644 sysdeps/csky/dl-sysdep.h delete mode 100644 sysdeps/ia64/dl-sysdep.h delete mode 100644 sysdeps/s390/s390-32/dl-sysdep.h delete mode 100644 sysdeps/sparc/dl-sysdep.h diff --git a/elf/rtld.c b/elf/rtld.c index d959dab0d0..afff1b87fa 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -157,16 +157,9 @@ static void dl_main_state_init (struct dl_main_state *state); extern char **_environ attribute_hidden; static void process_envvars (struct dl_main_state *state); -#ifdef DL_ARGV_NOT_RELRO -int _dl_argc attribute_hidden; -char **_dl_argv = NULL; -/* Nonzero if we were run directly. */ -unsigned int _dl_skip_args attribute_hidden; -#else int _dl_argc attribute_relro attribute_hidden; char **_dl_argv attribute_relro = NULL; unsigned int _dl_skip_args attribute_relro attribute_hidden; -#endif rtld_hidden_data_def (_dl_argv) #ifndef THREAD_SET_STACK_GUARD diff --git a/sysdeps/aarch64/dl-sysdep.h b/sysdeps/aarch64/dl-sysdep.h index 667786671c..1516dd7d3f 100644 --- a/sysdeps/aarch64/dl-sysdep.h +++ b/sysdeps/aarch64/dl-sysdep.h @@ -18,8 +18,4 @@ #include_next -/* _dl_argv cannot be attribute_relro, because _dl_start_user - might write into it after _dl_start returns. */ -#define DL_ARGV_NOT_RELRO 1 - #define DL_EXTERN_PROTECTED_DATA diff --git a/sysdeps/alpha/dl-sysdep.h b/sysdeps/alpha/dl-sysdep.h deleted file mode 100644 index 3099ee419f..0000000000 --- a/sysdeps/alpha/dl-sysdep.h +++ /dev/null @@ -1,23 +0,0 @@ -/* System-specific settings for dynamic linker code. Alpha version. - Copyright (C) 2002-2022 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see - . */ - -#include_next - -/* _dl_argv cannot be attribute_relro, because _dl_start_user - might write into it after _dl_start returns. */ -#define DL_ARGV_NOT_RELRO 1 diff --git a/sysdeps/arc/dl-sysdep.h b/sysdeps/arc/dl-sysdep.h index da060ceeee..cf4d160a73 100644 --- a/sysdeps/arc/dl-sysdep.h +++ b/sysdeps/arc/dl-sysdep.h @@ -18,8 +18,4 @@ #include_next -/* _dl_argv cannot be attribute_relro, because _dl_start_user - might write into it after _dl_start returns. */ -#define DL_ARGV_NOT_RELRO 1 - #define DL_EXTERN_PROTECTED_DATA diff --git a/sysdeps/arm/dl-sysdep.h b/sysdeps/arm/dl-sysdep.h index ce7a84a7de..7a99107436 100644 --- a/sysdeps/arm/dl-sysdep.h +++ b/sysdeps/arm/dl-sysdep.h @@ -18,8 +18,4 @@ #include_next -/* _dl_argv cannot be attribute_relro, because _dl_start_user - might write into it after _dl_start returns. */ -#define DL_ARGV_NOT_RELRO 1 - #define DL_EXTERN_PROTECTED_DATA diff --git a/sysdeps/csky/dl-sysdep.h b/sysdeps/csky/dl-sysdep.h deleted file mode 100644 index fc8a58b94c..0000000000 --- a/sysdeps/csky/dl-sysdep.h +++ /dev/null @@ -1,23 +0,0 @@ -/* System-specific settings for dynamic linker code. C-SKY version. - Copyright (C) 2018-2022 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see - . */ - -#include_next - -/* _dl_argv cannot be attribute_relro, because _dl_start_user - might write into it after _dl_start returns. */ -#define DL_ARGV_NOT_RELRO 1 diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 31de149f23..e3c4d09bc6 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -762,18 +762,10 @@ rtld_hidden_proto (__libc_stack_end) /* Parameters passed to the dynamic linker. */ extern int _dl_argc attribute_hidden attribute_relro; -extern char **_dl_argv -#ifndef DL_ARGV_NOT_RELRO - attribute_relro -#endif - ; +extern char **_dl_argv attribute_relro; rtld_hidden_proto (_dl_argv) #if IS_IN (rtld) -extern unsigned int _dl_skip_args attribute_hidden -# ifndef DL_ARGV_NOT_RELRO - attribute_relro -# endif - ; +extern unsigned int _dl_skip_args attribute_hidden attribute_relro; #endif #define rtld_progname _dl_argv[0] diff --git a/sysdeps/ia64/dl-sysdep.h b/sysdeps/ia64/dl-sysdep.h deleted file mode 100644 index e3a58bec24..0000000000 --- a/sysdeps/ia64/dl-sysdep.h +++ /dev/null @@ -1,23 +0,0 @@ -/* System-specific settings for dynamic linker code. IA-64 version. - Copyright (C) 2002-2022 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include_next - -/* _dl_argv cannot be attribute_relro, because _dl_start_user - might write into it after _dl_start returns. */ -#define DL_ARGV_NOT_RELRO 1 diff --git a/sysdeps/nios2/dl-sysdep.h b/sysdeps/nios2/dl-sysdep.h index 0354650042..257b37c258 100644 --- a/sysdeps/nios2/dl-sysdep.h +++ b/sysdeps/nios2/dl-sysdep.h @@ -18,8 +18,4 @@ #include_next -/* _dl_argv cannot be attribute_relro, because _dl_start_user - might write into it after _dl_start returns. */ -#define DL_ARGV_NOT_RELRO 1 - #define DL_EXTERN_PROTECTED_DATA diff --git a/sysdeps/s390/s390-32/dl-sysdep.h b/sysdeps/s390/s390-32/dl-sysdep.h deleted file mode 100644 index 699b50f156..0000000000 --- a/sysdeps/s390/s390-32/dl-sysdep.h +++ /dev/null @@ -1,23 +0,0 @@ -/* System-specific settings for dynamic linker code. S/390 version. - Copyright (C) 2014-2022 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see - . */ - -#include_next - -/* _dl_argv cannot be attribute_relro, because _dl_start_user - might write into it after _dl_start returns. */ -#define DL_ARGV_NOT_RELRO 1 diff --git a/sysdeps/sparc/dl-sysdep.h b/sysdeps/sparc/dl-sysdep.h deleted file mode 100644 index f32f16a107..0000000000 --- a/sysdeps/sparc/dl-sysdep.h +++ /dev/null @@ -1,23 +0,0 @@ -/* System-specific settings for dynamic linker code. SPARC version. - Copyright (C) 2002-2022 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include_next - -/* _dl_argv cannot be attribute_relro, because _dl_start_user - might write into it after _dl_start returns. */ -#define DL_ARGV_NOT_RELRO 1 diff --git a/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h b/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h index 0d2a1d093a..aa1de6b361 100644 --- a/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h +++ b/sysdeps/unix/sysv/linux/ia64/dl-sysdep.h @@ -48,8 +48,4 @@ extern int _dl_sysinfo_break attribute_hidden; ".previous"); #endif -/* _dl_argv cannot be attribute_relro, because _dl_start_user - might write into it after _dl_start returns. */ -#define DL_ARGV_NOT_RELRO 1 - #endif /* dl-sysdep.h */ From patchwork Wed May 4 06:27:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1626080 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=dop6W6V2; dkim-atps=neutral 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+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) 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 (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KtRkc6Pvcz9sGC for ; Wed, 4 May 2022 16:29:28 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9FC063857825 for ; Wed, 4 May 2022 06:29:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9FC063857825 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651645766; bh=gxCI/+So+Dq8DgsgKFHRfs+2u/5/6nEnDs5n1v0f4zQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=dop6W6V26Goys2OgOcTkCoCoUuw2zdowUEiYrlHV/y28wjKkCGZqDbV7GVuQvKQCT /ZubvjKh1gmD9R+G8ewtb8Q94HBqtdmVwjko1B9RLyU2cVZ9OgGxIMiPv+nRzsIa9t XGdzmBOYYEcE8fRvqnswHSac2NTPSUf4t6b1selE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70071.outbound.protection.outlook.com [40.107.7.71]) by sourceware.org (Postfix) with ESMTPS id 7A2A7385742D for ; Wed, 4 May 2022 06:27:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7A2A7385742D ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=DkyFO/8fr4rtJBMTm/+I3le3LGOwIHDHz3+gzHqiIwFdnaVVspKZesB7JajlOA5tDQpY4dXz7K2BaxghGhN4DgLtwbomrZeqV1q3lAqjyKnNZWy25XRcbIHLvP8D/TTNnOtxCtkv9R8NKKDd2YO/c5YwdarnsDTG9QiDgt03DyaeP7Ow21vRud3HhMvKB1qnYCXYCdNQpqtrMImcfhKB9tcHG2j//Lxft5ZfMtKM/32TsrTMuhQzaeIPQWQjfyamTxdl4kIe1xp2xrNZjv/56JZ7xTNA/ZGeWDBtUV+3o5mjJrHFsWRdn8WaDeQpwf40ffuJT6DS8iZmXiL9XLjsuw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gxCI/+So+Dq8DgsgKFHRfs+2u/5/6nEnDs5n1v0f4zQ=; b=Ru6VuTWw11PVngcUXe4UmO/R8W2Md5rqC0JtQ+4IL0slvfNLPR0BKJotF4uySGl+ps2LJMdInamey2dTFPitKrG+XDNBbqXHovS8vRhU2FOwc6EAPaM8adtAhCBidip2aWSmKh82HcFnhFiw66TMTqiqp5Q8UyMIMKwkz4QqYpnBSo8lciKId9RXk9yS4i4n7/ghyOqPBWgVGHap/m0Er+tWJHSPNb+EzrqBWsGIHJsjbP46kMsywUP617uC137eSxWeZb69Usvd4z7umUcyhP07fObN+uxY7SWKMnQlGvw0qWoyQg9DCFunJuA16c1w5l9Lcz48+Y5sXecety7XEw== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1, 1, smtp.mailfrom=arm.com] dmarc=[1, 1, header.from=arm.com]) Received: from DB7PR05CA0020.eurprd05.prod.outlook.com (2603:10a6:10:36::33) by AS8PR08MB6727.eurprd08.prod.outlook.com (2603:10a6:20b:393::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Wed, 4 May 2022 06:27:19 +0000 Received: from DB5EUR03FT055.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:36:cafe::ad) by DB7PR05CA0020.outlook.office365.com (2603:10a6:10:36::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.25 via Frontend Transport; Wed, 4 May 2022 06:27:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;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 DB5EUR03FT055.mail.protection.outlook.com (10.152.21.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.15 via Frontend Transport; Wed, 4 May 2022 06:27:19 +0000 Received: ("Tessian outbound 9511859e950a:v118"); Wed, 04 May 2022 06:27:19 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 41fa2def13464aa5 X-CR-MTA-TID: 64aa7808 Received: from cf6f7dce3374.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id FDCB50BB-96E0-432D-A9F3-886326EB5ADF.1; Wed, 04 May 2022 06:27:12 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id cf6f7dce3374.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 04 May 2022 06:27:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U/D/Ife/W2gVLQ0+eCqr6BnsGTup75j7itahhCHqtEeZj/C7wNm4JZHEHxgjk9Pk8nFScPjHezUVu4LMNCgIK3h6kD5amYKmedEcuL2i3wPymdncIthSSjyyNB6JpWugc6aCI2hPVn1jgGV6PdfS7PxyG1QejVLWf6YHbq8TaxtHhIZYKCTy0YZHuOVFwVGvKUpo7Sz3fnToc/QzKiW2Eme+a79sGZTf76mAXiHPnNZ5KTdDT3s47qw9DJO/rvb0gbioD2+hpeiFtr66xzbbRKmtaK6aGCB8GiRx/QihL+CGn3ncKaGeoHRYxp6FJ4OagQyRHbCHdN/e6OlGRubKZQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gxCI/+So+Dq8DgsgKFHRfs+2u/5/6nEnDs5n1v0f4zQ=; b=Kp1/GySe7h0eCdO1Vo6yrmc7nuxs5mH4Po7wwElfvhlTPn0sL1R3W1OZvTv7mP1MMv8x/HSz7KS4nG4Qo55PiQ89nM+V9POyY+XeR8yzDXtRAxrmdjPgvtTOPS6l09w4kbJSD1yXLMj051rPvcAyje2z5xRxlzr+x5aLTMqDZ+yVud67ZjbNcjkBCk1+JfEx9PpvDE98LJPeerH0PEMJNMRHi2aA47L/dBgLJGt5EEiO8nhR6hj1CmvXU2pyF/9ShCG0PvoqZL9ftk/auwA1oWCexdPoXaiGwYltk8IIz+GR8BEV/Bc+dqgdvmmF3zDvU2iqLLQ4ZUE3vV9ep1vrnw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none Received: from DU2PR04CA0270.eurprd04.prod.outlook.com (2603:10a6:10:28e::35) by AM0PR08MB5396.eurprd08.prod.outlook.com (2603:10a6:208:182::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.12; Wed, 4 May 2022 06:27:09 +0000 Received: from DBAEUR03FT053.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:28e:cafe::bf) by DU2PR04CA0270.outlook.office365.com (2603:10a6:10:28e::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.25 via Frontend Transport; Wed, 4 May 2022 06:27:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by DBAEUR03FT053.mail.protection.outlook.com (100.127.142.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Wed, 4 May 2022 06:27:09 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Wed, 4 May 2022 06:27:09 +0000 Received: from armchair.cambridge.arm.com (10.2.80.71) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Wed, 4 May 2022 06:27:09 +0000 To: Subject: [PATCH v4 3/4] linux: Add a getauxval test [BZ #23293] Date: Wed, 4 May 2022 07:27:05 +0100 Message-ID: <671e2f493e59ae35b68d5c72fc0f6865bf1d562b.1651643916.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 7a7bc408-50b9-4ed8-4943-08da2d972410 X-MS-TrafficTypeDiagnostic: AM0PR08MB5396:EE_|DB5EUR03FT055:EE_|AS8PR08MB6727:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: TWvHG/K8T3SAcTl7fiTZV4E5xr7BXvkOiXJ5ni/DtrnhHUn7CisXA00Dqqm/aru2m7WmX7qMO9LBhsTPvpfI44zpmHB5CtokjxdQz1MOytVGNXnxBmHtHjkn9a51gtZAk8Ish7uj34+cr1k8IUUEGOzI+FDnNRpY95JHxjAxB9dUkDDvqKTPvNpr/HIzyBIoSr7z/tv2ZPpUkb5K+ElwPk3N+4MMVZ1kA/XmPlxLCrd7bo50bqQNZ1BBh1Kn8XeL6cMPIXEvR8Uf9omkEU0wxwdG3sMt8taQbYFRVBWOe8bc9QSvi+qfWgbABgu4Do6ZvW7qzoChqff42/PUsVhbUObSsHPBHjF5ti9AGTqvCom8dvSTV94KMwBRKQuzWetH9r8z4fM15xuEnq9zUewz1izuq+3XALuJlkXW/1UfDNEWVPsCYbk86gkcXoAmIsjBtZgmY6sdRazhzx0WPSPQGn1sPCx+CVqjxqlvesNgewcmrKwOBsmpx7VRkSFp0hladz0pG2sTbizLIGAAHyK4ooyjtw+uCBGqJnaCzD1bQtaksRQZCEIsAjcZYtbFPFR0lVi3sQ2CAfmtTrSGj/a07/OPZoBZYNSvFhrhEu3jFNzzHdEED0ksTfcaxtdgGTLgGO/y84WwEMte3wnreOFrZqM4Olriba8mOadvMjMOrMC3TqvBp6J75e2O/sATsB1B5iRNsziLVVn7RRjqosyW5qS6UaJkS8uiMxBSLXzPAM1PdGE9VAaE1DO76c2gIFxcmbg6WJ0mVcBlzOlYBoBe6jT1o1Uuo2F2bjbqKYfBUuqo9cXv09/jpKiXh46ztmSv X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(70206006)(8676002)(508600001)(70586007)(86362001)(6916009)(316002)(26005)(186003)(426003)(336012)(47076005)(7696005)(356005)(6666004)(2616005)(40460700003)(36860700001)(81166007)(82310400005)(8936002)(36756003)(44832011)(5660300002)(2906002)(2004002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB5396 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT055.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 8f9e10a8-8e8d-4857-7fe8-08da2d971e05 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iy3am8Dzvm9Vj6RuNwK395KKnVtd8YbMC9OKGsZMkrsnKcgmek3KyMtp8zw1nqReZsA/dylk2NI3TrzWFGJO6zXR+Z6s4OzlI1jHSsM+jEW4j6so7eh/un5mBRTxlO4T+wZL+UOIP6jp587S30OLiSrTs4nafHtppNfsqjNUvre33e49YnVRIfFJ/sqxF+G+wDH/yAHbGSN2L1hKNk3g/UsQQzqwToiftKvUxRF5to9a/p6yCgB+tX7dMs9qMW+HK/LgFDj02x3h0LuDtNKGYA1zrazwOaMgcU25eM3iFtTHEp5MwqjnLSEfVf2yo++M/jOs/tNBk9aUMZfcTgYs6MZxU+NTtPZrq+wvtJe+RyQ48rgArvLGWmrWV4Lt8pe8zqnmM8ecjtl2bZ0lJRwlEm67g3Er20eIwznq3swKRqUNq4KXpIN5attYfe1zmqCkDcC20O2WV8MqRUOQ37KmsZkqao5V/kbNTx71HkoWoaBsPaEwtR5FIqn2zzggO4sy4oqd7wzZv2z8+TjULJRSgZhrReNvW1kPzPS9KWwLa4/oy+F2RiSceTXa9/eR8P7+n5vBGLJjIGwDfCqDuS/r9Db1kQGLJI0P8ICH+iuLAXQ88kBVOruFKWEYiFEA6VdoQ5XkP0RlOfGisOrmEIQTBdc83wgc5XMuRzdHheihvN7K3I0gwmkpRbqszrHIz3RyMAKTGmHje2Dmqh4Bzdup32dTcdCCZP+oo6AkR4oCNjhJHtybzI/LRnT7cn+tWgdR4r2JBI3BVJIQ3y+3/p7Usg3hgL5kNl0eFkRxp4xL1F4= 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:(13230001)(4636009)(46966006)(40470700004)(36840700001)(86362001)(70586007)(8676002)(508600001)(70206006)(6666004)(186003)(6916009)(316002)(336012)(47076005)(426003)(81166007)(2616005)(7696005)(26005)(40460700003)(82310400005)(36860700001)(36756003)(8936002)(44832011)(5660300002)(2906002)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 May 2022 06:27:19.4548 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7a7bc408-50b9-4ed8-4943-08da2d972410 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: DB5EUR03FT055.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6727 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" This is for bug 23293 and it relies on the glibc test system running tests via explicit ld.so invokation by default. Reviewed-by: Florian Weimer --- v4: - New patch. --- sysdeps/unix/sysv/linux/Makefile | 1 + sysdeps/unix/sysv/linux/tst-getauxval.c | 74 +++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/tst-getauxval.c diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index ca953804d0..89cb005c7d 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -126,6 +126,7 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \ tst-prctl \ tst-scm_rights \ tst-epoll \ + tst-getauxval \ # tests # For +depfiles in Makerules. diff --git a/sysdeps/unix/sysv/linux/tst-getauxval.c b/sysdeps/unix/sysv/linux/tst-getauxval.c new file mode 100644 index 0000000000..c4b6195743 --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-getauxval.c @@ -0,0 +1,74 @@ +/* Basic test for getauxval. + Copyright (C) 2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +static int missing; +static int mismatch; + +static void +check_nonzero (unsigned long t, const char *s) +{ + unsigned long v = getauxval (t); + printf ("%s: %lu (0x%lx)\n", s, v, v); + if (v == 0) + missing++; +} + +static void +check_eq (unsigned long t, const char *s, unsigned long want) +{ + unsigned long v = getauxval (t); + printf ("%s: %lu want: %lu\n", s, v, want); + if (v != want) + mismatch++; +} + +#define NZ(x) check_nonzero (x, #x) +#define EQ(x, want) check_eq (x, #x, want) + +static int +do_test (void) +{ + /* These auxv entries should be non-zero on Linux. */ + NZ (AT_PHDR); + NZ (AT_PHENT); + NZ (AT_PHNUM); + NZ (AT_PAGESZ); + NZ (AT_ENTRY); + NZ (AT_CLKTCK); + NZ (AT_RANDOM); + NZ (AT_EXECFN); + if (missing) + FAIL_EXIT1 ("Found %d missing auxv entries.\n", missing); + + /* Check against syscalls. */ + EQ (AT_UID, getuid ()); + EQ (AT_EUID, geteuid ()); + EQ (AT_GID, getgid ()); + EQ (AT_EGID, getegid ()); + if (mismatch) + FAIL_EXIT1 ("Found %d mismatching auxv entries.\n", mismatch); + + return 0; +} + +#include From patchwork Wed May 4 06:27:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 1626081 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=MVIMKGve; dkim-atps=neutral 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+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) 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 (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KtRlT0GYrz9sG6 for ; Wed, 4 May 2022 16:30:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C5FD0385742F for ; Wed, 4 May 2022 06:30:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C5FD0385742F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651645810; bh=xeTJYuqv4J+kyT3Q0Oe9cxcZrXQZUbCCEsUGeftT09Q=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=MVIMKGveJxVCzrS+a0HM3Yaama1nOh4tdLZgaoSrx9hb6E3fRnSUcfdVZH4En+BzU Obd2Jgzsy6tjsg68yWlix/RPGwwBCBQo136HfZ3d6wjDwPSMzBOd5rOReOqUCCvfWW NunI9r6vvOvklLe/CYZ0KDiRqJmY1oGXuJVsuVaU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-eopbgr50047.outbound.protection.outlook.com [40.107.5.47]) by sourceware.org (Postfix) with ESMTPS id 7CD0F3858418 for ; Wed, 4 May 2022 06:27:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7CD0F3858418 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=GzxdGmWAUqCbecG6ItsmCVrThxY1oB4ZcWJ97YGcXrIU+sAbMu0ViJa26BAKnV5Y5uZTZOOTPqbP1/Qa4mmWxa+L2vakk9UDbptpzkigmW9HVqyhvmM4oUIHsrhDwzc6iCje3ynnj7ci+wgB6VnS+ew9l6gLpdTR9l+YK4CeV6PmXxhsHUj3uUGmU53YhX9xkRlmdW4QOYBvZt6gmUSz1k8CRX8Gjjku2dMN6ECtUDouxeOpLAlyF3SorUJ5Bs7hQsVvv9AWXxKyNFHW6pDZEz3KYbvOKO2petQY2Ob0d1FuW1XGAzV3wXMdYja45FErvhnF5g4RnFQHQ632U1HKFA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xeTJYuqv4J+kyT3Q0Oe9cxcZrXQZUbCCEsUGeftT09Q=; b=A/EErJ/gsmSYTULgBieP++2xYmcCB8cVGoo3R+Ezqf9xU5PHp2JFMyV70Rz/51bC1qEsDsJJE1h1cAAI22sxpDVQ6eOj3A1zfoUX+DHyZuhiDinqopM54MPxs5fGjTy1N0XWZ7KNOr0Numzt7uxqeBYt+c82VEs5fSsXWDpN7W20f7HjRbG9TYtFotWuXujb76chOXnHEbNHWW2txuZMAF96IK6IH3RcH8CsKGkJT1PAzsYWManRQWyCRyTQguHuPD0zVuYv3LaYkY02nDMDgvcqzC/hFoC1O2JA2mn/Af7OpxNBnBoJqYnbhxuXQ8L6Kzc32fyLeF0LSuKWj1uzPA== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1, 1, smtp.mailfrom=arm.com] dmarc=[1, 1, header.from=arm.com]) Received: from DB9PR05CA0017.eurprd05.prod.outlook.com (2603:10a6:10:1da::22) by VI1PR08MB5439.eurprd08.prod.outlook.com (2603:10a6:803:13b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.14; Wed, 4 May 2022 06:27:26 +0000 Received: from DBAEUR03FT016.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:1da:cafe::ca) by DB9PR05CA0017.outlook.office365.com (2603:10a6:10:1da::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.25 via Frontend Transport; Wed, 4 May 2022 06:27:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;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 DBAEUR03FT016.mail.protection.outlook.com (100.127.142.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.15 via Frontend Transport; Wed, 4 May 2022 06:27:26 +0000 Received: ("Tessian outbound 9511859e950a:v118"); Wed, 04 May 2022 06:27:26 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: b9ada3eb648d6c70 X-CR-MTA-TID: 64aa7808 Received: from b52703bd12f7.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id EF557554-BFF5-41F4-AAFA-CB91814CC6A7.1; Wed, 04 May 2022 06:27:19 +0000 Received: from EUR02-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id b52703bd12f7.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 04 May 2022 06:27:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fl1yBvw7m9H6X3ssofprix16LfoJUMq0WhiV7Z3QNEx5r6K+3EJOM+KocBaQ7PwGD5iFobNfldt8/7NV0Rv6RMNixheahlcVxc6S81gxH6dTSnJaDWjTZ5ysDLkGQWehFDh0RYe9iKLw6urb9cw5vW81GncPwnF35mY4XT30Pl8jygyRX0zUMIpuwMjjBElUDK6v5CsqLwuQUyIxkgwIwGGFe40eXK4jzUTmwoF87Wvl0XbOOEjtgOTueA2ku4YupQaswqzTgVMhQjjkBrcoQvFOlNWpeO3k1kCRdHHi+S6jurIU7k6JG80cvxA+swgPsaym2js+Jel8XF7Bfrb3+w== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xeTJYuqv4J+kyT3Q0Oe9cxcZrXQZUbCCEsUGeftT09Q=; b=LYSytsCtNDNJV1ElmGjZVTWWguydcljWJbpSArz6K4XgJyRleDVSC13DUcbpiw3ZLqAXPRV5KOxs5OPDVZi90habt9bVYT/lWJJXhGVIRaTweEAIO0jj+h/qQUO3wg6Azj1undnNLBEeoCCkayLtn831JQ80lkPCoh0FWA3vNoICsOteNzG2wvKrETMv+ksRr5KZn2EvpJ1PHLfgLTt8DbFYTUPQIlPj94EaWDpzxuPOvT89DPoE7uT11p9Nnt67wk9+x0uSR/obSDRs0wuBz8HeoPFxknK9dhZxP0EWciTCxb1Q0UCWKBX4aABI4AAR7mgI7USrB4CNL75NC+uydg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none Received: from DBBPR09CA0006.eurprd09.prod.outlook.com (2603:10a6:10:c0::18) by AM0PR08MB4561.eurprd08.prod.outlook.com (2603:10a6:208:12d::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Wed, 4 May 2022 06:27:18 +0000 Received: from DBAEUR03FT062.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:c0:cafe::d) by DBBPR09CA0006.outlook.office365.com (2603:10a6:10:c0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24 via Frontend Transport; Wed, 4 May 2022 06:27:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by DBAEUR03FT062.mail.protection.outlook.com (100.127.142.64) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Wed, 4 May 2022 06:27:17 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Wed, 4 May 2022 06:27:20 +0000 Received: from armchair.cambridge.arm.com (10.2.80.71) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Wed, 4 May 2022 06:27:20 +0000 To: Subject: [PATCH v4 4/4] aarch64: Move ld.so _start to separate file and drop _dl_skip_args Date: Wed, 4 May 2022 07:27:16 +0100 Message-ID: <04cfa0c448fe88a5fd9895b65c4b8f15de63cda3.1651643916.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: c14419b5-cd08-459c-45a7-08da2d97285d X-MS-TrafficTypeDiagnostic: AM0PR08MB4561:EE_|DBAEUR03FT016:EE_|VI1PR08MB5439:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: wuusA/sLP8eYXXJBEMfmzuyvUBwtPPwo/bGZ+lfAwfaU3xaHR/CjpJZqS34PBpGEF6QVok+Uh+PZgGvzzD01zOWo9hugQ1hqBOHUmOZ7QXz9FMu9yFhSGM8ePlW3DdTbVsgAR2C2+6fkyFWw1MpbRug+4dmtfDvR94QGHnyVX5OscFh8Ap7h4FCAcL0ySEKQI8Lglg0bEmvElsZ1K4fh2sziN2Fp3WGqft/SdlJIhriaLPhkRlJS+nznd+943+SY07NBw2R4MHs5V1A0pl2PzglcncsnDKOHITF9X8kk69UAVKw1FZiruZI2ORo4sebMHiE4PAP47xlHdrIdN/x+sg3Wp5yv8DwkwUlyp5A+MVR9iD6QwUZ776hw8Vk7iipJYuEjkD8ooiCos0wq2B40Xd/NMBgW1pyGgdD4nKw6kaUegJEtQ832qHoSoWL0ILv7IxxVbUReH2P3awy80Ov8MsYTvmjMLZJ2eAkE1H+L4B0PFgLFbL/vsE4dSFx7NQ4JTmALz3ZnIKIF/Bv1+ht+0SeIqvtCxeAJgplhXhSyCmHV4XBhr+zAJXaUie1Wi2Xb0D6UKfAvoznm4GxlvtQ+WMGtex0y5qWaKEGh1I5qJwhHWf7r430KVFPmswPSiMjufQlfT+JY4kUf2Bidi91B8g/QC4k2BW9lnInzveat0qMNaEVs2q0tz1+oIBzI1lhvLEwsJ9POo8TLnqoE5IeSSixmU/3Fx2IG9He5lkVttCNrP/f5cPM8mZSy3MC/g9CjoeMaoBrrIY2fOXDv8whuRRjuXI3uUUbWe9KRAdHVzZ3phGWemNG6Tu8PzLKa5uoW X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(40460700003)(2616005)(83380400001)(81166007)(356005)(36860700001)(7696005)(2906002)(26005)(5660300002)(70206006)(70586007)(8676002)(82310400005)(186003)(47076005)(44832011)(316002)(426003)(86362001)(36756003)(8936002)(336012)(6916009)(508600001)(6666004)(2004002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB4561 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT016.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: a8b6daa3-dc82-4418-ddf2-08da2d9722ec X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RzMy2mI4zqnOTdiW3gb08AFQSO5rbVQF6dBMBNwUDA9gZPqJ9LR88lbqSpAv3oGVzyNy3ofzcxBtAkNcALs/CB2Kwo+8yUh7lZSwVkWkVZQ5FwgClsLxfbll9S00NX7VLUaPKG5tgJR2/sdrYxG6g+aGr4b+6qXn/skYhgq9jHKPKXiop0iD0H8bV1y9dYeXv9+FPXPg9zH7D7Gosr7n4eDRFDCDIEJIGOqxAi4tv7w/GGS280FTQKSEC0xepx2WaJAFSeLOxmxrk+5hoPOHHD+SuvijuKo5rLxZU2FI8/ioZixfR8k6OY3jkBTpN/9TSPD3UuiO88ey+1mjK9FRbFh36x7rHPps5n19ZsawxQcB7yIPZTkvLzVcmFYEr03soFFTTHG1ssQXJtRhiEDlA6jxLNi4OiRwZxic1dsJyPxxSx2szkWQP14ovDeP/+ERyhsZB51D5n4Kd8shsiwKewpXr2wk3XQ7taZ4Z5FRbxlX7ytYaYMCkS6idAqhKepr/Flw1uiZAx/XIJw+lywDQp9AhRutgxrRhNQs4Ej0hMk1VRkArdtkKO2ztDZBz1IS6I07YG/jx4LYmHZtcVyxKtd/2RU730j5at/c4xW2e/wK4+RnsZ1mITc9Mhq6Hw+Ihwu+Eck/DLmgPF5weAYWiB9jGjjXh+XtDRj6S9fWlEWgNviV+k/tWsYsqnfHhCJ8oRYFGA13sPYTnE5XGfVvoLt9F6hEimoyo0pcOscA9rQioGGbM/T2jRDRGNYtpyZAz/me5RQTrolX2zlE7zyT8/FcTZh85iq1SCChS9MWtRE= 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:(13230001)(4636009)(40470700004)(46966006)(36840700001)(8936002)(5660300002)(81166007)(316002)(26005)(6916009)(8676002)(70206006)(6666004)(70586007)(508600001)(36756003)(86362001)(336012)(7696005)(186003)(40460700003)(426003)(47076005)(83380400001)(36860700001)(44832011)(2906002)(82310400005)(2616005)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 May 2022 06:27:26.6859 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c14419b5-cd08-459c-45a7-08da2d97285d 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: DBAEUR03FT016.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB5439 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" A separate asm file is easier to maintain than a macro that expands to inline asm. The RTLD_START macro is only needed now because _dl_start is local in rtld.c, but _start has to call it, if _dl_start was made hidden then it could be empty. _dl_skip_args is no longer needed. --- v4: - adjust commit message about _dl_skip_args. v3: - mention _dl_skip_args v2: - fix typo in commit message. --- sysdeps/aarch64/Makefile | 1 + sysdeps/aarch64/dl-machine.h | 77 +----------------------------------- sysdeps/aarch64/dl-start.S | 53 +++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 75 deletions(-) create mode 100644 sysdeps/aarch64/dl-start.S diff --git a/sysdeps/aarch64/Makefile b/sysdeps/aarch64/Makefile index 7183895d04..17fb1c5b72 100644 --- a/sysdeps/aarch64/Makefile +++ b/sysdeps/aarch64/Makefile @@ -33,6 +33,7 @@ tst-audit27-ENV = LD_AUDIT=$(objpfx)tst-auditmod27.so endif ifeq ($(subdir),elf) +sysdep-rtld-routines += dl-start sysdep-dl-routines += tlsdesc dl-tlsdesc gen-as-const-headers += dl-link.sym diff --git a/sysdeps/aarch64/dl-machine.h b/sysdeps/aarch64/dl-machine.h index b40050a981..fe120bb507 100644 --- a/sysdeps/aarch64/dl-machine.h +++ b/sysdeps/aarch64/dl-machine.h @@ -105,81 +105,8 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[], return lazy; } -/* Initial entry point for the dynamic linker. The C function - _dl_start is the real entry point, its return value is the user - program's entry point */ -#ifdef __LP64__ -# define RTLD_START RTLD_START_1 ("x", "3", "sp") -#else -# define RTLD_START RTLD_START_1 ("w", "2", "wsp") -#endif - - -#define RTLD_START_1(PTR, PTR_SIZE_LOG, PTR_SP) asm ("\ -.text \n\ -.globl _start \n\ -.type _start, %function \n\ -.globl _dl_start_user \n\ -.type _dl_start_user, %function \n\ -_start: \n\ - // bti c \n\ - hint 34 \n\ - mov " PTR "0, " PTR_SP " \n\ - bl _dl_start \n\ - // returns user entry point in x0 \n\ - mov x21, x0 \n\ -_dl_start_user: \n\ - // get the original arg count \n\ - ldr " PTR "1, [sp] \n\ - // get the argv address \n\ - add " PTR "2, " PTR_SP ", #(1<<" PTR_SIZE_LOG ") \n\ - // get _dl_skip_args to see if we were \n\ - // invoked as an executable \n\ - adrp x4, _dl_skip_args \n\ - ldr w4, [x4, #:lo12:_dl_skip_args] \n\ - // do we need to adjust argc/argv \n\ - cmp w4, 0 \n\ - beq .L_done_stack_adjust \n\ - // subtract _dl_skip_args from original arg count \n\ - sub " PTR "1, " PTR "1, " PTR "4 \n\ - // store adjusted argc back to stack \n\ - str " PTR "1, [sp] \n\ - // find the first unskipped argument \n\ - mov " PTR "3, " PTR "2 \n\ - add " PTR "4, " PTR "2, " PTR "4, lsl #" PTR_SIZE_LOG " \n\ - // shuffle argv down \n\ -1: ldr " PTR "5, [x4], #(1<<" PTR_SIZE_LOG ") \n\ - str " PTR "5, [x3], #(1<<" PTR_SIZE_LOG ") \n\ - cmp " PTR "5, #0 \n\ - bne 1b \n\ - // shuffle envp down \n\ -1: ldr " PTR "5, [x4], #(1<<" PTR_SIZE_LOG ") \n\ - str " PTR "5, [x3], #(1<<" PTR_SIZE_LOG ") \n\ - cmp " PTR "5, #0 \n\ - bne 1b \n\ - // shuffle auxv down \n\ -1: ldp " PTR "0, " PTR "5, [x4, #(2<<" PTR_SIZE_LOG ")]! \n\ - stp " PTR "0, " PTR "5, [x3], #(2<<" PTR_SIZE_LOG ") \n\ - cmp " PTR "0, #0 \n\ - bne 1b \n\ - // Update _dl_argv \n\ - adrp x3, __GI__dl_argv \n\ - str " PTR "2, [x3, #:lo12:__GI__dl_argv] \n\ -.L_done_stack_adjust: \n\ - // compute envp \n\ - add " PTR "3, " PTR "2, " PTR "1, lsl #" PTR_SIZE_LOG " \n\ - add " PTR "3, " PTR "3, #(1<<" PTR_SIZE_LOG ") \n\ - adrp x16, _rtld_local \n\ - add " PTR "16, " PTR "16, #:lo12:_rtld_local \n\ - ldr " PTR "0, [x16] \n\ - bl _dl_init \n\ - // load the finalizer function \n\ - adrp x0, _dl_fini \n\ - add " PTR "0, " PTR "0, #:lo12:_dl_fini \n\ - // jump to the user_s entry point \n\ - mov x16, x21 \n\ - br x16 \n\ -"); +/* In elf/rtld.c _dl_start should be global so dl-start.S can reference it. */ +#define RTLD_START asm (".globl _dl_start"); #define elf_machine_type_class(type) \ ((((type) == AARCH64_R(JUMP_SLOT) \ diff --git a/sysdeps/aarch64/dl-start.S b/sysdeps/aarch64/dl-start.S new file mode 100644 index 0000000000..a3a57bd5a1 --- /dev/null +++ b/sysdeps/aarch64/dl-start.S @@ -0,0 +1,53 @@ +/* ld.so _start code. + Copyright (C) 2022 Free Software Foundation, Inc. + + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +ENTRY (_start) + /* Create an initial frame with 0 LR and FP */ + cfi_undefined (x30) + mov x29, #0 + mov x30, #0 + + mov x0, sp + PTR_ARG (0) + bl _dl_start + /* Returns user entry point in x0. */ + mov PTR_REG (21), PTR_REG (0) +.globl _dl_start_user +.type _dl_start_user, %function +_dl_start_user: + /* Get argc. */ + ldr PTR_REG (1), [sp] + /* Get argv. */ + add x2, sp, PTR_SIZE + /* Compute envp. */ + add PTR_REG (3), PTR_REG (2), PTR_REG (1), lsl PTR_LOG_SIZE + add PTR_REG (3), PTR_REG (3), PTR_SIZE + adrp x16, _rtld_local + add PTR_REG (16), PTR_REG (16), :lo12:_rtld_local + ldr PTR_REG (0), [x16] + bl _dl_init + /* Load the finalizer function. */ + adrp x0, _dl_fini + add PTR_REG (0), PTR_REG (0), :lo12:_dl_fini + /* Jump to the user's entry point. */ + mov x16, x21 + br x16 +END (_start)