[PATCH] Fix file handle and memory leaks in volume enumeration

5 views
Skip to first unread message

Christian Storm

unread,
Aug 17, 2021, 8:55:17 AM8/17/21
to efibootg...@googlegroups.com, Christian Storm
From: Christian Storm <christi...@siemens.com>

The allocated memory and file handles via get_volumes() is
actually never released: While close_volumes() is defined,
it's never called. Fix it by calling close_volumes().

Signed-off-by: Christian Storm <christi...@siemens.com>
---
main.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/main.c b/main.c
index 7949218..0bec838 100644
--- a/main.c
+++ b/main.c
@@ -160,6 +160,11 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
EFI_OUT_OF_RESOURCES);
}

+ status = close_volumes(volumes, volume_count);
+ if (EFI_ERROR(status)) {
+ WARNING(L"Cannot close volumes.\n", status);
+ }
+
if (bg_loader_params.timeout == 0) {
WARNING(L"Watchdog is disabled.\n");
} else {
--
2.32.0

Christian Storm

unread,
Aug 17, 2021, 8:55:20 AM8/17/21
to efibootg...@googlegroups.com, Christian Storm
From: Christian Storm <christi...@siemens.com>

If volumes[i].root == NULL, an error is printed, the return code
is updated, but there's no bailout/continue, hence the following
Close() call attempt dereferences a NULL pointer.
Avoid this by continue'ing the loop instead.

Signed-off-by: Christian Storm <christi...@siemens.com>
---
utils.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/utils.c b/utils.c
index 3929cb0..8088372 100644
--- a/utils.c
+++ b/utils.c
@@ -196,6 +196,7 @@ EFI_STATUS close_volumes(VOLUME_DESC *volumes, UINTN count)
if (!volumes[i].root) {
ERROR(L"Invalid handle for volume %d.\n", i);
result = EFI_INVALID_PARAMETER;
+ continue;
}
status = uefi_call_wrapper(volumes[i].root->Close, 1,
volumes[i].root);
--
2.32.0

Jan Kiszka

unread,
Aug 17, 2021, 11:23:37 AM8/17/21
to Christian Storm, efibootg...@googlegroups.com
Thanks, both applied.

Jan

--
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
Reply all
Reply to author
Forward
0 new messages