Linux EFI development
 help / color / mirror / Atom feed
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 v3 12/15] efi/zboot: Disentangle efi_remap_image() from efi_cache_sync_image()
Date: Mon, 16 Nov 2026 14:52:37 +0000	[thread overview]
Message-ID: <sashiko-outbox-217196@kernel.org> (raw)
In-Reply-To: <20261116142618.1687025-29-ardb+git@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] efi/zboot: unaligned code_size in efi_zboot_remap_image() on
  RISC-V
--

commit f296d871a4059f81fdcf9e8fdf0200c1435b74e5
Author: Ard Biesheuvel <ardb@kernel.org>

efi/zboot: Disentangle efi_remap_image() from efi_cache_sync_image()

This commit moves the efi_cache_sync_image() and efi_remap_image() calls out
of the decompressors and arm64's cache sync helper into efi_zboot_entry() via
a new efi_zboot_remap_image() helper.

> diff --git a/drivers/firmware/efi/libstub/zboot.c b/drivers/firmware/efi/libstub/zboot.c
> index 4cff756902ad4..9c7de225b39e5 100644
> --- a/drivers/firmware/efi/libstub/zboot.c
> +++ b/drivers/firmware/efi/libstub/zboot.c
> @@ -40,6 +40,17 @@ const struct efi_image_info *zboot_get_image_info(unsigned long image_base)
>  	return (void *)image_base + efistub_image_info_offset;
>  }
>  
> +static efi_status_t efi_zboot_remap_image(const struct efi_image_info *image_info,
> +					  unsigned long image_base,
> +					  unsigned long image_size)
> +{
> +	unsigned long code_size = efistub_kernel_codesize(image_info);
> +
> +	efi_cache_sync_image(image_base, code_size);
> +
> +	return efi_remap_image(image_base, image_size, code_size);
> +}
> +
>  asmlinkage efi_status_t __efiapi
>  efi_zboot_entry(efi_handle_t handle, efi_system_table_t *systab)
>  {
> @@ -107,7 +118,8 @@ efi_zboot_entry(efi_handle_t handle, efi_system_table_t *systab)
>  		goto error;
>  
>  	auto image_info = zboot_get_image_info(image_base);
> -	status = efi_stub_common(handle, image, image_info, cmdline_ptr);
> +	status = efi_zboot_remap_image(image_info, image_base, alloc_size) ?:
> +		 efi_stub_common(handle, image, image_info, cmdline_ptr);

[Severity: High]
Can efi_zboot_remap_image() pass a non-page-aligned code_size to
efi_remap_image() on RISC-V and abort the boot?

Previously, efi_remap_image() was only called from arm64's
efi_cache_sync_image() implementation.  Calling it from efi_zboot_entry()
now runs it on all zboot architectures and aborts the boot if it returns an
error.

efistub_kernel_codesize() returns __inittext_end - _text.  Unlike arm64 and
LoongArch, RISC-V places __inittext_end before the section and PE/COFF
alignment directives:

arch/riscv/kernel/vmlinux.lds.S:
	__inittext_end = .;
	. = ALIGN(SECTION_ALIGN);
#ifdef CONFIG_EFI
	. = ALIGN(PECOFF_SECTION_ALIGNMENT);
	__pecoff_text_end = .;
#endif

Because __inittext_end is only instruction-aligned on RISC-V, code_size
(along with image_base + code_size and alloc_size - code_size) is not a
multiple of EFI_PAGE_SIZE (4 KiB).  On UEFI firmware implementing
EFI_MEMORY_ATTRIBUTE_PROTOCOL, set_memory_attributes() and
clear_memory_attributes() reject the unaligned range with
EFI_INVALID_PARAMETER, causing efi_zboot_entry() to skip efi_stub_common()
and fail the boot.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116142618.1687025-17-ardb+git@google.com?part=12

  reply	other threads:[~2026-11-16 14:52 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 14:26 [PATCH v3 00/15] efi: Expose loaded image properties via info struct Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 01/15] efi/zboot: arm64: Add missing barrier after cache maintenance Ard Biesheuvel
2026-11-16 14:33   ` sashiko-bot
2026-11-16 14:26 ` [PATCH v3 02/15] riscv: Use _stext not _text to denote the start of kernel code Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 03/15] riscv: Make _text point to the start of the kernel image Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 04/15] efi/riscv: Rename __init_text_end to __inittext_end like other archs Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 05/15] efi/libstub: Avoid _end section marker in library code Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 06/15] efi/libstub: Capture loaded image information in struct efi_image_info Ard Biesheuvel
2026-11-16 14:59   ` sashiko-bot
2026-11-16 14:26 ` [PATCH v3 07/15] efi/libstub: Pass kernel entrypoint down to efi_enter_kernel() Ard Biesheuvel
2026-11-16 14:39   ` sashiko-bot
2026-11-16 14:26 ` [PATCH v3 08/15] efi/libstub: arm64: Use struct efi_image_info to access image properties Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 09/15] efi/libstub: loongarch: " Ard Biesheuvel
2026-11-16 14:40   ` sashiko-bot
2026-11-16 14:26 ` [PATCH v3 10/15] efi/libstub: riscv: " Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 11/15] efi/libstub: Make efi_remap_image() return efi_status_t Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 12/15] efi/zboot: Disentangle efi_remap_image() from efi_cache_sync_image() Ard Biesheuvel
2026-11-16 14:52   ` sashiko-bot [this message]
2026-11-16 14:26 ` [PATCH v3 13/15] efi/libstub: arm64: Drop zboot code_size hack Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 14/15] efi: Make config table based primary display handover ARM-only again Ard Biesheuvel
2026-11-16 14:26 ` [PATCH v3 15/15] 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-217196@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