Skip to content

Commit 04ca02c

Browse files
Ard Biesheuvelpundiramit
authored andcommitted
BACKPORT: efi/libstub: Unify command line param parsing
Merge the parsing of the command line carried out in arm-stub.c with the handling in efi_parse_options(). Note that this also fixes the missing handling of CONFIG_CMDLINE_FORCE=y, in which case the builtin command line should supersede the one passed by the firmware. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Matt Fleming <matt@codeblueprint.co.uk> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: bhe@redhat.com Cc: bhsharma@redhat.com Cc: bp@alien8.de Cc: eugene@hp.com Cc: evgeny.kalugin@intel.com Cc: jhugo@codeaurora.org Cc: leif.lindholm@linaro.org Cc: linux-efi@vger.kernel.org Cc: mark.rutland@arm.com Cc: roy.franz@cavium.com Cc: rruigrok@codeaurora.org Link: http://lkml.kernel.org/r/20170404160910.28115-1-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar <mingo@kernel.org> (cherry picked from commit 60f38de7a8d4e816100ceafd1b382df52527bd50) Change-Id: I936ac5f634bc677fa3dcc2f7bdc8b1b06603d57a Signed-off-by: Greg Hackmann <ghackmann@google.com>
1 parent 907c548 commit 04ca02c

5 files changed

Lines changed: 23 additions & 22 deletions

File tree

drivers/firmware/efi/libstub/arm-stub.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
#include "efistub.h"
2020

21-
bool __nokaslr;
22-
2321
static int efi_secureboot_enabled(efi_system_table_t *sys_table_arg)
2422
{
2523
static efi_guid_t const var_guid = EFI_GLOBAL_VARIABLE_GUID;
@@ -221,18 +219,6 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table,
221219
goto fail;
222220
}
223221

224-
/* check whether 'nokaslr' was passed on the command line */
225-
if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {
226-
static const u8 default_cmdline[] = CONFIG_CMDLINE;
227-
const u8 *str, *cmdline = cmdline_ptr;
228-
229-
if (IS_ENABLED(CONFIG_CMDLINE_FORCE))
230-
cmdline = default_cmdline;
231-
str = strstr(cmdline, "nokaslr");
232-
if (str == cmdline || (str > cmdline && *(str - 1) == ' '))
233-
__nokaslr = true;
234-
}
235-
236222
status = handle_kernel_image(sys_table, image_addr, &image_size,
237223
&reserve_addr,
238224
&reserve_size,
@@ -242,9 +228,13 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table,
242228
goto fail_free_cmdline;
243229
}
244230

245-
status = efi_parse_options(cmdline_ptr);
246-
if (status != EFI_SUCCESS)
247-
pr_efi_err(sys_table, "Failed to parse EFI cmdline options\n");
231+
if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) ||
232+
IS_ENABLED(CONFIG_CMDLINE_FORCE) ||
233+
cmdline_size == 0)
234+
efi_parse_options(CONFIG_CMDLINE);
235+
236+
if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && cmdline_size > 0)
237+
efi_parse_options(cmdline_ptr);
248238

249239
/*
250240
* Unauthenticated device tree data is a security hazard, so

drivers/firmware/efi/libstub/arm64-stub.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323

2424
#include "efistub.h"
2525

26-
extern bool __nokaslr;
27-
2826
efi_status_t __init handle_kernel_image(efi_system_table_t *sys_table_arg,
2927
unsigned long *image_addr,
3028
unsigned long *image_size,
@@ -40,7 +38,7 @@ efi_status_t __init handle_kernel_image(efi_system_table_t *sys_table_arg,
4038
u64 phys_seed = 0;
4139

4240
if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {
43-
if (!__nokaslr) {
41+
if (!nokaslr()) {
4442
status = efi_get_random_bytes(sys_table_arg,
4543
sizeof(phys_seed),
4644
(u8 *)&phys_seed);

drivers/firmware/efi/libstub/efi-stub-helper.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ static unsigned long __chunk_size = EFI_READ_CHUNK_SIZE;
4141
#define EFI_ALLOC_ALIGN EFI_PAGE_SIZE
4242
#endif
4343

44+
static int __section(.data) __nokaslr;
45+
46+
int __pure nokaslr(void)
47+
{
48+
return __nokaslr;
49+
}
50+
4451
struct file_info {
4552
efi_file_handle_t *handle;
4653
u64 size;
@@ -313,10 +320,14 @@ void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
313320
* environments, first in the early boot environment of the EFI boot
314321
* stub, and subsequently during the kernel boot.
315322
*/
316-
efi_status_t efi_parse_options(char *cmdline)
323+
efi_status_t efi_parse_options(char const *cmdline)
317324
{
318325
char *str;
319326

327+
str = strstr(cmdline, "nokaslr");
328+
if (str == cmdline || (str && str > cmdline && *(str - 1) == ' '))
329+
__nokaslr = 1;
330+
320331
/*
321332
* If no EFI parameters were specified on the cmdline we've got
322333
* nothing to do.

drivers/firmware/efi/libstub/efistub.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
/* error code which can't be mistaken for valid address */
66
#define EFI_ERROR (~0UL)
77

8+
extern int __pure nokaslr(void);
9+
810
void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
911

1012
efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, void *__image,

include/linux/efi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,7 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
12921292
unsigned long *load_addr,
12931293
unsigned long *load_size);
12941294

1295-
efi_status_t efi_parse_options(char *cmdline);
1295+
efi_status_t efi_parse_options(char const *cmdline);
12961296

12971297
bool efi_runtime_disabled(void);
12981298
#endif /* _LINUX_EFI_H */

0 commit comments

Comments
 (0)