From patchwork Sat Jan 15 05:22:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cocoa X-Patchwork-Id: 50057 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 EAE2D3858411 for ; Sat, 15 Jan 2022 05:23:01 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hillend.cent.gla.ac.uk (hillend.cent.gla.ac.uk [130.209.16.102]) by sourceware.org (Postfix) with ESMTPS id 082773858D35 for ; Sat, 15 Jan 2022 05:22:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 082773858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=research.gla.ac.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=research.gla.ac.uk Received: from cas07.campus.gla.ac.uk ([130.209.14.164]) by hillend.cent.gla.ac.uk with esmtp (Exim 4.72) (envelope-from ) id 1n8bWX-0001B9-8b for libc-alpha@sourceware.org; Sat, 15 Jan 2022 05:22:45 +0000 Received: from CMS09-02.campus.gla.ac.uk (172.20.14.170) by cas07.campus.gla.ac.uk (130.209.14.164) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Sat, 15 Jan 2022 05:22:44 +0000 Received: from cas07.campus.gla.ac.uk (130.209.14.164) by cms09-02.campus.gla.ac.uk (172.20.14.170) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Sat, 15 Jan 2022 05:22:44 +0000 Received: from GBR01-CWL-obe.outbound.protection.outlook.com (104.47.20.54) by cas07.campus.gla.ac.uk (130.209.14.164) with Microsoft SMTP Server (TLS) id 15.0.1497.26 via Frontend Transport; Sat, 15 Jan 2022 05:22:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=njtE49wgc1fuxR1W3T3BHMEarFe9RIjjfKiJyXbsfsOlBt2c8jVqXQ2l7ayStSd7tTyOvuFAGSxtn1cDzGAxADbiOZgt2oQDhlvMUOoahAnqiCxAa7c5ljmI1RyL9n+R7h67M43bfgv+3TR24MHOc1uE0g4zgF6W30zFOQOr7EdsmJwjAxCmBWzP6Xx0hl5Ud53WeAsZD8ZJ+5t2GiUg5486PMySTxwbk/ZgM5pZsA40e0KldZJwNf2SOx+QgiX2nAidkbCKEcEMuBwMPRdIbbyMthFuHH/BYj/BNIM5MEKS/lkkiiS82IR8Cgfu5QZb0Z8pW4oX/SjlLF/GvERKFQ== 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=H0pcrCyTjoGTfzzgcyPdnxc6ljy7Age+kGeCDmMBDO4=; b=itQM7G1xB4DZawAQlIm/0wkGIEYX8CxIK7nogMZbVQZkkEJU5HI74fH6NbwtcvRQnbrfI7JXAhN5MAew2aEx1OOQlF9EfSChv6clg4J1ttKI63VVrAcDT/xIFeiQETtxMU/whLCqZ5vx7hwW9R1wUC9WPRJ2yEGJXEvkloI0g/Ii3xMPByeE6mU3cEH5PPQ9HaVMreO2XARcBzSpwijQtFjh2MzjHwMaE4b6cmJR0QP+vPL30oxgPSZA44MuR/P7tTGw/3imu3cd/4WGd0mNSnAe+0qWMYF/wwM/r26GICQmqiuy8vPD+fqjJ0coWx/4cnwX5asT3Akp9Ujdmzoz1g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=research.gla.ac.uk; dmarc=pass action=none header.from=research.gla.ac.uk; dkim=pass header.d=research.gla.ac.uk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gla.onmicrosoft.com; s=selector2-gla-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H0pcrCyTjoGTfzzgcyPdnxc6ljy7Age+kGeCDmMBDO4=; b=cIBQK+2+mrwV9H7/oXEcZrokCLGsz+4wUTfTSTCyyfESuwm5+fJeGtBHkUNdg//H85HKNXcT8JKmbI0a6U7gcCWZqD0hoD7f03KhAX02NhcWbVqjeFO8mX8+/WVOdKrWUYxSKG32oOOzDtQcdOllVLNM4Uat+I07ODm+wlG+of4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=research.gla.ac.uk; Received: from CWLP265MB3873.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:111::9) by LO2P265MB3134.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:166::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.11; Sat, 15 Jan 2022 05:22:43 +0000 Received: from CWLP265MB3873.GBRP265.PROD.OUTLOOK.COM ([fe80::5442:240a:bbba:d6a0]) by CWLP265MB3873.GBRP265.PROD.OUTLOOK.COM ([fe80::5442:240a:bbba:d6a0%5]) with mapi id 15.20.4888.012; Sat, 15 Jan 2022 05:22:43 +0000 From: Cocoa To: Subject: [PATCH] elf: clearer error message when ELF machine mismatches Date: Sat, 15 Jan 2022 05:22:37 +0000 Message-ID: <20220115052237.50170-1-r.xu.1@research.gla.ac.uk> X-Mailer: git-send-email 2.30.1 (Apple Git-130) X-ClientProxiedBy: LO2P265CA0075.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8::15) To CWLP265MB3873.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:111::9) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8ddce184-b25f-4c74-a4ea-08d9d7e70ed8 X-MS-TrafficTypeDiagnostic: LO2P265MB3134:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OXFb24uF6XGLqyg9G8qzuH7z3IKlNuWIX/1WJQd4U+Mn//TQQuLMjHtcze/LuVndTj9QdsUD4JYdRltrivKu1mKN7m9T9kVHO1DoLPHKlSxkPSSUWV5R9mcYAeFGP/u7xhf+ETO32k/fQcL/GAGsFhinrW7q2HpQayk4l3sNi5+qF7j+9GFbD3peVlqxik8yYbhrsC9hi3trCsDKvLhXZb6UVwZKlyaT0U6ytqhWNZwWc8qM0dUx/0dcSryW1XdfjZHJbLT7dnkfqn4TMTANydJL1TuwEP7L6Y+21KOOCLxJwOm2O1yybtPbJpAL34p/UaAlTWZsDZ20liA3rqzTkdr0oNC4m9LsUNld4h8kvUuff3URtB6MBcqJWU7M1jt9Mm0XaT3a1Ik05Uloh7j7VQSbhHEO56RhR5G7eazswc5B5gUvOhapbUlL5Zj9+Jy0ShmovFYSOvCeZVSlc+JXbjcsCKf2o2yeZvqUJVRbwLfvnqiAXPynv+on1Bn4UWvIr88ni8B/zQYRaSgBDRaOsFWRmLVtbO1JnWOC3Pu+smP1jJEOc60ADzICNIxYyGSzfN4DlLgJosOSZwEnQkZ+06sRZxSGpXHoflLvqNinqlI3CD8sgbsWKt3zDUtsSKLsu1++AY8kwy9fz+7ad3P1lbTb89B/7M8b1LtgMQ8Q8zJvKlhQLqTafGuq/wK6qEqGyU2Y+c5eRQYLh1DbLBcAhg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CWLP265MB3873.GBRP265.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(4636009)(366004)(86362001)(66476007)(6486002)(52116002)(38100700002)(15650500001)(8676002)(2616005)(38350700002)(26005)(5660300002)(786003)(508600001)(2906002)(6916009)(66946007)(316002)(83380400001)(66556008)(1076003)(6506007)(186003)(6512007)(8936002)(6666004)(103116003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: h/QCcEEHItCrZAjnSGNP7auggV+3ZgFWusvG73HBav03mbd7ffSmLYVZGWsDjjtSJzUsWgHJbzuKfVakzvomKhQnpWrljlvS1+q6psS8qpTTSpIR4KTwjpDTHiZtOnhXWcC0NutxhLy3NH4fnF3Oq0bHSKTa3KFSYD5BkNrNbNEIiVA17plQWy56tquTEJxNxD51eiYr0neq+a9EypIo7lVhUvOOuHeDfalG0fOQQrPSYG4J1LRcAWF8i6RFo5ROzjzpbi/x1uakuOwHZGeCISD1zsDcbD1zCcX/g9TPqi6Hpnlj8VpS7ptgumwCJP3HuFpdYrNximc51oBwnqBguKxSccWOJ+t5/LU1+Wvkpxsk4x+YOdeSXO/NkEjwcWIKlwqMG5n0ZQCnd2SKMc/qXvvkGVCFnWy1mnenzd4VjJUr9g8ielzHEJ58LPSba+bf0hdxLwZFU//OXrMVLjgtojD+dbCQkduiQH10bYWoLGpXGs2tJtcPpGOSf1fIXh1sBeM4fgNmHkTG4Scxlr4JvDqjF0Trdq7aubLR7l51GngdH4n1jzqDem0LjLeecx8Iyrh8tq9alIRTyFwFOIPIpTFxyIIPwVQm9Lu1W4HUZnzeqsy0r/P/YDRQrnROMHIjs8cyHGCWFroajo77goOkLv6VV4oaoSMVIhcheRir6g4fkwiVpP/N1OsLXnhUsb0JOAUY9/r8GnWhIb9V4t48BP4bjuRFFaRALFMm8iT3AVArFoF82gjN1l869EyzgzqUmG82qhqsZvM+oDCTXwnE4KqvEujCEiWd8QJX/Xbjr1FfcgUXPEWQpKzLbOLTaJj9eyvngRa1QgfG8XNmgpDI64mioMD/YxvNttzA8Jt2SCMMLUgEMz7xzgi9cP9UsRAfuqgv5noGBFpDykoYEXZbhDpM/+xdKbIO12NWwEsZXz82klL58d0XpaM8LHEqrhiM7FkWrgzvjJ6T7dgK0m+IQiFNcxQA/IM1nhu2WvP5Ghk4fDsWA/noqVXJIz7v7pb3Yt1upLLV2rkQ2fv4pcO957iuqPgcehyp5BVPg1UCMBT29IxbTUifxbuUEhf/2dBfv2OuDh0UNWqfUNTaErbxf9Xbu3VeutfB1zbAMBs9LnYPy3Qs6Kggar9JjONhcC3p+7/X9CI8QEkZ6bVI16Bl/KknlpYjyw3ssfg1PCt7rxmuOa7t0DnWL+rAUUIdHQ2FShaqwVeKGX+f1QQdUGJmY93D3JzLT5m6wKT/ry/dHHPmcaC+b8D3/fs6ERwP1Bbq5g7NjSKNatoBrdHRG9V6UG7wce8fz13AoY+vpV3OBEmYdevVtf0985H6O2Dyh8OzyygmtCtFvI+Ezw27txWsRO9aPQe6OQ7wBjygxxeYBUwZkW/tuDfhS9mdKUlDwgCPUsX7aHjZi3RrY9PdseaMFCvWHJeBmVLAdPXPSajSkd6cZvJ3tdGKpGbEEDz62o0F2WMNRd/mXFfveiGbBi/88LXrwqqEG5zXVaRc2Q8+dWxFL0u4Tep8mUxWlbOLZaY5544Znr+SXZWCxnZhxR+0mEXPH/PF/gN53F6dtihLrSPJYctj5YO0qWpEu2vK/PcglFJKYJjnO4Fr265+Kasfu4RWGgg2BBxj3k+Z+xeqq4KgsxMltymYJUSnUwqqLBlgiVI4zieF1w8VZZvdWd4jPQ== X-MS-Exchange-CrossTenant-Network-Message-Id: 8ddce184-b25f-4c74-a4ea-08d9d7e70ed8 X-MS-Exchange-CrossTenant-AuthSource: CWLP265MB3873.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2022 05:22:43.7069 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 6e725c29-763a-4f50-81f2-2e254f0133c8 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Wjo7vBjsoi2Qvdf2swb81UBjgd7gfkPA89Z/ux+fD/1avGHBAJ5UOyRxu3zl9K2fE/fiat5L9CLahiFHJbOAy255J1eBE8QMnEYzq19TvZM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: LO2P265MB3134 X-OriginatorOrg: research.gla.ac.uk X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE 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: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The misleading error message happens when trying to load 64-bit/32-bit elf file but on a different machine(architecture). For example, load an aarch64 elf file on a x86_64 host will give the error message "No such file or directory" while the file exists. Lastly, sorry that I am not a native English speaker, therefore, please let me know if the error message needs to be phrased better, or please suggest a proper one. Many thanks. >8 Set the error message to "ELF file machine does not match the host" if elf machine does not match the host. The previous code jumps to close_and_out and set errno to ENOENT, which results in a misleading error message, "No such file or directory", while the file acutally exists. --- elf/dl-load.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 12744caf..818a15e1 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1729,7 +1729,10 @@ open_verify (const char *name, int fd, goto lose; } if (! __glibc_likely (elf_machine_matches_host (ehdr))) - goto close_and_out; + { + errstring = N_("ELF file machine does not match the host"); + goto lose; + } else if (__glibc_unlikely (ehdr->e_type != ET_DYN && ehdr->e_type != ET_EXEC)) {