From patchwork Fri May 24 10:25:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 10959647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 295F076 for ; Fri, 24 May 2019 10:25:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1503228872 for ; Fri, 24 May 2019 10:25:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08B4F28877; Fri, 24 May 2019 10:25:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 72BAB2887D for ; Fri, 24 May 2019 10:25:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=WDv2ySBp/cL11VGpQi0MjV6mgKjfNhjna3gbJbeogHk=; b=bhK uRGgrz0rYb/AitYSmrmjs621V3ro1KUnMxEaGtbHl1vDRrIlNPUOVYBt9gx0KXdW9OGmDDDGdMfNu tXN22oNIPEtFQcIE8AAquul76BT2LnxzAExwR8Vc6DrAggUmYvnt1IZJUwnAQwgQ7TP/JZHdaHh6C rqutQJQ/5nYUXCH9ntEQi7RBWhEA0PzWPmLlUoid43jCvYj2VhJ9mUeNS6nnJ8D7516zRENK7rJWL mCbIpZsBSBI0OjNfWGbs+GEQg94h6yb1/6ROPpTwSMP3gCKkTOu5P4aZ6Zpw4oOJcQY5mJo+1SMZd EaXttIe6NbW9DD8G/r92v1Xjp4fP6BA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hU7OU-0000Aw-P0; Fri, 24 May 2019 10:25:46 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hU7OR-00009c-Vs for linux-arm-kernel@lists.infradead.org; Fri, 24 May 2019 10:25:45 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3DD1B15A2; Fri, 24 May 2019 03:25:41 -0700 (PDT) Received: from e103592.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D6EB33F703; Fri, 24 May 2019 03:25:38 -0700 (PDT) From: Dave Martin To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 0/8] arm64: ARMv8.5-A: Branch Target Identification support Date: Fri, 24 May 2019 11:25:25 +0100 Message-Id: <1558693533-13465-1-git-send-email-Dave.Martin@arm.com> X-Mailer: git-send-email 2.1.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190524_032544_038077_83F424E3 X-CRM114-Status: GOOD ( 16.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, "H.J. Lu" , Yu-cheng Yu , Andrew Jones , Paul Elliott , Arnd Bergmann , Szabolcs Nagy , Will Deacon , Richard Henderson , linux-kernel@vger.kernel.org, =?utf-8?q?Kristina_Mart=C5=A1enko?= , Catalin Marinas , Sudakshina Das MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch implements support for ARMv8.5-A Branch Target Identification (BTI), which is a control flow integrity protection feature introduced as part of the ARMv8.5-A extensions [1]. The series is based on v5.2-rc1. Patch 1 is from Yu-Cheng Yu of Intel, providing generic support for parsing the ELF NT_GNU_PROPERTY_TYPE_0 note. It makes sense to share this mechanism with x86 rather than reinventing it. Various things need nailing down before this can be upstreamable: * Not tested with hugepages yet. (If anyone has any suggestions about how best to do that, please shout!) * The NT_GNU_PROPERTY_TYPE_0 ELF note parsing support is not upstream yet and may be subject to further change. Todo: * Add BTI protection in the vDSO, so that user code can no longer jump to random locations in there. Lack of this protection doesn't break anything, however. Tested on the ARM Fast Model. Notes: * GCC 9 can compile backwards-compatible BTI-enabled code with -mbranch-protection=bti or -mbranch-protection=standard. * Binutils trunk supports the new ELF note, but this isn't in a release yet. Creation of a BTI-enabled binary requires _everything_ linked in to be BTI-enabled. For now ld --force-bti can be used to override this, but some things may break until the required C library support is in place. There is no straightforward way to mark a .s file as BTI-enabled: scraping the output from gcc -S works as a quick hack for now. readelf -n can be used to examing the program properties in an ELF file. * Runtime mmap() and mprotect() can be used to enable BTI on a page-by-page basis using the new PROT_BTI_GUARDED, but the code in the affected pages still needs to be written or compiled to contain the appopriate BTI landing pads. Dave Martin (7): mm: Reserve asm-generic prot flag 0x10 for arch use arm64: docs: cpu-feature-registers: Document ID_AA64PFR1_EL1 arm64: Basic Branch Target Identification support elf: Parse program properties before destroying the old process elf: Allow arch to tweak initial mmap prot flags arm64: elf: Enable BTI at exec based on ELF program properties arm64: BTI: Decode BYTPE bits when printing PSTATE Yu-cheng Yu (1): binfmt_elf: Extract .note.gnu.property from an ELF file Documentation/arm64/cpu-feature-registers.txt | 18 +- Documentation/arm64/elf_hwcaps.txt | 4 + arch/arm64/Kconfig | 26 ++ arch/arm64/include/asm/cpucaps.h | 3 +- arch/arm64/include/asm/cpufeature.h | 6 + arch/arm64/include/asm/elf.h | 28 ++ arch/arm64/include/asm/esr.h | 2 +- arch/arm64/include/asm/hwcap.h | 1 + arch/arm64/include/asm/mman.h | 33 +++ arch/arm64/include/asm/pgtable-hwdef.h | 1 + arch/arm64/include/asm/pgtable.h | 2 +- arch/arm64/include/asm/ptrace.h | 3 + arch/arm64/include/asm/sysreg.h | 2 + arch/arm64/include/uapi/asm/hwcap.h | 1 + arch/arm64/include/uapi/asm/mman.h | 9 + arch/arm64/include/uapi/asm/ptrace.h | 1 + arch/arm64/kernel/cpufeature.c | 17 ++ arch/arm64/kernel/cpuinfo.c | 1 + arch/arm64/kernel/entry.S | 11 + arch/arm64/kernel/process.c | 64 ++++- arch/arm64/kernel/ptrace.c | 2 +- arch/arm64/kernel/signal.c | 5 + arch/arm64/kernel/syscall.c | 1 + arch/arm64/kernel/traps.c | 7 + fs/Kconfig.binfmt | 7 + fs/Makefile | 1 + fs/binfmt_elf.c | 31 ++- fs/gnu_property.c | 363 ++++++++++++++++++++++++++ include/linux/elf.h | 32 +++ include/linux/mm.h | 3 + include/uapi/asm-generic/mman-common.h | 1 + include/uapi/linux/elf.h | 14 + 32 files changed, 684 insertions(+), 16 deletions(-) create mode 100644 arch/arm64/include/asm/mman.h create mode 100644 arch/arm64/include/uapi/asm/mman.h create mode 100644 fs/gnu_property.c