From patchwork Wed Jul 1 14:39:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 39867 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 5E7FE3861841; Wed, 1 Jul 2020 14:39:38 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80041.outbound.protection.outlook.com [40.107.8.41]) by sourceware.org (Postfix) with ESMTPS id A14423857007 for ; Wed, 1 Jul 2020 14:39:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A14423857007 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=Ytsbhac+T0/gheTIVc0Pl4c+suCeuSoAt5XRkWYlbZo=; b=gW0tzTV/acUn3syXgUu6OhRtthI9pnDp3HlgUJaJka8MLFyNc8z9FFhEGbcBSBAZ2vmS2qlBbUjWy6y3VykFY8optn2C28/ODaM1SfWIKswEJNPtvilbUhulP4d1voIqxLWaNyLleoUfoCqccEgSfQdGyZyN2rOUxPQSH0Gpm5w= Received: from DB8PR03CA0006.eurprd03.prod.outlook.com (2603:10a6:10:be::19) by AM6PR08MB3927.eurprd08.prod.outlook.com (2603:10a6:20b:a1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.21; Wed, 1 Jul 2020 14:39:31 +0000 Received: from DB5EUR03FT051.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:be:cafe::fb) by DB8PR03CA0006.outlook.office365.com (2603:10a6:10:be::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.20 via Frontend Transport; Wed, 1 Jul 2020 14:39:30 +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 DB5EUR03FT051.mail.protection.outlook.com (10.152.21.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.20 via Frontend Transport; Wed, 1 Jul 2020 14:39:30 +0000 Received: ("Tessian outbound a4b10e5b482d:v62"); Wed, 01 Jul 2020 14:39:30 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 159f866b3c349364 X-CR-MTA-TID: 64aa7808 Received: from f317234e8b6c.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 6EBE48CC-19F4-4C59-B803-FA94F9E746ED.1; Wed, 01 Jul 2020 14:39:25 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id f317234e8b6c.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 01 Jul 2020 14:39:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JFQfSG6AWnjnR+yB3MSmAu9h6x28T5AdYF5TMHy6M1h7D6etodABfXprf5XQtcgscZ0qRuEh9JpwOq4CbPsGLItG/ad7uv5yjfMLYrS/9gpACJNGvvGcwQRQ42PS33wVoTTc68VB8Ar/3rAlRw7aeU/gef18mlUL2Nz5186pD0zh45kGkGwda8xFEaeaQyTMqaYdgVRO0PWAiX5ViNgLOV6ZqET/pJ9xXrJmM3Leikm9/idaEtkVZFrsQdtPyJPt7QKhSyxYcdhTpge5b5ydD9MJzFxKWon4BE2DlDE2w+++aK17/61KZ/svmcXC8Gu3onzCYas80lIcUmcj49y6BQ== 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=Ytsbhac+T0/gheTIVc0Pl4c+suCeuSoAt5XRkWYlbZo=; b=CoTGBM6OBWnmUnsfw29eJyjF++uS/G4nsf6KHEA96WP+B2yD7qwjjvve61zAPuqSTskn/i6D52Z3/tPcphXyoKpEVwFd2hdeWUxOookjwySGY1WJQ5DZ+GECMay5TSdwK0WK6eMRF3FivW3Cj0r4BAKxSOiRJX93lk0PIEwga+DZbE1zl8s9h3NGsKscFoHtbkJVg9yAaBpoX4kUluJSAOwF/ljktzKVCaJS+OvVbfa3GhGzrVk8Vt4nPRxaLrTZRKeDIGjyT3/+0iAmvB6MLkd7QCghJXbLM2UeJ1Qoq4E73VSM/eWx0LchBMgZJNRZZ3hOTub31OWMviME6gybcQ== 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=Ytsbhac+T0/gheTIVc0Pl4c+suCeuSoAt5XRkWYlbZo=; b=gW0tzTV/acUn3syXgUu6OhRtthI9pnDp3HlgUJaJka8MLFyNc8z9FFhEGbcBSBAZ2vmS2qlBbUjWy6y3VykFY8optn2C28/ODaM1SfWIKswEJNPtvilbUhulP4d1voIqxLWaNyLleoUfoCqccEgSfQdGyZyN2rOUxPQSH0Gpm5w= 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 AM6PR08MB3879.eurprd08.prod.outlook.com (2603:10a6:20b:8c::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.24; Wed, 1 Jul 2020 14:39:23 +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.3131.033; Wed, 1 Jul 2020 14:39:23 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v6 07/14] rtld: Clean up PT_NOTE and add PT_GNU_PROPERTY handling Date: Wed, 1 Jul 2020 15:39:17 +0100 Message-Id: <54251326567d18776646ce23d9d9489c6a35f410.1593612309.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0286.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a1::34) 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 LO2P265CA0286.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a1::34) 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, 1 Jul 2020 14:39:23 +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: bfa943eb-832a-4318-e5c8-08d81dcc9073 X-MS-TrafficTypeDiagnostic: AM6PR08MB3879:|AM6PR08MB3927: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8273;OLM:8273; X-Forefront-PRVS: 04519BA941 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: HZN4G81axqjIPFJefUx3HUJ/E/G9tAQzA5FLZE8GzrewMAH4cOr44BeWOladmqyVlRVcvcaEVJaK0PSVgAy0cNlgOognt9sFrXX3TYWNhufcZPOtoKLTA1GrF3jV4dlQEZBkdZs4MPL0WUrhiZ+VQCFAug78xObQrYbL6Fdy57aDPhjLbLrjQHaqmu1cT7J1DqCLpCkHjQw6xgsq07OSz2t4N9ij5gZK2ygb9sUn1vg44yOAJP+TmKjdI60h5Y/o/SZvw/DeIQCYzmKoF7vsLnW/IxAFGeKO9Nl50INZIHt8GJjJSRicQ+KnpnkuAjYmua4+azaEoyh6GdhnqhBfzNth5c6aF1PjR+iMpZ2d6emzQE7NZaeQul5NvOTvWSiHmR53+dksrR4A7TWsgZTyZoFyRLGMAPGtCPwMW2X3LdE= 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)(39860400002)(366004)(136003)(346002)(376002)(396003)(186003)(2906002)(52116002)(478600001)(36756003)(956004)(2616005)(6916009)(6512007)(66946007)(66476007)(44832011)(6666004)(66556008)(6486002)(69590400007)(83380400001)(5660300002)(26005)(6506007)(16526019)(86362001)(8936002)(316002)(8676002)(136400200001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: uoUgN/q5GRkMvZnUW3/0NCnFJTX/ZXK7jZaKS9lNZ3Oq2fxlasCl3HLI6PZKvx5rP60IXUm03qfcauVnLKTi0f4OV3xd05AfvrWqlH8yCU0lDPZ5cwrhe0Jx6gVafYiGtPEqds4nG6is8x1XbXUKd4FMAOjI27LtfPzZlCEjQrJsV0oisywEyx1Gwu0EYHv5t5nQnf7ffZjFo4jN6ApQ9mCZxqUxWzQ1nF8dAl0NlcEv6NXxr10jpJEA4puYDY9fepOxFtliHGpGQeOmdQZg8gGRmzN5pMN73jNwkSBxUEyOoVP9LZBrPW8PGfOk9TwT5mILslKcnN+NpT1z/ls5MJY2+CWtGODpQEJzu3kQh3GjHCetu2/d8GpJtphAfKVvYJVXYwbUIdWQljJzYGNcnGfzqO7MxuxCx2JRgmeU4Yt+krIx0c5pIt69MB7ibl0jR580ror38f5Hwfh6zPW3o8jTmNCVVDcly47JjCiVqno7OmgqfedAsg0GBfuLgsoc X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3879 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: DB5EUR03FT051.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)(39860400002)(346002)(376002)(396003)(136003)(46966005)(81166007)(69590400007)(6506007)(82740400003)(356005)(316002)(8936002)(6486002)(47076004)(478600001)(6512007)(26005)(186003)(2906002)(70586007)(6916009)(16526019)(44832011)(86362001)(70206006)(5660300002)(6666004)(956004)(83380400001)(2616005)(8676002)(36756003)(336012)(82310400002)(136400200001); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: d9c0399d-ee12-490a-e067-08d81dcc8c17 X-Forefront-PRVS: 04519BA941 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3eSCB7m/TPw4w0FpFxrXbNtihsaTvkT4EHVAqMr9OO8FRa44/wXewIxPAPqwcaojBPtcIvVpoaIS3QK8XjA0RnM49troO7VEhUwV/FtyyMXPqhSRE646c3cbjhVdWtGw83CLLGFr8LYLb3bL6SvYE1Y8+sclWaO/InJO4oNl/Wzh3fZefpUWlaphVD4vG7eSU5j04KC4zTERT6VlXM0Kl5J8jp/Xj0Zrt8l+2NPlHAfygXQO0/asSk8SpaEhNfxa5Mow+ODgLdasIk7LKRAGqTGTsJI823imP4g0Hh3mVeyiq1nb38NVdlbu+MC0jhiCLJRf3/Ft0DFmDz6886/CkCGG44TvStWtvxIMC10H+kzLFNyHIGRCzq7n0fhz4SObEW0aJlqFxgSN8lE0nXzoIiXnNTsaWz8XgUyD9Xch0VG/1e1Ijw41dZK6pVx2Rmvk0IlqYIjImv8PKW50ED2nqg== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jul 2020 14:39:30.6893 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bfa943eb-832a-4318-e5c8-08d81dcc9073 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: DB5EUR03FT051.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3927 X-Spam-Status: No, score=-16.3 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..32c74f79ef 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; }