Re: [PATCH v5 13/20] x86/kexec: Mark relocate_kernel page as ROX instead of RWX

From: Ning, Hongyu
Date: Wed Dec 11 2024 - 22:04:25 EST




On 2024/12/5 23:05, David Woodhouse wrote:
From: David Woodhouse <dwmw@xxxxxxxxxxxx>

All writes to the page now happen before it gets marked as executable
(or after it's already switched to the identmap page tables where it's
OK to be RWX).

Signed-off-by: David Woodhouse <dwmw@xxxxxxxxxxxx>
---
arch/x86/kernel/machine_kexec_64.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c
index c9fd60f8f806..9232ad1562c8 100644
--- a/arch/x86/kernel/machine_kexec_64.c
+++ b/arch/x86/kernel/machine_kexec_64.c
@@ -323,7 +323,7 @@ int machine_kexec_prepare(struct kimage *image)
__memcpy(control_page, __relocate_kernel_start, reloc_end - reloc_start);
- set_memory_x((unsigned long)control_page, 1);
+ set_memory_rox((unsigned long)control_page, 1);
return 0;
}
@@ -333,6 +333,7 @@ void machine_kexec_cleanup(struct kimage *image)
void *control_page = page_address(image->control_code_page);
set_memory_nx((unsigned long)control_page, 1);
+ set_memory_rw((unsigned long)control_page, 1);
free_transition_pgtable(image);
}

Hi David,

I've hit some kdump/kexec regression issue for guest kernel in KVM/QEMU based VM and reported in https://bugzilla.kernel.org/show_bug.cgi?id=219592.

based on further git bisect, it seems to be related with this commit, would you help to take a look?