Skip to content

Commit

Permalink
Do not assume program header is sorted by VA
Browse files Browse the repository at this point in the history
Do not assume program header is sorted ascendantly by virtual
address, otherwise loader_result.kernel_end may be wrong.

Signed-off-by: Liu Jiang <[email protected]>
  • Loading branch information
jiangliu authored and Samuel Ortiz committed Apr 2, 2020
1 parent af88796 commit 43d1c51
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion coverage_config_x86_64.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"coverage_score": 74.7,
"coverage_score": 74.8,
"exclude_path": "",
"crate_features": ""
}
3 changes: 2 additions & 1 deletion src/loader/x86_64/elf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 43d1c51

Please sign in to comment.