Skip to content

Commit d082d48

Browse files
lag-linarohansendc
authored andcommitted
x86/mm: Avoid using set_pgd() outside of real PGD pages
KPTI keeps around two PGDs: one for userspace and another for the kernel. Among other things, set_pgd() contains infrastructure to ensure that updates to the kernel PGD are reflected in the user PGD as well. One side-effect of this is that set_pgd() expects to be passed whole pages. Unfortunately, init_trampoline_kaslr() passes in a single entry: 'trampoline_pgd_entry'. When KPTI is on, set_pgd() will update 'trampoline_pgd_entry' (an 8-Byte globally stored [.bss] variable) and will then proceed to replicate that value into the non-existent neighboring user page (located +4k away), leading to the corruption of other global [.bss] stored variables. Fix it by directly assigning 'trampoline_pgd_entry' and avoiding set_pgd(). [ dhansen: tweak subject and changelog ] Fixes: 0925dda ("x86/mm/KASLR: Use only one PUD entry for real mode trampoline") Suggested-by: Dave Hansen <dave.hansen@linux.intel.com> Signed-off-by: Lee Jones <lee@kernel.org> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Cc: <stable@vger.kernel.org> Link: https://lore.kernel.org/all/20230614163859.924309-1-lee@kernel.org/g
1 parent a37f269 commit d082d48

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

arch/x86/mm/kaslr.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ void __meminit init_trampoline_kaslr(void)
172172
set_p4d(p4d_tramp,
173173
__p4d(_KERNPG_TABLE | __pa(pud_page_tramp)));
174174

175-
set_pgd(&trampoline_pgd_entry,
176-
__pgd(_KERNPG_TABLE | __pa(p4d_page_tramp)));
175+
trampoline_pgd_entry =
176+
__pgd(_KERNPG_TABLE | __pa(p4d_page_tramp));
177177
} else {
178-
set_pgd(&trampoline_pgd_entry,
179-
__pgd(_KERNPG_TABLE | __pa(pud_page_tramp)));
178+
trampoline_pgd_entry =
179+
__pgd(_KERNPG_TABLE | __pa(pud_page_tramp));
180180
}
181181
}

0 commit comments

Comments
 (0)