From: sashiko-bot@kernel.org
To: "Ard Biesheuvel" <ardb+git@google.com>, linux-efi@vger.kernel.org
Cc: "Ard Biesheuvel" <ardb@kernel.org>,
"Jason Gunthorpe" <jgg@nvidia.com>,
"Paul Walmsley" <pjw@kernel.org>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Albert Ou" <aou@eecs.berkeley.edu>,
"Huacai Chen" <chenhuacai@kernel.org>
Subject: Re: [PATCH v4 06/19] efi/libstub: arm: Size the decompressed kernel allocation precisely
Date: Wed, 18 Nov 2026 18:41:01 +0000 [thread overview]
Message-ID: <sashiko-outbox-221779@kernel.org> (raw)
In-Reply-To: <20261118182105.1633603-27-ardb+git@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] efi/libstub: arm: unaligned u32 read in handle_kernel_image()
--
commit b84ef299db1b32d7220e230864d358882c52170f
Author: Ard Biesheuvel <ardb@kernel.org>
efi/libstub: arm: Size the decompressed kernel allocation precisely
This commit sizes the ARM EFI stub's reserved memory window for the
decompressed kernel using the uncompressed image size, BSS size, and
initial page table size instead of a fixed 32 MiB limit, and reduces
EFI_PHYS_ALIGN to 2 MiB.
> diff --git a/drivers/firmware/efi/libstub/arm32-stub.c b/drivers/firmware/efi/libstub/arm32-stub.c
> index 1073dd9475160..1ab15d66e7092 100644
> --- a/drivers/firmware/efi/libstub/arm32-stub.c
> +++ b/drivers/firmware/efi/libstub/arm32-stub.c
> @@ -76,6 +76,12 @@ void efi_handle_post_ebs_state(void)
> &efi_entry_state->sctlr_after_ebs);
> }
>
> +/* last unaligned u32 in the image carries the uncompressed size */
> +extern u32 input_data_end[] __aligned(1);
> +
> +/* entry #3 in the zimage magic table carries the kernel's BSS size */
> +extern u32 zimage_magic_table[] asm("_table_start");
> +
> efi_status_t handle_kernel_image(unsigned long *image_addr,
> unsigned long *image_size,
> unsigned long *reserve_addr,
> @@ -83,18 +89,22 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
> efi_loaded_image_t *image,
> efi_handle_t image_handle)
> {
> - const int slack = TEXT_OFFSET - 5 * PAGE_SIZE;
> - int alloc_size = MAX_UNCOMP_KERNEL_SIZE + EFI_PHYS_ALIGN;
> + unsigned long kernel_memsize = input_data_end[-1] + zimage_magic_table[3];
[Severity: High]
Does input_data_end[-1] still perform a 4-byte-aligned word load when the
compressed payload length is not a multiple of 4?
In C, __aligned(1) on an array variable declaration applies to the array
symbol rather than the element type, so input_data_end decays to u32 * and
compilers emit a 32-bit ldr instruction even under -malignment-traps. In
arch/arm/boot/compressed/vmlinux.lds.S, input_data_end immediately follows
*(.piggydata) before . = ALIGN(4), so input_data_end - 4 has only 1-byte
alignment and triggers an alignment fault when the stub runs with the MMU
disabled or alignment traps enabled. Reading the size with
get_unaligned_le32((u8 *)input_data_end - 4) avoids the aligned u32
dereference.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118182105.1633603-21-ardb+git@google.com?part=6
next prev parent reply other threads:[~2026-11-18 18:41 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 18:21 [PATCH v4 00/19] efi: Expose loaded image properties via info struct Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 01/19] efi/zboot: arm64: Add missing barrier after cache maintenance Ard Biesheuvel
2026-11-18 18:28 ` sashiko-bot
2026-11-18 18:21 ` [PATCH v4 02/19] riscv: Use _stext not _text to denote the start of kernel code Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 03/19] riscv: Make _text point to the start of the kernel image Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 04/19] efi/riscv: Rename __init_text_end to __inittext_end like other archs Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 05/19] efi/libstub: Avoid _end section marker in library code Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 06/19] efi/libstub: arm: Size the decompressed kernel allocation precisely Ard Biesheuvel
2026-11-18 18:41 ` sashiko-bot [this message]
2026-11-18 18:21 ` [PATCH v4 07/19] efi/libstub: Avoid reserve_addr/_size in efi_kaslr_relocate_kernel() Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 08/19] efi/libstub: Capture loaded image information in struct efi_image_info Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 09/19] efi/libstub: Pass kernel entrypoint down to efi_enter_kernel() Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 10/19] efi/libstub: arm: Simplify handle_kernel_image() Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 11/19] efi/libstub: Drop reserve_addr/_size params from handle_kernel_image() Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 12/19] efi/libstub: arm64: Use struct efi_image_info to access image properties Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 13/19] efi/libstub: loongarch: " Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 14/19] efi/libstub: riscv: " Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 15/19] efi/libstub: Make efi_remap_image() return efi_status_t Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 16/19] efi/zboot: Disentangle efi_remap_image() from efi_cache_sync_image() Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 17/19] efi/libstub: arm64: Drop zboot code_size hack Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 18/19] efi: Make config table based primary display handover ARM-only again Ard Biesheuvel
2026-11-18 18:21 ` [PATCH v4 19/19] Revert "efi: earlycon: Reprobe after parsing config tables" Ard Biesheuvel
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=sashiko-outbox-221779@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=aou@eecs.berkeley.edu \
--cc=ardb+git@google.com \
--cc=ardb@kernel.org \
--cc=chenhuacai@kernel.org \
--cc=jgg@nvidia.com \
--cc=linux-efi@vger.kernel.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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