From 43d1c51c32474019acbd44738c6aebe7f69f7be2 Mon Sep 17 00:00:00 2001 From: Liu Jiang Date: Sun, 22 Mar 2020 16:14:53 +0800 Subject: [PATCH] Do not assume program header is sorted by VA Do not assume program header is sorted ascendantly by virtual address, otherwise loader_result.kernel_end may be wrong. Signed-off-by: Liu Jiang --- coverage_config_x86_64.json | 2 +- src/loader/x86_64/elf/mod.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/coverage_config_x86_64.json b/coverage_config_x86_64.json index 27f86931..898d1bf0 100644 --- a/coverage_config_x86_64.json +++ b/coverage_config_x86_64.json @@ -1,5 +1,5 @@ { - "coverage_score": 74.7, + "coverage_score": 74.8, "exclude_path": "", "crate_features": "" } diff --git a/src/loader/x86_64/elf/mod.rs b/src/loader/x86_64/elf/mod.rs index 34ea6092..4b6de40b 100644 --- a/src/loader/x86_64/elf/mod.rs +++ b/src/loader/x86_64/elf/mod.rs @@ -236,10 +236,11 @@ impl KernelLoader for Elf { .read_exact_from(mem_offset, kernel_image, phdr.p_filesz as usize) .map_err(|_| Error::ReadKernelImage)?; - loader_result.kernel_end = mem_offset + let kernel_end = mem_offset .raw_value() .checked_add(phdr.p_memsz as GuestUsize) .ok_or(KernelLoaderError::MemoryOverflow)?; + loader_result.kernel_end = std::cmp::max(loader_result.kernel_end, kernel_end); } // elf image has no setup_header which is defined for bzImage