From patchwork Thu May 5 13:58:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 53519 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 1353A3857827 for ; Thu, 5 May 2022 14:00:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1353A3857827 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651759222; bh=VqfHVVFde5W0zoZgSHULAv3YQvoopC5jeytq92eCi04=; 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=go1gUJgOAYmEFDGPuC/b4o8ZwaIuvYTI+KbNpWS5VzUBHj/kqZqX8TER729OBfgpV SqQO4ohhMKFhWQwA9sgBkUwmvy/EauCqd2aWIpa0Ut1L7klgZB1hhxFsrGmeM+h5YH bEJI0zVfKF4zVEx3ibJ+vKKN1ryiNRYlqqVGWSRw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70057.outbound.protection.outlook.com [40.107.7.57]) by sourceware.org (Postfix) with ESMTPS id 51A813858D3C for ; Thu, 5 May 2022 13:59:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 51A813858D3C ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=J6vYwjT3GquzET14KzFndSDmGcOaXnyMdaGM+1M6fs6LVTGnPgIBxo7gTm0bXYQH3ghZyUo/GfGtiFyXfTBWgTLfjbbHthagPquTesbS98AQst4HH1BTT1+YXQAnvZgQ5l7Jfelcg1O5KL15wtecoyFf6y2w+um2hzp6MgWnlbDUvVPfl++zQ4FXWWh4yEz4ZPYAm+Qs+M7tG3u1FfhWVEkBmBNNMR3afHmlksV4Fx/elMY/5eSXCf2vc+Wxo0KIuoqclb1HpleQ5NraRQ70Xgs/MjSIXmkbERDBeHZbIWHev44BUXg4XuaMWi4nb06If2T6eADXM7cSrYuKPj9toA== 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=VqfHVVFde5W0zoZgSHULAv3YQvoopC5jeytq92eCi04=; b=Tj75onUytHKZ/1bLxoH61ZrCJ6tmp1E08PwcHzkfwY6SH6qjl/Bbfb16SWCjBSK8VcdeUr/HgRLqmAryZeJH81KNYJtBlWs5mxO73miWa5oFBPCEoNwyX/DLR4O4GsG3pKSxqFglpvn5ORkus7y9vfnnX47WVJVtbslwm3I++wm2e0SuavQy/90eg78DYcK1Hsw0fLJ/rPv6pQkmx63h/gXXE9TAuKs/+JMof6W3fAt+2PkyIOkXADe6vOP8Jb9dM5Y4Fw8U54mmwAofsbXCiE2mes8lB8ZK8pUiLTiObqUxDbL7ZiHg7QXtoDBtjjgTYzBKOQZowz63YwiCAiHiVw== 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 AS9PR06CA0568.eurprd06.prod.outlook.com (2603:10a6:20b:485::30) by DB8PR08MB5498.eurprd08.prod.outlook.com (2603:10a6:10:11c::24) 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 13:59:03 +0000 Received: from AM5EUR03FT005.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:485:cafe::f0) by AS9PR06CA0568.outlook.office365.com (2603:10a6:20b:485::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.14 via Frontend Transport; Thu, 5 May 2022 13:59:03 +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 AM5EUR03FT005.mail.protection.outlook.com (10.152.16.146) 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 13:59:03 +0000 Received: ("Tessian outbound 62985e3c34b6:v118"); Thu, 05 May 2022 13:59:03 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 70ae863129179b0f X-CR-MTA-TID: 64aa7808 Received: from b745abee7bb6.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 22CDE61A-E3BB-4EB5-ADE7-3F91D8FCBB58.1; Thu, 05 May 2022 13:58:56 +0000 Received: from EUR02-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id b745abee7bb6.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 05 May 2022 13:58:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=htWT628GcXS0tyk4lZOzQBaO8chrcXUne+oDwWA2OuXyZoMVfxOba7bbPTwDzD6T++2jIr5tUn5f9MePUIE8b/WZ/kLCPQBJqJuv8P90HeV4xqoj1ERTZEBGWckNd1jefQrTgPZcEf/lxp10b+Qlc1cnBxVDVapX9R9cWJqDXBWUdS813+bgM9/efWNMBwkGhU/mnIO7mgvTIrtrNeMMrNXqQ+Gb/T3qyeABcPPJrO+4Tc93dOVrb+zVTxD+LAavO0yAAI/tRNn6OaHRqT2BSNuLSkgk5DUtRdDkUDGv92c7ctvqFBucOpznireOV3XjMB+3yIt1bowvZQjubwiATw== 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=VqfHVVFde5W0zoZgSHULAv3YQvoopC5jeytq92eCi04=; b=h6SMYleCyzEFQLY/6KsTalr7xcbSaBJ0kXYdrkQDAWK7m3wXQd8xrahsIrJV8uC3c7aZOyclKtFcAcEpI7la/wymgKwhhq5UR/qDvHb/bn0uARlBUfU1ApTXp/2YpJChraTB/TcaB7MfK+JpPWpQ7VaMXURkEO0hX1XceL9KshCE9eaPimSg/gZnbuBcZyd1esTW/YS9/xQVU8lyUoRVtsOjAKVaASgIVHDYOlzgEHZK42286CsJR1uDr/vFC5rT+kHCG0I9tqh+nSBGXefw7YrZQRPe4e0w2IUuH+H+YCiAI5YOg4g0/04Qi6ZR4q+TvWWCGYIhzSAxk19h7sr2Rw== 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 AS9PR06CA0265.eurprd06.prod.outlook.com (2603:10a6:20b:45f::34) by AM9PR08MB6786.eurprd08.prod.outlook.com (2603:10a6:20b:305::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.14; Thu, 5 May 2022 13:58:54 +0000 Received: from AM5EUR03FT050.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:45f:cafe::46) by AS9PR06CA0265.outlook.office365.com (2603:10a6:20b:45f::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.14 via Frontend Transport; Thu, 5 May 2022 13:58:54 +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 AM5EUR03FT050.mail.protection.outlook.com (10.152.17.47) 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 13:58:54 +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 13:58:52 +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 13:58:52 +0000 To: Subject: [PATCH v6 1/4] rtld: Use generic argv adjustment in ld.so [BZ #23293] Date: Thu, 5 May 2022 14:58:48 +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: 8e493dbb-1133-493c-1c75-08da2e9f6999 X-MS-TrafficTypeDiagnostic: AM9PR08MB6786:EE_|AM5EUR03FT005:EE_|DB8PR08MB5498: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: duLUEkjA7iuWx4O9C2Z9OdhdN1ERepYrijAW+3pWDmokc2rtyGM8biOUDw6sZdWb/uuZeIbqvdV23X6Caa4+tkB3A21hHmIKBDVH2QDqFhZ4kURXSO2D9bBSY1OyyMqQOSz7wz7JuAQ0DC3f33RCj/txzaoPFoGnx4NQ5sMjEee3fK+k0nqWBOD2pCL44UJS1pNwz5mKidPkas6icy4u7S5xKyhEGCcpHdotjE5UuNxuciBwRIZBaKZbRIv3BnGLWTTmIFB6Hi5GFUv5YNE1PccmacfepiyE6Ygyjl+jX2aykJtH1i6xapzltkwT9B8gKrr0xbZSxi3JuFP91hRhxbO/3cpeHmj782MIXGmGXmYg7ZWvUxBW78B14ygmBtlv0sf7W996EKiMeWKGyvsaH+zX3i6v3JamEv5Be1Leq6Efr2v6fN0yy1TXh8NT4XkfLZVxiQwEY0/2Ih4qtqk+8U+ob+Ugjts7o65YBohxvWn203K9qKvHq9EwYF+brVt3VPQGAP927GHPsiz5i3qAeKON6aeqw8W5P8V2HfWmLFru63zcuVzy28FotE6p/4lYdod1oy7j2LscoxfP48lLo7qaV/nuhRcaFF5qXLN9EpsWXARPl7BFzJQQW/k1E7nKVdnfqGGS4lT4yGb0shJtN5kngx1KvYNzSPFeX2Njvg0PEhEWvEc68z8ADkaLn2xF/sLM0Xc8Vsl1OJuea1FUpr9Ha+sCR6kAiJAQVY8qWQ8= 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)(46966006)(40470700004)(40460700003)(336012)(2616005)(356005)(426003)(186003)(7696005)(5660300002)(6666004)(8936002)(36756003)(44832011)(82310400005)(36860700001)(83380400001)(316002)(2906002)(86362001)(6916009)(26005)(508600001)(8676002)(70586007)(70206006)(81166007)(47076005)(41533002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB6786 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT005.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 933ab7f7-4cb9-4b3f-2e01-08da2e9f644d X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LLrDG8FhVfdU43ud97v5b5dWZnqBdFRePJ2HC2bOmUJTMQi/XjdAG6WfZ9SvRtLGe1ZgMXMuUqfwQhF7mEbgWNFL4yzwUkUOkphoHUgxEw858zo+tL6mljrev8wBpjAc2bvjDa0lP5uY+p6lS9Ar/jXEIydUm5jWIxntmkPGkCQhFgYLgZgduXGES0B7X6LYHvCcZbyfj3oYcL7HogR4FLqQAhHLYbf/Si/JsPv4N9R0roXCVPX7VBJy6yB0PVJa7Fan/tcNRHz374E5SGR850JmwwLEfMGejiB6rPiw4TUhwnaQCZZMYyhxqQkyfGOs8FwCvZ8+OWWePfCsmQU5AcVOO2Ov60lDRfCS5Sp/8n0XVKD7NIvlZ+p33Ec6Ae6HPD/3SfLFJxhRcTzXkpQqfJ3C/7FWb/lgHbkDnUA7sRcgJG9BFBer0VRrDETwzcReAoEryYAKq9BLd8mB0uw5oVEea74dcYWeqSZkkIfbg9yD5C+nJ8NcktwEggne/wIaU3GKcygc5eJvNe10GmZZVO5DwVwdxeCWgwAXu4nfdvD4AzpM5on82kk6NEgviYX8uW34MMGJEuMoA6RRYdI7Qmlu1nfMaqk/DFlyHBymNOyGDEOTWpMDcjokG5w1ArWn0z75TDeF09vB9VKjOrOHqWu5LGEG0Uy4D02FnBT8sQQEwQGlawR71JoYC6kNZUSycWGA6K/DSDJY7VldVkoYVA== 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)(70586007)(40460700003)(2616005)(70206006)(81166007)(8676002)(5660300002)(186003)(8936002)(82310400005)(83380400001)(6916009)(508600001)(26005)(44832011)(7696005)(2906002)(36860700001)(47076005)(36756003)(86362001)(336012)(426003)(6666004)(316002)(41533002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 13:59:03.1885 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8e493dbb-1133-493c-1c75-08da2e9f6999 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: AM5EUR03FT005.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB5498 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 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, only for consistency. The GNU Hurd start code relied on _dl_skip_args after dl_main returned, now it checks directly if args were adjusted and fixes the Hurd startup data accordingly. Follow up patches can remove _dl_skip_args and DL_ARGV_NOT_RELRO. Tested on aarch64-linux-gnu and cross tested on i686-gnu. Reviewed-by: Adhemerval Zanella Reviewed-by: Adhemerval Zanella --- v6: - don't pass start_argptr to _dl_main, just use _dl_argv-1. - add comment for _dl_start_args_adjust. - add assert checks to _dl_start_args_adjust and simplify it a bit. 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 | 73 ++++++++++++++++++++++++++++------- sysdeps/mach/hurd/dl-sysdep.c | 30 +++++++------- 2 files changed, 73 insertions(+), 30 deletions(-) diff --git a/elf/rtld.c b/elf/rtld.c index 3b2e05bf4c..b5070d453f 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -1306,6 +1306,62 @@ rtld_setup_main_map (struct link_map *main_map) return has_interp; } +/* Adjusts the contents of the stack and related globals for the user + entry point. The ld.so processed skip_args arguments and bumped + _dl_argv and _dl_argc accordingly. Those arguments are removed from + argv here. */ +static void +_dl_start_args_adjust (int skip_args) +{ + void **sp = (void **) (_dl_argv - skip_args - 1); + void **p = sp + skip_args; + + if (skip_args == 0) + return; + + /* Sanity check. */ + intptr_t argc = (intptr_t) sp[0] - skip_args; + assert (argc == _dl_argc); + + /* Adjust argc on stack. */ + sp[0] = (void *) (intptr_t) _dl_argc; + + /* Update globals in rtld. */ + _dl_argv -= skip_args; + _environ -= skip_args; + + /* Shuffle argv down. */ + do + *++sp = *++p; + while (*p != NULL); + + assert (_environ == (char **) (sp + 1)); + + /* Shuffle envp down. */ + do + *++sp = *++p; + while (*p != NULL); + +#ifdef HAVE_AUX_VECTOR + void **auxv = (void **) GLRO(dl_auxv) - skip_args; + GLRO(dl_auxv) = (ElfW(auxv_t *)) auxv; /* Aliasing violation. */ + assert (auxv == sp + 1); + + /* 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, @@ -1359,6 +1415,7 @@ dl_main (const ElfW(Phdr) *phdr, rtld_is_main = true; char *argv0 = NULL; + char **orig_argv = _dl_argv; /* Note the place where the dynamic linker actually came from. */ GL(dl_rtld_map).l_name = rtld_progname; @@ -1373,7 +1430,6 @@ dl_main (const ElfW(Phdr) *phdr, GLRO(dl_lazy) = -1; } - ++_dl_skip_args; --_dl_argc; ++_dl_argv; } @@ -1382,14 +1438,12 @@ dl_main (const ElfW(Phdr) *phdr, if (state.mode != rtld_mode_help) state.mode = rtld_mode_verify; - ++_dl_skip_args; --_dl_argc; ++_dl_argv; } else if (! strcmp (_dl_argv[1], "--inhibit-cache")) { GLRO(dl_inhibit_cache) = 1; - ++_dl_skip_args; --_dl_argc; ++_dl_argv; } @@ -1399,7 +1453,6 @@ dl_main (const ElfW(Phdr) *phdr, state.library_path = _dl_argv[2]; state.library_path_source = "--library-path"; - _dl_skip_args += 2; _dl_argc -= 2; _dl_argv += 2; } @@ -1408,7 +1461,6 @@ dl_main (const ElfW(Phdr) *phdr, { GLRO(dl_inhibit_rpath) = _dl_argv[2]; - _dl_skip_args += 2; _dl_argc -= 2; _dl_argv += 2; } @@ -1416,14 +1468,12 @@ dl_main (const ElfW(Phdr) *phdr, { audit_list_add_string (&state.audit_list, _dl_argv[2]); - _dl_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; _dl_argc -= 2; _dl_argv += 2; } @@ -1431,7 +1481,6 @@ dl_main (const ElfW(Phdr) *phdr, { argv0 = _dl_argv[2]; - _dl_skip_args += 2; _dl_argc -= 2; _dl_argv += 2; } @@ -1439,7 +1488,6 @@ dl_main (const ElfW(Phdr) *phdr, && _dl_argc > 2) { state.glibc_hwcaps_prepend = _dl_argv[2]; - _dl_skip_args += 2; _dl_argc -= 2; _dl_argv += 2; } @@ -1447,7 +1495,6 @@ dl_main (const ElfW(Phdr) *phdr, && _dl_argc > 2) { state.glibc_hwcaps_mask = _dl_argv[2]; - _dl_skip_args += 2; _dl_argc -= 2; _dl_argv += 2; } @@ -1456,7 +1503,6 @@ dl_main (const ElfW(Phdr) *phdr, { state.mode = rtld_mode_list_tunables; - ++_dl_skip_args; --_dl_argc; ++_dl_argv; } @@ -1465,7 +1511,6 @@ dl_main (const ElfW(Phdr) *phdr, { state.mode = rtld_mode_list_diagnostics; - ++_dl_skip_args; --_dl_argc; ++_dl_argv; } @@ -1511,7 +1556,6 @@ dl_main (const ElfW(Phdr) *phdr, _dl_usage (ld_so_name, NULL); } - ++_dl_skip_args; --_dl_argc; ++_dl_argv; @@ -1610,6 +1654,9 @@ 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 (_dl_argv - orig_argv); } else { diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c index 3cbe075615..8373962e62 100644 --- a/sysdeps/mach/hurd/dl-sysdep.c +++ b/sysdeps/mach/hurd/dl-sysdep.c @@ -76,6 +76,7 @@ _dl_sysdep_start (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; @@ -173,30 +176,23 @@ _dl_sysdep_start (void **start_argptr, /* 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. 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]) { From patchwork Thu May 5 13:58:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 53520 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 822CB384B0CB for ; Thu, 5 May 2022 14:01:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 822CB384B0CB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651759271; bh=3INzy7QVFBfC1wsKMLU1y5QP14MASxoyC4Dh9DShUCw=; 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=jodx38la+sQr3qPS8ubd2GN0bD7+FlU+KblTEKObA9IoJ6RP8J4N7z7gY2hYvZvNu sKlYXmrxVbCP28I2iox4C80dARk6gwY4OI8TAS+s6vprA4h0XLJcH+umNzK9SxYTof SO6C2Y02mUZA4UxTVtS9oWok7cIDG0gqzQrAbhWA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70082.outbound.protection.outlook.com [40.107.7.82]) by sourceware.org (Postfix) with ESMTPS id 6E534384F01E for ; Thu, 5 May 2022 13:59:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6E534384F01E ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=mHK3bXQnJdcgWP4usxTd9ZkSiPhHNol1LNmgsL8sbM17yrHEa36zZ/2m6qFtpZgLA9OvYdYv3zSR9pGV0LFIBZ+Z6JgH6i3YJLaPY5dXBuvzf5QouQbZYVz8ytH//DW9DWyIPZnbOSHKxW2X3RodTi6dO4uQV+tBQgIPOAmGfVQ4TQ2pxADPpqOhYy2huMyBe6UnfKhfeQRKoRjKcpvMuV4x7jiupROL5yOe98/EspMO2b8DoCi3fv1UEfazJAnkNNhVhH+VJ1KywbvCl30cbnnZIppdO+M5n7U55tBQM7NsvRyDhZ4XRU4tL6YB95eOpROEa4BPHkibGnvohRvwyg== 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=3INzy7QVFBfC1wsKMLU1y5QP14MASxoyC4Dh9DShUCw=; b=X5hQ1XgPOYX29VjO07jDqjO/3weABEthcKd6THMiB+0NLD5T30F8a1r1liX8kYrcRqv3JDiE3FJNJz1y92uT8i468VaY4+ASCSK0bK7RecAxYGYBXyGD8MiU3ysggTejqRhoOWpq9MG3U9MWzz9+TtDSyIIIWgk5TmRWNDYVs/FtuZmkMaecPoT3k3o4wjQ6j10dXZEU+MVXHx6kmMo9vR258qME8qIqawfEH5ObpZ6AgjFuZ70ZxX2M01AbH/pcGO9Vn5JDtkl027p2WzQdZ2gD5Q9cJzlLh9lSF61MIvopnK5cl3xFNMhPV7AlNe45legPE8mbcEzJOTIEtdItbg== 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 DU2PR04CA0015.eurprd04.prod.outlook.com (2603:10a6:10:3b::20) by VE1PR08MB5263.eurprd08.prod.outlook.com (2603:10a6:803:116::27) 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 13:59:09 +0000 Received: from DBAEUR03FT008.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:3b:cafe::ba) by DU2PR04CA0015.outlook.office365.com (2603:10a6:10:3b::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 13:59:08 +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 DBAEUR03FT008.mail.protection.outlook.com (100.127.142.107) 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 13:59:08 +0000 Received: ("Tessian outbound 9511859e950a:v118"); Thu, 05 May 2022 13:59:08 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: b7afec00be12cae5 X-CR-MTA-TID: 64aa7808 Received: from d37af081a25a.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id DC49563D-A526-40EE-B042-9CCA4D610FC9.1; Thu, 05 May 2022 13:59:01 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id d37af081a25a.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 05 May 2022 13:59:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jq6jSRlETa5zLdunwTA9zLZ1KPMKOUAiIX0OTSzkANwjLBfB9A0kKkduGcvl1HRwX8Ze9q05o/V+G7aCL2pwsbapjvG2OYKf6Cv/aZIGHicx3SMsvfbt5izTRyDb5/sO2zEDezADfVJudbxQvHZxsZrfFY1iWqvLX63dEItt4br2+eOPi/JYtuNfxDRSDKzGVaYR/1cSwPoE40P3xpFOTlVyie19643qUzGVKu4m2YxOqfrE0WdMA9Klq/rqcYAXv+MgKOds0zRcEkL2iEZJ0vQXFFLmHQ1EwfpkG8BQbh1OjbkanwuGcdjTDkGqhzwG/f55g6gxNVWv09jRvOASAg== 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=3INzy7QVFBfC1wsKMLU1y5QP14MASxoyC4Dh9DShUCw=; b=Ek0wjRTLF4mo+kPCec5xCSj+R6g3OL8mzw/eY9TKlX6T5vRtNZfB8EjBfAelaBqgSU5f/wmK0SCevnd57Xal9ZkSUbWnfZDjZbKsMyZaMfSRtvUOcwVW6XnFL58cgNz+sVzZJCb22DmCH/gjsRdeD6iGkuTbt43qYHvPY1VW9mkhL7vICX9BR1mGbFEfwRLzvDuXZAYpTHGOfagRBkPd/Feb3skPjY4YVS9FO74talr/vCgPvCJCGth/IK+Kiu+jgaBMhjTqmSF3OZKteVsa4PFzjZQRS2uHq2vv0RCwLo0d7naicPtmlZbUfhT21jldA3IQ/ofXTR/AOe5Qkxbp8Q== 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 AS9PR06CA0255.eurprd06.prod.outlook.com (2603:10a6:20b:45f::26) by AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Thu, 5 May 2022 13:59:00 +0000 Received: from AM5EUR03FT050.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:45f:cafe::3e) by AS9PR06CA0255.outlook.office365.com (2603:10a6:20b:45f::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.14 via Frontend Transport; Thu, 5 May 2022 13:59:00 +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 AM5EUR03FT050.mail.protection.outlook.com (10.152.17.47) 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 13:59:00 +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 13:59:03 +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 13:59:03 +0000 To: Subject: [PATCH v6 2/4] rtld: Remove DL_ARGV_NOT_RELRO and make _dl_skip_args const Date: Thu, 5 May 2022 14:58:59 +0100 Message-ID: <94c82dda28369de49a68e25ac606b828a2e4fd02.1651757640.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: 3db43076-b3d0-4716-73cf-08da2e9f6ce8 X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|DBAEUR03FT008:EE_|VE1PR08MB5263: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: VTyGycnsyXxF33lMqnut9VamE5x0p6OPdPM2j/WlVosUIE9p94VkQq28WPyUtl2zHN2b9On6tBV9nVUcl557STBV8SLD2Ilc5VhNICHIZv2FuOB2dX9J3WrjhzK/EIJ6xJ3jBHS2KxL5s7IPmcNCLaPd+wswIFUKEPqkZy+Z68bhvZ8Km1GyXwyww+csfMVDBD3w73AiseDG9ewoNG+REXUiIdLZlSNomPJqH+KdWVMTw3K/EpF6GRnKIfsU9scSCwIEJLioNNWG3yqUun3fW8s07WtbeGMDH77sqEX3BJ3Q+fCSvPbDscVxHquzkFxR7HB52A0qBB4YxXFROny52rZrOyNH3aJMLfy3zkN6Av2Y1E1dtedK8cl0V58Ao8wysTp1voQukR0Ip1iZ5ib3uvAXXOlh4edb9o2bCBoKeKVAwdsr+N+SCuP4dIFofCuMt9Woa+5DKMigtgyQXDxm9ApAKjssWrmbBs81+lyYfUJ51nwEFcspBWV1XPQz7ll9+GPlWRnpo4HILHoFrZ3eZXYePyqevpYwQlWjyuUhkAqvoqrm6g8rFJmaA50PbxLO91xtpCwM+88pTdce5WuwOSKMKpz6BaUrCXfaRlr4xK25nSf7uesK7+b6Qv1lxcMWl5HvC9d9CvK2i1gCaivIMTSeJv3ruixsJ7OkH69OPLl3KHzHqqT7cdMODwmEn3e41pkeaRqu62gknYjs8bG0MAEW7jfW9bGpOyK2NiuOczSVTJhKXclbwMvuUAcDFScCs6UcqI1wN1O2i/qw9NlH/K3cYOwC8zVfprAExAczp3vQ+7AqxDOZq4qr3AXPqJOi 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)(46966006)(40470700004)(36840700001)(83380400001)(6916009)(40460700003)(26005)(508600001)(8676002)(2906002)(36756003)(44832011)(82310400005)(70586007)(70206006)(316002)(8936002)(7696005)(4326008)(2616005)(356005)(6666004)(36860700001)(47076005)(336012)(426003)(30864003)(86362001)(5660300002)(81166007)(186003)(2004002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB7095 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT008.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 4dc04924-96a0-4f69-48c6-08da2e9f67de X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: t2uFASj9HYZns7bzO5swJxn+UL312pTza31MMHZufjJMNkTpSRiprkf6qHRAYqV9Zy3wkl//Jx08qznJffg4gqhDhXlwm+9dRT9Kz0slQH4qgzHDQbUqjJgUNKvT0+W4W6hrt6QqexX9RyijswzzuWMaIfnRXgILoB2tTwAfhNwMoxS3SCvLSS7fPvfOZ7Bnb4g/WVUoP4EipdCT/FZpefL6o/HKvRuThCByTspV8KacL7SnhQiKTUAx6D2QFw1JE08jAV1Z5vVDWd56izaCLQXxvKKugU0gZBwcAgEc7BEz+RUPnZXQsOq+lQzELdjWnu/kEELi2Kuyn8ICP55k8tmbXzUdOuS3FRxGV3UGLWMLGjqNoOt7MlqRvHzaqbNwUr/JSrKCyXlVGt6vszB77E+njpGCbamEKVeTzuFZGWZloJp3fvC6rdK5q8xb1WwDGliifmKCeuZPd7jXLHZ9hC9odZhVoPJGAWK2+ki3wAhXnpY18/l9114/AxOtdhMlP6Un4VzBXQeIfJK/60l8PRSamgMNiOfq5Xv2chgR33WgyFnHTsHukPa5/PVdYuCSFlOdoNDqiH96vVx0IbVwUazOSkILqTz7amUNS/Hztj38uI6u3e9jHfYKZqup4T3sG39cyBaGEPSFmTmr1tRbUKcO5w1JYxTuSu+c9/P/QxxPFfaG9ENHcLHPzYEO8EKXpDB2zHDfRIyUG0n4KET0IyOnXXfqS/PYsmf43aDkHLt1h8k9FnoijAU79Ae9MlJ5A9sVjQ3NsdyJcgqhnS64c3jI/7j+hMOU4H0BkhQgWyI= 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)(46966006)(40470700004)(86362001)(30864003)(36756003)(44832011)(5660300002)(8936002)(36860700001)(508600001)(2906002)(6666004)(82310400005)(7696005)(83380400001)(107886003)(2616005)(26005)(81166007)(336012)(47076005)(426003)(186003)(40460700003)(316002)(70586007)(70206006)(4326008)(8676002)(6916009)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 13:59:08.8197 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3db43076-b3d0-4716-73cf-08da2e9f6ce8 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: DBAEUR03FT008.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB5263 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" _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: Adhemerval Zanella --- v6: - const _dl_skip_args. v4: - New patch. Reviewed-by: Florian Weimer Tested-by: Florian Weimer --- elf/rtld.c | 10 ++-------- 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 | 13 +++---------- 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, 5 insertions(+), 153 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 b5070d453f..71f7095def 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -157,16 +157,10 @@ 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 +/* Always 0, only kept for not-yet-updated target start code. */ +const unsigned int _dl_skip_args attribute_hidden; 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 4a5e698db2..f3d3c78927 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -762,18 +762,11 @@ 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 - ; +/* Always 0, only kept for not-yet-updated target start code. */ +extern const unsigned int _dl_skip_args attribute_hidden; #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 13:59:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 53521 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 BA6A63857367 for ; Thu, 5 May 2022 14:02:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BA6A63857367 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651759337; 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=GqGO1cGfC1xiHKm7HI40oBlN1O8jb6BvbTReoHQgUVI6PHBftJ3Z4s2406PSmqSRR AIB85VrudLMnTurm3b1i+1Nn+oVQ40X7xMwfathayhn4eIwHShCxmLXW9PCB33kRwn 0sUw5yjQWmZOwdaEoRHM1qRKkXp8CFVhG0Rr7JB0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-eopbgr20080.outbound.protection.outlook.com [40.107.2.80]) by sourceware.org (Postfix) with ESMTPS id EC02A3857367 for ; Thu, 5 May 2022 13:59:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EC02A3857367 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=OXL5kMLlMcefdJarYW6jFXVwFLynh3aC94VdfUvbP5nx3UAxCX7sQrje/nTtuKdrqbKBxCAmkhPfb6Gxum1sWqOkn90J5wztiGI9DMjpkJqbc8LqMPDW+nbAbGWm1tg6172QIpbTAkqx9NnxgBzXSNSNQ3FE8J2qCAsx3PXUuNzLXi6zdceAaPv2MjwTs6it26FYmmm5Mq+FP2vGunVM2V+E2NHIDZArghu/j8Lq/nQPxdIHQhnJvlyIDIAa+0JUhRo7K8SVH3P4zDXC2gC3f+5l6KYacKD8eiKwcyWuR+FGXFj4oiuLbMaHRv4GegB+eeelBDOQu+hCBxMWY2ghvg== 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=Pw2/SCXSWJvoHtFMg4hHrjohhR+kIa1b7xFO1mbqLefN8Q27Z4uCQnItDM0Zeir3WNRu82aaaxOKICAXXkH7wMMVtBPTfwQNBFr4S/CrzPosLO6v/S5Ohrdm+Qiwah3LTU3edo9YiKENZ0Qm8CCYQ+3NFBMCxCu40Zpg+6LrSVsQSn5jBTjq3tyWvagBCKREa7rJjxbE+2l9k3u5qoZpAdh/RPGstI5l7eP9bZLj9osaSzDlIeeGqW6Y9OWKl6h9o3sSbhmDJFdLbLorN4c4UkZ1OAum6S03UmmmZro2LwPxSQbTQkSJcL207nx8SefVKH868+geo5HmTxL1ow1o3A== 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 AS9P250CA0001.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:532::7) by VE1PR08MB4845.eurprd08.prod.outlook.com (2603:10a6:802:a6::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Thu, 5 May 2022 13:59:21 +0000 Received: from AM5EUR03FT044.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:532:cafe::2d) by AS9P250CA0001.outlook.office365.com (2603:10a6:20b:532::7) 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 13:59:20 +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 AM5EUR03FT044.mail.protection.outlook.com (10.152.17.56) 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 13:59:20 +0000 Received: ("Tessian outbound 78191104f1b7:v118"); Thu, 05 May 2022 13:59:20 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 42bbed1f403b0815 X-CR-MTA-TID: 64aa7808 Received: from b87b46331062.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 115C427A-81CD-49C0-905A-11F8B42AAA9B.1; Thu, 05 May 2022 13:59:13 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id b87b46331062.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 05 May 2022 13:59:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Uz+kGMHM2KXiS7dSu/PKKXuHtZY6hvYr5a/iS/1q3LT08uf4bvEkg0MPGeY0Z8+F1Pp8U3L66rHvCV7jlUGyNrbBzfVoXFeF4xSCbkmBe4q0X85J3RM+UlGtZylVYGEPysrpvl0F2vEXxEPIiNxXpmOA1FfB/q7NTAKk+L+yx9s16s/Z0rnq+RxagffJUi8EZZYlMsunfJsq/szFtH1jy8nc6nlLmm7CM1GPoAdStzN/Z60nF0g8EG3x5Soaq4CTKsoGQQ5txz3UCLKBsOyCfRoigvQpP4s0ner73RBg7T8VKNGixu64IlUdmKB+kDN59+qXYvGoQDLTuINlzXUNqg== 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=kxiyFcJIQl4WDoZwc9SX3QaRBORuks8bO7j1XSURHoi8lGq62AbWrnQXrkiD25egvcBBu6JeMBuJtptjtd1XVItwpWizU0fEG0NH2yIxGo/UZIgQ3d7TXZBRuoSH026CgT6tbKEMqQ2WVkEoD9lBgVViqXfZ+JtyDGe7ZgKXvQRcyw/wdkgW7LdUnZEv8ZT3zfDQJhxVp1xp4pGD0gj9Ev4hZ81tG38tk+X5gtnjCwT+BudVnGelI7HTlrgns4thJNv4HVZsvKGLqlGSxuAu0atEQO9F1+ebYK+L7kYRe3Mw3PWUT7uPoZTnw9qRIrZpmWudKI5+ca4H6jj6EQn3yQ== 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 AS8P250CA0001.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:330::6) by DB9PR08MB7082.eurprd08.prod.outlook.com (2603:10a6:10:2c2::22) 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 13:59:11 +0000 Received: from VE1EUR03FT005.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:330:cafe::4d) by AS8P250CA0001.outlook.office365.com (2603:10a6:20b:330::6) 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 13:59:11 +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 VE1EUR03FT005.mail.protection.outlook.com (10.152.18.172) 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 13:59:11 +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 13:59:14 +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 13:59:14 +0000 To: Subject: [PATCH v6 3/4] linux: Add a getauxval test [BZ #23293] Date: Thu, 5 May 2022 14:59:10 +0100 Message-ID: <7b79ffb5ec178813653763651aa46403afd49cc2.1651757640.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: 6c52d724-6542-4b99-a24d-08da2e9f73fd X-MS-TrafficTypeDiagnostic: DB9PR08MB7082:EE_|AM5EUR03FT044:EE_|VE1PR08MB4845: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: 6G8XTgImMsH9uP8/75FUxH07ZQZVcxGBisukvBKkduA0vqs7pdfmgq0gIL2opiUKkGhILiU3cjMtMuznZVmZm9x6FboBrANyRzmK+n2Wv+6qNYcKLt7vh24sJWZKjn39W8Jrc3ALKyWkofQ8ZyEAp7gS1wLav3A13HsxA3JlOLEKXrsdh9SsGkLN/A2qqrlBGMXd4e122MaKxBrTi44QeYwIj8/HpmXpIptMvb9gM6AVSYvPHtSwFpSuYIGjgvGoxk2RqqIVASgVhiPJTjHdwxde++4+3cJL6eHgeuIRNHjdgy6dVyY4nkab3+m0OIAazKt4fB+eenjT61u8LfpIXKnkfYpT4R/yedk661kmjThc4fVwtnF/oPj8T3K5XQD9tPDTJlAVM8XR07o06cRrkwOhN83tVigkvPGutUnKnt/HO60Wph25qUilxCKHLBsoA2dDetu/pYZLUdR3eeYWnNq5l5Hv5Ea5pP5oq8RUGslr/EksnCl0BRZdtXSqIZVtJd9mXb3dfgoVddbjZ6EpWVi/i4bKiqES4t/qmoQvqG32p9Zp6PLVDOuZRl8N7tOFzKa7srASfbMOeJbEM3BTKcm8vv+7clAV//SfJZs0Klt65on7Dd/Hv2419tM74FHKlAiOEZ7uiOX7W3FgjxF56xr+WnwbxqPsDEU6jJ6pTT0b6weAbDmv7lF3Z93i3awpGc8Hew4mezQqJO5KLRUPceMnCIKh0oEFYqKjZyStZdwpsz1aeSTU/Zh5PJEYuNXwmX2nb63LR5P0CB0QSxWIF/MGjLcYSkFqGYI8XT2pe832Zi0mlumrFCDbxtNXEhBj 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)(6916009)(7696005)(508600001)(36860700001)(2906002)(70586007)(4326008)(70206006)(8936002)(8676002)(26005)(44832011)(5660300002)(6666004)(316002)(186003)(81166007)(426003)(82310400005)(336012)(86362001)(47076005)(36756003)(356005)(2616005)(40460700003)(2004002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB7082 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT044.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: d73d1920-d7de-4765-bae9-08da2e9f6e8e X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9dGFPV1Cd27ZGVk/9TmXQ8UfxQ1t8S206qj4JpIMauHegKCpoko8HR+bYrfLK5+CzjqCGTuRwrIOmaSg7zVvggy5R0VgUJTw4Wag6ME4nN7L9IA6LeeHYAxyvrhB4ui7bgcH//UUyt3E1e08ouXYbLWpWXRIivs3p+boHM7Rnlww8KwxhVeajq+rpzH21Ct4DDNjpp0XxuFfWWpgw/rTklCKAaJc/oSQpotMzeoNV1RrOzGPNkrrMFeCBd8WOaEYcPcQhlMn0iVCvaJewKqOuAbu4bx4lFKwHEOp665FVYphJwz62CtbHBsnY5zDpdZxLTrYrHo4kqqZI7wQmhdvBIVglGTjfuURoOVpDZUOMkgjgCeEHlD6x7X8H43/Wrzsn4sXFzFKQrBRNyEz3bzbCTMbqo2SCXMbEgWijKxTTzlFUwyeHcm+vKqV6VVXa3h8B6kSXir9P2hD/pDaGPlIVVWDTPWkZ9cmlhLlkk64mtP9+gc2ZDH7Sl79TPUYmkycfhFOntwqOTXNqPH5wcr4FQt2BaEX1FfLrkrSHlRakabQUpUT0PKQjicIoDhWBaeeZKJvgJejd8Im500zLvhWsZfQwzHuFBno1K1b9U3xtk5wG2LTjT7DRddSH9K7WixdDT+NSlKyiwSHAW6gezaPjnET7JqQGqSY0N7j3mMneeXDBE5VWnFoAKzpSrD/3HdDZbPgj27UgQXLx9X85lTRZt/GJtX6i8lC1HmO2EfPDFlLezRP5lfS+I+MiaCBvQhqElwc3Z6dbdDzOyJABDph4ppLGV6GWS/NgIMN1uyxpVw= 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)(46966006)(40470700004)(8676002)(4326008)(6666004)(86362001)(316002)(70206006)(36860700001)(81166007)(70586007)(186003)(426003)(336012)(8936002)(7696005)(47076005)(5660300002)(44832011)(508600001)(107886003)(2906002)(26005)(40460700003)(82310400005)(36756003)(2616005)(6916009)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 13:59:20.6462 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6c52d724-6542-4b99-a24d-08da2e9f73fd 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: AM5EUR03FT044.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB4845 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 Reviewed-by: Adhemerval Zanella --- 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 13:59:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 53522 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 962EA3856257 for ; Thu, 5 May 2022 14:03:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 962EA3856257 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651759386; 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=WlOu56Vf7AVvulibqOJS+vcERwqzXPJw+sMGEEPY5UzvglNqyT1kbs8/JwAHKfra4 Urv9bgu+wmil/OoHdvt5pcSOw605girfGhzc1U7W7ViUy2Azqbq96FBkz61B8MdVyN Cb6FXC9Pxfpy7OMG4eP4mtAoGsdSwwDPUUdHES2I= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70088.outbound.protection.outlook.com [40.107.7.88]) by sourceware.org (Postfix) with ESMTPS id 9A8D83856243 for ; Thu, 5 May 2022 13:59:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9A8D83856243 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=gbiPd1h5JAhascCHTO2DEtWdHAb+k96vG98hDNmWHY0ImQNvW5Gj0+2b/ycTSZtPdaRrA+18RAZMlc0/2yw1p1wx914g1hqELMpS1Pzj2ZEemE4ty23rSw0Ejovh7dmp/GITpttlWF2wCMrWQfTIW7hZxywa5tHUwF5LBSu/tro7lFVfN1dGVxMDjO57wk8zV9IXPpO2vb8SS2anqWEh8PNX5kUV4u10ZPSnk8eRF+O9URiVaE5meKLN2zrha21vQBt+hYzhpT14chHAGE9tpu1fZRlWmVNAHdfQz2M5Tw9AcrDF71dVkYBTddLva62ecTKe0wwHc7oW7wyXYFOJgg== 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=TyWZtIS61RO8jk/8uhxGvFrOORGeqzos3e0CrZ9N1PPjXusvyHjEC/FGnFkCOs0PcsQSqAk2a7n2aqgZLEruFyu5QEyRILN4mkNl3Xwg9e2EmkCUcDdW6RJALXTdpoGqx5k272AIVTwS9sqlBS9Y3SLQeRmk7FHgyOwgvcx3r0rrPVUiU62mpwuxHhS0lR6D5/2oZWeN2LmTykiASJ/vKa+6FIxiewcQ6f69EGmO8ny6we4Gd0KnRLIihFOgWeZNuKZz6oB0TnjfNZnOmGluU++AbZ3zy7LeEWtQMfiOZggCqT2rQODtIuZTb8t0LQ1Di83BEjc8ITdUujquFpj4jQ== 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 DB6PR0202CA0043.eurprd02.prod.outlook.com (2603:10a6:4:a5::29) by VI1PR08MB4046.eurprd08.prod.outlook.com (2603:10a6:803:e4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Thu, 5 May 2022 13:59:40 +0000 Received: from DBAEUR03FT048.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:a5:cafe::1c) by DB6PR0202CA0043.outlook.office365.com (2603:10a6:4:a5::29) 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 13:59:40 +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 DBAEUR03FT048.mail.protection.outlook.com (100.127.142.200) 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 13:59:40 +0000 Received: ("Tessian outbound 62985e3c34b6:v118"); Thu, 05 May 2022 13:59:40 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 49d4c9054822e286 X-CR-MTA-TID: 64aa7808 Received: from 113264d9b725.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 8A581E08-9F6F-45D7-93E0-A7537E1CC7EE.1; Thu, 05 May 2022 13:59:34 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 113264d9b725.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 05 May 2022 13:59:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b9HoDVei2PvG6FSA4ZW9X9OSV+qHYJy/Yqi+XjOznYmmcjAnCWfFzfD2uT2RCJX1KdhWCa09VNyga2LF1Qt/PctbIG/B6282bO9ZuczVba5h2aFIZubjOm91ZVOwWTXpVyfYyRlI+q0mBgWrqCgrNDzHHENGjsvh2HIIsEWWrccXlL9DTk3GiKihD/IXnfZt6z9vvva99901Fi9jCpEUoocsUwtR3sy/v2cW+g6DZ8iSqu680yrkhC7a1bZw6cbbno5ItPUQccQg3rTniP/2dlfZDS/OeC3TIgsX+4kFPWqhOPdWX3lC9Jf+UTeqXIQ8MLejeshxNxSmX1aKlDzPlw== 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=CVwr86A74D22qnqF0gmxQi7rHPriwLwjZre8LXt3tD+AP+4PIHrTKavK2WlEavYR5bgpKcEWpXnAtrWnruRq79/zagY55xqQGugXtNDVPAcZ2pBGkpv8h6wntjo7IsOTJ225VFL0akFDGVx8HUe8leL3q+ONK3mPE5GoOETtJg5dPcDSFZnwmLria/MnLTd9doHuhSvRw6yEuXOHm2Ba6zAZ0IFiJismBgprYD5iYcPqftTXkfPx4MFBIT9uNd+hyQoVvsDiOnO+SqPdjUd8oSAwt1boSJGg2CTVMAOiubaZ+t3Uhp2llvOPKPBxsR8/AsB8OEIujxCeZ2asZThUvA== 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 AM0PR04CA0068.eurprd04.prod.outlook.com (2603:10a6:208:1::45) by VI1PR0801MB1741.eurprd08.prod.outlook.com (2603:10a6:800:5a::19) 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 13:59:22 +0000 Received: from VE1EUR03FT034.eop-EUR03.prod.protection.outlook.com (2603:10a6:208:1:cafe::e1) by AM0PR04CA0068.outlook.office365.com (2603:10a6:208:1::45) 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 13:59:22 +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 VE1EUR03FT034.mail.protection.outlook.com (10.152.18.85) 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 13:59:22 +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 13:59:25 +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 13:59:25 +0000 To: Subject: [PATCH v6 4/4] aarch64: Move ld.so _start to separate file and drop _dl_skip_args Date: Thu, 5 May 2022 14:59:21 +0100 Message-ID: <30ecd158a7425badc5996450816a3ca3dd86e9c9.1651757640.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: b642dbe0-55a7-4b34-88c1-08da2e9f7faf X-MS-TrafficTypeDiagnostic: VI1PR0801MB1741:EE_|DBAEUR03FT048:EE_|VI1PR08MB4046: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: eAamhI8BI3cY3hDqXCo7Ns6By9ue8UYqMFtRn6ZEzfFiRizn/zLshX/QRr2ITpHJny4irdj8kDFC1DDy3Vz55vdeot4trYWCivFBejfkYDRBGPkbEHpkBaZENjwXx1aksoXsemctD1l6YtYd14NSXqSGiHV4gM1So3wuMuT51EyTzaXWIZ7i1Xhx5I1bSBm0BnTXEDm56YuXmjtWH5rh1rWA5Z9P8agNjt7QfOWr4xG2w3NiskfqoiEvOZzOH38hXgKaxHXJqqxUe9xnb6uvU/4v5gECi0mSYQzZA6QeXREA4kkOfO4hqhwSwDJP5yhvT5NOuHi6ce3a6G3LXgtyB7nQfsBWEK/vIXXOR0Z9KgN2Uhv/0JnJMIZESz7sOPys/+OGupJeEHmtjjYrulGr+yPFjPF5/3F5ra03QHG3/ffD/y912v39jZrbtax12DwfBRF69sVCBhJE8oT3NfCRxpEjY4qTUeU0cykyf9u/qhPd2RV5WTWhKI1JKgKrloxJtlLUCOth1pUTNkO89P9D8AzFlmftwR7qyD1QVA3Cn6psu53xdWpP4hjmEzfD5YBVbciXEPA1MHESX21i8qy+Z2VHTksW2YVbKR5qkRm8/1GCcQyNA2IyLvkc0oe0j7Gkwf9YMKy2FdcWFSnMlizI6+ffTwysegdOODHuxI4j2bZh+Uv8573Q6uVxJBgjMqJjYNMZ5DF/xYfl40mvw/xJXej/sbt/f74EmyoaTGNFGJ/WzV091+zpKDTsH28TI3cRr0rBnEpAlqclSKgHszZlfCnVwcsUENYQ6zGrlq5li120S7Vus4+0LlazqBC4NHst 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)(316002)(6916009)(36860700001)(36756003)(83380400001)(8936002)(82310400005)(86362001)(26005)(44832011)(6666004)(7696005)(5660300002)(70586007)(70206006)(508600001)(8676002)(2616005)(336012)(426003)(186003)(40460700003)(47076005)(356005)(2906002)(81166007)(2004002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1741 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT048.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 74071e79-8d1d-4883-8d7b-08da2e9f7503 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eGAlEOTBlavq2gyrn8lMU1M6abrMnekY46esqtIldOZrj8ZGLV4DnnhYvtPceVD/uUC8HuE6B42lvwc7twef5Hj+qSZp4jOJdeByw+PUjznt+4nfXXlMDr+efzZmokOMaX9qUf3zBH9TyU9GiXP3G28VS11DAuyQIjniYWtV28CiR4MGeMIm+yXUbNeOSO3l+xKSty2qWxo4Tma2rfLRJyWiR99jfXZhWCPEsyQplLtssBPt/3iqfxQRv/kFyL2w+PySSSfJFFMUcXTYMPQVgObZ4cmITVxTu/tRWQ1hQKe8JCT8PR7UkWfePzbgavGZbHqlmZXOg29KQ+K/dmnRwCqUtR1tJ2etXNGLKYzcgAeMjUqca+H3OG58LNOt/ylIYySRcYxj+7QTjROXl1XS9/RqBZ7WbiJ/yQMRzWzVd2sBykLHzrJkjgP2dIYdHZxb/vkwpeQ6lqA6x0Xv1KK7l/Ea4ZfheYq/DbsmZQaJ8jUCFvyx9UkNCuTEjZvs2NrCfulHJM2FZZFAxy94ig1uzlofOc+MMnNA3bCbpLJVKkf44FHD3pQy8L/8kNP1z2D9mBlo5u8H2lLGEeq6U/icJnOLBgGT4wxizF3ZbANV2JxWwN4jCUTRrr88NPkRQyCZQEjbQfezoZN4dgxFZo087jsvwj1Bms/d+woAIL92jC0iCVuevWqAbq2yS/xrBynTAgefaZEq8fE3TqGiylBeMgHVXcZAYuvxrGt9Bh65rQhMykfGKg52QNTB1O0x3yHhg5kaOkUlzgYbdKe89yWZJ0gYOUCyMw49nXeDDfQMpCE= 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)(8676002)(26005)(186003)(81166007)(316002)(70206006)(86362001)(70586007)(2616005)(6666004)(7696005)(508600001)(82310400005)(426003)(336012)(6916009)(36860700001)(44832011)(47076005)(83380400001)(2906002)(40460700003)(5660300002)(8936002)(36756003)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2022 13:59:40.3078 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b642dbe0-55a7-4b34-88c1-08da2e9f7faf 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: DBAEUR03FT048.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB4046 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. Reviewed-by: Adhemerval Zanella --- 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)