Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further improve load_certs() for non-compliant drivers/firmwares #560

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -1486,18 +1486,28 @@ load_certs(EFI_HANDLE image_handle)
UINTN old = buffersize;
efi_status = dir->Read(dir, &buffersize, buffer);
if (efi_status == EFI_BUFFER_TOO_SMALL) {
if (buffersize != old) {
buffer = ReallocatePool(buffer, old, buffersize);
if (buffer == NULL) {
perror(L"Failed to read directory %s - %r\n",
PathName, EFI_OUT_OF_RESOURCES);
if (buffersize == old) {
/*
* Some UEFI drivers or firmwares are not compliant with
* the EFI_FILE_PROTOCOL.Read() specs and do not return the
* required buffer size along with EFI_BUFFER_TOO_SMALL.
* Work around this by progressively increasing the buffer
* size, up to a certain point, until the call succeeds.
*/
perror(L"Error reading directory %s - "
L"non-compliant UEFI driver or firmware!\n",
PathName);
buffersize = (buffersize < 4) ? 4 : buffersize * 2;
if (buffersize > 1024)
goto done;
}
continue;
}
perror(L"Failed to read directory %s - buggy firmware\n",
PathName);
goto done;
buffer = ReallocatePool(buffer, old, buffersize);
if (buffer == NULL) {
perror(L"Failed to read directory %s - %r\n",
PathName, EFI_OUT_OF_RESOURCES);
goto done;
}
continue;
} else if (EFI_ERROR(efi_status)) {
perror(L"Failed to read directory %s - %r\n", PathName,
efi_status);
Expand Down