Skip to content

Commit cc66e48

Browse files
coibyakpm00
authored andcommitted
x86/crash: make the page that stores the dm crypt keys inaccessible
This adds an addition layer of protection for the saved copy of dm crypt key. Trying to access the saved copy will cause page fault. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Coiby Xu <[email protected]> Suggested-by: Pingfan Liu <[email protected]> Acked-by: Baoquan He <[email protected]> Cc: "Daniel P. Berrange" <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Dave Young <[email protected]> Cc: Jan Pazdziora <[email protected]> Cc: Milan Broz <[email protected]> Cc: Ondrej Kozina <[email protected]> Cc: Vitaly Kuznetsov <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 5eb3f60 commit cc66e48

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

arch/x86/kernel/machine_kexec_64.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,13 +598,35 @@ static void kexec_mark_crashkres(bool protect)
598598
kexec_mark_range(control, crashk_res.end, protect);
599599
}
600600

601+
/* make the memory storing dm crypt keys in/accessible */
602+
static void kexec_mark_dm_crypt_keys(bool protect)
603+
{
604+
unsigned long start_paddr, end_paddr;
605+
unsigned int nr_pages;
606+
607+
if (kexec_crash_image->dm_crypt_keys_addr) {
608+
start_paddr = kexec_crash_image->dm_crypt_keys_addr;
609+
end_paddr = start_paddr + kexec_crash_image->dm_crypt_keys_sz - 1;
610+
nr_pages = (PAGE_ALIGN(end_paddr) - PAGE_ALIGN_DOWN(start_paddr))/PAGE_SIZE;
611+
if (protect)
612+
set_memory_np((unsigned long)phys_to_virt(start_paddr), nr_pages);
613+
else
614+
__set_memory_prot(
615+
(unsigned long)phys_to_virt(start_paddr),
616+
nr_pages,
617+
__pgprot(_PAGE_PRESENT | _PAGE_NX | _PAGE_RW));
618+
}
619+
}
620+
601621
void arch_kexec_protect_crashkres(void)
602622
{
603623
kexec_mark_crashkres(true);
624+
kexec_mark_dm_crypt_keys(true);
604625
}
605626

606627
void arch_kexec_unprotect_crashkres(void)
607628
{
629+
kexec_mark_dm_crypt_keys(false);
608630
kexec_mark_crashkres(false);
609631
}
610632
#endif

0 commit comments

Comments
 (0)