This is a note to let you know that I've just added the patch titled x86/efistub: Give up if memory attribute protocol returns an error to the 6.1-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: x86-efistub-give-up-if-memory-attribute-protocol-returns-an-error.patch and it can be found in the queue-6.1 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From a7a6a01f88e87dec4bf2365571dd2dc7403d52d0 Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel <ardb@xxxxxxxxxx> Date: Fri, 26 Jan 2024 12:14:30 +0100 Subject: x86/efistub: Give up if memory attribute protocol returns an error From: Ard Biesheuvel <ardb@xxxxxxxxxx> commit a7a6a01f88e87dec4bf2365571dd2dc7403d52d0 upstream. The recently introduced EFI memory attributes protocol should be used if it exists to ensure that the memory allocation created for the kernel permits execution. This is needed for compatibility with tightened requirements related to Windows logo certification for x86 PCs. Currently, we simply strip the execute protect (XP) attribute from the entire range, but this might be rejected under some firmware security policies, and so in a subsequent patch, this will be changed to only strip XP from the executable region that runs early, and make it read-only (RO) as well. In order to catch any issues early, ensure that the memory attribute protocol works as intended, and give up if it produces spurious errors. Note that the DXE services based fallback was always based on best effort, so don't propagate any errors returned by that API. Fixes: a1b87d54f4e4 ("x86/efistub: Avoid legacy decompressor when doing EFI boot") Signed-off-by: Ard Biesheuvel <ardb@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/firmware/efi/libstub/x86-stub.c | 24 ++++++++++++++---------- drivers/firmware/efi/libstub/x86-stub.h | 4 ++-- 2 files changed, 16 insertions(+), 12 deletions(-) --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -212,8 +212,8 @@ static void retrieve_apple_device_proper } } -void efi_adjust_memory_range_protection(unsigned long start, - unsigned long size) +efi_status_t efi_adjust_memory_range_protection(unsigned long start, + unsigned long size) { efi_status_t status; efi_gcd_memory_space_desc_t desc; @@ -225,13 +225,17 @@ void efi_adjust_memory_range_protection( rounded_end = roundup(start + size, EFI_PAGE_SIZE); if (memattr != NULL) { - efi_call_proto(memattr, clear_memory_attributes, rounded_start, - rounded_end - rounded_start, EFI_MEMORY_XP); - return; + status = efi_call_proto(memattr, clear_memory_attributes, + rounded_start, + rounded_end - rounded_start, + EFI_MEMORY_XP); + if (status != EFI_SUCCESS) + efi_warn("Failed to clear EFI_MEMORY_XP attribute\n"); + return status; } if (efi_dxe_table == NULL) - return; + return EFI_SUCCESS; /* * Don't modify memory region attributes, they are @@ -244,7 +248,7 @@ void efi_adjust_memory_range_protection( status = efi_dxe_call(get_memory_space_descriptor, start, &desc); if (status != EFI_SUCCESS) - return; + break; next = desc.base_address + desc.length; @@ -269,8 +273,10 @@ void efi_adjust_memory_range_protection( unprotect_start, unprotect_start + unprotect_size, status); + break; } } + return EFI_SUCCESS; } static efi_char16_t *efistub_fw_vendor(void) @@ -800,9 +806,7 @@ static efi_status_t efi_decompress_kerne *kernel_entry = addr + entry; - efi_adjust_memory_range_protection(addr, kernel_total_size); - - return EFI_SUCCESS; + return efi_adjust_memory_range_protection(addr, kernel_total_size); } static void __noreturn enter_kernel(unsigned long kernel_addr, --- a/drivers/firmware/efi/libstub/x86-stub.h +++ b/drivers/firmware/efi/libstub/x86-stub.h @@ -5,8 +5,8 @@ extern void trampoline_32bit_src(void *, bool); extern const u16 trampoline_ljmp_imm_offset; -void efi_adjust_memory_range_protection(unsigned long start, - unsigned long size); +efi_status_t efi_adjust_memory_range_protection(unsigned long start, + unsigned long size); #ifdef CONFIG_X86_64 efi_status_t efi_setup_5level_paging(void); Patches currently in stable-queue which might be from ardb@xxxxxxxxxx are queue-6.1/x86-boot-compressed-avoid-touching-ecx-in-startup32_set_idt_entry.patch queue-6.1/x86-boot-compressed-only-build-mem_encrypt.s-if-amd_mem_encrypt-y.patch queue-6.1/x86-decompressor-avoid-magic-offsets-for-efi-handover-entrypoint.patch queue-6.1/efi-capsule-loader-fix-incorrect-allocation-size.patch queue-6.1/x86-efistub-avoid-placing-the-kernel-below-load_physical_addr.patch queue-6.1/x86-decompressor-move-global-symbol-references-to-c-code.patch queue-6.1/x86-boot-compressed-move-startup32_load_idt-into-.text-section.patch queue-6.1/x86-efistub-avoid-legacy-decompressor-when-doing-efi-boot.patch queue-6.1/x86-decompressor-only-call-the-trampoline-when-changing-paging-levels.patch queue-6.1/x86-efistub-give-up-if-memory-attribute-protocol-returns-an-error.patch queue-6.1/x86-boot-compressed-rename-efi_thunk_64.s-to-efi-mixed.s.patch queue-6.1/x86-decompressor-merge-trampoline-cleanup-with-switching-code.patch queue-6.1/x86-boot-compressed-move-efi32_pe_entry-out-of-head_64.s.patch queue-6.1/efi-verify-that-variable-services-are-supported.patch queue-6.1/x86-decompressor-call-trampoline-directly-from-c-code.patch queue-6.1/x86-efistub-perform-4-5-level-paging-switch-from-the-stub.patch queue-6.1/x86-boot-compressed-pull-global-variable-reference-into-startup32_load_idt.patch queue-6.1/x86-boot-rename-conflicting-boot_params-pointer-to-boot_params_ptr.patch queue-6.1/x86-efistub-perform-snp-feature-test-while-running-in-the-firmware.patch queue-6.1/x86-efistub-simplify-and-clean-up-handover-entry-code.patch queue-6.1/x86-boot-compressed-simplify-idt-gdt-preserve-restore-in-the-efi-thunk.patch queue-6.1/x86-decompressor-assign-paging-related-global-variables-earlier.patch queue-6.1/x86-boot-compressed-move-32-bit-entrypoint-code-into-.text-section.patch queue-6.1/efi-libstub-add-memory-attribute-protocol-definitions.patch queue-6.1/x86-boot-compressed-move-efi32_pe_entry-into-.text-section.patch queue-6.1/efi-libstub-add-limit-argument-to-efi_random_alloc.patch queue-6.1/x86-decompressor-avoid-the-need-for-a-stack-in-the-32-bit-trampoline.patch queue-6.1/x86-boot-compressed-move-startup32_check_sev_cbit-out-of-head_64.s.patch queue-6.1/x86-boot-compressed-efi-merge-multiple-definitions-of-image_offset-into-one.patch queue-6.1/x86-boot-compressed-move-startup32_load_idt-out-of-head_64.s.patch queue-6.1/efi-x86-fix-the-missing-kaslr_flag-bit-in-boot_params-hdr.loadflags.patch queue-6.1/decompress-use-8-byte-alignment.patch queue-6.1/x86-boot-compressed-move-efi32_entry-out-of-head_64.s.patch queue-6.1/efi-libstub-use-efi_loader_code-region-when-moving-the-kernel-in-memory.patch queue-6.1/crypto-arm64-neonbs-fix-out-of-bounds-access-on-short-input.patch queue-6.1/arm64-efi-limit-allocations-to-48-bit-addressable-physical-region.patch queue-6.1/x86-boot-compressed-move-bootargs-parsing-out-of-32-bit-startup-code.patch queue-6.1/efivarfs-request-at-most-512-bytes-for-variable-names.patch queue-6.1/x86-boot-compressed-adhere-to-calling-convention-in-get_sev_encryption_bit.patch queue-6.1/x86-boot-compressed-move-startup32_check_sev_cbit-into-.text.patch queue-6.1/x86-efistub-prefer-efi-memory-attributes-protocol-over-dxe-services.patch queue-6.1/efi-efivars-prevent-double-registration.patch queue-6.1/x86-decompressor-store-boot_params-pointer-in-callee-save-register.patch queue-6.1/x86-boot-efistub-assign-global-boot_params-variable.patch queue-6.1/x86-efistub-clear-bss-in-efi-handover-protocol-entrypoint.patch queue-6.1/x86-efistub-branch-straight-to-kernel-entry-point-from-c-code.patch queue-6.1/x86-decompressor-factor-out-kernel-decompression-and-relocation.patch queue-6.1/x86-decompressor-call-trampoline-as-a-normal-function.patch queue-6.1/x86-decompressor-pass-pgtable-address-to-trampoline-directly.patch queue-6.1/x86-decompressor-use-standard-calling-convention-for-trampoline.patch queue-6.1/efi-x86-avoid-physical-kaslr-on-older-dell-systems.patch queue-6.1/x86-efi-make-the-deprecated-efi-handover-protocol-optional.patch