From 26abc82f3ccd3d331fc3002d1bb8cd3547f59bc2 Mon Sep 17 00:00:00 2001 From: Victor Sun Date: Wed, 24 Feb 2021 11:49:20 +0800 Subject: [PATCH] HV: panic on 0 address when do e820_alloc_memory Current memory allocation algorithm is to find the available address from the highest possible address below max_address. If the function returns 0, means all memory is used up and we have to put the resource at address 0, this is dangerous for a running hypervisor. Also returns 0 would make code logic very complicated, since memcpy_s() doesn't support address 0 copy. Tracked-On: #5626 Signed-off-by: Victor Sun Reviewed-by: Jason Chen CJ --- hypervisor/arch/x86/e820.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hypervisor/arch/x86/e820.c b/hypervisor/arch/x86/e820.c index 23899a232..b847f093c 100644 --- a/hypervisor/arch/x86/e820.c +++ b/hypervisor/arch/x86/e820.c @@ -115,7 +115,13 @@ uint64_t e820_alloc_memory(uint32_t size_arg, uint64_t max_addr) } } - if (ret == INVALID_HPA) { + if ((ret == INVALID_HPA) || (ret == 0UL)) { + /* current memory allocation algorithm is to find the available address from the highest + * possible address below max_addr. if ret == 0, means all memory is used up and we have to + * put the resource at address 0, this is dangerous. + * Also ret == 0 would make code logic very complicated, since memcpy_s() doesn't support + * address 0 copy. + */ panic("Requested memory from E820 cannot be reserved!!"); }