Skip to content

Commit a8bd38d

Browse files
vnikhilprakashwilldeacon
authored andcommitted
arm64: mm: Make hibernation aware of KFENCE
In the restore path, swsusp_arch_suspend_exit uses copy_page() to over-write memory. However, with features like KFENCE enabled, there could be situations where it may have marked some pages as not valid, due to which it could be reported as invalid accesses. Consider a situation where page 'P' was part of the hibernation image. Now, when the resume kernel tries to restore the pages, the same page 'P' is already in use in the resume kernel and is kfence protected, due to which its mapping is removed from linear map. Since restoring pages happens with the resume kernel page tables, we would end up accessing 'P' during copy and results in kernel pagefault. The proposed fix tries to solve this issue by marking PTE as valid for such kfence protected pages. Co-developed-by: Pavankumar Kondeti <quic_pkondeti@quicinc.com> Signed-off-by: Pavankumar Kondeti <quic_pkondeti@quicinc.com> Signed-off-by: Nikhil V <quic_nprakash@quicinc.com> Link: https://lore.kernel.org/r/20230713070757.4093-1-quic_nprakash@quicinc.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 55b87b7 commit a8bd38d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

arch/arm64/mm/trans_pgd.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/bug.h>
2525
#include <linux/mm.h>
2626
#include <linux/mmzone.h>
27+
#include <linux/kfence.h>
2728

2829
static void *trans_alloc(struct trans_pgd_info *info)
2930
{
@@ -41,7 +42,8 @@ static void _copy_pte(pte_t *dst_ptep, pte_t *src_ptep, unsigned long addr)
4142
* the temporary mappings we use during restore.
4243
*/
4344
set_pte(dst_ptep, pte_mkwrite(pte));
44-
} else if (debug_pagealloc_enabled() && !pte_none(pte)) {
45+
} else if ((debug_pagealloc_enabled() ||
46+
is_kfence_address((void *)addr)) && !pte_none(pte)) {
4547
/*
4648
* debug_pagealloc will removed the PTE_VALID bit if
4749
* the page isn't in use by the resume kernel. It may have

0 commit comments

Comments
 (0)