efi/libstub: Clean up command line parsing routine
authorArd Biesheuvel <ardb@kernel.org>
Mon, 10 Feb 2020 16:02:46 +0000 (17:02 +0100)
committerArd Biesheuvel <ardb@kernel.org>
Sun, 23 Feb 2020 20:57:15 +0000 (21:57 +0100)
commit91d150c0cc637b9d9d6394936add7cd2b7ccc410
treecc604ef224f2a8c476d19984b6d0ef42454c25f0
parent31f5e546655b502d508e160e6cab20462089e34d
efi/libstub: Clean up command line parsing routine

We currently parse the command non-destructively, to avoid having to
allocate memory for a copy before passing it to the standard parsing
routines that are used by the core kernel, and which modify the input
to delineate the parsed tokens with NUL characters.

Instead, we call strstr() and strncmp() to go over the input multiple
times, and match prefixes rather than tokens, which implies that we
would match, e.g., 'nokaslrfoo' in the stub and disable KASLR, while
the kernel would disregard the option and run with KASLR enabled.

In order to avoid having to reason about whether and how this behavior
may be abused, let's clean up the parsing routines, and rebuild them
on top of the existing helpers.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
arch/arm64/kernel/image-vars.h
drivers/firmware/efi/libstub/Makefile
drivers/firmware/efi/libstub/efi-stub-helper.c
drivers/firmware/efi/libstub/skip_spaces.c [new file with mode: 0644]
drivers/firmware/efi/libstub/string.c
drivers/firmware/efi/libstub/x86-stub.c