From: Giacomo Mazzola <gmazz@amazon.de>
To: <kvm@vger.kernel.org>
Cc: Giacomo Mazzola <gmazz@amazon.de>, Andrew Jones <andrew.jones@linux.dev>
Subject: [kvm-unit-tests PATCH v2 7/8] efi: fix load_options_size conversion to character count
Date: Tue, 20 Oct 2026 15:25:24 +0000 [thread overview]
Message-ID: <20261020152525.57694-8-gmazz@amazon.de> (raw)
In-Reply-To: <20261020152525.57694-1-gmazz@amazon.de>
load_options_size is in bytes, but options_chars is used as the
iteration count over the u16 load options array. Divide by
sizeof(u16) to convert from bytes to UTF-16 code units; without
this, the loop reads past the end of the load options buffer.
The original Linux kernel code (drivers/firmware/efi/libstub/
efi-stub-helper.c) from which this function was adapted performs
the same conversion:
options_chars = options_size / sizeof(efi_char16_t);
This was lost when the function was ported to KUT.
Fixes: 85c3c524 ("lib/efi: Add support for getting the cmdline")
Signed-off-by: Giacomo Mazzola <gmazz@amazon.de>
Reviewed-by: Andrew Jones <andrew.jones@linux.dev>
---
lib/efi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/efi.c b/lib/efi.c
index f396bd71..d1be2bfc 100644
--- a/lib/efi.c
+++ b/lib/efi.c
@@ -134,7 +134,7 @@ static char *efi_convert_cmdline(struct efi_loaded_image_64 *image, int *cmd_lin
{
const u16 *s2;
unsigned long cmdline_addr = 0;
- int options_chars = image->load_options_size;
+ int options_chars = image->load_options_size / sizeof(u16);
const u16 *options = image->load_options;
int options_bytes = 0, safe_options_bytes = 0; /* UTF-8 bytes */
bool in_quote = false;
--
2.47.3
next prev parent reply other threads:[~2026-10-20 15:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 15:25 [kvm-unit-tests PATCH v2 0/8] x86: fixes for running KUT as EFI on non-QEMU KVM hosts Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 1/8] x86: efi: use PER_CPU_SIZE for per-CPU stack allocation Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 2/8] x86: fix EFI memory allocator to clamp regions to 4 GiB Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 3/8] x86: skip PMU init when no PMU is advertised Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 4/8] x86: fix ISR thunk to use absolute indirect jump Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 5/8] x86: replace per-AP bringup prints with a single summary line Giacomo Mazzola
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 6/8] x86: add timeout-based SMP bringup when fw_cfg is unavailable Giacomo Mazzola
2026-10-20 15:25 ` Giacomo Mazzola [this message]
2026-10-20 15:25 ` [kvm-unit-tests PATCH v2 8/8] lib: parse KUT_ENV= from command line into environ Giacomo Mazzola
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=20261020152525.57694-8-gmazz@amazon.de \
--to=gmazz@amazon.de \
--cc=andrew.jones@linux.dev \
--cc=kvm@vger.kernel.org \
/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