From: Greg Kroah-Hartman Date: Sat, 30 Mar 2024 09:37:19 +0000 (+0100) Subject: 6.1-stable patches X-Git-Tag: v6.7.12~120 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=568ff4063b859c487959c5e450610569d54f4a55;p=thirdparty%2Fkernel%2Fstable-queue.git 6.1-stable patches added patches: efi-libstub-cast-away-type-warning-in-use-of-max.patch init-open-initrd.image-with-o_largefile.patch x86-efistub-add-missing-boot_params-for-mixed-mode-compat-entry.patch --- diff --git a/queue-6.1/efi-libstub-cast-away-type-warning-in-use-of-max.patch b/queue-6.1/efi-libstub-cast-away-type-warning-in-use-of-max.patch new file mode 100644 index 00000000000..d22f5cfe7d7 --- /dev/null +++ b/queue-6.1/efi-libstub-cast-away-type-warning-in-use-of-max.patch @@ -0,0 +1,30 @@ +From 61d130f261a3c15ae2c4b6f3ac3517d5d5b78855 Mon Sep 17 00:00:00 2001 +From: Ard Biesheuvel +Date: Tue, 26 Mar 2024 11:15:25 +0100 +Subject: efi/libstub: Cast away type warning in use of max() + +From: Ard Biesheuvel + +commit 61d130f261a3c15ae2c4b6f3ac3517d5d5b78855 upstream. + +Avoid a type mismatch warning in max() by switching to max_t() and +providing the type explicitly. + +Fixes: 3cb4a4827596abc82e ("efi/libstub: fix efi_random_alloc() ...") +Signed-off-by: Ard Biesheuvel +Signed-off-by: Greg Kroah-Hartman +--- + drivers/firmware/efi/libstub/randomalloc.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/drivers/firmware/efi/libstub/randomalloc.c ++++ b/drivers/firmware/efi/libstub/randomalloc.c +@@ -119,7 +119,7 @@ efi_status_t efi_random_alloc(unsigned l + continue; + } + +- target = round_up(max(md->phys_addr, alloc_min), align) + target_slot * align; ++ target = round_up(max_t(u64, md->phys_addr, alloc_min), align) + target_slot * align; + pages = size / EFI_PAGE_SIZE; + + status = efi_bs_call(allocate_pages, EFI_ALLOCATE_ADDRESS, diff --git a/queue-6.1/init-open-initrd.image-with-o_largefile.patch b/queue-6.1/init-open-initrd.image-with-o_largefile.patch new file mode 100644 index 00000000000..d714baccf39 --- /dev/null +++ b/queue-6.1/init-open-initrd.image-with-o_largefile.patch @@ -0,0 +1,36 @@ +From 4624b346cf67400ef46a31771011fb798dd2f999 Mon Sep 17 00:00:00 2001 +From: John Sperbeck +Date: Sun, 17 Mar 2024 15:15:22 -0700 +Subject: init: open /initrd.image with O_LARGEFILE + +From: John Sperbeck + +commit 4624b346cf67400ef46a31771011fb798dd2f999 upstream. + +If initrd data is larger than 2Gb, we'll eventually fail to write to the +/initrd.image file when we hit that limit, unless O_LARGEFILE is set. + +Link: https://lkml.kernel.org/r/20240317221522.896040-1-jsperbeck@google.com +Signed-off-by: John Sperbeck +Cc: Jens Axboe +Cc: Nick Desaulniers +Cc: Peter Zijlstra +Cc: Thomas Gleixner +Cc: +Signed-off-by: Andrew Morton +Signed-off-by: Greg Kroah-Hartman +--- + init/initramfs.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/init/initramfs.c ++++ b/init/initramfs.c +@@ -680,7 +680,7 @@ static void __init populate_initrd_image + + printk(KERN_INFO "rootfs image is not initramfs (%s); looks like an initrd\n", + err); +- file = filp_open("/initrd.image", O_WRONLY | O_CREAT, 0700); ++ file = filp_open("/initrd.image", O_WRONLY|O_CREAT|O_LARGEFILE, 0700); + if (IS_ERR(file)) + return; + diff --git a/queue-6.1/series b/queue-6.1/series index 414a157bbdf..eba8281f1c1 100644 --- a/queue-6.1/series +++ b/queue-6.1/series @@ -207,3 +207,6 @@ x86-coco-get-rid-of-accessor-functions.patch x86-kconfig-remove-config_amd_mem_encrypt_active_by_default.patch x86-sev-fix-position-dependent-variable-references-in-startup-code.patch mm-migrate-set-swap-entry-values-of-thp-tail-pages-properly.patch +init-open-initrd.image-with-o_largefile.patch +x86-efistub-add-missing-boot_params-for-mixed-mode-compat-entry.patch +efi-libstub-cast-away-type-warning-in-use-of-max.patch diff --git a/queue-6.1/x86-efistub-add-missing-boot_params-for-mixed-mode-compat-entry.patch b/queue-6.1/x86-efistub-add-missing-boot_params-for-mixed-mode-compat-entry.patch new file mode 100644 index 00000000000..52005040875 --- /dev/null +++ b/queue-6.1/x86-efistub-add-missing-boot_params-for-mixed-mode-compat-entry.patch @@ -0,0 +1,142 @@ +From d21f5a59ea773826cc489acb287811d690b703cc Mon Sep 17 00:00:00 2001 +From: Ard Biesheuvel +Date: Sun, 24 Mar 2024 17:10:53 +0100 +Subject: x86/efistub: Add missing boot_params for mixed mode compat entry + +From: Ard Biesheuvel + +commit d21f5a59ea773826cc489acb287811d690b703cc upstream. + +The pure EFI stub entry point does not take a struct boot_params from +the boot loader, but creates it from scratch, and populates only the +fields that still have meaning in this context (command line, initrd +base and size, etc) + +The original mixed mode implementation used the EFI handover protocol +instead, where the boot loader (i.e., GRUB) populates a boot_params +struct and passes it to a special Linux specific EFI entry point that +takes the boot_params pointer as its third argument. + +When the new mixed mode implementation was introduced, using a special +32-bit PE entrypoint in the 64-bit kernel, it adopted the pure approach, +and relied on the EFI stub to create the struct boot_params. This is +preferred because it makes the bootloader side much easier to implement, +as it does not need any x86-specific knowledge on how struct boot_params +and struct setup_header are put together. This mixed mode implementation +was adopted by systemd-boot version 252 and later. + +When commit + + e2ab9eab324c ("x86/boot/compressed: Move 32-bit entrypoint code into .text section") + +refactored this code and moved it out of head_64.S, the fact that ESI +was populated with the address of the base of the image was overlooked, +and to simplify the code flow, ESI is now zeroed and stored to memory +unconditionally in shared code, so that the NULL-ness of that variable +can still be used later to determine which mixed mode boot protocol is +in use. + +With ESI pointing to the base of the image, it can serve as a struct +boot_params pointer for startup_32(), which only accesses the init_data +and kernel_alignment fields (and the scratch field as a temporary +stack). Zeroing ESI means that those accesses produce garbage now, even +though things appear to work if the first page of memory happens to be +zeroed, and the region right before LOAD_PHYSICAL_ADDR (== 16 MiB) +happens to be free. + +The solution is to pass a special, temporary struct boot_params to +startup_32() via ESI, one that is sufficient for getting it to create +the page tables correctly and is discarded right after. This involves +setting a minimal alignment of 4k, only to get the statically allocated +page tables line up correctly, and setting init_size to the executable +image size (_end - startup_32). This ensures that the page tables are +covered by the static footprint of the PE image. + +Given that EFI boot no longer calls the decompressor and no longer pads +the image to permit the decompressor to execute in place, the same +temporary struct boot_params should be used in the EFI handover protocol +based mixed mode implementation as well, to prevent the page tables from +being placed outside of allocated memory. + +Fixes: e2ab9eab324c ("x86/boot/compressed: Move 32-bit entrypoint code into .text section") +Cc: # v6.1+ +Closes: https://lore.kernel.org/all/20240321150510.GI8211@craftyguy.net/ +Reported-by: Clayton Craft +Tested-by: Clayton Craft +Tested-by: Hans de Goede +Signed-off-by: Ard Biesheuvel +Signed-off-by: Greg Kroah-Hartman +--- + arch/x86/boot/compressed/efi_mixed.S | 20 +++++++++++++++----- + 1 file changed, 15 insertions(+), 5 deletions(-) + +--- a/arch/x86/boot/compressed/efi_mixed.S ++++ b/arch/x86/boot/compressed/efi_mixed.S +@@ -15,10 +15,12 @@ + */ + + #include ++#include + #include + #include + #include + #include ++#include + + .code64 + .text +@@ -155,6 +157,7 @@ SYM_FUNC_END(__efi64_thunk) + SYM_FUNC_START(efi32_stub_entry) + call 1f + 1: popl %ecx ++ leal (efi32_boot_args - 1b)(%ecx), %ebx + + /* Clear BSS */ + xorl %eax, %eax +@@ -169,6 +172,7 @@ SYM_FUNC_START(efi32_stub_entry) + popl %ecx + popl %edx + popl %esi ++ movl %esi, 8(%ebx) + jmp efi32_entry + SYM_FUNC_END(efi32_stub_entry) + #endif +@@ -245,8 +249,6 @@ SYM_FUNC_END(efi_enter32) + * + * Arguments: %ecx image handle + * %edx EFI system table pointer +- * %esi struct bootparams pointer (or NULL when not using +- * the EFI handover protocol) + * + * Since this is the point of no return for ordinary execution, no registers + * are considered live except for the function parameters. [Note that the EFI +@@ -272,9 +274,18 @@ SYM_FUNC_START_LOCAL(efi32_entry) + leal (efi32_boot_args - 1b)(%ebx), %ebx + movl %ecx, 0(%ebx) + movl %edx, 4(%ebx) +- movl %esi, 8(%ebx) + movb $0x0, 12(%ebx) // efi_is64 + ++ /* ++ * Allocate some memory for a temporary struct boot_params, which only ++ * needs the minimal pieces that startup_32() relies on. ++ */ ++ subl $PARAM_SIZE, %esp ++ movl %esp, %esi ++ movl $PAGE_SIZE, BP_kernel_alignment(%esi) ++ movl $_end - 1b, BP_init_size(%esi) ++ subl $startup_32 - 1b, BP_init_size(%esi) ++ + /* Disable paging */ + movl %cr0, %eax + btrl $X86_CR0_PG_BIT, %eax +@@ -300,8 +311,7 @@ SYM_FUNC_START(efi32_pe_entry) + + movl 8(%ebp), %ecx // image_handle + movl 12(%ebp), %edx // sys_table +- xorl %esi, %esi +- jmp efi32_entry // pass %ecx, %edx, %esi ++ jmp efi32_entry // pass %ecx, %edx + // no other registers remain live + + 2: popl %edi // restore callee-save registers