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 28, 2020
1 parent c51e6e1 commit 025db34
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 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": ""
}
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -291,7 +292,7 @@ where
kernel_image
.read_exact(&mut buf)
.map_err(|_| Error::ReadNoteHeader)?;
if buf == [b'x', b'e', b'n', b'\0'] {
if buf == [b'X', b'e', b'n', b'\0'] {
break;
}
}
Expand Down
Binary file modified src/loader/x86_64/elf/test_badnote.bin
100755 → 100644
Binary file not shown.
Binary file modified src/loader/x86_64/elf/test_elfnote.bin
100755 → 100644
Binary file not shown.

0 comments on commit 025db34

Please sign in to comment.