From patchwork Tue Nov 29 14:18:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13058631 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 81C59C4321E for ; Tue, 29 Nov 2022 14:20:30 +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=c2r/alFfr7hREqIDER1qtSEVXljkZGqLQsTXMiHtePM=; b=0U+yXg/eOSSREJ Q9x+xkPwDl/XphPg5zO36MCsZZoR5atHfxdUwvqBoKk2mvdDsNv0QvilkT8FrDkB8oQrxthW4lRCM NUIpBaRpywzygbqaHZ8T3onL4AjIpHuqGt3+W8i133aFnWVIeyWRLzTCsVNj8XrHmLzlV1Ewokt3i MKmh1ua0HShH5+ZcTjD+9j48qR5wySKdaAhBw68dc34cNvzkJ14aC6dLgFLtSVs12IKcTiaXMjFc1 a2sleU8R6zJGNfGMZUbvfiZYVCSxQ1wWfZXdxn4uoKG/0WPSPKDkiVAbvWdf5UfNIL6dfyVuJ3aZT HO/bYs70kRUbgkp5CFmg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p01SL-009Akm-Cv; Tue, 29 Nov 2022 14:19:29 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p01RD-009AJK-FU for linux-arm-kernel@lists.infradead.org; Tue, 29 Nov 2022 14:18:20 +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 CBB3D6176F; Tue, 29 Nov 2022 14:18:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 701EAC433D6; Tue, 29 Nov 2022 14:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669731497; bh=j5CIKPVnk6x5nzzeaKmG6KC9k0X4ZL1NuiInXmGW3u0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qAdNeDFYEPgXqwlEdlgABNVYIHUZrzjh3SyeWlZs9nMnQ8o+fPaorgZGGn1kyhkjC IXHfPSWMpXBC9wZn3Y1dOiErckyfyIiOWFHWJwv2D1vBDEoMJn3cIEZlSmvM3EK9Yj w5jYjlDS8jfkwZku8BtULBVNiPzeJodVRYNf8zyX+OYJrL/8b3L9HkZaZanHdR3AHy euiJxLRnm/cRcoGFEdyAdhSyA2kmfkfKAB8MIUCXgoBbp9SpQII6bK5lRZEkMuc7z6 Y8EvGt6Fxcr67AN7We6Wk93572y4WNwUVIX7Xgs5lm4YOIGrcDJTjor5e8NnRM2b3b QVca2PfiCCmrw== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Marc Zyngier , Will Deacon , Mark Rutland , Kees Cook , Catalin Marinas , Mark Brown Subject: [PATCH 3/4] arm64: efi: Add return address protection to runtime wrapper Date: Tue, 29 Nov 2022 15:18:02 +0100 Message-Id: <20221129141803.1746898-4-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221129141803.1746898-1-ardb@kernel.org> References: <20221129141803.1746898-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1497; i=ardb@kernel.org; h=from:subject; bh=j5CIKPVnk6x5nzzeaKmG6KC9k0X4ZL1NuiInXmGW3u0=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjhhSYeoDUBqUnh/xuLIrbR8oSQZ9UJxsZiRYzvgHM bkjeMCKJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY4YUmAAKCRDDTyI5ktmPJIapDA DHLRUNv1/4nT0Z7RPGXM+uiHKP99O8MoUpuRqtgrlrc5odsC9+9gJBFA7DFHfD+gX0vKF6BFgem0+R 1B59IeKkWLWeSYi4kIaPQET9dZpWCFyIoNbwHLzcrBtcCbzhJwiefkfk7rENiBern2ANcfSXoNVKIh BGOBYDo/CXHBhjLGJeeX5xP3HtWvBcMeBBfKgHc+RqDIo6mV8DFJOrTYtbDXsJntYYuAl36AdltKUU 2pEk7lICRIcZ+BCkR424jyt+Wi2o6eu0kvjFfBzFJXXNBIXaQ4skTtyN4XtiX2Ff89Ye1DPmXnXXrq 3rD2iwQ/myTQ03u/kutST14s/zEipjZ/iX5ozq7NIezig7Zbg1iS4AY8aGsVMhJz2ne+hdmUHctUn5 Zcy8It/JGvSSwGniiqQRfhE957wK/0Fe+sWOrp8CuHFIqwgG5Woa0R0XFjd3AB8ANStK488wcarsLN aBoL0aY4VVINDK6KqzQGe0rMEF0q6QQokG0C/8ytLzZ54= 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-20221129_061819_622402_53318DD6 X-CRM114-Status: GOOD ( 12.35 ) 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 Add return address protection to the EFI runtime wrapper so that this code is less likely to be taken advantage for ROP/JOP style attacks. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/efi-rt-wrapper.S | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kernel/efi-rt-wrapper.S b/arch/arm64/kernel/efi-rt-wrapper.S index afd3e81e1b627b87..874da02f3a1664c3 100644 --- a/arch/arm64/kernel/efi-rt-wrapper.S +++ b/arch/arm64/kernel/efi-rt-wrapper.S @@ -6,6 +6,7 @@ #include SYM_FUNC_START(__efi_rt_asm_wrapper) + protect_return_address stp x29, x30, [sp, #-112]! mov x29, sp @@ -46,9 +47,7 @@ SYM_FUNC_START(__efi_rt_asm_wrapper) ldp x1, x2, [sp, #16] cmp x2, x18 ldp x29, x30, [sp], #112 - b.ne 0f - ret -0: + /* * With CONFIG_SHADOW_CALL_STACK, the kernel uses x18 to store a * shadow stack pointer, which we need to restore before returning to @@ -59,7 +58,10 @@ SYM_FUNC_START(__efi_rt_asm_wrapper) #ifdef CONFIG_SHADOW_CALL_STACK ldr_this_cpu x18, __efi_rt_asm_recover_sp + 8, x9 #endif - + b.ne 0f + restore_return_address + ret +0: b efi_handle_corrupted_x18 // tail call SYM_FUNC_END(__efi_rt_asm_wrapper) @@ -74,5 +76,7 @@ SYM_CODE_START(__efi_rt_asm_recover) ldp x27, x28, [sp, #96] ldp x29, x30, [sp], #112 + restore_return_address + b efi_handle_runtime_exception SYM_CODE_END(__efi_rt_asm_recover)