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

Commit 61a2a67

Browse files
Fares Mehannagregkh
Fares Mehanna
authored andcommitted
arm64: trans_pgd: mark PTEs entries as valid to avoid dead kexec()
[ Upstream commit 7eced90 ] The reasons for PTEs in the kernel direct map to be marked invalid are not limited to kfence / debug pagealloc machinery. In particular, memfd_secret() also steals pages with set_direct_map_invalid_noflush(). When building the transitional page tables for kexec from the current kernel's page tables, those pages need to become regular writable pages, otherwise, if the relocation places kexec segments over such pages, a fault will occur during kexec, leading to host going dark during kexec. This patch addresses the kexec issue by marking any PTE as valid if it is not none. While this fixes the kexec crash, it does not address the security concern that if processes owning secret memory are not terminated before kexec, the secret content will be mapped in the new kernel without being scrubbed. Suggested-by: Jan H. Schönherr <jschoenh@amazon.de> Signed-off-by: Fares Mehanna <faresx@amazon.de> Link: https://lore.kernel.org/r/20240902163309.97113-1-faresx@amazon.de Signed-off-by: Will Deacon <will@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 2f78e4a commit 61a2a67

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

arch/arm64/mm/trans_pgd.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ static void _copy_pte(pte_t *dst_ptep, pte_t *src_ptep, unsigned long addr)
4242
* the temporary mappings we use during restore.
4343
*/
4444
__set_pte(dst_ptep, pte_mkwrite_novma(pte));
45-
} else if ((debug_pagealloc_enabled() ||
46-
is_kfence_address((void *)addr)) && !pte_none(pte)) {
45+
} else if (!pte_none(pte)) {
4746
/*
4847
* debug_pagealloc will removed the PTE_VALID bit if
4948
* the page isn't in use by the resume kernel. It may have
5049
* been in use by the original kernel, in which case we need
5150
* to put it back in our copy to do the restore.
5251
*
52+
* Other cases include kfence / vmalloc / memfd_secret which
53+
* may call `set_direct_map_invalid_noflush()`.
54+
*
5355
* Before marking this entry valid, check the pfn should
5456
* be mapped.
5557
*/

0 commit comments

Comments
 (0)