From patchwork Wed Jul 8 12:12:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 39971 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 6A84338618A5; Wed, 8 Jul 2020 12:12:43 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10042.outbound.protection.outlook.com [40.107.1.42]) by sourceware.org (Postfix) with ESMTPS id 671AC386102B for ; Wed, 8 Jul 2020 12:12:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 671AC386102B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Szabolcs.Nagy@arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OA2tRNMznIX6Zx1KFN/4pCUCPNqeVaHPDf67jh+ZYDI=; b=ZQiWmcUZMeyfcjWtXPFs57H94ujlm4XJRVU3GLKWBXa84sdowvQMjd0HKrewTdlb3DVnkl2yi040Y0+AV8fG0lJMs6W6DJmravj+HDCZ+liWyg4TY1mCr5TZpbPWQcWvjgm+6TsWg+lM5gVwz+hu5kawLjl6uUWw0LdefzYZR2M= Received: from AM5PR0602CA0014.eurprd06.prod.outlook.com (2603:10a6:203:a3::24) by AM7PR08MB5431.eurprd08.prod.outlook.com (2603:10a6:20b:10c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21; Wed, 8 Jul 2020 12:12:38 +0000 Received: from AM5EUR03FT052.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:a3:cafe::ce) by AM5PR0602CA0014.outlook.office365.com (2603:10a6:203:a3::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.20 via Frontend Transport; Wed, 8 Jul 2020 12:12:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; sourceware.org; dmarc=bestguesspass 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 AM5EUR03FT052.mail.protection.outlook.com (10.152.17.161) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Wed, 8 Jul 2020 12:12:38 +0000 Received: ("Tessian outbound 114f46c34313:v62"); Wed, 08 Jul 2020 12:12:38 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 4298853517d09933 X-CR-MTA-TID: 64aa7808 Received: from fe98daa91a0c.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 09E11812-DE31-498D-844E-19ABFEE74090.1; Wed, 08 Jul 2020 12:12:32 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id fe98daa91a0c.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 08 Jul 2020 12:12:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CMIlj45u30T4b/Bj0/Mp6mrQ10GQ8RPmWhannUIJ9Y4QnbDxG2/G32nkX9xF5ulqyZmQl9cVl+8i0XXRCQ9V85XOB7FxkrWV4NHMlxvzL7s7/4drKaxz2e2LNyafDnRSl/DhLNZvz4B2DIIkTc0yxG3POz5etQfIi66WIhYNrAItv/apYLrMm5IEM2JErpaUR+yWn5kC49WR3H5oSiJOVwBYMxuAnIssrjEuQuaM7mYY7OMxJ4SVZgkI/UwbgDclUh5WxOCEnyaQAqu0w917SEzCJMm7U4IcatxWfZPe7wmG74p5yLQXwq0Okogg4wFQQWtylvk0wQJpqGKlARaQIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OA2tRNMznIX6Zx1KFN/4pCUCPNqeVaHPDf67jh+ZYDI=; b=GaYTZ5ZKyRyatEBY3mW19aX1Et/tf4XKLjA/kMtbAMjNwXEtpdiu/g+owqsmRCArzA4gj+EDuO1lLA/UxUNwmsKwhJJ1sFe76NJsSyWeiXngHNEk4I4htAy1RmsrENELT29o7GMMhQfthjPg9btnxZNMr0KDnbMFrEngD+lBFuWH2KTCZJjm8MifxBsOAl3THvPnZp8ZBkRkW8XO/1LG7OC1bBzbzoJq71VfzHBQPTkcfjsqiZqoiJiwI18HJ9hgnS6JCH4LEk3RweOvSLrNKQ+GhALaLTGdPX4jv6vjAusnsCRelP+bsanXveiLPnnR4X/g1Z4znbnnSrt9i1zWDQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OA2tRNMznIX6Zx1KFN/4pCUCPNqeVaHPDf67jh+ZYDI=; b=ZQiWmcUZMeyfcjWtXPFs57H94ujlm4XJRVU3GLKWBXa84sdowvQMjd0HKrewTdlb3DVnkl2yi040Y0+AV8fG0lJMs6W6DJmravj+HDCZ+liWyg4TY1mCr5TZpbPWQcWvjgm+6TsWg+lM5gVwz+hu5kawLjl6uUWw0LdefzYZR2M= Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) by AM7PR08MB5527.eurprd08.prod.outlook.com (2603:10a6:20b:de::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.28; Wed, 8 Jul 2020 12:12:31 +0000 Received: from AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::2404:de9f:78c0:313c]) by AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::2404:de9f:78c0:313c%6]) with mapi id 15.20.3153.031; Wed, 8 Jul 2020 12:12:31 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v7 07/14] rtld: Clean up PT_NOTE and add PT_GNU_PROPERTY handling Date: Wed, 8 Jul 2020 13:12:25 +0100 Message-Id: <216a0255dddce1487ae556e6961bc52bd397d35f.1594209990.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0140.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9f::32) To AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.53) by LO2P265CA0140.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9f::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.23 via Frontend Transport; Wed, 8 Jul 2020 12:12:30 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [217.140.106.53] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1ec5ded0-d74e-4a1f-c71d-08d8233834ac X-MS-TrafficTypeDiagnostic: AM7PR08MB5527:|AM7PR08MB5431: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8273;OLM:8273; X-Forefront-PRVS: 04583CED1A X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: +n0PgbA68TA7qwnS/1J/Zd80890yP1T2HiW1cQI26VrSqQWNk4+Q5Zlm80dLRBhDx4Ueg8SRJXoRhD68BGWgsJfb4NQqyZQ98r5sYXl9Ai0R9qDQvjWHtSmt98ABEkHMUV+D4CKGCc51OnpmKfP2W2nqv/nkrBfNBNva/cKhHqA7HfNXxOZkAgvtRCuCl8vUn+uVrAl4MTT5PLfSnaSJKNPzDoCZLZODMW+CEgMvVilhfNTLpnoXmpN6bm8GJH0spCALBkSVw4D4F/VaF+REfbGDIyRViIFJXJt6vcWVUoiAomPZV3EQYCCvNLCBuNSk/IiVnkPcP8DZ/IxGTToakNdvy+cMyMkLIt9qDlDhuC62p7HvuQ0tQP30dLSl1zOBPXzksONH9ASfFYn9iBqv4tuSZNzwffioOtDzPT9f47w= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3047.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(136003)(39860400002)(396003)(376002)(346002)(366004)(8676002)(478600001)(6506007)(2616005)(956004)(8936002)(44832011)(16526019)(2906002)(186003)(26005)(36756003)(66476007)(66556008)(6916009)(316002)(66946007)(6666004)(5660300002)(83380400001)(86362001)(69590400007)(6512007)(6486002)(52116002)(136400200001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Ae2z+LqHw3TgaDnXqE5laZqp+5F5H/N2L+yJU8Q3EB2hdbBtlqSxhjWUXPR4wG3SAAWQdA2XbhCKhm1wbFtNglMGHOdWLZRsPTQzwTs7J3nuHOlUK7KV2j2zxAaME++nqlIYsId/taeVqek96K6wdz2LLyeRqW/h8YV9RwvY24EBxb3rdY0h0iKUtwQ8F+IfZiAp0GX0LAcf5S4BPnbE6i0FbMrnc6aieleoEJamSs2VrcmfHuQvyp+UyDkJMI20hq2rqMaKRc6w5PQ5Pl04rktaXOnCo0r0ldp/PsZpBGJ93anlcfS2CV8fLm2o2X+iHHKf5B4SV+wrwBxCxHKbt334y7oVdbkmr5jW86FfNX36uIaOxgXhqgrB/VEzdAaO2y8iyuI4dem4j0CKEi7g6aMCVd8Jaq2vJdII6f9I+ZeBfz+3X1o30LY58CJAmcEAs8MhcItzX6dsyfFCo7NEEeDtTeDVgKPherk+vbw1tjU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5527 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT052.eop-EUR03.prod.protection.outlook.com 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; SFTY:; SFS:(4636009)(396003)(376002)(136003)(39860400002)(346002)(46966005)(8936002)(36756003)(6666004)(5660300002)(69590400007)(44832011)(356005)(81166007)(8676002)(2616005)(36906005)(26005)(6512007)(82740400003)(2906002)(82310400002)(336012)(316002)(16526019)(186003)(956004)(47076004)(6486002)(70586007)(6916009)(70206006)(478600001)(6506007)(83380400001)(86362001)(136400200001); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 5d6a57c7-c44e-4eb1-00f3-08d823383046 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NS49F9kTwDh28Ay117NXeemXJvfBe7SOYTSJjsr+GXSMQS2MU/B6ZXUptFHO1L8HIGdxdHsmMPpbMbtImgyaRgyb9Al3oG4pWZByjArKLf0dWyabUBbxFv+VWhSGYxgujYsrIANF1qSovEZ13OyR53LQ5ilYXqzdIQmQcRsOf8Flo2k3Evsz9eRTNIV9qRoxGHrScmHrdJqs+cBO8tgvLkvRq6ZalofT6NJ426CxNdte+PSBKUVphr/CAUBkpZKNsaB9Z/4zLUg4sUv6FztrJhip4/Et8EkYYFo1giDN+Wr/MHxQ05TjUUlbDx91HBArnvKK5KLajE06Dlx7JeRq6/pksfIxkmhAK5UnG1JdT/WjMcEvAVFQJbOnNoRTbffDNJtHl+W0bufpxkYUW/XWWXJkNcMPu/PBMW3/ISs0BKcgD9dYNiwC5/XuP/jdL1gTx5FfOvZKIEBtFHaXJu7hsA== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2020 12:12:38.1034 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1ec5ded0-d74e-4a1f-c71d-08d8233834ac 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: AM5EUR03FT052.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5431 X-Spam-Status: No, score=-16.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Add generic code to handle PT_GNU_PROPERTY notes. Invalid content is ignored, _dl_process_pt_gnu_property is always called after PT_LOAD segments are mapped and it has no failure modes. Currently only one NT_GNU_PROPERTY_TYPE_0 note is handled, which contains target specific properties: the _dl_process_gnu_property hook is called for each property. The old _dl_process_pt_note and _rtld_process_pt_note differ in how the program header is read. The old _dl_process_pt_note is called before PT_LOAD segments are mapped and _rtld_process_pt_note is called after PT_LOAD segments are mapped. The old _rtld_process_pt_note is removed and _dl_process_pt_note is always called after PT_LOAD segments are mapped and now it has no failure modes. The program headers are scanned backwards so that PT_NOTE can be skipped if PT_GNU_PROPERTY exists. Co-Authored-By: H.J. Lu Reviewed-by: Adhemerval Zanella --- elf/dl-load.c | 94 ++++++++++++++++++++++++++++++++++---- elf/rtld.c | 14 ++++-- sysdeps/generic/dl-prop.h | 23 +++++----- sysdeps/generic/ldsodefs.h | 4 ++ sysdeps/x86/dl-prop.h | 47 +++---------------- 5 files changed, 118 insertions(+), 64 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 06f2ba7264..e39980fb19 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -853,6 +853,77 @@ lose (int code, int fd, const char *name, char *realname, struct link_map *l, } +/* Process PT_GNU_PROPERTY program header PH in module L after + PT_LOAD segments are mapped. Only one NT_GNU_PROPERTY_TYPE_0 + note is handled which contains processor specific properties. */ + +void +_dl_process_pt_gnu_property (struct link_map *l, const ElfW(Phdr) *ph) +{ + const ElfW(Nhdr) *note = (const void *) (ph->p_vaddr + l->l_addr); + const ElfW(Addr) size = ph->p_memsz; + const ElfW(Addr) align = ph->p_align; + + /* The NT_GNU_PROPERTY_TYPE_0 note must be aligned to 4 bytes in + 32-bit objects and to 8 bytes in 64-bit objects. Skip notes + with incorrect alignment. */ + if (align != (__ELF_NATIVE_CLASS / 8)) + return; + + const ElfW(Addr) start = (ElfW(Addr)) note; + unsigned int last_type = 0; + + while ((ElfW(Addr)) (note + 1) - start < size) + { + /* Find the NT_GNU_PROPERTY_TYPE_0 note. */ + if (note->n_namesz == 4 + && note->n_type == NT_GNU_PROPERTY_TYPE_0 + && memcmp (note + 1, "GNU", 4) == 0) + { + /* Check for invalid property. */ + if (note->n_descsz < 8 + || (note->n_descsz % sizeof (ElfW(Addr))) != 0) + return; + + /* Start and end of property array. */ + unsigned char *ptr = (unsigned char *) (note + 1) + 4; + unsigned char *ptr_end = ptr + note->n_descsz; + + do + { + unsigned int type = *(unsigned int *) ptr; + unsigned int datasz = *(unsigned int *) (ptr + 4); + + /* Property type must be in ascending order. */ + if (type < last_type) + return; + + ptr += 8; + if ((ptr + datasz) > ptr_end) + return; + + last_type = type; + + /* Target specific property processing. */ + if (_dl_process_gnu_property (l, type, datasz, ptr) == 0) + return; + + /* Check the next property item. */ + ptr += ALIGN_UP (datasz, sizeof (ElfW(Addr))); + } + while ((ptr_end - ptr) >= 8); + + /* Only handle one NT_GNU_PROPERTY_TYPE_0. */ + return; + } + + note = ((const void *) note + + ELF_NOTE_NEXT_OFFSET (note->n_namesz, note->n_descsz, + align)); + } +} + + /* Map in the shared object NAME, actually located in REALNAME, and already opened on FD. */ @@ -1145,14 +1216,6 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, l->l_relro_addr = ph->p_vaddr; l->l_relro_size = ph->p_memsz; break; - - case PT_NOTE: - if (_dl_process_pt_note (l, ph, fd, fbp)) - { - errstring = N_("cannot process note segment"); - goto call_lose; - } - break; } if (__glibc_unlikely (nloadcmds == 0)) @@ -1188,6 +1251,21 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, maplength, has_holes, loader); if (__glibc_unlikely (errstring != NULL)) goto call_lose; + + /* Process program headers again after load segments are mapped in + case processing requires accessing those segments. Scan program + headers backward so that PT_NOTE can be skipped if PT_GNU_PROPERTY + exits. */ + for (ph = &phdr[l->l_phnum]; ph != phdr; --ph) + switch (ph[-1].p_type) + { + case PT_NOTE: + _dl_process_pt_note (l, &ph[-1]); + break; + case PT_GNU_PROPERTY: + _dl_process_pt_gnu_property (l, &ph[-1]); + break; + } } if (l->l_ld == 0) diff --git a/elf/rtld.c b/elf/rtld.c index 882b070cc0..f4c2602d65 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -1507,11 +1507,17 @@ of this helper program; chances are you did not intend to run this program.\n\ main_map->l_relro_addr = ph->p_vaddr; main_map->l_relro_size = ph->p_memsz; break; - + } + /* Process program headers again, but scan them backwards so + that PT_NOTE can be skipped if PT_GNU_PROPERTY exits. */ + for (ph = &phdr[phnum]; ph != phdr; --ph) + switch (ph[-1].p_type) + { case PT_NOTE: - if (_rtld_process_pt_note (main_map, ph)) - _dl_error_printf ("\ -ERROR: '%s': cannot process note segment.\n", _dl_argv[0]); + _dl_process_pt_note (main_map, &ph[-1]); + break; + case PT_GNU_PROPERTY: + _dl_process_pt_gnu_property (main_map, &ph[-1]); break; } diff --git a/sysdeps/generic/dl-prop.h b/sysdeps/generic/dl-prop.h index 6b0f2aa95a..f1cf576fe3 100644 --- a/sysdeps/generic/dl-prop.h +++ b/sysdeps/generic/dl-prop.h @@ -20,11 +20,11 @@ #define _DL_PROP_H /* The following functions are used by the dynamic loader and the - dlopen machinery to process PT_NOTE entries in the binary or - shared object. The notes can be used to change the behaviour of - the loader, and as such offer a flexible mechanism for hooking in - various checks related to ABI tags or implementing "flag day" ABI - transitions. */ + dlopen machinery to process PT_NOTE and PT_GNU_PROPERTY entries in + the binary or shared object. The notes can be used to change the + behaviour of the loader, and as such offer a flexible mechanism + for hooking in various checks related to ABI tags or implementing + "flag day" ABI transitions. */ static inline void __attribute__ ((always_inline)) _rtld_main_check (struct link_map *m, const char *program) @@ -36,17 +36,16 @@ _dl_open_check (struct link_map *m) { } -#ifdef FILEBUF_SIZE -static inline int __attribute__ ((always_inline)) -_dl_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph, - int fd, struct filebuf *fbp) +static inline void __attribute__ ((always_inline)) +_dl_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph) { - return 0; } -#endif +/* Called for each property in the NT_GNU_PROPERTY_TYPE_0 note of L, + processing of the properties continues until this returns 0. */ static inline int __attribute__ ((always_inline)) -_rtld_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph) +_dl_process_gnu_property (struct link_map *l, uint32_t type, uint32_t datasz, + void *data) { return 0; } diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index d08b97a5ef..c525ffa12c 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -910,6 +910,10 @@ extern void _dl_setup_hash (struct link_map *map) attribute_hidden; extern void _dl_rtld_di_serinfo (struct link_map *loader, Dl_serinfo *si, bool counting); +/* Process PT_GNU_PROPERTY program header PH in module L after + PT_LOAD segments are mapped. */ +void _dl_process_pt_gnu_property (struct link_map *l, const ElfW(Phdr) *ph); + /* Search loaded objects' symbol tables for a definition of the symbol referred to by UNDEF. *SYM is the symbol table entry containing the diff --git a/sysdeps/x86/dl-prop.h b/sysdeps/x86/dl-prop.h index 516f88ea80..89911e19e2 100644 --- a/sysdeps/x86/dl-prop.h +++ b/sysdeps/x86/dl-prop.h @@ -19,8 +19,6 @@ #ifndef _DL_PROP_H #define _DL_PROP_H -#include - extern void _dl_cet_check (struct link_map *, const char *) attribute_hidden; extern void _dl_cet_open_check (struct link_map *) @@ -146,48 +144,17 @@ _dl_process_cet_property_note (struct link_map *l, #endif } -#ifdef FILEBUF_SIZE -static inline int __attribute__ ((unused)) -_dl_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph, - int fd, struct filebuf *fbp) +static inline void __attribute__ ((unused)) +_dl_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph) { -# if CET_ENABLED - const ElfW(Nhdr) *note; - ElfW(Nhdr) *note_malloced = NULL; - ElfW(Addr) size = ph->p_filesz; - - if (ph->p_offset + size <= (size_t) fbp->len) - note = (const void *) (fbp->buf + ph->p_offset); - else - { - if (size < __MAX_ALLOCA_CUTOFF) - note = alloca (size); - else - { - note_malloced = malloc (size); - note = note_malloced; - } - if (__pread64_nocancel (fd, (void *) note, size, ph->p_offset) != size) - { - if (note_malloced) - free (note_malloced); - return -1; - } - } - - _dl_process_cet_property_note (l, note, size, ph->p_align); - if (note_malloced) - free (note_malloced); -# endif - return 0; + const ElfW(Nhdr) *note = (const void *) (ph->p_vaddr + l->l_addr); + _dl_process_cet_property_note (l, note, ph->p_memsz, ph->p_align); } -#endif -static inline int __attribute__ ((unused)) -_rtld_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph) +static inline int __attribute__ ((always_inline)) +_dl_process_gnu_property (struct link_map *l, uint32_t type, uint32_t datasz, + void *data) { - const ElfW(Nhdr) *note = (const void *) (ph->p_vaddr + l->l_addr); - _dl_process_cet_property_note (l, note, ph->p_memsz, ph->p_align); return 0; }