mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-07 11:28:32 +00:00
efi/esrt: Fix handling of early ESRT table mapping
As reported by Tyler, efi_esrt_init() will return without releasing the ESRT table header mapping if it encounters a table with an unexpected version. Replacing the 'return' with 'goto err_memunmap' would fix this particular occurrence, but, as it turns out, the code is rather peculiar to begin with: - it never uses the header mapping after memcpy()'ing out its contents, - it maps and unmaps the entire table without ever looking at the contents. So let's refactor this code to unmap the table header right after the memcpy() so we can get rid of the error handling path altogether, and drop the second mapping entirely. Reported-by: Tyler Baicar <tbaicar@codeaurora.org> 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 Jones <pjones@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20180312084500.10764-5-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
parent
7e904a91bf
commit
136d5d57e3
1 changed files with 5 additions and 14 deletions
|
@ -279,6 +279,7 @@ void __init efi_esrt_init(void)
|
|||
}
|
||||
|
||||
memcpy(&tmpesrt, va, sizeof(tmpesrt));
|
||||
early_memunmap(va, size);
|
||||
|
||||
if (tmpesrt.fw_resource_version == 1) {
|
||||
entry_size = sizeof (*v1_entries);
|
||||
|
@ -291,7 +292,7 @@ void __init efi_esrt_init(void)
|
|||
if (tmpesrt.fw_resource_count > 0 && max - size < entry_size) {
|
||||
pr_err("ESRT memory map entry can only hold the header. (max: %zu size: %zu)\n",
|
||||
max - size, entry_size);
|
||||
goto err_memunmap;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -304,7 +305,7 @@ void __init efi_esrt_init(void)
|
|||
if (tmpesrt.fw_resource_count > 128) {
|
||||
pr_err("ESRT says fw_resource_count has very large value %d.\n",
|
||||
tmpesrt.fw_resource_count);
|
||||
goto err_memunmap;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -315,19 +316,11 @@ void __init efi_esrt_init(void)
|
|||
if (max < size + entries_size) {
|
||||
pr_err("ESRT does not fit on single memory map entry (size: %zu max: %zu)\n",
|
||||
size, max);
|
||||
goto err_memunmap;
|
||||
}
|
||||
|
||||
/* remap it with our (plausible) new pages */
|
||||
early_memunmap(va, size);
|
||||
size += entries_size;
|
||||
va = early_memremap(efi.esrt, size);
|
||||
if (!va) {
|
||||
pr_err("early_memremap(%p, %zu) failed.\n", (void *)efi.esrt,
|
||||
size);
|
||||
return;
|
||||
}
|
||||
|
||||
size += entries_size;
|
||||
|
||||
esrt_data = (phys_addr_t)efi.esrt;
|
||||
esrt_data_size = size;
|
||||
|
||||
|
@ -336,8 +329,6 @@ void __init efi_esrt_init(void)
|
|||
efi_mem_reserve(esrt_data, esrt_data_size);
|
||||
|
||||
pr_debug("esrt-init: loaded.\n");
|
||||
err_memunmap:
|
||||
early_memunmap(va, size);
|
||||
}
|
||||
|
||||
static int __init register_entries(void)
|
||||
|
|
Loading…
Reference in a new issue