ANDROID: KVM: arm64: Fix hyp_alloc() upper size check
The maximum size is of an allocation is bound to the u32 type of alloc in struct chunk_hdr. Bug: 431949921 Bug: 357781595 Reported-by: Hiroyuki Katsura <hk590@cam.ac.uk> Change-Id: Ifedf1e778afd9c728b654ac223f5f725edc65034 Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
This commit is contained in:
committed by
Treehugger Robot
parent
60ca34a631
commit
b3fdeb8b13
@@ -552,6 +552,12 @@ void *hyp_alloc(size_t size)
|
||||
size_t missing_map;
|
||||
int ret = 0;
|
||||
|
||||
/* constrained by chunk_hdr *_size types */
|
||||
if (size > U32_MAX) {
|
||||
ret = -E2BIG;
|
||||
goto end_unlocked;
|
||||
}
|
||||
|
||||
size = ALIGN(size ?: MIN_ALLOC, MIN_ALLOC);
|
||||
|
||||
hyp_spin_lock(&allocator->lock);
|
||||
@@ -587,9 +593,11 @@ void *hyp_alloc(size_t size)
|
||||
}
|
||||
|
||||
WARN_ON(chunk_install(chunk, size, last_chunk, allocator));
|
||||
|
||||
end:
|
||||
hyp_spin_unlock(&allocator->lock);
|
||||
|
||||
end_unlocked:
|
||||
*(this_cpu_ptr(&hyp_allocator_errno)) = ret;
|
||||
|
||||
/* Enforce zeroing allocated memory */
|
||||
|
||||
Reference in New Issue
Block a user