From d996511e4327ee2437d2078a1a8cd9898d22003b Mon Sep 17 00:00:00 2001 From: Quentin Perret Date: Mon, 5 Dec 2022 15:52:57 +0000 Subject: [PATCH] ANDROID: arm64: patching: Add aarch64_addr_write() The process of applying hypervisor relocations involves patching addresses in the hypervisor object. In the existing KVM nVHE relocation procedure, the relocations are applied early enough for write-permission not to be a problem when touching e.g. the rodata section. But applying relocations on hypervisor modules embedded in a kernel module proves more challenging, as the kernel module loader will actively map text and rodata sections read-only. In order to allow patching in those sections, let's introduce a new helper function using the text fixmap to temporarily map the relevant pages writable. Bug: 244543039 Bug: 244373730 Change-Id: I9dcdade1927e5bc121db87bc950fb70a374c44cd Signed-off-by: Quentin Perret --- arch/arm64/include/asm/patching.h | 1 + arch/arm64/kernel/patching.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/arch/arm64/include/asm/patching.h b/arch/arm64/include/asm/patching.h index 6bf5adc56295..82b1e0c66809 100644 --- a/arch/arm64/include/asm/patching.h +++ b/arch/arm64/include/asm/patching.h @@ -6,6 +6,7 @@ int aarch64_insn_read(void *addr, u32 *insnp); int aarch64_insn_write(void *addr, u32 insn); +int aarch64_addr_write(void *addr, u64 dst); int aarch64_insn_patch_text_nosync(void *addr, u32 insn); int aarch64_insn_patch_text(void *addrs[], u32 insns[], int cnt); diff --git a/arch/arm64/kernel/patching.c b/arch/arm64/kernel/patching.c index b949db008562..b336073fe6b1 100644 --- a/arch/arm64/kernel/patching.c +++ b/arch/arm64/kernel/patching.c @@ -90,6 +90,11 @@ int __kprobes aarch64_insn_write(void *addr, u32 insn) return __aarch64_text_write(addr, &__insn, AARCH64_INSN_SIZE); } +int __kprobes aarch64_addr_write(void *addr, u64 dst) +{ + return __aarch64_text_write(addr, &dst, sizeof(dst)); +} + int __kprobes aarch64_insn_patch_text_nosync(void *addr, u32 insn) { u32 *tp = addr;