diff --git a/src/loader/x86_64/elf/mod.rs b/src/loader/x86_64/elf/mod.rs index 0a7c29f9..4c193902 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 @@ -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; } } diff --git a/src/loader/x86_64/elf/test_badnote.bin b/src/loader/x86_64/elf/test_badnote.bin old mode 100755 new mode 100644 index cbe4cb59..99013dd5 Binary files a/src/loader/x86_64/elf/test_badnote.bin and b/src/loader/x86_64/elf/test_badnote.bin differ diff --git a/src/loader/x86_64/elf/test_elfnote.bin b/src/loader/x86_64/elf/test_elfnote.bin old mode 100755 new mode 100644 index 36efd2d3..e2fc7faa Binary files a/src/loader/x86_64/elf/test_elfnote.bin and b/src/loader/x86_64/elf/test_elfnote.bin differ