From 1076010de4364a9fd21b25906f366dd7ee633ebe Mon Sep 17 00:00:00 2001 From: Masamichi Takagi Date: Sat, 4 Mar 2017 15:10:39 +0900 Subject: [PATCH] Boundary check in early_alloc_pages() --- arch/x86/kernel/memory.c | 6 +++++- lib/include/ihk/mm.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/memory.c b/arch/x86/kernel/memory.c index dc5df9d3..74e5d95e 100644 --- a/arch/x86/kernel/memory.c +++ b/arch/x86/kernel/memory.c @@ -45,7 +45,11 @@ void *early_alloc_pages(int nr_pages) last_page = phys_to_virt(virt_to_phys(last_page)); } else if (last_page == (void *)-1) { panic("Early allocator is already finalized. Do not use it.\n"); - } + } else { + if(virt_to_phys(last_page) >= bootstrap_mem_end) { + panic("Early allocator: Out of memory\n"); + } + } p = last_page; last_page += (nr_pages * PAGE_SIZE); diff --git a/lib/include/ihk/mm.h b/lib/include/ihk/mm.h index 97da7066..b1cd80d6 100644 --- a/lib/include/ihk/mm.h +++ b/lib/include/ihk/mm.h @@ -34,6 +34,8 @@ enum ihk_mc_gma_type { IHK_MC_RESERVED_AREA_END, }; +extern unsigned long bootstrap_mem_end; + enum ihk_mc_ma_type { IHK_MC_MA_AVAILABLE, IHK_MC_MA_RESERVED,