Skip to content

Commit d144d8a

Browse files
dwmw2bp3tk0v
authored andcommitted
x86/kexec: Disable global pages before writing to control page
The kernel switches to a new set of page tables during kexec. The global mappings (_PAGE_GLOBAL==1) can remain in the TLB after this switch. This is generally not a problem because the new page tables use a different portion of the virtual address space than the normal kernel mappings. The critical exception to that generalisation (and the only mapping which isn't an identity mapping) is the kexec control page itself — which was ROX in the original kernel mapping, but should be RWX in the new page tables. If there is a global TLB entry for that in its prior read-only state, it definitely needs to be flushed before attempting to write through that virtual mapping. It would be possible to just avoid writing to the virtual address of the page and defer all writes until they can be done through the identity mapping. But there's no good reason to keep the old TLB entries around, as they can cause nothing but trouble. Clear the PGE bit in %cr4 early, before storing data in the control page. Fixes: 5a82223 ("x86/kexec: Mark relocate_kernel page as ROX instead of RWX") Closes: https://bugzilla.kernel.org/show_bug.cgi?id=219592 Reported-by: Nathan Chancellor <[email protected]> Reported-by: "Ning, Hongyu" <[email protected]> Co-developed-by: Dave Hansen <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Signed-off-by: David Woodhouse <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Tested-by: "Ning, Hongyu" <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8939301 commit d144d8a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

arch/x86/kernel/relocate_kernel_64.S

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,20 @@ SYM_CODE_START_NOALIGN(relocate_kernel)
7070
movq kexec_pa_table_page(%rip), %r9
7171
movq %r9, %cr3
7272

73+
/* Leave CR4 in %r13 to enable the right paging mode later. */
74+
movq %cr4, %r13
75+
76+
/* Disable global pages immediately to ensure this mapping is RWX */
77+
movq %r13, %r12
78+
andq $~(X86_CR4_PGE), %r12
79+
movq %r12, %cr4
80+
7381
/* Save %rsp and CRs. */
82+
movq %r13, saved_cr4(%rip)
7483
movq %rsp, saved_rsp(%rip)
7584
movq %rax, saved_cr3(%rip)
7685
movq %cr0, %rax
7786
movq %rax, saved_cr0(%rip)
78-
/* Leave CR4 in %r13 to enable the right paging mode later. */
79-
movq %cr4, %r13
80-
movq %r13, saved_cr4(%rip)
8187

8288
/* save indirection list for jumping back */
8389
movq %rdi, pa_backup_pages_map(%rip)

0 commit comments

Comments
 (0)