Skip to content

Commit 46d1907

Browse files
committed
Merge tag 'efi-fixes-for-v6.10-3' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi
Pull EFI fixes from Ard Biesheuvel: "Another small set of EFI fixes. Only the x86 one is likely to affect any actual users (and has a cc:stable), but the issue it fixes was only observed in an unusual context (kexec in a confidential VM). - Ensure that EFI runtime services are not unmapped by PAN on ARM - Avoid freeing the memory holding the EFI memory map inadvertently on x86 - Avoid a false positive kmemleak warning on arm64" * tag 'efi-fixes-for-v6.10-3' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi: efi/arm64: Fix kmemleak false positive in arm64_efi_rt_init() efi/x86: Free EFI memory map only when installing a new one. efi/arm: Disable LPAE PAN when calling EFI runtime services
2 parents 3d54351 + 46e27b9 commit 46d1907

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

arch/arm/include/asm/efi.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <asm/mach/map.h>
1515
#include <asm/mmu_context.h>
1616
#include <asm/ptrace.h>
17+
#include <asm/uaccess.h>
1718

1819
#ifdef CONFIG_EFI
1920
void efi_init(void);
@@ -25,6 +26,18 @@ int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md, boo
2526
#define arch_efi_call_virt_setup() efi_virtmap_load()
2627
#define arch_efi_call_virt_teardown() efi_virtmap_unload()
2728

29+
#ifdef CONFIG_CPU_TTBR0_PAN
30+
#undef arch_efi_call_virt
31+
#define arch_efi_call_virt(p, f, args...) ({ \
32+
unsigned int flags = uaccess_save_and_enable(); \
33+
efi_status_t res = _Generic((p)->f(args), \
34+
efi_status_t: (p)->f(args), \
35+
default: ((p)->f(args), EFI_ABORTED)); \
36+
uaccess_restore(flags); \
37+
res; \
38+
})
39+
#endif
40+
2841
#define ARCH_EFI_IRQ_FLAGS_MASK \
2942
(PSR_J_BIT | PSR_E_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT | \
3043
PSR_T_BIT | MODE_MASK)

arch/arm64/kernel/efi.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <linux/efi.h>
1111
#include <linux/init.h>
12+
#include <linux/kmemleak.h>
1213
#include <linux/screen_info.h>
1314
#include <linux/vmalloc.h>
1415

@@ -213,6 +214,7 @@ l: if (!p) {
213214
return -ENOMEM;
214215
}
215216

217+
kmemleak_not_leak(p);
216218
efi_rt_stack_top = p + THREAD_SIZE;
217219
return 0;
218220
}

arch/x86/include/asm/efi.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ extern int __init efi_memmap_alloc(unsigned int num_entries,
401401
struct efi_memory_map_data *data);
402402
extern void __efi_memmap_free(u64 phys, unsigned long size,
403403
unsigned long flags);
404-
#define __efi_memmap_free __efi_memmap_free
405404

406405
extern int __init efi_memmap_install(struct efi_memory_map_data *data);
407406
extern int __init efi_memmap_split_count(efi_memory_desc_t *md,

arch/x86/platform/efi/memmap.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,22 @@ int __init efi_memmap_alloc(unsigned int num_entries,
9292
*/
9393
int __init efi_memmap_install(struct efi_memory_map_data *data)
9494
{
95+
unsigned long size = efi.memmap.desc_size * efi.memmap.nr_map;
96+
unsigned long flags = efi.memmap.flags;
97+
u64 phys = efi.memmap.phys_map;
98+
int ret;
99+
95100
efi_memmap_unmap();
96101

97102
if (efi_enabled(EFI_PARAVIRT))
98103
return 0;
99104

100-
return __efi_memmap_init(data);
105+
ret = __efi_memmap_init(data);
106+
if (ret)
107+
return ret;
108+
109+
__efi_memmap_free(phys, size, flags);
110+
return 0;
101111
}
102112

103113
/**

drivers/firmware/efi/memmap.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
#include <asm/early_ioremap.h>
1616
#include <asm/efi.h>
1717

18-
#ifndef __efi_memmap_free
19-
#define __efi_memmap_free(phys, size, flags) do { } while (0)
20-
#endif
21-
2218
/**
2319
* __efi_memmap_init - Common code for mapping the EFI memory map
2420
* @data: EFI memory map data
@@ -51,11 +47,6 @@ int __init __efi_memmap_init(struct efi_memory_map_data *data)
5147
return -ENOMEM;
5248
}
5349

54-
if (efi.memmap.flags & (EFI_MEMMAP_MEMBLOCK | EFI_MEMMAP_SLAB))
55-
__efi_memmap_free(efi.memmap.phys_map,
56-
efi.memmap.desc_size * efi.memmap.nr_map,
57-
efi.memmap.flags);
58-
5950
map.phys_map = data->phys_map;
6051
map.nr_map = data->size / data->desc_size;
6152
map.map_end = map.map + data->size;

0 commit comments

Comments
 (0)