Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 23f0263

Browse files
vdonnefortWill Deacon
authored andcommitted
ANDROID: KVM: arm64: Addr sanity check for pKVM HVC registration
Use the assert_in_mod_range() to validate the registered callback is part of a module VA space. This feature requires CONFIG_NVHE_EL2_DEBUG. Bug: 278749606 Bug: 269245057 Change-Id: I4c4d60ac77882fc2d36c3c73b096f4ba9afb83e5 Signed-off-by: Vincent Donnefort <[email protected]>
1 parent b8f47e9 commit 23f0263

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

arch/arm64/kvm/hyp/include/nvhe/mm.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,9 @@ void pkvm_remove_mappings(void *from, void *to);
3535
int __pkvm_map_module_page(u64 pfn, void *va, enum kvm_pgtable_prot prot);
3636
void __pkvm_unmap_module_page(u64 pfn, void *va);
3737
void *__pkvm_alloc_module_va(u64 nr_pages);
38+
#ifdef CONFIG_NVHE_EL2_DEBUG
39+
void assert_in_mod_range(unsigned long addr);
40+
#else
41+
static inline void assert_in_mod_range(unsigned long addr) { }
42+
#endif /* CONFIG_NVHE_EL2_DEBUG */
3843
#endif /* __KVM_HYP_MM_H */

arch/arm64/kvm/hyp/nvhe/mm.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static void update_mod_range(unsigned long addr, size_t size)
124124
hyp_spin_unlock(&mod_range_lock);
125125
}
126126

127-
static void assert_in_mod_range(unsigned long addr)
127+
void assert_in_mod_range(unsigned long addr)
128128
{
129129
/*
130130
* This is not entirely watertight if there are private range
@@ -137,7 +137,6 @@ static void assert_in_mod_range(unsigned long addr)
137137
}
138138
#else
139139
static inline void update_mod_range(unsigned long addr, size_t size) { }
140-
static inline void assert_in_mod_range(unsigned long addr) { }
141140
#endif
142141

143142
void *__pkvm_alloc_module_va(u64 nr_pages)

arch/arm64/kvm/hyp/nvhe/modules.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ int __pkvm_register_hcall(unsigned long hvn_hyp_va)
171171
dyn_hcall_t hfn = (void *)hvn_hyp_va;
172172
int reserved_id, ret;
173173

174+
assert_in_mod_range(hvn_hyp_va);
175+
174176
hyp_spin_lock(&dyn_hcall_lock);
175177

176178
reserved_id = atomic_read(&num_dynamic_hcalls);

0 commit comments

Comments
 (0)