Hollis Blanchard
2006-Jun-30 20:42 UTC
[Xen-devel] [patch] improve ELF loader error messages
Provide more specific and helpful error messages during ELF loading. Signed-off-by: Jimi Xenidis <jimix@watson.ibm.com> Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com> diff -r 68928d1c8ab6 tools/libxc/xc_load_elf.c --- a/tools/libxc/xc_load_elf.c Fri Jun 30 15:24:44 2006 -0500 +++ b/tools/libxc/xc_load_elf.c Fri Jun 30 15:40:09 2006 -0500 @@ -169,8 +169,11 @@ static int parseelfimage(const char *ima elf_pa_off_defined = (p != NULL); elf_pa_off = elf_pa_off_defined ? strtoull(p+17, &p, 0) : virt_base; - if ( elf_pa_off_defined && !virt_base_defined ) - goto bad_image; + if ( elf_pa_off_defined && !virt_base_defined ) { + ERROR("Neither ELF_PADDR_OFFSET nor VIRT_BASE found in __xen_guest" + " section."); + return -EINVAL; + } for ( h = 0; h < ehdr->e_phnum; h++ ) { @@ -178,8 +181,11 @@ static int parseelfimage(const char *ima if ( !is_loadable_phdr(phdr) ) continue; vaddr = phdr->p_paddr - elf_pa_off + virt_base; - if ( (vaddr + phdr->p_memsz) < vaddr ) - goto bad_image; + if ( (vaddr + phdr->p_memsz) < vaddr ) { + ERROR("ELF program header %d is too large.", h); + return -EINVAL; + } + if ( vaddr < kernstart ) kernstart = vaddr; if ( (vaddr + phdr->p_memsz) > kernend ) @@ -201,8 +207,10 @@ static int parseelfimage(const char *ima if ( (kernstart > kernend) || (dsi->v_kernentry < kernstart) || (dsi->v_kernentry > kernend) || - (dsi->v_start > kernstart) ) - goto bad_image; + (dsi->v_start > kernstart) ) { + ERROR("ELF start or entries are out of bounds."); + return -EINVAL; + } if ( (p = strstr(guestinfo, "BSD_SYMTAB")) != NULL ) dsi->load_symtab = 1; @@ -214,10 +222,6 @@ static int parseelfimage(const char *ima loadelfsymtab(image, 0, 0, NULL, dsi); return 0; - - bad_image: - ERROR("Malformed ELF image."); - return -EINVAL; } static int -- Hollis Blanchard IBM Linux Technology Center _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel