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 committed Mar 22, 2020
1 parent dc38cc8 commit 78165be
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,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(Error::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 78165be

Please sign in to comment.