From a23e2f0de7a61b6e895a915676eba3a1fda2cd78 Mon Sep 17 00:00:00 2001 From: Jan Setje-Eilers Date: Fri, 15 Dec 2023 21:31:48 -0800 Subject: netboot read_image() should not hardcode DEFAULT_LOADER The netboot path up until now hardcodes DEFAULT_LOADER as the only possible filename to load. This is pretty limiting and needs to be fixed. Signed-off-by: Jan Setje-Eilers --- include/netboot.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/netboot.h') diff --git a/include/netboot.h b/include/netboot.h index 98b174a3..a7bf6cd8 100644 --- a/include/netboot.h +++ b/include/netboot.h @@ -5,7 +5,7 @@ extern BOOLEAN findNetboot(EFI_HANDLE image_handle); -extern EFI_STATUS parseNetbootinfo(EFI_HANDLE image_handle); +extern EFI_STATUS parseNetbootinfo(EFI_HANDLE image_handle, CHAR8 *name); extern EFI_STATUS FetchNetbootimage(EFI_HANDLE image_handle, VOID **buffer, UINT64 *bufsiz); -- cgit v1.2.3 From 2b49dc13aed3723c7c841c2788217ff7b0e821df Mon Sep 17 00:00:00 2001 From: Jan Setje-Eilers Date: Fri, 12 Jul 2024 17:07:45 -0700 Subject: Suppress file open failures for some netboot cases Reading files during a netboot comes with the caveat that fetching files from a network does not support anything like listing a directory. In the past this has meant that we do not try to open optional files during a netboot. However at least the revocation.efi file is now tested during a netboot, which will print an error when it is not found. Since that error is spurious we should allow for those errors to be suppressed. This is also desirable since we will likely go looking for additional files in the near future. Signed-off-by: Jan Setje-Eilers --- include/netboot.h | 5 ++++- netboot.c | 13 +++++++++---- shim.c | 23 ++++++++++++++--------- 3 files changed, 27 insertions(+), 14 deletions(-) (limited to 'include/netboot.h') diff --git a/include/netboot.h b/include/netboot.h index a7bf6cd8..296f10f0 100644 --- a/include/netboot.h +++ b/include/netboot.h @@ -3,10 +3,13 @@ #ifndef SHIM_NETBOOT_H #define SHIM_NETBOOT_H +#define SUPPRESS_NETBOOT_OPEN_FAILURE_NOISE 1 + extern BOOLEAN findNetboot(EFI_HANDLE image_handle); extern EFI_STATUS parseNetbootinfo(EFI_HANDLE image_handle, CHAR8 *name); -extern EFI_STATUS FetchNetbootimage(EFI_HANDLE image_handle, VOID **buffer, UINT64 *bufsiz); +extern EFI_STATUS FetchNetbootimage(EFI_HANDLE image_handle, VOID **buffer, + UINT64 *bufsiz, int flags); #endif /* SHIM_NETBOOT_H */ diff --git a/netboot.c b/netboot.c index a4cc7acd..46765427 100644 --- a/netboot.c +++ b/netboot.c @@ -368,7 +368,8 @@ status_from_error(UINT8 error_code) } } -EFI_STATUS FetchNetbootimage(EFI_HANDLE image_handle UNUSED, VOID **buffer, UINT64 *bufsiz) +EFI_STATUS FetchNetbootimage(EFI_HANDLE image_handle UNUSED, VOID **buffer, + UINT64 *bufsiz, int flags) { EFI_STATUS efi_status; EFI_PXE_BASE_CODE_TFTP_OPCODE read = EFI_PXE_BASE_CODE_TFTP_READ_FILE; @@ -376,7 +377,8 @@ EFI_STATUS FetchNetbootimage(EFI_HANDLE image_handle UNUSED, VOID **buffer, UINT BOOLEAN nobuffer = FALSE; UINTN blksz = 512; - console_print(L"Fetching Netboot Image %a\n", full_path); + if (~flags & SUPPRESS_NETBOOT_OPEN_FAILURE_NOISE) + console_print(L"Fetching Netboot Image %a\n", full_path); if (*buffer == NULL) { *buffer = AllocatePool(4096 * 1024); if (!*buffer) @@ -399,7 +401,8 @@ try_again: if (EFI_ERROR(efi_status)) { if (pxe->Mode->TftpErrorReceived) { - console_print(L"TFTP error %u: %a\n", + if (~flags & SUPPRESS_NETBOOT_OPEN_FAILURE_NOISE) + console_print(L"TFTP error %u: %a\n", pxe->Mode->TftpError.ErrorCode, pxe->Mode->TftpError.ErrorString); @@ -412,7 +415,9 @@ try_again: * * https://github.com/tianocore/edk2/pull/6287 */ - console_print(L"Unknown TFTP error, treating as file not found\n"); + if (~flags & SUPPRESS_NETBOOT_OPEN_FAILURE_NOISE) + console_print(L"Unknown TFTP error, treating " + "as file not found\n"); efi_status = EFI_NOT_FOUND; } diff --git a/shim.c b/shim.c index bf0c9e6c..d040992d 100644 --- a/shim.c +++ b/shim.c @@ -1055,7 +1055,8 @@ str16_to_str8(CHAR16 *str16, CHAR8 **str8) * Load and run an EFI executable */ EFI_STATUS read_image(EFI_HANDLE image_handle, CHAR16 *ImagePath, - CHAR16 **PathName, void **data, int *datasize) + CHAR16 **PathName, void **data, int *datasize, + int flags) { EFI_STATUS efi_status; void *sourcebuffer = NULL; @@ -1092,10 +1093,11 @@ EFI_STATUS read_image(EFI_HANDLE image_handle, CHAR16 *ImagePath, } FreePool(netbootname); efi_status = FetchNetbootimage(image_handle, &sourcebuffer, - &sourcesize); + &sourcesize, flags); if (EFI_ERROR(efi_status)) { - perror(L"Unable to fetch TFTP image: %r\n", - efi_status); + if (~flags & SUPPRESS_NETBOOT_OPEN_FAILURE_NOISE) + perror(L"Unable to fetch TFTP image: %r\n", + efi_status); return efi_status; } *data = sourcebuffer; @@ -1107,8 +1109,9 @@ EFI_STATUS read_image(EFI_HANDLE image_handle, CHAR16 *ImagePath, &sourcesize, netbootname); if (EFI_ERROR(efi_status)) { - perror(L"Unable to fetch HTTP image %a: %r\n", - netbootname, efi_status); + if (~flags & SUPPRESS_NETBOOT_OPEN_FAILURE_NOISE) + perror(L"Unable to fetch HTTP image %a: %r\n", + netbootname, efi_status); return efi_status; } *data = sourcebuffer; @@ -1147,7 +1150,7 @@ EFI_STATUS start_image(EFI_HANDLE image_handle, CHAR16 *ImagePath) int datasize = 0; efi_status = read_image(image_handle, ImagePath, &PathName, &data, - &datasize); + &datasize, 0); if (EFI_ERROR(efi_status)) goto done; @@ -1435,7 +1438,8 @@ load_revocations_file(EFI_HANDLE image_handle, CHAR16 *PathName) uint8_t *sspv_latest = NULL; efi_status = read_image(image_handle, L"revocations.efi", &PathName, - &data, &datasize); + &data, &datasize, + SUPPRESS_NETBOOT_OPEN_FAILURE_NOISE); if (EFI_ERROR(efi_status)) return efi_status; @@ -1499,7 +1503,8 @@ load_cert_file(EFI_HANDLE image_handle, CHAR16 *filename, CHAR16 *PathName) int i; efi_status = read_image(image_handle, filename, &PathName, - &data, &datasize); + &data, &datasize, + SUPPRESS_NETBOOT_OPEN_FAILURE_NOISE); if (EFI_ERROR(efi_status)) return efi_status; -- cgit v1.2.3