Skip to content

Commit b2a18c2

Browse files
committed
Merge branch 'efi-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull EFI fixes from Ingo Molnar: "Various fixes all over the map: prevent boot crashes on HyperV, classify UEFI randomness as bootloader randomness, fix EFI boot for the Raspberry Pi2, fix efi_test permissions, etc" * 'efi-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: efi/efi_test: Lock down /dev/efi_test and require CAP_SYS_ADMIN x86, efi: Never relocate kernel below lowest acceptable address efi: libstub/arm: Account for firmware reserved memory at the base of RAM efi/random: Treat EFI_RNG_PROTOCOL output as bootloader randomness efi/tpm: Return -EINVAL when determining tpm final events log size fails efi: Make CONFIG_EFI_RCI2_TABLE selectable on x86 only
2 parents d540c39 + 359efcc commit b2a18c2

File tree

11 files changed

+56
-21
lines changed

11 files changed

+56
-21
lines changed

arch/x86/boot/compressed/eboot.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <asm/e820/types.h>
1414
#include <asm/setup.h>
1515
#include <asm/desc.h>
16+
#include <asm/boot.h>
1617

1718
#include "../string.h"
1819
#include "eboot.h"
@@ -813,7 +814,8 @@ efi_main(struct efi_config *c, struct boot_params *boot_params)
813814
status = efi_relocate_kernel(sys_table, &bzimage_addr,
814815
hdr->init_size, hdr->init_size,
815816
hdr->pref_address,
816-
hdr->kernel_alignment);
817+
hdr->kernel_alignment,
818+
LOAD_PHYSICAL_ADDR);
817819
if (status != EFI_SUCCESS) {
818820
efi_printk(sys_table, "efi_relocate_kernel() failed!\n");
819821
goto fail;

drivers/firmware/efi/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ config RESET_ATTACK_MITIGATION
182182

183183
config EFI_RCI2_TABLE
184184
bool "EFI Runtime Configuration Interface Table Version 2 Support"
185+
depends on X86 || COMPILE_TEST
185186
help
186187
Displays the content of the Runtime Configuration Interface
187188
Table version 2 on Dell EMC PowerEdge systems as a binary

drivers/firmware/efi/efi.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz,
554554
sizeof(*seed) + size);
555555
if (seed != NULL) {
556556
pr_notice("seeding entropy pool\n");
557-
add_device_randomness(seed->bits, seed->size);
557+
add_bootloader_randomness(seed->bits, seed->size);
558558
early_memunmap(seed, sizeof(*seed) + size);
559559
} else {
560560
pr_err("Could not map UEFI random seed!\n");

drivers/firmware/efi/libstub/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ lib-$(CONFIG_EFI_ARMSTUB) += arm-stub.o fdt.o string.o random.o \
5252

5353
lib-$(CONFIG_ARM) += arm32-stub.o
5454
lib-$(CONFIG_ARM64) += arm64-stub.o
55+
CFLAGS_arm32-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
5556
CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
5657

5758
#

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

+13-3
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
195195
unsigned long dram_base,
196196
efi_loaded_image_t *image)
197197
{
198+
unsigned long kernel_base;
198199
efi_status_t status;
199200

200201
/*
@@ -204,9 +205,18 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
204205
* loaded. These assumptions are made by the decompressor,
205206
* before any memory map is available.
206207
*/
207-
dram_base = round_up(dram_base, SZ_128M);
208+
kernel_base = round_up(dram_base, SZ_128M);
208209

209-
status = reserve_kernel_base(sys_table, dram_base, reserve_addr,
210+
/*
211+
* Note that some platforms (notably, the Raspberry Pi 2) put
212+
* spin-tables and other pieces of firmware at the base of RAM,
213+
* abusing the fact that the window of TEXT_OFFSET bytes at the
214+
* base of the kernel image is only partially used at the moment.
215+
* (Up to 5 pages are used for the swapper page tables)
216+
*/
217+
kernel_base += TEXT_OFFSET - 5 * PAGE_SIZE;
218+
219+
status = reserve_kernel_base(sys_table, kernel_base, reserve_addr,
210220
reserve_size);
211221
if (status != EFI_SUCCESS) {
212222
pr_efi_err(sys_table, "Unable to allocate memory for uncompressed kernel.\n");
@@ -220,7 +230,7 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
220230
*image_size = image->image_size;
221231
status = efi_relocate_kernel(sys_table, image_addr, *image_size,
222232
*image_size,
223-
dram_base + MAX_UNCOMP_KERNEL_SIZE, 0);
233+
kernel_base + MAX_UNCOMP_KERNEL_SIZE, 0, 0);
224234
if (status != EFI_SUCCESS) {
225235
pr_efi_err(sys_table, "Failed to relocate kernel.\n");
226236
efi_free(sys_table, *reserve_size, *reserve_addr);

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

+10-14
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,11 @@ efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
260260
}
261261

262262
/*
263-
* Allocate at the lowest possible address.
263+
* Allocate at the lowest possible address that is not below 'min'.
264264
*/
265-
efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
266-
unsigned long size, unsigned long align,
267-
unsigned long *addr)
265+
efi_status_t efi_low_alloc_above(efi_system_table_t *sys_table_arg,
266+
unsigned long size, unsigned long align,
267+
unsigned long *addr, unsigned long min)
268268
{
269269
unsigned long map_size, desc_size, buff_size;
270270
efi_memory_desc_t *map;
@@ -311,13 +311,8 @@ efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
311311
start = desc->phys_addr;
312312
end = start + desc->num_pages * EFI_PAGE_SIZE;
313313

314-
/*
315-
* Don't allocate at 0x0. It will confuse code that
316-
* checks pointers against NULL. Skip the first 8
317-
* bytes so we start at a nice even number.
318-
*/
319-
if (start == 0x0)
320-
start += 8;
314+
if (start < min)
315+
start = min;
321316

322317
start = round_up(start, align);
323318
if ((start + size) > end)
@@ -698,7 +693,8 @@ efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
698693
unsigned long image_size,
699694
unsigned long alloc_size,
700695
unsigned long preferred_addr,
701-
unsigned long alignment)
696+
unsigned long alignment,
697+
unsigned long min_addr)
702698
{
703699
unsigned long cur_image_addr;
704700
unsigned long new_addr = 0;
@@ -731,8 +727,8 @@ efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
731727
* possible.
732728
*/
733729
if (status != EFI_SUCCESS) {
734-
status = efi_low_alloc(sys_table_arg, alloc_size, alignment,
735-
&new_addr);
730+
status = efi_low_alloc_above(sys_table_arg, alloc_size,
731+
alignment, &new_addr, min_addr);
736732
}
737733
if (status != EFI_SUCCESS) {
738734
pr_efi_err(sys_table_arg, "Failed to allocate usable memory for kernel.\n");

drivers/firmware/efi/test/efi_test.c

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/init.h>
1515
#include <linux/proc_fs.h>
1616
#include <linux/efi.h>
17+
#include <linux/security.h>
1718
#include <linux/slab.h>
1819
#include <linux/uaccess.h>
1920

@@ -717,6 +718,13 @@ static long efi_test_ioctl(struct file *file, unsigned int cmd,
717718

718719
static int efi_test_open(struct inode *inode, struct file *file)
719720
{
721+
int ret = security_locked_down(LOCKDOWN_EFI_TEST);
722+
723+
if (ret)
724+
return ret;
725+
726+
if (!capable(CAP_SYS_ADMIN))
727+
return -EACCES;
720728
/*
721729
* nothing special to do here
722730
* We do accept multiple open files at the same time as we

drivers/firmware/efi/tpm.c

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ int __init efi_tpm_eventlog_init(void)
8888

8989
if (tbl_size < 0) {
9090
pr_err(FW_BUG "Failed to parse event in TPM Final Events Log\n");
91+
ret = -EINVAL;
9192
goto out_calc;
9293
}
9394

include/linux/efi.h

+16-2
Original file line numberDiff line numberDiff line change
@@ -1579,9 +1579,22 @@ char *efi_convert_cmdline(efi_system_table_t *sys_table_arg,
15791579
efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg,
15801580
struct efi_boot_memmap *map);
15811581

1582+
efi_status_t efi_low_alloc_above(efi_system_table_t *sys_table_arg,
1583+
unsigned long size, unsigned long align,
1584+
unsigned long *addr, unsigned long min);
1585+
1586+
static inline
15821587
efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
15831588
unsigned long size, unsigned long align,
1584-
unsigned long *addr);
1589+
unsigned long *addr)
1590+
{
1591+
/*
1592+
* Don't allocate at 0x0. It will confuse code that
1593+
* checks pointers against NULL. Skip the first 8
1594+
* bytes so we start at a nice even number.
1595+
*/
1596+
return efi_low_alloc_above(sys_table_arg, size, align, addr, 0x8);
1597+
}
15851598

15861599
efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
15871600
unsigned long size, unsigned long align,
@@ -1592,7 +1605,8 @@ efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
15921605
unsigned long image_size,
15931606
unsigned long alloc_size,
15941607
unsigned long preferred_addr,
1595-
unsigned long alignment);
1608+
unsigned long alignment,
1609+
unsigned long min_addr);
15961610

15971611
efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
15981612
efi_loaded_image_t *image,

include/linux/security.h

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ enum lockdown_reason {
105105
LOCKDOWN_NONE,
106106
LOCKDOWN_MODULE_SIGNATURE,
107107
LOCKDOWN_DEV_MEM,
108+
LOCKDOWN_EFI_TEST,
108109
LOCKDOWN_KEXEC,
109110
LOCKDOWN_HIBERNATION,
110111
LOCKDOWN_PCI_ACCESS,

security/lockdown/lockdown.c

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static const char *const lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = {
2020
[LOCKDOWN_NONE] = "none",
2121
[LOCKDOWN_MODULE_SIGNATURE] = "unsigned module loading",
2222
[LOCKDOWN_DEV_MEM] = "/dev/mem,kmem,port",
23+
[LOCKDOWN_EFI_TEST] = "/dev/efi_test access",
2324
[LOCKDOWN_KEXEC] = "kexec of unsigned images",
2425
[LOCKDOWN_HIBERNATION] = "hibernation",
2526
[LOCKDOWN_PCI_ACCESS] = "direct PCI access",

0 commit comments

Comments
 (0)