* [Qemu-devel] fix ELF loading for 0-length sections
@ 2012-02-21 10:42 Damian, Alexandru
2012-02-21 11:08 ` Peter Maydell
0 siblings, 1 reply; 3+ messages in thread
From: Damian, Alexandru @ 2012-02-21 10:42 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 2279 bytes --]
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 <alexandru.damian@intel.com>
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 jkosina@suse.cz.
Signed-off-by: Alexandru Damian <alexandru.damian@intel.com>
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;
[-- Attachment #2: Type: text/html, Size: 2672 bytes --]
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] fix ELF loading for 0-length sections
2012-02-21 10:42 [Qemu-devel] fix ELF loading for 0-length sections Damian, Alexandru
@ 2012-02-21 11:08 ` Peter Maydell
2012-02-25 8:48 ` Damian, Alexandru
0 siblings, 1 reply; 3+ messages in thread
From: Peter Maydell @ 2012-02-21 11:08 UTC (permalink / raw)
To: Damian, Alexandru; +Cc: Riku Voipio, qemu-devel
On 21 February 2012 10:42, Damian, Alexandru <alexandru.damian@intel.com> wrote:
> 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.
CC'ing Riku (linux-user maintainer).
>
> Cheers,
> Alex
>
> ----------------
> commit a42e5231c1be5f09caeb6c73e34933cd7efa7023
> Author: Alexandru DAMIAN <alexandru.damian@intel.com>
> 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 jkosina@suse.cz.
>
> Signed-off-by: Alexandru Damian <alexandru.damian@intel.com>
Convention is to submit patches as git-format-patch style emails.
> 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
Please don't make unrelated whitespace changes.
>
> 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.
> + */
This comment could be better:
/* mmap() will fail EINVAL if given a zero size, but a
* segment with zero filesize is perfectly valid (and
* handled by the kernel's ELF loading code).
*/
> + 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);
Something in your patch submission path is wrapping long lines.
> + if (error == -1) {
> + goto exit_perror;
> + }
QEMU coding style is four-space indents, but the indent in your new
code is mostly eight-space.
> }
>
> vaddr_ef = vaddr + eppnt->p_filesz;
>
Otherwise looks OK.
-- PMM
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] fix ELF loading for 0-length sections
2012-02-21 11:08 ` Peter Maydell
@ 2012-02-25 8:48 ` Damian, Alexandru
0 siblings, 0 replies; 3+ messages in thread
From: Damian, Alexandru @ 2012-02-25 8:48 UTC (permalink / raw)
To: Peter Maydell; +Cc: Riku Voipio, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 4104 bytes --]
Hi guys,
Please don't submit these patches yet - I will re-submit from a different
email, to lessen the
legal complications.
I'm also adding a couple of new patches - just a heads up, when
transferring structs or arrays
in a syscall/ioctl, pointers also need conversions between target memory
space and host memory space.
i.e.
#if HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 32
case TYPE_LONG:
case TYPE_ULONG:
*(uint32_t *)dst = tswap32(*(uint32_t *)src);
break;
case TYPE_PTRVOID:
/* we actually convert pointer values between host and target */
if (to_host) {
*(uint32_t *)dst = (uint32_t)g2h(*(uint32_t*)src);
}
else {
*(uint32_t *)dst = (uint32_t)h2g(*(uint32_t*)src);
}
break;
Cheers,
Alex
On Tue, Feb 21, 2012 at 3:08 AM, Peter Maydell <peter.maydell@linaro.org>wrote:
> On 21 February 2012 10:42, Damian, Alexandru <alexandru.damian@intel.com>
> wrote:
> > 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.
>
> CC'ing Riku (linux-user maintainer).
>
> >
> > Cheers,
> > Alex
> >
> > ----------------
> > commit a42e5231c1be5f09caeb6c73e34933cd7efa7023
> > Author: Alexandru DAMIAN <alexandru.damian@intel.com>
> > 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 jkosina@suse.cz.
> >
> > Signed-off-by: Alexandru Damian <alexandru.damian@intel.com>
>
> Convention is to submit patches as git-format-patch style emails.
>
> > 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
>
> Please don't make unrelated whitespace changes.
>
> >
> > 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.
> > + */
>
> This comment could be better:
> /* mmap() will fail EINVAL if given a zero size, but a
> * segment with zero filesize is perfectly valid (and
> * handled by the kernel's ELF loading code).
> */
>
> > + 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);
>
> Something in your patch submission path is wrapping long lines.
>
> > + if (error == -1) {
> > + goto exit_perror;
> > + }
>
> QEMU coding style is four-space indents, but the indent in your new
> code is mostly eight-space.
>
> > }
> >
> > vaddr_ef = vaddr + eppnt->p_filesz;
> >
>
> Otherwise looks OK.
>
> -- PMM
>
[-- Attachment #2: Type: text/html, Size: 5350 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-02-25 8:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-21 10:42 [Qemu-devel] fix ELF loading for 0-length sections Damian, Alexandru
2012-02-21 11:08 ` Peter Maydell
2012-02-25 8:48 ` Damian, Alexandru
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.