qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] fix ELF loading for 0-length sections


From: Damian, Alexandru
Subject: [Qemu-devel] fix ELF loading for 0-length sections
Date: Tue, 21 Feb 2012 12:42:55 +0200

Hi,

I got a problem with QEMU refusing to load an ELF binary with 0-length sections,
while the kernel has no issue doing this.

This patch adds a check that has been in kernel since 2008 at least.

Cheers,
Alex

----------------
commit a42e5231c1be5f09caeb6c73e34933cd7efa7023
Author: Alexandru DAMIAN <address@hidden>
Date:   Tue Feb 21 12:34:36 2012 +0200

    Do not attempt to map 0-length sections
   
    Mmap will return an invalid argument, but 0-length sections
    are valid in any case. The kernel as a similar check
    when loading elf binaries courtesy of address@hidden.
   
    Signed-off-by: Alexandru Damian <address@hidden>

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index ea61d0d..71d0ae3 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -918,9 +918,9 @@ static inline void init_thread(struct target_pt_regs *regs,
 
 #define elf_check_arch(x) ( (x) == ELF_ARCH )
 
-#define ELF_CLASS    ELFCLASS64
-#define ELF_DATA    ELFDATA2MSB
-#define ELF_ARCH    EM_S390
+#define ELF_CLASS        ELFCLASS64
+#define ELF_DATA        ELFDATA2MSB
+#define ELF_ARCH        EM_S390
 
 static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
 {
@@ -1565,11 +1565,16 @@ static void load_elf_image(const char *image_name, int image_fd,
             vaddr_po = TARGET_ELF_PAGEOFFSET(vaddr);
             vaddr_ps = TARGET_ELF_PAGESTART(vaddr);
 
-            error = target_mmap(vaddr_ps, eppnt->p_filesz + vaddr_po,
-                                elf_prot, MAP_PRIVATE | MAP_FIXED,
-                                image_fd, eppnt->p_offset - vaddr_po);
-            if (error == -1) {
-                goto exit_perror;
+            /* Don't attempt to map 0 bytes len sections.
+               Kernel also has this check.
+            */
+            if (eppnt->p_filesz + vaddr_po != 0) {
+                    error = target_mmap(vaddr_ps, eppnt->p_filesz + vaddr_po,
+                                        elf_prot, MAP_PRIVATE | MAP_FIXED,
+                                        image_fd, eppnt->p_offset - vaddr_po);
+                    if (error == -1) {
+                        goto exit_perror;
+                    }
             }
 
             vaddr_ef = vaddr + eppnt->p_filesz;


reply via email to

[Prev in Thread] Current Thread [Next in Thread]