Skip to content

Commit 474aca6

Browse files
fmoessbauerjan-kiszka
authored andcommitted
kernel-stub: fix nullptr deref on error getting boot part UUID
The caller of disk_get_part_uuid is responsible for checking the return value, as this function returns NULL in case of an error. This was not done, leading to a nullptr dereference on error. We fix this by checking the return code. Further, we now issue a error message in case the UUID cannot be determined. Fixes: 7c90e82 ("efi: implement systemd boot loader interface") Reported-by: Jan Kiszka <[email protected]> Signed-off-by: Felix Moessbauer <[email protected]> Signed-off-by: Jan Kiszka <[email protected]>
1 parent c9ac673 commit 474aca6

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

main.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,18 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
203203

204204
UINT16 *boot_medium_uuidstr =
205205
disk_get_part_uuid(loaded_image->DeviceHandle);
206-
bg_interface_params.loader_device_part_uuid = boot_medium_uuidstr;
207-
status = set_bg_interface_vars(&bg_interface_params);
208-
if (EFI_ERROR(status)) {
209-
WARNING(L"Cannot set bootloader interface variables (%r)\n",
210-
status);
206+
if (!boot_medium_uuidstr) {
207+
WARNING(L"Cannot get boot partition UUID\n");
208+
} else {
209+
bg_interface_params.loader_device_part_uuid = boot_medium_uuidstr;
210+
status = set_bg_interface_vars(&bg_interface_params);
211+
if (EFI_ERROR(status)) {
212+
WARNING(L"Cannot set bootloader interface variables (%r)\n",
213+
status);
214+
}
215+
INFO(L"LoaderDevicePartUUID=%s\n", boot_medium_uuidstr);
216+
FreePool(boot_medium_uuidstr);
211217
}
212-
INFO(L"LoaderDevicePartUUID=%s\n", boot_medium_uuidstr);
213-
FreePool(boot_medium_uuidstr);
214218
FreePool(payload_dev_path);
215219
FreePool(boot_medium_path);
216220

0 commit comments

Comments
 (0)