Skip to contentSkip to conversation

efi/libstub: prevent read overflow in find_file_option()

PATCH In review Dan Carpenter 2 participants 2 messages Apr 23, 2021 – May 10, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi/libstub: prevent read overflow in find_file_option()

If the buffer has slashes up to the end then this will read past the end of the array. I don't anticipate that this is an issue for many people in real life, but it's the right thing to do and it makes static checkers happy.

Fixes 7a88a6227dc7 ("efi/libstub: Fix path separator regression")
---
 drivers/firmware/efi/libstub/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/libstub/file.c +1 -1
index 4e81c6077188..dd95f330fe6e 100644
@@ -103,7 +103,7 @@ static int find_file_option(const efi_char16_t *cmdline, int cmdline_len,
 		return 0;
 
 	/* Skip any leading slashes */
-	while (cmdline[i] == L'/' || cmdline[i] == L'\\')
+	while (i < cmdline_len && (cmdline[i] == L'/' || cmdline[i] == L'\\'))
 		i++;
 
 	while (--result_len > 0 && i < cmdline_len) {
Signature · 1 line
2.30.2
maintainer
#1 lore raw
Quoted 26 lines · Dan Carpenter

If the buffer has slashes up to the end then this will read past the end of the array. I don't anticipate that this is an issue for many people in real life, but it's the right thing to do and it makes static checkers happy.

Fixes 7a88a6227dc7 ("efi/libstub: Fix path separator regression")
---
 drivers/firmware/efi/libstub/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/libstub/file.c +1 -2
index 4e81c6077188..dd95f330fe6e 100644
@@ -103,7 +103,7 @@ static int find_file_option(const efi_char16_t *cmdline, int cmdline_len,
                return 0;
 
        /* Skip any leading slashes */
-       while (cmdline[i] == L'/' || cmdline[i] == L'\\')
+       while (i < cmdline_len && (cmdline[i] == L'/' || cmdline[i] == L'\\'))
                i++;
 
        while (--result_len > 0 && i < cmdline_len) {
--
Quoted 2 lines

2.30.2

Thanks Dan, I will queue this up.