From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D4C9C3A589 for ; Tue, 20 Aug 2019 09:57:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 678E022CF4 for ; Tue, 20 Aug 2019 09:57:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729610AbfHTJ5u (ORCPT ); Tue, 20 Aug 2019 05:57:50 -0400 Received: from foss.arm.com ([217.140.110.172]:37834 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728414AbfHTJ5u (ORCPT ); Tue, 20 Aug 2019 05:57:50 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 71B20344; Tue, 20 Aug 2019 02:57:49 -0700 (PDT) Received: from e103592.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 36F563F706; Tue, 20 Aug 2019 02:57:48 -0700 (PDT) From: Dave Martin To: linux-kernel@vger.kernel.org Cc: linux-arch@vger.kernel.org, Kees Cook , Thomas Gleixner , Jann Horn , "H.J. Lu" , Eugene Syromiatnikov , Florian Weimer , Yu-cheng Yu , Peter Zijlstra Subject: [RFC PATCH 0/2] ELF: Alternate program property parser Date: Tue, 20 Aug 2019 10:57:41 +0100 Message-Id: <1566295063-7387-1-git-send-email-Dave.Martin@arm.com> X-Mailer: git-send-email 2.1.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This series is an experimental reimplementation of ELF property parsing (see NT_GNU_PROPERTY_TYPE_0, [1]) for the ELF loader. This is intended for comparison / merging with [2] (or could replace it, if people think this approach is better). Either way, I'd like to get something in place so that we can build AArch64 BTI support on top of it. Any thoughts? Key differences from [2]: * Scanning for the PT_PROGRAM_PROPERTY program header is intergrated into the existing scan loops, rather than being done separately. * In keeping with the rest of the ELF loader code, error checks are kept to a minimum. Except to avoid buffer overruns, the ELF file is not checked for well-formedness. As a sanity check, the code still checks for a correct NT_GNU_PROPERTY_TYPE_0 note header at the start of the PT_PROGRAM_PROPERTY segment, but perhaps this isn't needed either. * 1K is statically allocated on the stack for the properties, and if the ELF properties are larger than that, the ELF file is rejected with ENOEXEC. There is no limit defined in [1] for the total size of the properties, but common sense seems suggests that 1K is likely to be ample space. * The properties are found, read and parsed exactly once. [2] does this once _per property_ requested by the arch code: that's not a problem today, but it will become inefficient with there are multiple properties in the file that the kernel needs to look at. Instead, the arch arch_parse_elf_property() hook is called once per property found. To minimise overhead, the arch code can implement this hook inline. This approach assumes that the number of properties in a given ELF is say, no more than 20 or so. The code could be redesigned in the future if/when this iteration becomes an overhead (i.e., probably never). [1] Linux Extensions to gABI https://github.com/hjl-tools/linux-abi/wiki/Linux-Extensions-to-gABI [2] [PATCH v8 22/27] binfmt_elf: Extract .note.gnu.property from an ELF file https://lore.kernel.org/lkml/20190813205225.12032-23-yu-cheng.yu@intel.com/ Dave Martin (2): ELF: UAPI and Kconfig additions for ELF program properties ELF: Add ELF program property parsing support fs/Kconfig.binfmt | 3 ++ fs/binfmt_elf.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++ fs/compat_binfmt_elf.c | 4 ++ include/linux/elf.h | 21 +++++++++ include/uapi/linux/elf.h | 11 +++++ 5 files changed, 148 insertions(+) -- 2.1.4