Skip to content

Commit

Permalink
efi/libstub: Fix path separator regression
Browse files Browse the repository at this point in the history
Commit 9302c1b ("efi/libstub: Rewrite file I/O routine") introduced a
regression that made a couple of (badly configured) systems fail to
boot [1]: Until 5.6, we silently accepted Unix-style file separators in
EFI paths, which might violate the EFI standard, but are an easy to make
mistake. This fix restores the pre-5.7 behaviour.

[1] https://bbs.archlinux.org/viewtopic.php?id=256273

Fixes: 9302c1b ("efi/libstub: Rewrite file I/O routine")
Signed-off-by: Philipp Fent <fent@in.tum.de>
Link: https://lore.kernel.org/r/20200615115109.7823-1-fent@in.tum.de
[ardb: rewrite as chained if/else statements]
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
  • Loading branch information
Philipp Fent authored and Ard Biesheuvel committed Jun 15, 2020
1 parent 24552d1 commit 7a88a62
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions drivers/firmware/efi/libstub/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,20 @@ static int find_file_option(const efi_char16_t *cmdline, int cmdline_len,
if (!found)
return 0;

/* Skip any leading slashes */
while (cmdline[i] == L'/' || cmdline[i] == L'\\')
i++;

while (--result_len > 0 && i < cmdline_len) {
if (cmdline[i] == L'\0' ||
cmdline[i] == L'\n' ||
cmdline[i] == L' ')
efi_char16_t c = cmdline[i++];

if (c == L'\0' || c == L'\n' || c == L' ')
break;
*result++ = cmdline[i++];
else if (c == L'/')
/* Replace UNIX dir separators with EFI standard ones */
*result++ = L'\\';
else
*result++ = c;
}
*result = L'\0';
return i;
Expand Down

0 comments on commit 7a88a62

Please sign in to comment.