Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

Commit 445b69e

Browse files
hansendcKAGA-KOKO
authored andcommitted
x86/pti: Make unpoison of pgd for trusted boot work for real
The inital fix for trusted boot and PTI potentially misses the pgd clearing if pud_alloc() sets a PGD. It probably works in *practice* because for two adjacent calls to map_tboot_page() that share a PGD entry, the first will clear NX, *then* allocate and set the PGD (without NX clear). The second call will *not* allocate but will clear the NX bit. Defer the NX clearing to a point after it is known that all top-level allocations have occurred. Add a comment to clarify why. [ tglx: Massaged changelog ] Fixes: 262b6b3 ("x86/tboot: Unbreak tboot with PTI enabled") Signed-off-by: Dave Hansen <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Andrea Arcangeli <[email protected]> Cc: Jon Masters <[email protected]> Cc: "Tim Chen" <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 612e8e9 commit 445b69e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

arch/x86/kernel/tboot.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ static int map_tboot_page(unsigned long vaddr, unsigned long pfn,
127127
p4d = p4d_alloc(&tboot_mm, pgd, vaddr);
128128
if (!p4d)
129129
return -1;
130-
pgd->pgd &= ~_PAGE_NX;
131130
pud = pud_alloc(&tboot_mm, p4d, vaddr);
132131
if (!pud)
133132
return -1;
@@ -139,6 +138,17 @@ static int map_tboot_page(unsigned long vaddr, unsigned long pfn,
139138
return -1;
140139
set_pte_at(&tboot_mm, vaddr, pte, pfn_pte(pfn, prot));
141140
pte_unmap(pte);
141+
142+
/*
143+
* PTI poisons low addresses in the kernel page tables in the
144+
* name of making them unusable for userspace. To execute
145+
* code at such a low address, the poison must be cleared.
146+
*
147+
* Note: 'pgd' actually gets set in p4d_alloc() _or_
148+
* pud_alloc() depending on 4/5-level paging.
149+
*/
150+
pgd->pgd &= ~_PAGE_NX;
151+
142152
return 0;
143153
}
144154

0 commit comments

Comments
 (0)