ANDROID: KVM: arm64: Add __pkvm_module_{memcpy,memset}()

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 c50d32859e ("arm64: Add types to indirect called assembly
                       functions")
 commit b952a9cf3de2 ("crypto: arm64/aes-neonbs - fix crash with CFI
                       enabled"))
 commit ccace936ee ("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 <ptosi@google.com>
This commit is contained in:
Pierre-Clément Tosi
2024-02-22 10:14:27 +00:00
committed by Mostafa Saleh
parent 60707bba73
commit 83eb7b07ed
+12 -2
View File
@@ -16,6 +16,16 @@
#include <nvhe/trace/trace.h>
#include <nvhe/trap_handler.h>
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,