# HG changeset patch
# User Jimi Xenidis <jimix@xxxxxxxxxxxxxx>
# Node ID f0b7557c9ae41feb099ea828060cb33270c2173d
# Parent d6a49aaee3122e14a1bb7583fd03cdcd8bd2e480
[ppc] allow the elf loading of a 64bit image when running in 32 bits
This most of this patch was sent upstream. In addition failure gotos
were removed and replaces with real breadcrumbs as to why we failed.
Signed-off-by: Jimi Xenidis <jimix@xxxxxxxxxxxxxx>
---
tools/libxc/xc_load_elf.c | 34 +++++++++++++++++++---------------
1 files changed, 19 insertions(+), 15 deletions(-)
diff -r d6a49aaee312 -r f0b7557c9ae4 tools/libxc/xc_load_elf.c
--- a/tools/libxc/xc_load_elf.c Mon Jun 26 16:08:27 2006 -0500
+++ b/tools/libxc/xc_load_elf.c Wed Jun 28 15:15:54 2006 -0400
@@ -73,7 +73,7 @@ static int parseelfimage(const char *ima
Elf_Ehdr *ehdr = (Elf_Ehdr *)image;
Elf_Phdr *phdr;
Elf_Shdr *shdr;
- unsigned long kernstart = ~0UL, kernend=0UL, vaddr, virt_base, elf_pa_off;
+ Elf_Addr kernstart = -1, kernend = 0, vaddr, virt_base, elf_pa_off;
const char *shstrtab;
char *guestinfo=NULL, *p;
int h, virt_base_defined, elf_pa_off_defined;
@@ -167,15 +167,17 @@ static int parseelfimage(const char *ima
/* Initial guess for virt_base is 0 if it is not explicitly defined. */
p = strstr(guestinfo, "VIRT_BASE=");
virt_base_defined = (p != NULL);
- virt_base = virt_base_defined ? strtoul(p+10, &p, 0) : 0;
+ virt_base = virt_base_defined ? strtoull(p+10, &p, 0) : 0;
/* Initial guess for elf_pa_off is virt_base if not explicitly defined. */
p = strstr(guestinfo, "ELF_PADDR_OFFSET=");
elf_pa_off_defined = (p != NULL);
- elf_pa_off = elf_pa_off_defined ? strtoul(p+17, &p, 0) : virt_base;
-
- if ( elf_pa_off_defined && !virt_base_defined )
- goto bad_image;
+ elf_pa_off = elf_pa_off_defined ? strtoull(p+17, &p, 0) : virt_base;
+
+ if ( elf_pa_off_defined && !virt_base_defined ) {
+ ERROR("no PA or VA base defined in ELF image");
+ return -EINVAL;
+ }
for ( h = 0; h < ehdr->e_phnum; h++ )
{
@@ -183,8 +185,12 @@ 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 ) {
+ /* XXX Are we checking for vaddr to wrap here? */
+ ERROR("ELF program header too large.");
+ return -EINVAL;
+ }
+
if ( vaddr < kernstart )
kernstart = vaddr;
if ( (vaddr + phdr->p_memsz) > kernend )
@@ -201,13 +207,15 @@ static int parseelfimage(const char *ima
dsi->v_kernentry = ehdr->e_entry;
if ( (p = strstr(guestinfo, "VIRT_ENTRY=")) != NULL )
- dsi->v_kernentry = strtoul(p+11, &p, 0);
+ dsi->v_kernentry = strtoull(p+11, &p, 0);
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;
@@ -219,10 +227,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
_______________________________________________
Xen-ppc-devel mailing list
Xen-ppc-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-ppc-devel
|