From patchwork Tue Aug 20 09:57:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 171785 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp4177675ily; Tue, 20 Aug 2019 02:57:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqzrKgck0DUT80IJCz/RxuS9fiFFL28X69XiN7ZgopQeYcphkw8nGfTniulA+uUasvEe6HKB X-Received: by 2002:aa7:8b10:: with SMTP id f16mr29568059pfd.44.1566295071741; Tue, 20 Aug 2019 02:57:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566295071; cv=none; d=google.com; s=arc-20160816; b=M1qH/ueHCsAlfHxWzMZW5HgnXlVtQPgTejpeK03aprdd6tWxEZb1dg8TTjSqxkyVn3 upZxQMIcRRuEF0MGDkatDmQZOxtP1AIrt712oo6GyqikxqagyiuiPrUTxPilKcu8RQr4 C3hNgK5SNbb5NCRzb7zV31cnnrObaanXKH9hiB2ctg0qfB/42F6262KBgSJ5crZMb6SR vyQUsF0WhSL8Lc77IvfF53WJ+yINvsNWjgk7sWOvOsWIaz93zrOujJZJwE1PsxLBKFi+ 5LGd5Ozreu8o1t8toAHrBDHddHwkybCDZt5Y8BDKs3H7bNuAdHKEponn9/dgdhNmHpGX utsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=B+zbDJVVuU1xoHgE+0Z8rNVq+jTrGSequFT/8ymDZv0=; b=1H/exAU/xYB+xYXWjGue+bqHa0o+NzoE9GlX2giDMgQbjkfjFjpmOCyjC2gUs9H5Gj O4pmyPLSgoh/8ktl6xQeE/dg59A6QGdnt35MI7fXhoN8Cpl2adZdOCTcxDFYNLZEewl3 +Hr8dSCrxUZ4sP8u3N8EGD/ahCyTUDOjLdOooaVK7x3+1Z5+m4ijv+s8/kHqcUnkQQyR wAaJOu68pqerimkCBpdNqk8e1v1TqD0d4Bp/Q9H55lbLMhPRbx7uXcFXZbLCtDiQGpvD Vy7d1H+NndW9Ufa60fZKAIpcrZRSm/TmgpIWgAcUTAiR1t5lwGTmDyx9OLkU3bs585oB vcoA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 67si12387801pfb.242.2019.08.20.02.57.51; Tue, 20 Aug 2019 02:57:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729610AbfHTJ5u (ORCPT + 28 others); 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