]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
efi/libstub: prevent read overflow in find_file_option()
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 23 Apr 2021 11:48:31 +0000 (14:48 +0300)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 30 Jun 2021 06:27:43 +0000 (08:27 +0200)
BugLink: https://bugs.launchpad.net/bugs/1933691
[ Upstream commit c4039b29fe9637e1135912813f830994af4c867f ]

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")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
drivers/firmware/efi/libstub/file.c

index 4e81c6077188ede20f43800dc66ac28497142209..dd95f330fe6e173ef8bed69f2b59b7e2cbaddb57 100644 (file)
@@ -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) {