From 83eb7b07ed95a1c1181c3dda340573ea3046cfd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Cl=C3=A9ment=20Tosi?= Date: Thu, 22 Feb 2024 10:14:27 +0000 Subject: [PATCH] ANDROID: KVM: arm64: Add __pkvm_module_{memcpy,memset}() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pKVM modules built with KCFI checks would fail when calling module_ops->memcpy(...) or module_ops->memset(...) as those directly point to the arch implementations (within the core kernel) which are not declared with SYM_TYPED_START() i.e. don't have the KCFI u32 type id prefix. Therefore, expose these in the module_ops using C wrappers (which the compiler will properly decorate) so that KCFI checks in modules pass. This adds an extra level of indirection when calling the functions, which could be avoided by decorating the asm routines, similar to commit c50d32859e70 ("arm64: Add types to indirect called assembly functions") commit b952a9cf3de2 ("crypto: arm64/aes-neonbs - fix crash with CFI enabled")) commit ccace936eec7 ("x86: Add types to indirectly called assembly functions") but, given that the issue only concerns pKVM modules (not yet supported upstream), prefer a pKVM-only solution. Bug: 278010198 Bug: 278749606 Change-Id: I0d241755ae7980b454fce2cef98a3f0bf7c22263 Signed-off-by: Pierre-Clément Tosi --- arch/arm64/kvm/hyp/nvhe/modules.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/modules.c b/arch/arm64/kvm/hyp/nvhe/modules.c index 128bcde56b3b..364939a754f7 100644 --- a/arch/arm64/kvm/hyp/nvhe/modules.c +++ b/arch/arm64/kvm/hyp/nvhe/modules.c @@ -16,6 +16,16 @@ #include #include +static void *__pkvm_module_memcpy(void *to, const void *from, size_t count) +{ + return memcpy(to, from, count); +} + +static void *__pkvm_module_memset(void *dst, int c, size_t count) +{ + return memset(dst, c, count); +} + static void __kvm_flush_dcache_to_poc(void *addr, size_t size) { kvm_flush_dcache_to_poc((unsigned long)addr, (unsigned long)size); @@ -134,8 +144,8 @@ const struct pkvm_module_ops module_ops = { .host_unshare_hyp = __pkvm_host_unshare_hyp, .pin_shared_mem = hyp_pin_shared_mem, .unpin_shared_mem = hyp_unpin_shared_mem, - .memcpy = memcpy, - .memset = memset, + .memcpy = __pkvm_module_memcpy, + .memset = __pkvm_module_memset, .hyp_pa = hyp_virt_to_phys, .hyp_va = hyp_phys_to_virt, .kern_hyp_va = __kern_hyp_va,