From: Yuho Choi <oss.patchbox@gmail.com>
To: Tom Rini <trini@konsulko.com>
Cc: Masahisa Kojima <kojima.masahisa@socionext.com>,
Heinrich Schuchardt <xypron.glpk@gmx.de>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Simon Glass <sjg@chromium.org>,
u-boot@lists.u-boot-project.org,
Yuho Choi <oss.patchbox@gmail.com>
Subject: [PATCH] bootmenu: fix leak of entries for missing or inactive boot options
Date: Tue, 3 Nov 2026 13:00:30 -0500 [thread overview]
Message-ID: <20261103180110.1025372-1-oss.patchbox@gmail.com> (raw)
prepare_uefi_bootorder_entry() allocates a menu entry for each index in
BootOrder before it reads the Boot#### variable. The entry is only
linked into the menu if the variable exists and the boot option has
LOAD_OPTION_ACTIVE set, and bootmenu_destroy() only frees linked
entries. When the variable is missing or the option is inactive, the
entry is neither linked nor freed.
With CONFIG_CMD_BOOTEFI_BOOTMGR=y and CONFIG_CMD_EFICONFIG=y, each time
the menu is created with UEFI entries ('bootmenu -e' or
CONFIG_AUTOBOOT_MENU_SHOW), one entry is therefore leaked for every
such BootOrder index.
Allocate the entry only for an active boot option. If this allocation
fails, free load_option and bootorder before returning, as the error
path for the title buffer already does; bootorder used to be leaked
there.
Fixes: c606c0059f7f ("bootmenu: add UEFI boot entry into bootmenu")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
Tested on sandbox_defconfig (LTO disabled for gdb) with Boot0001 active,
Boot0002 missing and Boot0003 inactive in BootOrder, running
'bootmenu -e' with bootmenu_delay=1 several times and reading
dlmallinfo().uordblks before each run. Without this patch each run used
128 bytes more heap than a control run with only Boot0001 in BootOrder,
which matches the two 48-byte entries; with it there is no difference.
The menu still lists only Boot0001.
| 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
--git a/cmd/bootmenu.c b/cmd/bootmenu.c
index b55f5579409..39fc16f8c27 100644
--- a/cmd/bootmenu.c
+++ b/cmd/bootmenu.c
@@ -304,10 +304,6 @@ static int prepare_uefi_bootorder_entry(struct bootmenu_data *menu,
num = size / sizeof(u16);
for (j = 0; j < num; j++) {
- entry = malloc(sizeof(struct bootmenu_entry));
- if (!entry)
- return -ENOMEM;
-
efi_create_indexed_name(varname, sizeof(varname),
"Boot", bootorder[j]);
load_option = efi_get_var(varname, &efi_global_variable_guid, &size);
@@ -318,13 +314,18 @@ static int prepare_uefi_bootorder_entry(struct bootmenu_data *menu,
if (ret != EFI_SUCCESS) {
log_warning("Invalid load option for %ls\n", varname);
free(load_option);
- free(entry);
continue;
}
if (lo.attributes & LOAD_OPTION_ACTIVE) {
char *buf;
+ entry = malloc(sizeof(struct bootmenu_entry));
+ if (!entry) {
+ free(load_option);
+ free(bootorder);
+ return -ENOMEM;
+ }
buf = calloc(1, utf16_utf8_strlen(lo.label) + 1);
if (!buf) {
free(load_option);
--
2.43.0
reply other threads:[~2026-11-03 18:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261103180110.1025372-1-oss.patchbox@gmail.com \
--to=oss.patchbox@gmail.com \
--cc=ilias.apalodimas@linaro.org \
--cc=kojima.masahisa@socionext.com \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
--cc=xypron.glpk@gmx.de \
/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