From patchwork Thu May 5 06:58:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 53492 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 804BB395201C for ; Thu, 5 May 2022 07:00:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 804BB395201C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651734023; bh=eyAtwR+ydbfGE7bFundmhuOaeYCOj1yLiEToAhcfgcM=; 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=lh6T1Pe9+g68Wutnwc7J9k8TVqLl/KrG2Lo/3DIlXFoN7jsEyMIhiR1gealyzm4oA T2Id1gl1l1na/yeF7XiB4u5/T2UXAcEB2NCqI/sAH2ye8PTgLR2EEer2Wo1pL+VEuk 74bPFP+6G8EIYMGRx+U/WD/obwNMwf2GCL1xVmao= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-eopbgr140089.outbound.protection.outlook.com [40.107.14.89]) by sourceware.org (Postfix) with ESMTPS id DB210385736E for ; Thu, 5 May 2022 06:59:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DB210385736E ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=SiQOztWe7s4yXiW++5INd3WWjgAv+Sps+jkQB1Wv26OHC+u864zribDLreE+TmBnTtSDLVQD5nipjs1Dvr40dtlTQb/dglbbvW85YcJx/nhjU1viHkEmYp7Tr0wapLspVHB8PPgQXsR5Q5NU2KhD7oLH3Dg7Ae9QdfCOxGgpjEePp4F/ZMhjAMiI/Nz2L7mrgtl6OmhOga0wqrYYf36IKGKD7rRwbnVDpEgXtybI/qnXD055SjtYPFXSBmHUALygy1oiTkNu3muIzyc/iHTNDjI/7VcKg87vO5y5uSaar6Ucj4Y5KgNvEEEtTuOUrOOwgkEgXlIs5gHojCXZxqLzfQ== 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=eyAtwR+ydbfGE7bFundmhuOaeYCOj1yLiEToAhcfgcM=; b=D3H9Y5fLqaJA9/eScUaGSCE67ImPGpQc2Ct8PYBXQxRgtrlVa/i+51+hResTpwYuzHXqLj9u3L8kBSIFCYaM9Gfrf73h3Kvn0tv6HFvagdnRjajGw4Cg8mhHBz1TfrBDiFWA32Ijc7LYufJ8y6svCWaT1yfr2JB8C54UbavEUzsR9m73ZEL8Aabs9Pn/oVsSy9btf7tikA0nFJVIBW/H2UKJVojk9fExI5PIZOePUgibkWJPMuoEvA1eQ4eK95HE6kZQdfqGngdRjijw6Ngg1IIv4Q523GY0ys/JwsYMZwrINgZdtMbe+ag9Prqbi+SArs9R8o7U/Dxu0Pgw4b8jiw== 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 AM0PR04CA0006.eurprd04.prod.outlook.com (2603:10a6:208:122::19) by AM6PR08MB3909.eurprd08.prod.outlook.com (2603:10a6:20b:8e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Thu, 5 May 2022 06:58:58 +0000 Received: from VE1EUR03FT063.eop-EUR03.prod.protection.outlook.com (2603:10a6:208:122:cafe::53) by AM0PR04CA0006.outlook.office365.com (2603:10a6:208:122::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.27 via Frontend Transport; Thu, 5 May 2022 06:58:58 +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 VE1EUR03FT063.mail.protection.outlook.com (10.152.18.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 06:58:57 +0000 Received: ("Tessian outbound facaf1373bbd:v118"); Thu, 05 May 2022 06:58:57 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: fe13b167dab63b1b X-CR-MTA-TID: 64aa7808 Received: from 11bacbc4ae6b.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id E6D61105-8EC3-4767-A68D-909F0CF272B5.1; Thu, 05 May 2022 06:58:51 +0000 Received: from EUR03-AM5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 11bacbc4ae6b.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 05 May 2022 06:58:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YiPRYmP2nwUG9TNDOvLAD1GnsbfGeJSFJ37+upwx6W4Wj1/LAuv7KFvl2P1kptFiVjULDR/CXxY3VF9hbNZ5760mrotapEoan7YcTtRUQWbP++IB4XwtIngO6jjHljYt+BjqtwKgYJLJMVxRTR2ioehLr6ykXdoCRu6ZYmvfiHbDUILMde88QZW+7CWPLGt3nRQQ4p3sjJ3BjWgwujG5WrvFGuNosRtLuN05C54XHwai5G36BZOjUoQzOW7aTG4wciZU923hWZCSF9y/gfrFnLibv/sWwrwQTWDK1p6sIUtKGG1MAuU2/1jf51lnc3WiDYV3Xp+CsSxNnc68MqJ1Yw== 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=eyAtwR+ydbfGE7bFundmhuOaeYCOj1yLiEToAhcfgcM=; b=RIyzv+Qa31Ip9yXPWKIgoQgNTEM85mpSpRTCSpoCt7KKLiDPgbuDiA1O0JuM6zMPQ8kV1mQSrG9ZXx0Ap7h4+e3t8ODNl85bMrpOCQRWoih/41fVU14R70XXHcuXXSZK1F+rWY7sOg2cMv2zWqyInXrQgJjelow6BjbIT2cAflpoJBFGYtJ6fB8DuXHXgWMcmFDgVh4tjrgVRmkD68P1kXaQKsWeYDogzV3waPYqPMVEMF1QeNwbdcVMebQyGFbOeF71DYhgZ/iT5jgLIhFDF5p1KFEWud4GbHDjMHpu68CiF0ZcqqZV4W6WMPISDHv5OIXV0xKILvKMLKOk4WNciw== 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 AS9PR06CA0084.eurprd06.prod.outlook.com (2603:10a6:20b:464::6) by DB7PR08MB3274.eurprd08.prod.outlook.com (2603:10a6:5:1f::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.25; Thu, 5 May 2022 06:58:48 +0000 Received: from VE1EUR03FT043.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:464:cafe::62) by AS9PR06CA0084.outlook.office365.com (2603:10a6:20b:464::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13 via Frontend Transport; Thu, 5 May 2022 06:58:47 +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 VE1EUR03FT043.mail.protection.outlook.com (10.152.19.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 06:58:47 +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; Thu, 5 May 2022 06:58:50 +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; Thu, 5 May 2022 06:58:50 +0000 To: Subject: [PATCH v5 1/4] rtld: Use generic argv adjustment in ld.so [BZ #23293] Date: Thu, 5 May 2022 07:58:45 +0100 Message-ID: <73fd4d711532f95c9815bacbedc13d97a77294c2.1651732417.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: c06e6814-bbee-43bf-c0c6-08da2e64ba24 X-MS-TrafficTypeDiagnostic: DB7PR08MB3274:EE_|VE1EUR03FT063:EE_|AM6PR08MB3909: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: oQAQC5/kFLeY1NnnczKyTxEjktssqGhcCNtdn8iEZ1XvtKUeaAdfDFZ9+/kN8DeltiaO/qqVgj5i6j3jOzmQIHNzOJv95ZyMlwePZkoagDj8CBmzmicHuyptI9lcHh0Xbn0/Zezbpvk9yCrZSgg0d6VO+KgPJtd0iKKAjbJ7QfCJhm1P3qIZvKqk953glVgAs3T9NIXdUXpHA13/4GExggtdASPcrgdgTGNb5z3kiaV2Qzye8mrbl8hRg3Y/D6wdo8+PjVdhxxmQD608H4m86hMhGc9seH33a56jkcT08BnHlwlPdGIb9P8KugWHRRYkVYSCMoiZMozUVEhK19RxZg25ajp/bAjYs1XD3SiXQTxFVCo6hPuYn8TH7VyTAk0ySQZvJa7oO/P9H8+GjJzm3HoV8D1TjKr19HsTUZ56mj5kmTz1UVXU2yZVWmdm6ZfgCcehsgyQ7gmuvDqRvKNW47v3y8OHoCYVGgx5gofUjk2MZYZq5A4BpOx+ckEd+cOpVLjaB49mb40BpNVY5QLZqK9LEImfCFn6OXz73SySVIhvZIeBBv6d4DQhAdSa6IS4f45K7UAiQsXQqjsf9vlxG+dWUEkone9yq52XIVN8SOY/VV+d9o16spsfxHBk/GvlVt0bpkFOvmPKEn4dFaoSNBXN71EuihzKazInG4jriQcpLiyymfOI4RyygTTLvvGT2f7rP8d6M1Bi68rEo5wNXAW4qdZKXc+xI4GhUIF/ebk= 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)(44832011)(508600001)(30864003)(5660300002)(2906002)(6916009)(26005)(86362001)(8676002)(70586007)(7696005)(6666004)(70206006)(40460700003)(8936002)(36756003)(82310400005)(316002)(356005)(81166007)(36860700001)(186003)(2616005)(336012)(47076005)(426003)(83380400001)(41533002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR08MB3274 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT063.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 30f6a19b-e0b2-4541-a16b-08da2e64b3e5 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: n+lbfQwpnL6SSibiROCALuG/yceoslE4arXvZCwMH2SdEtkkyxS9MI5jEwqY/5OKHAlYKN+2RA6BXnoi0sRmb0oOZ52MHbuGwHM3hnYpwWMZzwZf2WpMcmVr7iJK4oCEQr4N7xs+yYZz7osMR5JPDPJmQThpcFLOR0ksLE/cK+O/YuIuLFxmwAtEQMer4k9SVrvNOvzda15+6FGSAFhu6/EctC4C0IxmPPyX3/afquG9t2HyXqxmXvQ8Rxswce1ur+19wPrM5HguAmvfiJVOEGBqAeysP4xkn2UBM0GMa3vU21/3aKwGsMNFSRtvyrbn8Iz6XeIekNe8C7/hh7WXMnQd14Qogkyk+IWXw4AfIlr6nuLBID+1cUxy8nRLoeQ9G4XJnq+hv5x1RNiaPb0YO407JnDLAD6XiBgnQdbbGcHZ+cUvvCFQgfyyRCx7KOqHkC3l9CzFuf6JzOqPOdvzLsNwn6vlAiLinvKjkocx+PEJ5Cse5fuN4/msRsniycuU60yd2SmPjFv+VrmzkcqHhUF5K/JH+XWz5ZiM/AkEhKIL3lCvYnAuJSDJSIhWxxf758Le7aaOWl4aUUYph/BdWf2+hEXbThzkC6mqn3O7cSmUgz5nKuHBTDD/xvQZobxHbHRgB7xksq5LgfQB7eZyGoeaNTBwUWgKLau2VSYUGVlqnws88R78oUfgEH/Hcc4rqxwls/bPQOI8bTGGX1AfIw== 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)(30864003)(316002)(44832011)(70586007)(7696005)(5660300002)(86362001)(81166007)(8676002)(70206006)(8936002)(6666004)(2616005)(82310400005)(36756003)(47076005)(426003)(336012)(186003)(40460700003)(83380400001)(36860700001)(2906002)(26005)(508600001)(6916009)(41533002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 06:58:57.9518 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c06e6814-bbee-43bf-c0c6-08da2e64ba24 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: VE1EUR03FT063.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3909 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+patchwork=sourceware.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. The GNU Hurd start code needed some changes, because it relied on _dl_skip_args after dl_main returned. Follow up patches can remove _dl_skip_args and DL_ARGV_NOT_RELRO. --- v5: - Hurd specific changes. 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/mach/hurd/dl-sysdep.c | 36 ++++++------- sysdeps/unix/sysv/linux/dl-sysdep.c | 5 +- 4 files changed, 90 insertions(+), 37 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/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c index 3cbe075615..ff71aa6639 100644 --- a/sysdeps/mach/hurd/dl-sysdep.c +++ b/sysdeps/mach/hurd/dl-sysdep.c @@ -72,10 +72,11 @@ ElfW(Addr) _dl_sysdep_start (void **start_argptr, void (*dl_main) (const ElfW(Phdr) *phdr, ElfW(Word) phent, ElfW(Addr) *user_entry, - ElfW(auxv_t) *auxv)) + ElfW(auxv_t) *auxv, void **start_argptr)) { void go (intptr_t *argdata) { + char *orig_argv0; char **p; /* Cache the information in various global variables. */ @@ -84,6 +85,8 @@ _dl_sysdep_start (void **start_argptr, _environ = &_dl_argv[_dl_argc + 1]; for (p = _environ; *p++;); /* Skip environ pointers and terminator. */ + orig_argv0 = _dl_argv[0]; + if ((void *) p == _dl_argv[0]) { static struct hurd_startup_data nodata; @@ -169,34 +172,29 @@ _dl_sysdep_start (void **start_argptr, up and leave us to transfer control to USER_ENTRY. */ (*dl_main) ((const ElfW(Phdr) *) _dl_hurd_data->phdr, _dl_hurd_data->phdrsz / sizeof (ElfW(Phdr)), - (ElfW(Addr) *) &_dl_hurd_data->user_entry, NULL); + (ElfW(Addr) *) &_dl_hurd_data->user_entry, NULL, + (void **) argdata); /* The call above might screw a few things up. - First of all, if _dl_skip_args is nonzero, we are ignoring - the first few arguments. However, if we have no Hurd startup - data, it is the magical convention that ARGV[0] == P. The + P is the location after the terminating NULL of the list of + environment variables. It has to point to the Hurd startup + data or if that's missing then P == ARGV[0] must hold. The startup code in init-first.c will get confused if this is not the case, so we must rearrange things to make it so. We'll - overwrite the origional ARGV[0] at P with ARGV[_dl_skip_args]. + recompute P and move the Hurd data or the new ARGV[0] there. - Secondly, if we need to be secure, it removes some dangerous - environment variables. If we have no Hurd startup date this - changes P (since that's the location after the terminating - NULL in the list of environment variables). We do the same - thing as in the first case but make sure we recalculate P. - If we do have Hurd startup data, we have to move the data - such that it starts just after the terminating NULL in the - environment list. + Note: directly invoked ld.so can move arguments and env vars + or in secure mode it can remove dangerous env vars. We use memmove, since the locations might overlap. */ - if (__libc_enable_secure || _dl_skip_args) - { - char **newp; - for (newp = _environ; *newp++;); + char **newp; + for (newp = _environ; *newp++;); - if (_dl_argv[-_dl_skip_args] == (char *) p) + if (newp != p || _dl_argv[0] != orig_argv0) + { + if (orig_argv0 == (char *) p) { if ((char *) newp != _dl_argv[0]) { 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 Thu May 5 06:58:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 53493 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2F5A4395381E for ; Thu, 5 May 2022 07:01:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F5A4395381E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651734068; bh=N45MuaSrFJjz2HBgqxS90PzfUuyqlkvFmWor5LS+SEI=; 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=pP5p1kHpH9fZBoJUG/VsknoIUng2qbBy8kN2gpUupUyILSqPpruPllHu8uZocMACN o6S3wqumXlgJB/8reU3HGM+DyJBZbhwfdHIzKUA1C9R+QKNHaLzRR3ZeS23tczjl+B QIky2Wy9UiNYOb9lZltmPLc83nhQ/FDTJXvQVEFE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10069.outbound.protection.outlook.com [40.107.1.69]) by sourceware.org (Postfix) with ESMTPS id 7061E3856DD7 for ; Thu, 5 May 2022 06:59:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7061E3856DD7 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=OWRP92QaAKxZpHz0/XY49k+qi/CPFycqerArHDQ2uwO27O60GAsNgGAmTmGUrFa1ZcU0lQJM8MfL+uJLSwRfS/9CuC/jgog5h3G6zPOIukaB1+r+96Qgmm0OKs6goGpYnxO/Qo5fVBMw18Kh5PWSgvKYqNlo+9YtF/BIJw0xVnJ2dKsiHyt/7RX7nHBdpLezypWOZuekb2mLELUvb8hjQe8m6QWIY3mQgDoJBs2/mJRsBel17qz6rcuQ6DqsZO2/iFhcf0mQ6IZ8tEmVYnUPAHCeaFiz1Hzfz/DPIOJd0Y1rrXlxSDRyEgzbDTi9mStEXj0Ag4zMncvh1D91badHNA== 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=N45MuaSrFJjz2HBgqxS90PzfUuyqlkvFmWor5LS+SEI=; b=e3RJhHiAMrUIZFfkjMqyzsNU5DcbiI0pCFhGIUL/i0M/PfFuc/hCS7bk/yR9LAzUBhPBpdJK3ZdM21/KcEpdgI8xTTrx0CvdVgR3oE5qnVCGNnoe9y0T3qeItiqP5KEBd2MDdh5tlytK3wYeimUj9/OgBnwR5zvemLRurrfaW+z1Dt0b3IpjuiXURj6UpwJASuz4litqYxlf/L8Vm8o4mhiW328nkBYv3r/kHdLwd9tU2SkAj6DEgKZyah/c8xZVsNyhF+hjZvYArbnqvDNNlPQNrOpcCKz7KojTVec0Ai+ds3d5ggFGB8n5ix8uKmNAbQki46/vnKxLz/3Xh1bTvA== 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 AM6P192CA0043.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:82::20) by VI1PR08MB2880.eurprd08.prod.outlook.com (2603:10a6:802:1c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.25; Thu, 5 May 2022 06:59:06 +0000 Received: from AM5EUR03FT016.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:82:cafe::b5) by AM6P192CA0043.outlook.office365.com (2603:10a6:209:82::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.12 via Frontend Transport; Thu, 5 May 2022 06:59:06 +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 AM5EUR03FT016.mail.protection.outlook.com (10.152.16.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 06:59:06 +0000 Received: ("Tessian outbound 2d401af10eb3:v118"); Thu, 05 May 2022 06:59:05 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 3fd3ee6faef46f80 X-CR-MTA-TID: 64aa7808 Received: from 043f49dda3da.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 933A0655-9F37-4FE7-B8EE-45BCA5BB16F7.1; Thu, 05 May 2022 06:58:59 +0000 Received: from EUR02-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 043f49dda3da.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 05 May 2022 06:58:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QrnJtAOwpAJZGcXXhCOIt0hf+xt8beRZFCdqk/xmbcbQBwJSxeiuX678Kiu6yvSsKv6jOkBnWBE71S3fhOhY/9l/1sfV76MdZgzI+LizO8M6Nz66eEy5NUh6wlHKJE8nthDAio8a6VbHkPNHoYE46mPfxBq53KsCDWjTjU63TuOTpy2V7XoKXGsq8FSDPLwG1C0cg0mXQozTpwtSMSJiBsicOMMX//II8J+dy4KDW276hyBYULGIlnVCwkTw9QS14nDUb0xyEEtsjM6OsyEXxicjNbbUyT9fMLyZ4ZxqOzgP4UEkN1TSbSTBsV0T9lbkSHsDKV2SHpRjQf2P6tDVfw== 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=N45MuaSrFJjz2HBgqxS90PzfUuyqlkvFmWor5LS+SEI=; b=ARVgOTSBspTuRdCzFxbVnBTAE78nR1Gz+xFfXEOfQUJk2CV80HL4M/MfNttQqYuUL6tET6KWVArsEKSXHkSTaFzNCLKLu/27yICVgdMLCtvLkkdggWew6/RGq58i9cXgYXEq+manDa42t4OLiVPgjGT04sqnsQwYfrHVE7bCrhA0ZXPznbh7WrivfDWRqmAwmtkagVxM9fWb+Qe2yMe0AxJ/o2/W8X/arxEK9xNEiv5Hy0vigrepWGAU6n37UPVLNGr8GUlhs4c82clSnkmOOpMgK9oxQAO+EjaLnsXR/Jy+hj94rYhF+k7+wb7alRZh9D4itVbgNE1HzjC6KsIFQQ== 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 AM6P195CA0043.EURP195.PROD.OUTLOOK.COM (2603:10a6:209:87::20) by AS8PR08MB6994.eurprd08.prod.outlook.com (2603:10a6:20b:34c::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.12; Thu, 5 May 2022 06:58:58 +0000 Received: from VE1EUR03FT027.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:87:cafe::45) by AM6P195CA0043.outlook.office365.com (2603:10a6:209:87::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13 via Frontend Transport; Thu, 5 May 2022 06:58:57 +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 VE1EUR03FT027.mail.protection.outlook.com (10.152.18.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 06:58:57 +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; Thu, 5 May 2022 06:59:01 +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; Thu, 5 May 2022 06:59:00 +0000 To: Subject: [PATCH v5 2/4] rtld: Remove DL_ARGV_NOT_RELRO Date: Thu, 5 May 2022 07:58:56 +0100 Message-ID: <8db827d67ca16fee222c832d5dcdc7fcbb51323c.1651732417.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: 427e4fd2-b520-4bee-ad2f-08da2e64bf02 X-MS-TrafficTypeDiagnostic: AS8PR08MB6994:EE_|AM5EUR03FT016:EE_|VI1PR08MB2880: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: PxXwY/gruMt4ZGIpeSAUVCn3aQ9XR8zeg/bOtjjKzByu7RZ885vBcZqfz8uZ6y2a2FPOna4ybjBC5IrsWX4lrsJIs0/5F6y3VwfJ1728y8878q8/2AmI+Zso0qmjhKFQHtULLLvWvbSN402b76q7AnsyqPyZHslxO72HWK5+xYElq0hotJASL8j6FiS7KTS+fSPsuR0zxlEBFm4YhEnBI0eBWi9FMgzYVkKntTt7sgFMhB2UDHTescJmU/r4G3EvHzHFIiQsG6kO58//8F7O0LLLytul2zgBZaPb9H9a4bCcGPXnUFkin3h8+chPdYVjeiwwG6goSsc2F093vWTKEVz0J+yl6kJhS1Iza+hiip5NLrBIjacO1LtvKWSIAKlcTiPfaJ7nM2wBDec+giNDOuYRHF7fxx5tzkFxnoBMAYAfpJLUxfYwC5FXH8SS51AwxSi0E4hbwKOmdEdRtrmzRvOZhtRhMw9JvmcMiZxGNWDTri/zgLpPj5qKvhfEk5ILonFP+h29DFBXFKjIriwPSSyZlN0JMXvPf9PrivfzNh/B1Zv0EXxGRcOdks6FZZLYvGVlUCtqppDqQ6TjMshB9y71o5Q7X0VzUcKKHXHFoXXqTbUOMKvb39lLgRARaLU68IY07K5/rx85SoqTIZ3u3uswCGSaYp/JQ9rG4J/DWCy9oIWsAkqUBP6PwrrahfVv6c8iZaWuvNw03g1NUR9o5gjvEnF1UcRGSVqX/5cvQG/sEQRcf9l0KWNdoABkAgf5eQy0OQQ/jMrpEDHrpcUpy84YyRrCLu0BHzsxXg23a+h/ay0MDw8pg92YXEm7ny0H 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)(36840700001)(46966006)(7696005)(36860700001)(83380400001)(6916009)(2906002)(508600001)(70586007)(4326008)(40460700003)(86362001)(70206006)(44832011)(8676002)(8936002)(26005)(6666004)(5660300002)(316002)(30864003)(186003)(81166007)(82310400005)(426003)(336012)(36756003)(47076005)(356005)(2616005)(2004002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6994 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT016.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 57cac17f-6f17-47d2-8819-08da2e64b9da X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: I/8oNeAdxsHXnwJQytgaN/QVEYjHUOQia4Q3phbC6u7KkmuhKiTcwJuDQZRoMS143e8VxM36zlVR2z0d4WCOz0vV9wzQdaHVGDWIwDEFm0e4Yf13RTLLDwvQZ7fKaRkzQi8ivqKksi5xc3RhkHJAymIpSfw61+cZCjRcLQ3pkcefjNsbDp+Y+SFvy0JKwwPp0ccwrkV+Kf6cgKHlejfeRjBSS93CtqBh9XAGSO1VJeeKHPH154LohDfs85iTPQI5OaY//ygnF1I5U6ND+mejSY/XvVOJUSPqsNbI9TvIl1B2TdlG/2IMObX1IBhRXKWFEIcN45rhiVxMQuRyCdJePdeHXSOVYZyzr1wOKQmPZ6SDrujiTxrJzTUp0cdbd8jKv3CW2+ZSHQd1oFFvXaljQrBytrfi0H0vj4N9D9pGHRWZ6vaB9ifMHiqoNNX6eCKZbVU1xgSN0Uki/KGrWmC2YIC2qeBolQnMx3TbuFzw9NK1HDEVay/t2AdEBvt340DWgvZk5c2HCy5YMaoATh4U1KerhMzF2ri9s6cptKhC1dR1w1Mc+uUckzEc81FBa84Wy+GP3GAx2y6nCfQ/zesK27dE3af840btO4CzxJaa5gXUr8MfRr7OWsX121GQbgT/bvbz6i+ogIuhpP2T2t4yXLlwjPcfqGgxfDhxLMJc+6wT4F7ErJ8AvN+X5KnmTjpSrhwRawfaB0w0Nf82gcnUgjJyRACDg8Id4N94bFTTz9h1Wzwo6fdhFkY3RCebKD313KCq4B3y6bSqz9b3HQIC6PCqpTeAva90GI8owrQbmZQ= 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)(36840700001)(40470700004)(508600001)(81166007)(86362001)(8936002)(44832011)(30864003)(5660300002)(2906002)(36756003)(186003)(426003)(2616005)(336012)(7696005)(6666004)(47076005)(82310400005)(107886003)(40460700003)(26005)(83380400001)(36860700001)(6916009)(316002)(8676002)(4326008)(70586007)(70206006)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 06:59:06.1796 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 427e4fd2-b520-4bee-ad2f-08da2e64bf02 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: AM5EUR03FT016.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB2880 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 Cc: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.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 Thu May 5 06:59:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 53494 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B7DD73886C4A for ; Thu, 5 May 2022 07:01:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B7DD73886C4A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651734117; bh=u+RFq1Dit/uVdanv3e0GmxN/tXuLxDuep/zQfp1Wfcc=; 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=IbeayaXdQavW4/qfuqeNPiC4YvErAcxqVp5eQVCveW4ZnKZebO/3SaT+WVWiqSuhl UfynDSh/Jf5PeMp4q81aNV2mpvvy6K29eHhROE/NEfrIMBnyATpf+oWWY6p6UytnNJ RFbC+lEMog9OD+XrSyb3r609utUeFpTjJoJliXZw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10054.outbound.protection.outlook.com [40.107.1.54]) by sourceware.org (Postfix) with ESMTPS id 8CCC1383940F for ; Thu, 5 May 2022 06:59:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8CCC1383940F ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=J12ogOWarYKF+WoZ71XuJmywcG5WbPStwTyPElCC9fIYRLzX0xRwD4uIy5xO5Ig9xKAYfAad8GUKsy73WIRp5EnieVGjkerL0wrtwVlqrHN2IepsJomZXN1ms1E3w0BLWnWmG/DWqgzyYaVsN7KhdrBOFTN4FZZfPTesQIiLWF8DswUzu+aOqtOwCfkhEYApK1i1/H87e5jG6Ka9/JWlp2CN7vgNaBGva2FXr0nd/dAYIJgKxTh+eeqGe+xPZ7IwGaugubJyiuuxZBaM7MRy9/qmj9e8vbCxRLvBXlTVnd5J3tHkm4PIXuFBxxYHI+jpK/iQadGezunEJiYLTR2ssA== 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=u+RFq1Dit/uVdanv3e0GmxN/tXuLxDuep/zQfp1Wfcc=; b=ZR1GzIBXvxuR9gzZQ7F6diOB9rxySYV5PRruIUmqAl0IwhaJpL+jAIyRvY0anAxgHGEEpS8k0/9DnrDSY0CSmZ1fU0tAe5/FMo6MuCSP6b1GiW7enpiEyWVEvVdf5DmbWItm+bjNgXcZzK+5+zMgTezM3QZkT8pz+nuHDtaxqKyP4Cw5Ca61ssuGkEEesBkFcFOMCB4ktjwXuSB0dPOkCWZNRErMBaAGA8hpHumogiIGFKJ+yQbIUY2xsEZmDiExaYlKx1n3BtncOVWMDiuRteIy6Gce6sStsng/H3Xvf+aWNc36pJUMYJOAvCEBviWWU+CWY5iP07W2NgKbekvGhw== 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 DB6P18901CA0013.EURP189.PROD.OUTLOOK.COM (2603:10a6:4:16::23) by VE1PR08MB5709.eurprd08.prod.outlook.com (2603:10a6:800:1a7::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Thu, 5 May 2022 06:59:18 +0000 Received: from DBAEUR03FT026.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:16:cafe::cd) by DB6P18901CA0013.outlook.office365.com (2603:10a6:4:16::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13 via Frontend Transport; Thu, 5 May 2022 06:59:17 +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 DBAEUR03FT026.mail.protection.outlook.com (100.127.142.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 06:59:17 +0000 Received: ("Tessian outbound ac9bb5dd84f6:v118"); Thu, 05 May 2022 06:59:17 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: a45d2d09c0e4df9c X-CR-MTA-TID: 64aa7808 Received: from b1d6027c3532.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 012EDF73-8F9F-4CDB-B214-20D1B6A68094.1; Thu, 05 May 2022 06:59:10 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id b1d6027c3532.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 05 May 2022 06:59:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ffQU8yRyyYn9mWyc5v9ocJx3lDmOhrQNGI5sH6SSHq4VllFO45aDdSno5aX4Ne0z2FI9Q3NlD6JEJiCSVE0cqZIahP4z5KJh1xYQTtkDooHT3c6PK9m7oFmDib5gd7Uq7tGc+aoUDB+LmbGvkFT1P4RfGmaGn+tf2l1caAqoELSFlw6URd4gdvWUAsvtCqrawGaHjmF6JNz4yGtZNclHCwclZC+WbvmJY9QxEnokAIsJqIWgxji7P6ulxK/833uYuWJDi7SkI3UXYFhYO85oLVx33nH+jaDTso4ari1rAaGtOAZhqvJgmK3uT9Z1iXJlDTLQYVc7ZW7MIkW34V4LEw== 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=u+RFq1Dit/uVdanv3e0GmxN/tXuLxDuep/zQfp1Wfcc=; b=fRqRESJV0Ed0C8xgMhS6omJm24Gu4RUh1L3zPFPD1vZb46SMacKDCMW+EudOzlvrmWC/MSex7+kLP+tK+hYgOxq1t4cniFQSTndwLC+mtVbJ4G0HhnoBoZYSTo7c7mi7G87tyQZU44niF7qpiEcjhH8c8Et+On8O/fozlyWecGtAyn1yTTtiQJvF9m7tp+xoTbUBBMeXf4ex8L6r39DL4Ovw+65cyVWNvgevRjezs513eQNrZqmF1I9OA+oqlJ+Bb7qsq6nZScBlCmOFXFdJPb5r53fwX7lMTegIGYT5R5qMul3YStVod6+kvbmw6a2i5PnWUnYv9f+4Wbq9rL3q2g== 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 AS9PR06CA0240.eurprd06.prod.outlook.com (2603:10a6:20b:45e::9) by AM6PR08MB5286.eurprd08.prod.outlook.com (2603:10a6:20b:aa::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.25; Thu, 5 May 2022 06:59:08 +0000 Received: from AM5EUR03FT012.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:45e:cafe::1) by AS9PR06CA0240.outlook.office365.com (2603:10a6:20b:45e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.12 via Frontend Transport; Thu, 5 May 2022 06:59:08 +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 AM5EUR03FT012.mail.protection.outlook.com (10.152.16.161) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 06:59:08 +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; Thu, 5 May 2022 06:59:12 +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; Thu, 5 May 2022 06:59:07 +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; Thu, 5 May 2022 06:59:12 +0000 To: Subject: [PATCH v5 3/4] linux: Add a getauxval test [BZ #23293] Date: Thu, 5 May 2022 07:59:07 +0100 Message-ID: <3f32aa2bdd587520534496b41a7225ea42804734.1651732417.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: 7d1505e5-16ea-4e82-d575-08da2e64c58d X-MS-TrafficTypeDiagnostic: AM6PR08MB5286:EE_|DBAEUR03FT026:EE_|VE1PR08MB5709: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: 1cmG6duZtoKrl+DFSOHg1FJWKlcetr30LKFhwEWqHapo2jqG2sXxAdiZMJUybtcc2EGWmw4V4TrGu8CoItRi4BB/ZXUDdDIAACVukBPT9L0SSaOe9+djMtvLzvECinbj5i4TZMGwkFpy6NCsPrm8q1ocoDipIYg8luW1yBgkbDbDrwhTFe6pcP6ZpaLm+9wfTcg1wMp5PZwX/YzdexTcyqeIBmcKGIfqFMt7Mu8O/gbygzf4MD8L3tGQJaq3a+1lm/BUn0lStfqJUfbmUdRpwIkcH6erclG7i+1p1YgxGCugfUyozt7X50HWRcyUDvc2BlKCihHJlCTkU5nTrll31ODVXNd1nvuJ/Y50z4bg1/ipIQFFWyMcWy1qKILJgt2OS+ihHoWuR6WticLOfouWGJc/zp05VBupToALxCljuTKEO6Ch4lkNnZotvX4tm4UqMW1TD5WqrviPKkqEnUY6tW6RdHRTd9bm0984RPtiDQV4KZ0Z/bfkLAjvNKsOaEXFoBLy4WX1kqKNk4DHWmLHocGvtT1CrOGqvIZCtSZ2L3NVQeYijaKbIDAdaT7rlaPwDNeffVGRBDzVqxRzhBgSU4ljRR1q5YDpG6zvMwrbDFOKJ0B8z2HymTeEUNAuCYtVV/hmZBcmK0KcTaWOCm33Opx81Fd+X6gxYkd5RONnoQmzAhEDynkwTl7uWVBVl+lbuP8LQb05j3vc9MexMhiXmm5XNpHgcz9T9kk40o+dxdzLPC6N9bVCEyloDx2MVv6OYJF7gO35bHzgZiuW4g+UJsSb3SIxMkRkFnfkzsy6V/c2ycXtNL1Mhem9qDWaG3yD 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)(5660300002)(40460700003)(36860700001)(8936002)(2616005)(44832011)(8676002)(82310400005)(7696005)(26005)(36756003)(426003)(186003)(2906002)(356005)(47076005)(336012)(70206006)(6666004)(6916009)(70586007)(4326008)(81166007)(316002)(86362001)(508600001)(2004002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB5286 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT026.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 39ef21df-92bb-413e-a6eb-08da2e64c064 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XvEEFWeHFAH5y8LLIPS4IBUb+i9nbSbkA3r5TaKJPyaci98SMML8jf7Q0bq8YFpdEfwjSlE+53yZ35RBv4xMH1MFkeGG7Tbf4o5Cr1aCzHJwyR0khm1t016jp9WCp0bM9RvUMGoo89IwMtse+JsPSgFUeNnk/RamxOdBvZsv3UgyLCXYyjrwxCFW+GJLvYjAGCueOFCsNkCMivtCEyRO5aZcypzufsuCKJa7VICfWUtZ8y0emjbj25dLUNy7FyUpbxdnDDNpTskNzguuExiQM6qilziFC7FMhSoOKahT/Ytpyt98VOvwzw5FL8JR1jQpm6qfHlhg+DNWXqlpeADJIvAOLU7bCXefnHHPSVYaE/En6s+09CdBFhm2lET197Tz8IW/29IZXiDYDg1xfeRWlcZoCn1l6vHddyJ0icbQhEgVzIp6X8Hi2I5+NcqIXtC5Aob3oLmAVhwap9oWFXApW335Aem0QBlGm5TXyqxjmpBAC1wAhrCThooa2zQunMbbUWLeY4rK473i6VtZWgGQlDyAvGj1xgzgbqwYQX+0onV6bW3skiFA+/fXBblqXwiUvMFxp9C4rqWZVNJ3HZQasjl0XDpnmTfHssYhLyYhNcvrQT9C+NiwvvCnUpwr7XFaUHtma5W1lhp9skxFzPyiH4qF6czhIV3aSvKl5kY9yNP8SiFf7qJmzw2WismKw/lQDjXonge/PMKwOrjmx4ETAlxK7IXWwVsQVdfeHwPLag3ErP0uXiYJW52vBL4cyaRPozEo1ClOl1362uV1wxK5vQxUVV/UnnE9aTjGZVpCsYA= 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)(36840700001)(40470700004)(6666004)(47076005)(426003)(186003)(7696005)(336012)(2906002)(26005)(86362001)(81166007)(2616005)(82310400005)(40460700003)(107886003)(36860700001)(8936002)(316002)(6916009)(508600001)(36756003)(5660300002)(8676002)(4326008)(70586007)(70206006)(44832011)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 06:59:17.2204 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7d1505e5-16ea-4e82-d575-08da2e64c58d 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: DBAEUR03FT026.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB5709 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 Cc: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.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 Thu May 5 06:59:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 53495 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9C1643954C78 for ; Thu, 5 May 2022 07:02:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C1643954C78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651734162; 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=THQoHCEr/YbjvWT9+Sj2keGBBKnHOFbSpQhG2047Swf79dFYhDoTcGWTmnt+H2R3E FJgnYPZqa2g7iC/yQ8bzH60cPyOP9xIJ1mcdB1BtCiQ8BUxDDDucN+spPhTL1+m+PV 3/d/FNHp2lBwe7TNSIs5blmCCk3C+V/Buq46OTYw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80048.outbound.protection.outlook.com [40.107.8.48]) by sourceware.org (Postfix) with ESMTPS id 52804386EC38 for ; Thu, 5 May 2022 06:59:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 52804386EC38 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=fxdAgJu0VWjD6iS53QHPTgVFEQ1GRtnjm6Hv84//WcnjKCHs9/BVBUUDmRghG5DdYL5GmMYPRW/f454/EvJ7I/+ko/7iYR8rX0fzQrkzvNyA8Z5HQENuswSYtEuwIMkwCb1UYWgDqDVXYoqkaKgjl4BsoOE0aqAi+O4zDl+mGMLO/F2eHYm59rk5y7lDsJMmL5M3mcjGVWDW4djnUv7CcjGrI93cfDCgj/dpwxB2KWDt3VDrh6l4uZCyqFSsyhEQzWMXV99oPuF9gMH7WxCD1jUKKEiYjjIN2vWkWub/Eo0n0tzEUoeKWSI9+um+IX+7Dtn5wqhrCEx/VioHS/K6Hg== 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=Ev+20GM4cL1ahyYqJtP7WOCY/8ZN+6quF63VVjS9s/To9oMzdAL+DfImL4fxqeG8Gy1jTgNXr2a5osBHxPk7td28PkDRBUWumuyfopncOzFiCTh8hn3sIpcUJgdW4nB7bhA5G1JuXHIV2VjCII15TwWrtRuuyWoPPcP43LaR7gA/KDv6s85KqZ9tVc7LDqEHTL9QGA5f1mUtp1G/LHwK3nDKf/1+bUGMQH6OiSRsM/M0Il66Is/NPeeTiBC7/ufqmOztCQH12rDMS0exSScrx8D06VqUl8BYiOrJdWzQJxveS7aN9IvKHgVhFo2FGn7HcW/g8RrYTpHdx4une2/znA== 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 DB6PR0501CA0034.eurprd05.prod.outlook.com (2603:10a6:4:67::20) by VI1PR08MB3517.eurprd08.prod.outlook.com (2603:10a6:803:79::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Thu, 5 May 2022 06:59:27 +0000 Received: from DBAEUR03FT062.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:67:cafe::96) by DB6PR0501CA0034.outlook.office365.com (2603:10a6:4:67::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.27 via Frontend Transport; Thu, 5 May 2022 06:59: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 DBAEUR03FT062.mail.protection.outlook.com (100.127.142.64) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 06:59:26 +0000 Received: ("Tessian outbound ab7864ef57f2:v118"); Thu, 05 May 2022 06:59:26 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: cde3d48d0569f8ea X-CR-MTA-TID: 64aa7808 Received: from 14f797fcb2e7.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 90B110DE-6057-4CC7-A04F-04AEBF4A813D.1; Thu, 05 May 2022 06:59:20 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 14f797fcb2e7.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 05 May 2022 06:59:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QzENH0frd4hdDwyvXE1tJzxdolgWhz1aZ5m857AX8kLBhGgvf8wMs4xWhYiU2fTt8G/Ftxd1+p0Z2yPkyKCWdEuFBV/dwP4W1RsBdEf7t+ihDpcXQatEW6MDFmq9UeWJoDtyLvxR/W4il+pQ34GCwsSbhT318ACplpCPYhk9gjlKBwq8fkWFCxTTLeoiaotK6RvnDY/IAbe7n5rsmauh03pPS0dJh/3OGzZm+H+vmsVBAYkCYRJAFujIyiMuAxlvuWmYuII85dWgMUOBc/3518eFnY08rDEcBCj1CnQMdobYBO7ePtoy3/H5QOpFzngN0FhwVXrCAMiNfVvDtFrYPg== 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=ZBVXlGWxnqwGTD4FZNFM7SRCcUvQS1tOY+1gBKVwMGkZ8Z+4y4DJIB9cfsHsruRtSfKeIkyyX4Csg3lLY5JGKh2cmek6USCjA/dbEmCIlFDbMlywo5GbgQr4iglyMFqeplGg8aQcvlXUIntDKcb7o+QxSY/ih8H+x4y2bwPWalAOkM9SfbJ4+KYSpEQ+95Qf/4JSq0NkrHlsfuGH/JDoeoI1ZqAfg6yfBtiCaVmdeHzvFusKA3q1NxJMV9Vcc/zmHTuijLTjBT6vKFyDWLg6Vmn9kSr7rF2LbU0I9OsIsqu/DKLOjuLUM+19A3SmE/vl4vAa3bfpXLNL2GdUS4yidA== 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 AM6PR02CA0011.eurprd02.prod.outlook.com (2603:10a6:20b:6e::24) by AS8PR08MB6456.eurprd08.prod.outlook.com (2603:10a6:20b:336::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.12; Thu, 5 May 2022 06:59:19 +0000 Received: from AM5EUR03FT060.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:6e:cafe::50) by AM6PR02CA0011.outlook.office365.com (2603:10a6:20b:6e::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.27 via Frontend Transport; Thu, 5 May 2022 06:59:19 +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 AM5EUR03FT060.mail.protection.outlook.com (10.152.16.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5227.15 via Frontend Transport; Thu, 5 May 2022 06:59:19 +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; Thu, 5 May 2022 06:59:23 +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; Thu, 5 May 2022 06:59:23 +0000 To: Subject: [PATCH v5 4/4] aarch64: Move ld.so _start to separate file and drop _dl_skip_args Date: Thu, 5 May 2022 07:59:18 +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: cc94d9e1-2fb5-47ef-757e-08da2e64cb48 X-MS-TrafficTypeDiagnostic: AS8PR08MB6456:EE_|DBAEUR03FT062:EE_|VI1PR08MB3517: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: ZCX9L1m23xsAvsBPU+4aTpsGrrp9sYE6VI2xDXerkajM5njp7NVUGsLq3w7sidV2y5dHANG2wpz1sL6aGeVGE9VFBg5/pe7vT4+Tz8/BPkTW3ZSip+uIM7ufEyeiBOjtdzE8HWQe5+9sAw73gX5fi7rcdAxMlDWF6M26L5zc4qDYt/OWEpRz7i4sdL4MFF9NUwMqj099SSyxyGqdCGv+1SsupwGTLCTAAhhckdRZXwJFP4bwja88pu83vNTo180O5+T3U8X9yTyGVCmKpTgjRk5eg2oUclkGpGQgjG3rwQ1F+XSpI0/dtPoxNDT1tfVGz75MmDXHUJUNuiTH0ZP6PmUjptT2RAj5MRINdusbM3Yym52DfoddS3ieOCVaQwHsjjbQtMvzyDjALKUMGpUq7PImqSv2NglDxbHmJEzEEnSbDO5pEMeOBtvPB6B7l7p84j19Im9O+W3TxlyuoaCkooaHB0KGZkUTT1hTSIKb7vcrhmH7/2SA91qZ/49Vr5HAgcT1o1uOaXmzPchx9701XFfOIDKIS9jCLTM5OPttGkGTAzfA3YmoWG4xYWM7BW8bi2XHQw/ReeZ5/V/8yuc2UaMlM6iDnxGI6hy2cfdisnNjVlQiQzPWpg0Q64u290OnFgUlVrYChqdAwkaNXUdc412xqz1cfH2u9rhmEqQLz438BOGFS7eQgD2li22zuupNk+D+VubMz6SShUz4059LfSPJnDZCAasT+40j7lXwlCE0f6iCXvobctVfMe9f135bip4N6i8BQUCjo7ymsqazSyWV7vE8vYwvYOorKOkXw5UYEZTioH9z6He3Cl8NKAOv 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)(356005)(40460700003)(36860700001)(81166007)(7696005)(2616005)(6666004)(44832011)(5660300002)(36756003)(83380400001)(2906002)(82310400005)(8936002)(70206006)(8676002)(70586007)(508600001)(26005)(186003)(426003)(47076005)(336012)(6916009)(86362001)(316002)(2004002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6456 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT062.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 78810d0a-9ea8-4aca-a878-08da2e64c6da X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5ozlw8TprzwQTKOcA5XZz3Oqa0TuH2xpmEwyXfZKfB9ShxiVxRLzEnVHlzkbI46NdYHcybDV6WBMmnUDcVv2uQgI0Kk4db+wzlqRd9s7gUVUha3gw7B24VzNdzR25rWhGymoorK4oikKG2Urf9raTOFN+PTie9Ifh9EU1L2wMcN/BBDUlsVGCHgEP8DandvF8A3JLzbxRO6bDjjtDNR3p+rMY+DzhHh08dOGVBdOkauqtI9B8aSa4W6a8hh6s9rZm9q91ypSGZicOStedTDQWh9gdB45Goy+jwUFz6PDVEXmf/S+quwHHj5BC+ERkXJylPUMkwWOZNMh5Zwa8GSp3O4ilT1QnxTxUB5DxUEOVQEfjSu1po7a7ReEA2IGHbQhqooNp3zFzz3B00Q/a2jDg68fh2pea2OJe6OAdULzLMO4kSpaNkLT4VRs76nVdWeMi7k5Ek/V92stqcOPBVJEoa6CFvEsvHI4QzzfuuhzkV8v/gWoZOI1sYp55qXzSkZJnxSG0K76xZi2gfm5N1K1Fc3MbZOtoVk7IwcEKhjaveuzuV1Sl98UhnvtnzN90v5fRT7lLL/ZI4c4XIQ5JegmEPuE5XeT9V1NL0iv00Lovm8kYp4N7Y0YUZBKp24wCmqFLIpOcEPgLr8j8QqANhaJ7LyCUagf0HyTJA8NBRgrpl9bZutDb5JIm4NlFfd/YZd0e6B/YBHNmdO528pK9bzEfJRxxlnX8VRUXKaXYmK6fxfnUv3l+ZPbhldsKvfbsfd4mBnmv1cDae7ZhVvpYRxRR2sP5/WL+cR8biyMQBp4huo= 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)(7696005)(426003)(82310400005)(47076005)(44832011)(5660300002)(336012)(316002)(40460700003)(26005)(186003)(36756003)(508600001)(2906002)(8936002)(6666004)(70586007)(70206006)(8676002)(83380400001)(86362001)(6916009)(36860700001)(2616005)(81166007)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 06:59:26.8321 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cc94d9e1-2fb5-47ef-757e-08da2e64cb48 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: DBAEUR03FT062.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB3517 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+patchwork=sourceware.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)