From nobody Wed Nov 27 04:55:12 2024 Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90B6313698B for ; Sun, 13 Oct 2024 05:16:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728796606; cv=none; b=cLSuv9eKl6Mz9g3DXutWnxVYbC4o0vdiHi1WJAEtNqlkFl/6zy7v1aNckMLYaWzWytWd3aWF1AHLe/1QdIT65gMPLiBwZYZpTD4t2hHoCTL3SZLSMODI+3egyAexnXsX+XpUSdQLV2vUNgh76vNsS5X+1r6b7pf1ldzzFsKUvlI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728796606; c=relaxed/simple; bh=sRtVbwNxdfVu2vbZgaqrwb50MI2xFXkt8+JflgP2Ng4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HIAbxmxoPO5lpxXCRBd69uXddiZhK39HoG13/NhjCyYYy6BxCjQphYTESeWaR9TbJID0ynD9EFsd3gzTm3GB9SoM517nsk0qbxKr0XCK7mWXl31AhAJaJb/jVtjmY041N1FowNnCY+DjbHO2XBVDEzAbFPLhAo80ENeW72H2JoY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=marek.ca; spf=pass smtp.mailfrom=marek.ca; dkim=pass (2048-bit key) header.d=marek.ca header.i=@marek.ca header.b=RW4owqNQ; arc=none smtp.client-ip=209.85.160.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=marek.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marek.ca Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marek.ca header.i=@marek.ca header.b="RW4owqNQ" Received: by mail-qt1-f169.google.com with SMTP id d75a77b69052e-46045199e4dso34975381cf.3 for ; Sat, 12 Oct 2024 22:16:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marek.ca; s=google; t=1728796603; x=1729401403; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lsemdzDcD3ScL7UtYb4qSNAEzD93a7YTEXoVruVLDeo=; b=RW4owqNQM8VT51X8ZyiQs+6hMruDBp5Ybm88tYEaoXz8aZtIlhTpWkDNUBhTBLZvnr s/BH4w9G0GFD+7PNQsjCTk8nBCOiCw4IqOAD8r+ND06mXuGbdN5v/TCFVORsiD4xAKml cPWBNqi+U/4zme24QZNHEKar4mtY6VsO6iiqML3ZRhWBVXlcSERPIYYFMXf4xZ/BXwIO Yx7WbhZJ66hbVZQkODG+b3WFJWNXJ3noL2TnegCKCJtHsg8QrUDiEl6ukqodJSgUb1zI e4TNEdWJgpodW13sbxv077tZyw+Hgzcc7cDHVXOfXvqQvDzyALxbeaF/nWt4lVQLB3LN SNCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728796603; x=1729401403; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lsemdzDcD3ScL7UtYb4qSNAEzD93a7YTEXoVruVLDeo=; b=ScpHgJQK83yS/GUekfeCfb9u25tBHmwwn10PPMBqUDXSneo1HKRfb5GpSn/kW0ycJ5 JvhaNxEWEaD+U4UiQG41JVCfBXApMofWxpcdRUPbtKJRxNeEX46+GgnrnI0OrssKuTui Nv3iO9L735YMbkYex3hz4Qq5XwECGOe4JButevDmFUa3pnfDjs+SEauo3EL4Lz880626 4bYJjivDuQMIHrwA7yn2uQsTUO01hcI8TJLICczFtBxYJuo+6mEKBRhwHBdemE3MHnLJ uxnP1voNjeu5KLRSk2goHdbnuEw0dNzU6m1FDJcw4IZiLQco4cLkaR2kOaUwyrPvrqPN TQXw== X-Forwarded-Encrypted: i=1; AJvYcCWWl1YGddazvn9puG4Il9BLeFQXlIQTOp4r2ifRxlytEDhXvruOPp0z+UbOTbh2fkaW73funkCgV8Zz8u8=@vger.kernel.org X-Gm-Message-State: AOJu0YzWWSvHYjKaZqrx0xAn/qSDX6K6YcZ6NIAzIB8WSWk/LdUwHoAs wBBrrBUGvTtaU7YO5BQwDH5JOPfutpx8h7fg5A6O5UCPwppfsIpYOaXPn2bmp/ntu8eUmjIsYBi SwWk= X-Google-Smtp-Source: AGHT+IEJcVxGqbdsBJXR94Q+RFwE89gyLs20hW2lUTpW+OZmmGTlP++w1tn9M0e5g55xMNBBUkWP1A== X-Received: by 2002:a05:622a:1a1b:b0:458:5e19:b3a4 with SMTP id d75a77b69052e-460584b4f3bmr83882861cf.38.1728796603424; Sat, 12 Oct 2024 22:16:43 -0700 (PDT) Received: from localhost.localdomain (modemcable125.110-19-135.mc.videotron.ca. [135.19.110.125]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-460427dafc0sm31457681cf.35.2024.10.12.22.16.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Oct 2024 22:16:43 -0700 (PDT) From: Jonathan Marek To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Kuppuswamy Sathyanarayanan , Ingo Molnar , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 1/2] efi/libstub: fix efi_parse_options() ignoring the default command line Date: Sun, 13 Oct 2024 01:11:56 -0400 Message-ID: <20241013051239.22564-2-jonathan@marek.ca> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241013051239.22564-1-jonathan@marek.ca> References: <20241013051239.22564-1-jonathan@marek.ca> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" efi_convert_cmdline() always returns a size of at least 1 because it counts the NUL terminator, so the "cmdline_size =3D=3D 0" condition is not possibl= e. Change it to check if the string starts with a NUL character to get the intended behavior: to use CONFIG_CMDLINE when load_options_size is 0. Fixes: 60f38de7a8d4 ("efi/libstub: Unify command line param parsing") Signed-off-by: Jonathan Marek --- drivers/firmware/efi/libstub/efi-stub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi= /libstub/efi-stub.c index 958a680e0660d..2a1b43f9e0fa2 100644 --- a/drivers/firmware/efi/libstub/efi-stub.c +++ b/drivers/firmware/efi/libstub/efi-stub.c @@ -129,7 +129,7 @@ efi_status_t efi_handle_cmdline(efi_loaded_image_t *ima= ge, char **cmdline_ptr) =20 if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || IS_ENABLED(CONFIG_CMDLINE_FORCE) || - cmdline_size =3D=3D 0) { + cmdline[0] =3D=3D 0) { status =3D efi_parse_options(CONFIG_CMDLINE); if (status !=3D EFI_SUCCESS) { efi_err("Failed to parse options\n"); --=20 2.45.1 From nobody Wed Nov 27 04:55:12 2024 Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7121013C677 for ; Sun, 13 Oct 2024 05:16:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728796616; cv=none; b=gN2nR8B4YlTxquSQFI3eulHBCqX7Qhr7bjNMdV4uxIRHMGHERQDbnDSSKp+VapN3hGTwSV1fxt4vbod/LJQKWsnEh8prk8MxgalkmPEgMthIVvkBfWuNhElrv2SZuBs95IH8BZB01k2rC7ZrXAkg0jJjXu4Ytp9C16QYNq2lyic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728796616; c=relaxed/simple; bh=fIzRBXSOO+dxpaYVoJyqkg9GLudSmxuh9CFKoFX8k14=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NQOSW2J4CfnkXRHcvGXtWti4vdK+xd3HVD++rLPW1g5aJ0HrofXJApkDgjC6tPLA6q1HVkZgOWvFBBYrvrxygfDChH7UXwMfy+vticwl2arxcDuNAea8bGYkHqQ5HZUSepDM9h2U7u63QzeuBj39MFCv/SR++9ECaAK0WvMmobY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=marek.ca; spf=pass smtp.mailfrom=marek.ca; dkim=pass (2048-bit key) header.d=marek.ca header.i=@marek.ca header.b=c7kXOqTK; arc=none smtp.client-ip=209.85.160.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=marek.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=marek.ca Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=marek.ca header.i=@marek.ca header.b="c7kXOqTK" Received: by mail-qt1-f177.google.com with SMTP id d75a77b69052e-45f05f87ca5so18765101cf.2 for ; Sat, 12 Oct 2024 22:16:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marek.ca; s=google; t=1728796613; x=1729401413; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UFCs9PVCOi6nYpoct0VXtnvh8Q54CTxgvHENhcgbqFw=; b=c7kXOqTKuWxcUSIXOLiWlQnthDTpRpzu1Bmp32d1jXx/eC8BUzpZczF9Sh2TXG5e8y 9oiTCYwomBROXwtUhzLaRS+eMrfQ9QlN8+0tFuVW7vbh6H90Ar8aiXuS+VmO5ZWaQHXp +IKFdncOptkUvcvJ/Q0KQSx8SBrq7HicTdjFSDkLd/w6prZPd3tUsCyLoL8BBw5Ho6AL /3grdBKgqeaP44hmgl1RNiKXRzwcQOYuoBLf1Tx3vFuiusZnfK3qyqrd/u/Oso+0fCrw PAC52Gny/DuMnoq8pnqvJ1dIBO8u9NWC0gwL0KP1P0+r6OgqO8gfJvIsgQM0HglttYuR O4mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728796613; x=1729401413; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UFCs9PVCOi6nYpoct0VXtnvh8Q54CTxgvHENhcgbqFw=; b=qIHU55qSCfp17MYaF43eKKCwaUzznFfrWAI4TJxqWsUFpB07nirLQMCvh3mU6cGv9p ud0r+dKMyy2ByPQsK8xVP7EGexZ7s+C27JWLk3pP3I9Kc0D0rY1/pyephZd8J8VOyoGk 5bg4NL8cpnHVHmma+GQmLbJ8y7LNqrSkpbkjmr8TQrDoXATNIBJWXLXyZxmUCohtK8aM QxC6DyHn8dn0QtZvRtJy32AzJBpv4mw6hAwf7BYJw4tNSFAZgG219jGgAyPHs9/S6TAY CBgipydrDqoUrZEVipW8r4wfeCMlZw+gJYqE34jy4voPlOoOo6VQEtxGYJlEeQ0Bp+W1 ja8A== X-Forwarded-Encrypted: i=1; AJvYcCX6H49DG0W+j4mIO3HwbeJkotpfhwzy6UZ5CuKsjb6BvH/SBvvJksAK1CW6K742jdZf/tFLWRld7mH4DTY=@vger.kernel.org X-Gm-Message-State: AOJu0YyqUOKljpM2f2a+VIBxiuRvGoB8yvt+gg0vn5qsXOyhEoLVKi6y 0vargUe+z/e02SF2hvsWBl1Cs88hIYrp9O3ae1cMt45w7a5AeKKlzoYpmPSawiA= X-Google-Smtp-Source: AGHT+IHG/xSyGmuyE8zwbcJNVk9iuBjHLpkXy8T1dg6AUG/GGj7Wobe9jHwQHwbRGzlAQ/O6I9nPgQ== X-Received: by 2002:ac8:7d47:0:b0:458:4eae:6c6c with SMTP id d75a77b69052e-4604bbcccb2mr102971461cf.30.1728796613223; Sat, 12 Oct 2024 22:16:53 -0700 (PDT) Received: from localhost.localdomain (modemcable125.110-19-135.mc.videotron.ca. [135.19.110.125]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-460427dafc0sm31457681cf.35.2024.10.12.22.16.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Oct 2024 22:16:52 -0700 (PDT) From: Jonathan Marek To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Kuppuswamy Sathyanarayanan , "Borislav Petkov (AMD)" , "Kirill A. Shutemov" , Kees Cook , Aditya Garg , Nikolay Borisov , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 2/2] efi/libstub: remove unnecessary cmd_line_len from efi_convert_cmdline() Date: Sun, 13 Oct 2024 01:11:57 -0400 Message-ID: <20241013051239.22564-3-jonathan@marek.ca> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241013051239.22564-1-jonathan@marek.ca> References: <20241013051239.22564-1-jonathan@marek.ca> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" efi_convert_cmdline() always sets cmdline_size to at least 1 on success, so the "cmdline_size > 0" does nothing and can be removed (the intent was to avoid parsing an empty string, but there is nothing wrong with parsing an empty string, it is only making boot negligibly slower). Then the cmd_line_len argument to efi_convert_cmdline can be removed because there is nothing left using it. Signed-off-by: Jonathan Marek --- drivers/firmware/efi/libstub/efi-stub-helper.c | 3 +-- drivers/firmware/efi/libstub/efi-stub.c | 5 ++--- drivers/firmware/efi/libstub/efistub.h | 2 +- drivers/firmware/efi/libstub/x86-stub.c | 3 +-- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmw= are/efi/libstub/efi-stub-helper.c index de659f6a815fd..e7346f8edb38c 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -327,7 +327,7 @@ static efi_status_t efi_measure_tagged_event(unsigned l= ong load_addr, * Size of memory allocated return in *cmd_line_len. * Returns NULL on error. */ -char *efi_convert_cmdline(efi_loaded_image_t *image, int *cmd_line_len) +char *efi_convert_cmdline(efi_loaded_image_t *image) { const efi_char16_t *options =3D efi_table_attr(image, load_options); u32 options_size =3D efi_table_attr(image, load_options_size); @@ -405,7 +405,6 @@ char *efi_convert_cmdline(efi_loaded_image_t *image, in= t *cmd_line_len) snprintf((char *)cmdline_addr, options_bytes, "%.*ls", options_bytes - 1, options); =20 - *cmd_line_len =3D options_bytes; return (char *)cmdline_addr; } =20 diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi= /libstub/efi-stub.c index 2a1b43f9e0fa2..f09e277ba2108 100644 --- a/drivers/firmware/efi/libstub/efi-stub.c +++ b/drivers/firmware/efi/libstub/efi-stub.c @@ -112,7 +112,6 @@ static u32 get_supported_rt_services(void) =20 efi_status_t efi_handle_cmdline(efi_loaded_image_t *image, char **cmdline_= ptr) { - int cmdline_size =3D 0; efi_status_t status; char *cmdline; =20 @@ -121,7 +120,7 @@ efi_status_t efi_handle_cmdline(efi_loaded_image_t *ima= ge, char **cmdline_ptr) * protocol. We are going to copy the command line into the * device tree, so this can be allocated anywhere. */ - cmdline =3D efi_convert_cmdline(image, &cmdline_size); + cmdline =3D efi_convert_cmdline(image); if (!cmdline) { efi_err("getting command line via LOADED_IMAGE_PROTOCOL\n"); return EFI_OUT_OF_RESOURCES; @@ -137,7 +136,7 @@ efi_status_t efi_handle_cmdline(efi_loaded_image_t *ima= ge, char **cmdline_ptr) } } =20 - if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && cmdline_size > 0) { + if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) { status =3D efi_parse_options(cmdline); if (status !=3D EFI_SUCCESS) { efi_err("Failed to parse options\n"); diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/= libstub/efistub.h index 685098f9626f2..76e44c185f29e 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -1056,7 +1056,7 @@ void efi_free(unsigned long size, unsigned long addr); =20 void efi_apply_loadoptions_quirk(const void **load_options, u32 *load_opti= ons_size); =20 -char *efi_convert_cmdline(efi_loaded_image_t *image, int *cmd_line_len); +char *efi_convert_cmdline(efi_loaded_image_t *image); =20 efi_status_t efi_get_memory_map(struct efi_boot_memmap **map, bool install_cfg_tbl); diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi= /libstub/x86-stub.c index f8e465da344d5..188c8000d245e 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -537,7 +537,6 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, efi_guid_t proto =3D LOADED_IMAGE_PROTOCOL_GUID; struct boot_params *boot_params; struct setup_header *hdr; - int options_size =3D 0; efi_status_t status; unsigned long alloc; char *cmdline_ptr; @@ -569,7 +568,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, hdr->initrd_addr_max =3D INT_MAX; =20 /* Convert unicode cmdline to ascii */ - cmdline_ptr =3D efi_convert_cmdline(image, &options_size); + cmdline_ptr =3D efi_convert_cmdline(image); if (!cmdline_ptr) { efi_free(PARAM_SIZE, alloc); efi_exit(handle, EFI_OUT_OF_RESOURCES); --=20 2.45.1