Skip to content

Commit 77cfefe

Browse files
nivedita76ksacilotto
authored andcommitted
efi/x86: Free efi_pgd with free_pages()
BugLink: https://bugs.launchpad.net/bugs/1908561 [ Upstream commit c2fe61d ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Ian May <ian.may@canonical.com>
1 parent eccd56f commit 77cfefe

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

arch/x86/platform/efi/efi_64.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,28 +217,30 @@ int __init efi_alloc_page_tables(void)
217217
gfp_mask = GFP_KERNEL | __GFP_ZERO;
218218
efi_pgd = (pgd_t *)__get_free_pages(gfp_mask, PGD_ALLOCATION_ORDER);
219219
if (!efi_pgd)
220-
return -ENOMEM;
220+
goto fail;
221221

222222
pgd = efi_pgd + pgd_index(EFI_VA_END);
223223
p4d = p4d_alloc(&init_mm, pgd, EFI_VA_END);
224-
if (!p4d) {
225-
free_page((unsigned long)efi_pgd);
226-
return -ENOMEM;
227-
}
224+
if (!p4d)
225+
goto free_pgd;
228226

229227
pud = pud_alloc(&init_mm, p4d, EFI_VA_END);
230-
if (!pud) {
231-
if (pgtable_l5_enabled())
232-
free_page((unsigned long) pgd_page_vaddr(*pgd));
233-
free_pages((unsigned long)efi_pgd, PGD_ALLOCATION_ORDER);
234-
return -ENOMEM;
235-
}
228+
if (!pud)
229+
goto free_p4d;
236230

237231
efi_mm.pgd = efi_pgd;
238232
mm_init_cpumask(&efi_mm);
239233
init_new_context(NULL, &efi_mm);
240234

241235
return 0;
236+
237+
free_p4d:
238+
if (pgtable_l5_enabled())
239+
free_page((unsigned long)pgd_page_vaddr(*pgd));
240+
free_pgd:
241+
free_pages((unsigned long)efi_pgd, PGD_ALLOCATION_ORDER);
242+
fail:
243+
return -ENOMEM;
242244
}
243245

244246
/*

0 commit comments

Comments
 (0)