Skip to content

Commit fe66317

Browse files
committed
x86/crash: make the page that stores the dm crypt keys inaccessible
JIRA: https://issues.redhat.com/browse/RHEL-104939 Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git commit cc66e48 Author: Coiby Xu <coxu@redhat.com> Date: Fri May 2 09:12:42 2025 +0800 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/20250502011246.99238-9-coxu@redhat.com Signed-off-by: Coiby Xu <coxu@redhat.com> Suggested-by: Pingfan Liu <kernelfans@gmail.com> Acked-by: Baoquan He <bhe@redhat.com> Cc: "Daniel P. Berrange" <berrange@redhat.com> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Dave Young <dyoung@redhat.com> Cc: Jan Pazdziora <jpazdziora@redhat.com> Cc: Milan Broz <gmazyland@gmail.com> Cc: Ondrej Kozina <okozina@redhat.com> Cc: Vitaly Kuznetsov <vkuznets@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Coiby Xu <coxu@redhat.com>
1 parent 88742dc commit fe66317

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
@@ -572,13 +572,35 @@ static void kexec_mark_crashkres(bool protect)
572572
kexec_mark_range(control, crashk_res.end, protect);
573573
}
574574

575+
/* make the memory storing dm crypt keys in/accessible */
576+
static void kexec_mark_dm_crypt_keys(bool protect)
577+
{
578+
unsigned long start_paddr, end_paddr;
579+
unsigned int nr_pages;
580+
581+
if (kexec_crash_image->dm_crypt_keys_addr) {
582+
start_paddr = kexec_crash_image->dm_crypt_keys_addr;
583+
end_paddr = start_paddr + kexec_crash_image->dm_crypt_keys_sz - 1;
584+
nr_pages = (PAGE_ALIGN(end_paddr) - PAGE_ALIGN_DOWN(start_paddr))/PAGE_SIZE;
585+
if (protect)
586+
set_memory_np((unsigned long)phys_to_virt(start_paddr), nr_pages);
587+
else
588+
__set_memory_prot(
589+
(unsigned long)phys_to_virt(start_paddr),
590+
nr_pages,
591+
__pgprot(_PAGE_PRESENT | _PAGE_NX | _PAGE_RW));
592+
}
593+
}
594+
575595
void arch_kexec_protect_crashkres(void)
576596
{
577597
kexec_mark_crashkres(true);
598+
kexec_mark_dm_crypt_keys(true);
578599
}
579600

580601
void arch_kexec_unprotect_crashkres(void)
581602
{
603+
kexec_mark_dm_crypt_keys(false);
582604
kexec_mark_crashkres(false);
583605
}
584606
#endif

0 commit comments

Comments
 (0)