Re: [PATCH 3/3] efi/libstub: consider CONFIG_CMDLINE for initrd= and dtb= options

From: Ard Biesheuvel
Date: Sat Oct 12 2024 - 03:55:23 EST


On Sat, 12 Oct 2024 at 00:52, Jonathan Marek <jonathan@xxxxxxxx> wrote:
>
> Replace cmdline with CONFIG_CMDLINE when it should be used instead of
> load_options.
>
> In the EXTEND case, it may be necessary to combine both CONFIG_CMDLINE and
> load_options. In that case, keep the old behavior and print a warning about
> the incorrect behavior.
>

The core kernel has its own handling for EXTEND/FORCE, so while we
should parse it in the EFI stub to look for options that affect the
stub's own behavior, we should not copy it into the command line that
the stub provides to the core kernel.

E.g., drivers/of/fdt.c takes the bootargs from the DT and combines
them with CONFIG_CMDLINE.


> Signed-off-by: Jonathan Marek <jonathan@xxxxxxxx>
> ---
> drivers/firmware/efi/libstub/file.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/drivers/firmware/efi/libstub/file.c b/drivers/firmware/efi/libstub/file.c
> index d6a025df07dcf..2a69e2b3583d4 100644
> --- a/drivers/firmware/efi/libstub/file.c
> +++ b/drivers/firmware/efi/libstub/file.c
> @@ -208,6 +208,18 @@ efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
> if (IS_ENABLED(CONFIG_X86) && !efi_nochunk)
> efi_chunk_size = EFI_READ_CHUNK_SIZE;
>
> + if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) ||
> + IS_ENABLED(CONFIG_CMDLINE_FORCE) ||
> + cmdline_len == 0) {
> + if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && cmdline_len > 0) {
> + /* both CONFIG_CMDLINE and load_options should be used */
> + efi_warn("ignoring %ls from CONFIG_CMDLINE\n", optstr);
> + } else {
> + cmdline = L"" CONFIG_CMDLINE;
> + cmdline_len = ARRAY_SIZE(L"" CONFIG_CMDLINE) - 1;
> + }
> + }
> +
> alloc_addr = alloc_size = 0;
> do {
> struct finfo fi;
> --
> 2.45.1
>