Skip to content

Commit c2fe61d

Browse files
nivedita76ardbiesheuvel
authored andcommitted
efi/x86: Free efi_pgd with free_pages()
Commit d9e9a64 ("x86/mm/pti: Allocate a separate user PGD") changed the PGD allocation to allocate PGD_ALLOCATION_ORDER pages, so in the error path it should be freed using free_pages() rather than free_page(). Commit 06ace26 ("x86/efi: Free efi_pgd with free_pages()") fixed one instance of this, but missed another. Move the freeing out-of-line to avoid code duplication and fix this bug. Fixes: d9e9a64 ("x86/mm/pti: Allocate a separate user PGD") Link: https://lore.kernel.org/r/20201110163919.1134431-1-nivedita@alum.mit.edu Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent fe5186c commit c2fe61d

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

arch/x86/platform/efi/efi_64.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,28 +78,30 @@ int __init efi_alloc_page_tables(void)
7878
gfp_mask = GFP_KERNEL | __GFP_ZERO;
7979
efi_pgd = (pgd_t *)__get_free_pages(gfp_mask, PGD_ALLOCATION_ORDER);
8080
if (!efi_pgd)
81-
return -ENOMEM;
81+
goto fail;
8282

8383
pgd = efi_pgd + pgd_index(EFI_VA_END);
8484
p4d = p4d_alloc(&init_mm, pgd, EFI_VA_END);
85-
if (!p4d) {
86-
free_page((unsigned long)efi_pgd);
87-
return -ENOMEM;
88-
}
85+
if (!p4d)
86+
goto free_pgd;
8987

9088
pud = pud_alloc(&init_mm, p4d, EFI_VA_END);
91-
if (!pud) {
92-
if (pgtable_l5_enabled())
93-
free_page((unsigned long) pgd_page_vaddr(*pgd));
94-
free_pages((unsigned long)efi_pgd, PGD_ALLOCATION_ORDER);
95-
return -ENOMEM;
96-
}
89+
if (!pud)
90+
goto free_p4d;
9791

9892
efi_mm.pgd = efi_pgd;
9993
mm_init_cpumask(&efi_mm);
10094
init_new_context(NULL, &efi_mm);
10195

10296
return 0;
97+
98+
free_p4d:
99+
if (pgtable_l5_enabled())
100+
free_page((unsigned long)pgd_page_vaddr(*pgd));
101+
free_pgd:
102+
free_pages((unsigned long)efi_pgd, PGD_ALLOCATION_ORDER);
103+
fail:
104+
return -ENOMEM;
103105
}
104106

105107
/*

0 commit comments

Comments
 (0)