patches.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev, Ard Biesheuvel <ardb@kernel.org>,
	Lee Jones <lee@kernel.org>
Subject: [PATCH 5.10 80/98] arm64: efi: Execute runtime services from a dedicated stack
Date: Sun, 22 Jan 2023 16:04:36 +0100	[thread overview]
Message-ID: <20230122150232.812272676@linuxfoundation.org> (raw)
In-Reply-To: <20230122150229.351631432@linuxfoundation.org>

From: Ard Biesheuvel <ardb@kernel.org>

commit ff7a167961d1b97e0e205f245f806e564d3505e7 upstream.

With the introduction of PRMT in the ACPI subsystem, the EFI rts
workqueue is no longer the only caller of efi_call_virt_pointer() in the
kernel. This means the EFI runtime services lock is no longer sufficient
to manage concurrent calls into firmware, but also that firmware calls
may occur that are not marshalled via the workqueue mechanism, but
originate directly from the caller context.

For added robustness, and to ensure that the runtime services have 8 KiB
of stack space available as per the EFI spec, introduce a spinlock
protected EFI runtime stack of 8 KiB, where the spinlock also ensures
serialization between the EFI rts workqueue (which itself serializes EFI
runtime calls) and other callers of efi_call_virt_pointer().

While at it, use the stack pivot to avoid reloading the shadow call
stack pointer from the ordinary stack, as doing so could produce a
gadget to defeat it.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Cc: Lee Jones <lee@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 arch/arm64/include/asm/efi.h       |    3 +++
 arch/arm64/kernel/efi-rt-wrapper.S |   13 ++++++++++++-
 arch/arm64/kernel/efi.c            |   27 +++++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 1 deletion(-)

--- a/arch/arm64/include/asm/efi.h
+++ b/arch/arm64/include/asm/efi.h
@@ -25,6 +25,7 @@ int efi_set_mapping_permissions(struct m
 ({									\
 	efi_virtmap_load();						\
 	__efi_fpsimd_begin();						\
+	spin_lock(&efi_rt_lock);					\
 })
 
 #define arch_efi_call_virt(p, f, args...)				\
@@ -36,10 +37,12 @@ int efi_set_mapping_permissions(struct m
 
 #define arch_efi_call_virt_teardown()					\
 ({									\
+	spin_unlock(&efi_rt_lock);					\
 	__efi_fpsimd_end();						\
 	efi_virtmap_unload();						\
 })
 
+extern spinlock_t efi_rt_lock;
 efi_status_t __efi_rt_asm_wrapper(void *, const char *, ...);
 
 #define ARCH_EFI_IRQ_FLAGS_MASK (PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT)
--- a/arch/arm64/kernel/efi-rt-wrapper.S
+++ b/arch/arm64/kernel/efi-rt-wrapper.S
@@ -16,6 +16,12 @@ SYM_FUNC_START(__efi_rt_asm_wrapper)
 	 */
 	stp	x1, x18, [sp, #16]
 
+	ldr_l	x16, efi_rt_stack_top
+	mov	sp, x16
+#ifdef CONFIG_SHADOW_CALL_STACK
+	str	x18, [sp, #-16]!
+#endif
+
 	/*
 	 * We are lucky enough that no EFI runtime services take more than
 	 * 5 arguments, so all are passed in registers rather than via the
@@ -29,6 +35,7 @@ SYM_FUNC_START(__efi_rt_asm_wrapper)
 	mov	x4, x6
 	blr	x8
 
+	mov	sp, x29
 	ldp	x1, x2, [sp, #16]
 	cmp	x2, x18
 	ldp	x29, x30, [sp], #32
@@ -42,6 +49,10 @@ SYM_FUNC_START(__efi_rt_asm_wrapper)
 	 * called with preemption disabled and a separate shadow stack is used
 	 * for interrupts.
 	 */
-	mov	x18, x2
+#ifdef CONFIG_SHADOW_CALL_STACK
+	ldr_l	x18, efi_rt_stack_top
+	ldr	x18, [x18, #-16]
+#endif
+
 	b	efi_handle_corrupted_x18	// tail call
 SYM_FUNC_END(__efi_rt_asm_wrapper)
--- a/arch/arm64/kernel/efi.c
+++ b/arch/arm64/kernel/efi.c
@@ -143,3 +143,30 @@ asmlinkage efi_status_t efi_handle_corru
 	pr_err_ratelimited(FW_BUG "register x18 corrupted by EFI %s\n", f);
 	return s;
 }
+
+DEFINE_SPINLOCK(efi_rt_lock);
+
+asmlinkage u64 *efi_rt_stack_top __ro_after_init;
+
+/* EFI requires 8 KiB of stack space for runtime services */
+static_assert(THREAD_SIZE >= SZ_8K);
+
+static int __init arm64_efi_rt_init(void)
+{
+	void *p;
+
+	if (!efi_enabled(EFI_RUNTIME_SERVICES))
+		return 0;
+
+	p = __vmalloc_node(THREAD_SIZE, THREAD_ALIGN, GFP_KERNEL,
+			   NUMA_NO_NODE, &&l);
+l:	if (!p) {
+		pr_warn("Failed to allocate EFI runtime stack\n");
+		clear_bit(EFI_RUNTIME_SERVICES, &efi.flags);
+		return -ENOMEM;
+	}
+
+	efi_rt_stack_top = p + THREAD_SIZE;
+	return 0;
+}
+core_initcall(arm64_efi_rt_init);



  parent reply	other threads:[~2023-01-22 15:14 UTC|newest]

Thread overview: 103+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-22 15:03 [PATCH 5.10 00/98] 5.10.165-rc1 review Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 01/98] btrfs: fix trace event name typo for FLUSH_DELAYED_REFS Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 02/98] pNFS/filelayout: Fix coalescing test for single DS Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 03/98] selftests/bpf: check null propagation only neither reg is PTR_TO_BTF_ID Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 04/98] tools/virtio: initialize spinlocks in vring_test.c Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 05/98] net/ethtool/ioctl: return -EOPNOTSUPP if we have no phy stats Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 06/98] RDMA/srp: Move large values to a new enum for gcc13 Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 07/98] btrfs: always report error in run_one_delayed_ref() Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 08/98] x86/asm: Fix an assembler warning with current binutils Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 09/98] f2fs: lets avoid panic if extent_tree is not created Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 10/98] wifi: brcmfmac: fix regression for Broadcom PCIe wifi devices Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 11/98] wifi: mac80211: sdata can be NULL during AMPDU start Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 12/98] Add exception protection processing for vd in axi_chan_handle_err function Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 13/98] zonefs: Detect append writes at invalid locations Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 14/98] nilfs2: fix general protection fault in nilfs_btree_insert() Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 15/98] efi: fix userspace infinite retry read efivars after EFI runtime services page fault Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 16/98] ALSA: hda/realtek - Turn on power early Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 17/98] drm/i915/gt: Reset twice Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 18/98] Bluetooth: hci_qca: Wait for timeout during suspend Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 19/98] Bluetooth: hci_qca: Fix driver shutdown on closed serdev Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 20/98] io_uring: dont gate task_work run on TIF_NOTIFY_SIGNAL Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 21/98] io_uring: improve send/recv error handling Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 22/98] io_uring: ensure recv and recvmsg handle MSG_WAITALL correctly Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 23/98] io_uring: add flag for disabling provided buffer recycling Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 24/98] io_uring: support MSG_WAITALL for IORING_OP_SEND(MSG) Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 25/98] io_uring: allow re-poll if we made progress Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 26/98] io_uring: fix async accept on O_NONBLOCK sockets Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 27/98] io_uring: check for valid register opcode earlier Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 28/98] io_uring: lock overflowing for IOPOLL Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 29/98] io_uring: fix CQ waiting timeout handling Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 30/98] io_uring: ensure that cached task references are always put on exit Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 31/98] io_uring: remove duplicated calls to io_kiocb_ppos Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 32/98] io_uring: update kiocb->ki_pos at execution time Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 33/98] io_uring: do not recalculate ppos unnecessarily Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 34/98] io_uring/rw: defer fsnotify calls to task context Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 35/98] xhci-pci: set the dma max_seg_size Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 36/98] usb: xhci: Check endpoint is valid before dereferencing it Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 37/98] xhci: Fix null pointer dereference when host dies Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 38/98] xhci: Add update_hub_device override for PCI xHCI hosts Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 39/98] xhci: Add a flag to disable USB3 lpm on a xhci root port level Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 40/98] usb: acpi: add helper to check port lpm capability using acpi _DSM Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 41/98] xhci: Detect lpm incapable xHC USB3 roothub ports from ACPI tables Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 42/98] prlimit: do_prlimit needs to have a speculation check Greg Kroah-Hartman
2023-01-22 15:03 ` [PATCH 5.10 43/98] USB: serial: option: add Quectel EM05-G (GR) modem Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 44/98] USB: serial: option: add Quectel EM05-G (CS) modem Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 45/98] USB: serial: option: add Quectel EM05-G (RS) modem Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 46/98] USB: serial: option: add Quectel EC200U modem Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 47/98] USB: serial: option: add Quectel EM05CN (SG) modem Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 48/98] USB: serial: option: add Quectel EM05CN modem Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 49/98] staging: vchiq_arm: fix enum vchiq_status return types Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 50/98] USB: misc: iowarrior: fix up header size for USB_DEVICE_ID_CODEMERCS_IOW100 Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 51/98] misc: fastrpc: Dont remove map on creater_process and device_release Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 52/98] misc: fastrpc: Fix use-after-free race condition for maps Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 53/98] usb: core: hub: disable autosuspend for TI TUSB8041 Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 54/98] comedi: adv_pci1760: Fix PWM instruction handling Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 55/98] mmc: sunxi-mmc: Fix clock refcount imbalance during unbind Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 56/98] mmc: sdhci-esdhc-imx: correct the tuning start tap and step setting Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 57/98] btrfs: fix race between quota rescan and disable leading to NULL pointer deref Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 58/98] cifs: do not include page data when checking signature Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 59/98] thunderbolt: Use correct function to calculate maximum USB3 link rate Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 60/98] tty: serial: qcom-geni-serial: fix slab-out-of-bounds on RX FIFO buffer Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 61/98] USB: gadgetfs: Fix race between mounting and unmounting Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 62/98] USB: serial: cp210x: add SCALANCE LPE-9000 device id Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 63/98] usb: host: ehci-fsl: Fix module alias Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 64/98] usb: typec: altmodes/displayport: Add pin assignment helper Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 65/98] usb: typec: altmodes/displayport: Fix pin assignment calculation Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 66/98] usb: gadget: g_webcam: Send color matching descriptor per frame Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 67/98] usb: gadget: f_ncm: fix potential NULL ptr deref in ncm_bitrate() Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 68/98] usb-storage: apply IGNORE_UAS only for HIKSEMI MD202 on RTL9210 Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 69/98] dt-bindings: phy: g12a-usb2-phy: fix compatible string documentation Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 70/98] dt-bindings: phy: g12a-usb3-pcie-phy: " Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 71/98] serial: pch_uart: Pass correct sg to dma_unmap_sg() Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 72/98] dmaengine: tegra210-adma: fix global intr clear Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 73/98] serial: atmel: fix incorrect baudrate setup Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 74/98] gsmi: fix null-deref in gsmi_get_variable Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 75/98] mei: me: add meteor lake point M DID Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 76/98] drm/i915: re-disable RC6p on Sandy Bridge Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 77/98] drm/amd/display: Fix set scaling doesns work Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 78/98] drm/amd/display: Calculate output_color_space after pixel encoding adjustment Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 79/98] drm/amd/display: Fix COLOR_SPACE_YCBCR2020_TYPE matrix Greg Kroah-Hartman
2023-01-22 15:04 ` Greg Kroah-Hartman [this message]
2023-01-22 15:04 ` [PATCH 5.10 81/98] efi: rt-wrapper: Add missing include Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 82/98] Revert "drm/amdgpu: make display pinning more flexible (v2)" Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 83/98] x86/fpu: Use _Alignof to avoid undefined behavior in TYPE_ALIGN Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 84/98] tracing: Use alignof__(struct {type b;}) instead of offsetof() Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 85/98] arch: fix broken BuildID for arm64 and riscv Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 86/98] s390: define RUNTIME_DISCARD_EXIT to fix link error with GNU ld < 2.36 Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 87/98] powerpc/vmlinux.lds: Define RUNTIME_DISCARD_EXIT Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 88/98] powerpc/vmlinux.lds: Dont discard .rela* for relocatable builds Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 89/98] powerpc/vmlinux.lds: Dont discard .comment Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 90/98] io_uring: io_kiocb_update_pos() should not touch file for non -1 offset Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 91/98] io_uring/net: fix fast_iov assignment in io_setup_async_msg() Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 92/98] net/ulp: use consistent error code when blocking ULP Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 93/98] net/mlx5: fix missing mutex_unlock in mlx5_fw_fatal_reporter_err_work() Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 94/98] Revert "wifi: mac80211: fix memory leak in ieee80211_if_add()" Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 95/98] soc: qcom: apr: Make qcom,protection-domain optional again Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 96/98] Bluetooth: hci_qca: Wait for SSR completion during suspend Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 97/98] Bluetooth: hci_qca: check for SSR triggered flag while suspend Greg Kroah-Hartman
2023-01-22 15:04 ` [PATCH 5.10 98/98] Bluetooth: hci_qca: Fixed issue during suspend Greg Kroah-Hartman
2023-01-23  7:16 ` [PATCH 5.10 00/98] 5.10.165-rc1 review Naresh Kamboju
2023-01-23 11:18 ` Sudip Mukherjee
2023-01-23 11:31 ` Pavel Machek
2023-01-23 11:46   ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230122150232.812272676@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=ardb@kernel.org \
    --cc=lee@kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).