Re: [tip: efi/core] efi: Support for MOK variable config table

From: Borislav Petkov
Date: Mon Sep 21 2020 - 11:56:03 EST


On Fri, Sep 18, 2020 at 08:30:54AM -0000, tip-bot2 for Lenny Szubowicz wrote:
> +void __init efi_mokvar_table_init(void)
> +{
> + efi_memory_desc_t md;
> + u64 end_pa;
> + void *va = NULL;
> + size_t cur_offset = 0;
> + size_t offset_limit;
> + size_t map_size = 0;
> + size_t map_size_needed = 0;
> + size_t size;
> + struct efi_mokvar_table_entry *mokvar_entry;
> + int err = -EINVAL;
> +
> + if (!efi_enabled(EFI_MEMMAP))
> + return;
> +
> + if (efi.mokvar_table == EFI_INVALID_TABLE_ADDR)
> + return;
> + /*
> + * The EFI MOK config table must fit within a single EFI memory
> + * descriptor range.
> + */
> + err = efi_mem_desc_lookup(efi.mokvar_table, &md);
> + if (err) {
> + pr_warn("EFI MOKvar config table is not within the EFI memory map\n");
> + return;
> + }
> + end_pa = efi_mem_desc_end(&md);
> + if (efi.mokvar_table >= end_pa) {
> + pr_err("EFI memory descriptor containing MOKvar config table is invalid\n");
> + return;
> + }
> + offset_limit = end_pa - efi.mokvar_table;
> + /*
> + * Validate the MOK config table. Since there is no table header
> + * from which we could get the total size of the MOK config table,
> + * we compute the total size as we validate each variably sized
> + * entry, remapping as necessary.
> + */
> + while (cur_offset + sizeof(*mokvar_entry) <= offset_limit) {
> + mokvar_entry = va + cur_offset;
> + map_size_needed = cur_offset + sizeof(*mokvar_entry);
> + if (map_size_needed > map_size) {
> + if (va)
> + early_memunmap(va, map_size);
> + /*
> + * Map a little more than the fixed size entry
> + * header, anticipating some data. It's safe to
> + * do so as long as we stay within current memory
> + * descriptor.
> + */
> + map_size = min(map_size_needed + 2*EFI_PAGE_SIZE,
> + offset_limit);

i386 allmodconfig build gives here:

In file included from ./arch/x86/include/asm/percpu.h:27:0,
from ./arch/x86/include/asm/current.h:6,
from ./arch/x86/include/asm/processor.h:17,
from ./arch/x86/include/asm/timex.h:5,
from ./include/linux/timex.h:65,
from ./include/linux/time32.h:13,
from ./include/linux/time.h:73,
from ./include/linux/efi.h:17,
from drivers/firmware/efi/mokvar-table.c:35:
drivers/firmware/efi/mokvar-table.c: In function ‘efi_mokvar_table_init’:
./include/linux/kernel.h:850:29: warning: comparison of distinct pointer types lacks a cast
(!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
^
./include/linux/kernel.h:864:4: note: in expansion of macro ‘__typecheck’
(__typecheck(x, y) && __no_side_effects(x, y))
^~~~~~~~~~~
./include/linux/kernel.h:874:24: note: in expansion of macro ‘__safe_cmp’
__builtin_choose_expr(__safe_cmp(x, y), \
^~~~~~~~~~
./include/linux/kernel.h:883:19: note: in expansion of macro ‘__careful_cmp’
#define min(x, y) __careful_cmp(x, y, <)
^~~~~~~~~~~~~
drivers/firmware/efi/mokvar-table.c:149:15: note: in expansion of macro ‘min’
map_size = min(map_size_needed + 2*EFI_PAGE_SIZE,
^~~

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette