From: Vincent Mailhol <mailhol@kernel.org>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: linux-efi@vger.kernel.org, x86@kernel.org,
linux-kernel@vger.kernel.org,
Vincent Mailhol <mailhol@kernel.org>
Subject: [PATCH] efi: pass NUL-inclusive sizes to ucs2_as_utf8()
Date: Tue, 8 Sep 2026 19:24:34 +0200 [thread overview]
Message-ID: <20260908172555.3356-1-mailhol@kernel.org> (raw)
In-Reply-To: <20260906130817.1151961-9-ardb@kernel.org>
An upcoming change will update ucs2_as_utf8() to expose a strscpy()
style API where the size argument is the destination buffer size,
including space for the final NUL terminator.
Some EFI callers currently pass the exact number of UTF-8 payload bytes
that they expect to copy and add the terminator themselves afterwards.
Extend those sizes to include the final NUL terminator so the upcoming
contract change does not truncate the converted output by one byte.
Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
---
Hi Ard,
I saw that you pushed on efi-libstub-native-utf16 WIP branch [1] and did
some testing, despite those changes not yet submitted for review.
There is an off-by-one error following your ucs2_as_utf8() code
refactor. This patch prevents the issue. It should be cherry-picked just
before your "efi/libstub: Use ucs2_string library for UTF-16 to UTF-8
conversion" commit.
There is one final off-by-one in "efi/libstub: Use ucs2_string library
for UTF-16 to UTF-8 conversion" itself. This is the fix:
---8<---
diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
index e9b714ca811db..db0bde514f7fd 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -379,8 +379,7 @@ char *efi_convert_cmdline(efi_loaded_image_t *image)
if (status != EFI_SUCCESS)
return NULL;
- ucs2_as_utf8(cmdline_addr, options, options_bytes - 1);
- cmdline_addr[options_bytes - 1] = '\0';
+ ucs2_as_utf8(cmdline_addr, options, options_bytes);
return cmdline_addr;
}
---8<---
[1] https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/log/?h=efi-libstub-native-utf16
---
drivers/firmware/efi/efi.c | 2 +-
fs/efivarfs/vars.c | 5 ++---
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 6d987d7f97781..221804e7d5390 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -304,7 +304,7 @@ static __init int efivar_ssdt_load(void)
}
limit = min(EFIVAR_SSDT_NAME_MAX, name_size);
- ucs2_as_utf8(utf8_name, name, limit - 1);
+ ucs2_as_utf8(utf8_name, name, limit);
if (strncmp(utf8_name, efivar_ssdt, limit) != 0)
continue;
diff --git a/fs/efivarfs/vars.c b/fs/efivarfs/vars.c
index 6833c3d24b541..1ddc89e13518f 100644
--- a/fs/efivarfs/vars.c
+++ b/fs/efivarfs/vars.c
@@ -237,7 +237,7 @@ efivar_get_utf8name(const efi_char16_t *name16, efi_guid_t *vendor)
if (!name)
return NULL;
- ucs2_as_utf8(name, name16, len);
+ ucs2_as_utf8(name, name16, len + 1);
name[len] = '-';
@@ -264,8 +264,7 @@ efivar_validate(efi_guid_t vendor, efi_char16_t *var_name, u8 *data,
if (!utf8_name)
return false;
- ucs2_as_utf8(utf8_name, var_name, utf8_size);
- utf8_name[utf8_size] = '\0';
+ ucs2_as_utf8(utf8_name, var_name, utf8_size + 1);
for (i = 0; variable_validate[i].name[0] != '\0'; i++) {
const char *name = variable_validate[i].name;
--
2.43.0
next prev parent reply other threads:[~2026-09-08 17:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-06 13:08 [PATCH 0/7] efi/libstub: Avoid UTF-16 conversion busywork Ard Biesheuvel
2026-09-06 13:08 ` [PATCH 1/7] x86/boot: Drop pointless re-implementation of panic() Ard Biesheuvel
2026-09-06 13:08 ` [PATCH 2/7] lib/ucs2_string: Avoid WARN in library code Ard Biesheuvel
2026-09-06 13:08 ` [PATCH 3/7] efi/libstub: Use ucs2_string library for UTF-16 to UTF-8 conversion Ard Biesheuvel
2026-09-06 13:08 ` [PATCH 4/7] efi/libstub: Avoid efi_puts() for compile time constant strings Ard Biesheuvel
2026-09-06 13:08 ` [PATCH 5/7] efi/libstub: Output UTF-16 directly from vsnprintf() Ard Biesheuvel
2026-09-09 12:46 ` David Laight
2026-09-06 13:08 ` [PATCH 6/7] efi/libstub: Add support for printing human readable GUIDs Ard Biesheuvel
2026-09-06 13:08 ` [PATCH 7/7] efi/libstub: Add efi_snprintf() to construct wide strings Ard Biesheuvel
2026-09-06 22:14 ` [PATCH 0/7] efi/libstub: Avoid UTF-16 conversion busywork Vincent Mailhol
2026-09-08 17:24 ` Vincent Mailhol [this message]
2026-09-09 11:38 ` [PATCH] efi: pass NUL-inclusive sizes to ucs2_as_utf8() 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=20260908172555.3356-1-mailhol@kernel.org \
--to=mailhol@kernel.org \
--cc=ardb@kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=x86@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
all inboxes | Powered by JetHome®