From patchwork Thu May 5 16:10:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 12839762 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 857D3C433EF for ; Thu, 5 May 2022 16:11:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=x02EYO4nFeOPHsckcTbsFVvQNdZVUREOGakZoGYF48A=; b=D1Btqz8+LrvIod 0MsIq9crJ/6uHHcDFWupQfGLGDZIJ6o6bgu9vVVb6vfu83dF288f1aJXKbp8FIRqLAIiG8P6WUFiU urJXUJ7d046REg4zGsd3WnPzbOu203FR4VGBt2gmQ43g1YgQ4wmR/neVKB0UOCn0OAEyi1BrkcCHy Ty4aWSvLKZV1kSHbYEeRMoVELeNZd2Me0LwHskevEpBYzIeS+Y/GJGIfV+9lzCoxrHbojawvRG4Tr ThZchDZPGqlzW19jg7NeipcW2hykYw+pTwIRaF1XkC7XUNxVf08MzXMNNhCs3arRlvxw2kpn0agRm LYHYwA+f/yNvEat8Hl+g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nme3u-00Gn3B-PT; Thu, 05 May 2022 16:10:42 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nme3k-00Gn09-JT for linux-arm-kernel@lists.infradead.org; Thu, 05 May 2022 16:10:34 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E400061E26; Thu, 5 May 2022 16:10:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 190C1C385B1; Thu, 5 May 2022 16:10:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651767031; bh=QDVLzpeJgRUO8ekEYXYRCe3+zpE+zhaLUf11RtkqhFc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BoCZCZp7HfqVbJ2HGFg+X5VGoC+qtXtIV+wLW7o8EGu5riV4dihz0jVWv2wUp5hBU Jo/CAbmrYp2riaLztEF82S6hwBNbZN4/BATxACnc+BbTwM2Knc6KREVyH4oe1S+NUW idSit+rF/xTwg5VizgEY6kkLEAeyJoV7uhb1ZgjAT4KcC9LsIb8M4J3wvO6LcsFzwE 9McQeeUIO1rELr06ihOUVU2g6carbJBlEXXMOYiKbu+FGI5j2Wi3HirI4gWZlnIh6u VLv4ICPP2gdg1YVpHbR+1zwpXbM3i9UHrtvT2QEhxngjiskUJJSBTP812GwK4nrkjb 9PjDkp8HvQxbg== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: will@kernel.org, mark.rutland@arm.com, catalin.marinas@arm.com, maz@kernel.org, Ard Biesheuvel , Kees Cook , Sami Tolvanen , Fangrui Song , Nick Desaulniers , Dan Li Subject: [RFC PATCH v2 1/3] arm64: unwind: add asynchronous unwind tables to kernel and modules Date: Thu, 5 May 2022 18:10:09 +0200 Message-Id: <20220505161011.1801596-2-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220505161011.1801596-1-ardb@kernel.org> References: <20220505161011.1801596-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4048; h=from:subject; bh=QDVLzpeJgRUO8ekEYXYRCe3+zpE+zhaLUf11RtkqhFc=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBic/bgDpiZPmvpifUJRS/J/CS+mpUuj8FzYXrnF/g5 +CuIQKeJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYnP24AAKCRDDTyI5ktmPJMo5DA CDtRbJ0ujhl/8Z65lQUeJ8XPhUGSS/JwcSr2rfyPRJ9YX5eLLj/bPi+Wt4MmVn5yuFGjV3iA3eCkEi PW4EVL92NKijvPk3TAxLmZvxRf77ho66SgmSsnGO96rPQbPDLBsEQ9CKnlInRi49iIUiwfdj/sOhCJ EJJ6uo3fUglZ8bx3uUNT1M0QZa1NpMPjkOpMvk7TZNctW0UR2lV6TBdolxASLW0i3c+ZOoFL6ifoaw fibjmmB+qEiDRXuNcHLX6MygTZIBQbNyZXkTHP2G1ZipTYBqFGaAbiUAbNWK48eKJcTxW6pA2HUNJs +DeWG1PzmnpWQkO4dai0SIFuDAhgm09UPKW74dvX7wGaNs4clbl/Kfz4a+nRPgH5DAqDo0jcsqcmVX sPL/+ON1LxcSbKGS5om6kILWt5jyTXzcSqzdOLfrvJVeu3D+2vx+CzVUg+CaSCrl7jm1ILbBe+kJWT FHsQXhd8SIROYnxuTac/N2qaxO/yd4Qmf7YW3Y8dBCYY4= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220505_091032_756335_DC516E5B X-CRM114-Status: GOOD ( 18.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Enable asynchronous unwind table generation for both the core kernel as well as modules, and emit the resulting .eh_frame sections as init code so we can use the unwind directives for code patching at boot or module load time. This will be used by dynamic shadow call stack support, which will rely on code patching rather than compiler codegen to emit the shadow call stack push and pop instructions. Signed-off-by: Ard Biesheuvel Reviewed-by: Nick Desaulniers --- arch/arm64/Kconfig | 3 +++ arch/arm64/Makefile | 5 +++++ arch/arm64/include/asm/module.lds.h | 8 ++++++++ arch/arm64/kernel/vmlinux.lds.S | 16 ++++++++++++++++ drivers/firmware/efi/libstub/Makefile | 1 + 5 files changed, 33 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 57c4c995965f..b6302f7cd73f 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -354,6 +354,9 @@ config KASAN_SHADOW_OFFSET default 0xeffffff800000000 if ARM64_VA_BITS_36 && KASAN_SW_TAGS default 0xffffffffffffffff +config UNWIND_TABLES + bool + source "arch/arm64/Kconfig.platforms" menu "Kernel Features" diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 2f1de88651e6..a4c6807ecbaf 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -45,8 +45,13 @@ KBUILD_CFLAGS += $(call cc-option,-mabi=lp64) KBUILD_AFLAGS += $(call cc-option,-mabi=lp64) # Avoid generating .eh_frame* sections. +ifneq ($(CONFIG_UNWIND_TABLES),y) KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables KBUILD_AFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables +else +KBUILD_CFLAGS += -fasynchronous-unwind-tables +KBUILD_AFLAGS += -fasynchronous-unwind-tables +endif ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y) prepare: stack_protector_prepare diff --git a/arch/arm64/include/asm/module.lds.h b/arch/arm64/include/asm/module.lds.h index 094701ec5500..dbba4b7559aa 100644 --- a/arch/arm64/include/asm/module.lds.h +++ b/arch/arm64/include/asm/module.lds.h @@ -17,4 +17,12 @@ SECTIONS { */ .text.hot : { *(.text.hot) } #endif + +#ifdef CONFIG_UNWIND_TABLES + /* + * Currently, we only use unwind info at module load time, so we can + * put it into the .init allocation. + */ + .init.eh_frame : { *(.eh_frame) } +#endif } diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index edaf0faf766f..2f4908c8d152 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -122,6 +122,17 @@ jiffies = jiffies_64; #define TRAMP_TEXT #endif +#ifdef CONFIG_UNWIND_TABLES +#define UNWIND_DATA_SECTIONS \ + .eh_frame : { \ + __eh_frame_start = .; \ + *(.eh_frame) \ + __eh_frame_end = .; \ + } +#else +#define UNWIND_DATA_SECTIONS +#endif + /* * The size of the PE/COFF section that covers the kernel image, which * runs from _stext to _edata, must be a round multiple of the PE/COFF @@ -150,6 +161,9 @@ SECTIONS /DISCARD/ : { *(.interp .dynamic) *(.dynsym .dynstr .hash .gnu.hash) +#ifndef CONFIG_UNWIND_TABLES + *(.eh_frame) +#endif } . = KIMAGE_VADDR; @@ -228,6 +242,8 @@ SECTIONS __alt_instructions_end = .; } + UNWIND_DATA_SECTIONS + . = ALIGN(SEGMENT_ALIGN); __inittext_end = .; __initdata_begin = .; diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index d0537573501e..78c46638707a 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -20,6 +20,7 @@ cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ \ # disable the stackleak plugin cflags-$(CONFIG_ARM64) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \ -fpie $(DISABLE_STACKLEAK_PLUGIN) \ + -fno-unwind-tables -fno-asynchronous-unwind-tables \ $(call cc-option,-mbranch-protection=none) cflags-$(CONFIG_ARM) := $(subst $(CC_FLAGS_FTRACE),,$(KBUILD_CFLAGS)) \ -fno-builtin -fpic \