Skip to contentSkip to conversation

libxc: elf_kernel loader: Remove check for shstrtab

PATCH Superseded Anthony PERARD 3 participants 8 messages May 15, 2019 – May 17, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxc: elf_kernel loader: Remove check for shstrtab

This was probably useful to load ELF Note, but now ELF notes "should live in a PT_NOTE segment" (elfnote.h).

With notes living in segment, there are no need for sections, so there is nothing to be stored in the shstrtab.

This patch would allow to write a simpler ELF header for an OVMF blob (which isn't an ELF) and allow it to be loaded as a PVH kernel. The header only needs to declare two program segments:
- one to tell an ELF loader where to put the blob,
- one for a Xen ELFNOTE.

The ELFNOTE is to comply to the pvh design which wants the XEN_ELFNOTE_PHYS32_ENTRY to declare a blob as compaptible with the PVH boot ABI.

Note that without the ELFNOTE, libxc will load an ELF but with the plain ELF loader, which doesn't check for shstrtab.

---
 tools/libxc/xc_dom_elfloader.c | 9 ---------
 1 file changed, 9 deletions(-)
tools/libxc/xc_dom_elfloader.c +0 -9
index 82b5f2ee79..b327db219d 100644
@@ -165,15 +165,6 @@ static elf_negerrnoval xc_dom_parse_elf_kernel(struct xc_dom_image *dom)
         return rc;
     }
 
-    /* Find the section-header strings table. */
-    if ( ELF_PTRVAL_INVALID(elf->sec_strtab) )
-    {
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: ELF image"
-                     " has no shstrtab", __FUNCTION__);
-        rc = -EINVAL;
-        goto out;
-    }
-
     /* parse binary and get xen meta info */
     elf_parse_binary(elf);
     if ( elf_xen_parse(elf, &dom->parms) != 0 )
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · Anthony PERARD

This was probably useful to load ELF Note, but now ELF notes "should live in a PT_NOTE segment" (elfnote.h).

With notes living in segment, there are no need for sections, so there is nothing to be stored in the shstrtab.

This patch would allow to write a simpler ELF header for an OVMF blob (which isn't an ELF) and allow it to be loaded as a PVH kernel. The header only needs to declare two program segments:
- one to tell an ELF loader where to put the blob,
- one for a Xen ELFNOTE.

Quoted 8 lines

The ELFNOTE is to comply to the pvh design which wants the XEN_ELFNOTE_PHYS32_ENTRY to declare a blob as compaptible with the PVH boot ABI.

Note that without the ELFNOTE, libxc will load an ELF but with the plain ELF loader, which doesn't check for shstrtab.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
In reply to Anthony PERARD
Quoted 30 lines · Anthony PERARD

This was probably useful to load ELF Note, but now ELF notes "should live in a PT_NOTE segment" (elfnote.h).

With notes living in segment, there are no need for sections, so there is nothing to be stored in the shstrtab.

This patch would allow to write a simpler ELF header for an OVMF blob (which isn't an ELF) and allow it to be loaded as a PVH kernel. The header only needs to declare two program segments:
- one to tell an ELF loader where to put the blob,
- one for a Xen ELFNOTE.

The ELFNOTE is to comply to the pvh design which wants the XEN_ELFNOTE_PHYS32_ENTRY to declare a blob as compaptible with the PVH boot ABI.

Note that without the ELFNOTE, libxc will load an ELF but with the plain ELF loader, which doesn't check for shstrtab.

---
 tools/libxc/xc_dom_elfloader.c | 9 ---------
 1 file changed, 9 deletions(-)
tools/libxc/xc_dom_elfloader.c +0 -0
index 82b5f2ee79..b327db219d 100644
@@ -165,15 +165,6 @@ static elf_negerrnoval xc_dom_parse_elf_kernel(struct xc_dom_image *dom)
         return rc;

tools/libxc/xc_dom_elfloader.c static elf_negerrnoval xc_dom_parse_elf_kernel(struct xc_dom_image *dom) · line 175

Quoted 10 lines
tools/libxc/xc_dom_elfloader.c +0 -8
     }
 
-    /* Find the section-header strings table. */
-    if ( ELF_PTRVAL_INVALID(elf->sec_strtab) )
-    {
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: ELF image"
-                     " has no shstrtab", __FUNCTION__);
-        rc = -EINVAL;
-        goto out;
-    }

This might be fine for newer binaries, but you'll break older ones.

Instead, you should skip searching for strtab if we've already located the Xen notes.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 44 lines · Andrew Cooper
Quoted 30 lines · Anthony PERARD

This was probably useful to load ELF Note, but now ELF notes "should live in a PT_NOTE segment" (elfnote.h).

With notes living in segment, there are no need for sections, so there is nothing to be stored in the shstrtab.

This patch would allow to write a simpler ELF header for an OVMF blob (which isn't an ELF) and allow it to be loaded as a PVH kernel. The header only needs to declare two program segments:
- one to tell an ELF loader where to put the blob,
- one for a Xen ELFNOTE.

The ELFNOTE is to comply to the pvh design which wants the XEN_ELFNOTE_PHYS32_ENTRY to declare a blob as compaptible with the PVH boot ABI.

Note that without the ELFNOTE, libxc will load an ELF but with the plain ELF loader, which doesn't check for shstrtab.

---
 tools/libxc/xc_dom_elfloader.c | 9 ---------
 1 file changed, 9 deletions(-)
tools/libxc/xc_dom_elfloader.c +0 -0
index 82b5f2ee79..b327db219d 100644
@@ -165,15 +165,6 @@ static elf_negerrnoval xc_dom_parse_elf_kernel(struct xc_dom_image *dom)
         return rc;

tools/libxc/xc_dom_elfloader.c static elf_negerrnoval xc_dom_parse_elf_kernel(struct xc_dom_image *dom) · line 175

Quoted 10 lines
tools/libxc/xc_dom_elfloader.c +0 -8
     }
 
-    /* Find the section-header strings table. */
-    if ( ELF_PTRVAL_INVALID(elf->sec_strtab) )
-    {
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: ELF image"
-                     " has no shstrtab", __FUNCTION__);
-        rc = -EINVAL;
-        goto out;
-    }

This might be fine for newer binaries, but you'll break older ones.

Quoted 2 lines

Instead, you should skip searching for strtab if we've already located the Xen notes.

AIUI old binaries always have shstrtab while it isn't always true for new ones.

Unfortunately my attempt to figure out the history of this piece of code is futile.

Wei.

Quoted 2 lines

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
In reply to Andrew Cooper
Quoted 44 lines · Andrew Cooper
Quoted 30 lines · Anthony PERARD

This was probably useful to load ELF Note, but now ELF notes "should live in a PT_NOTE segment" (elfnote.h).

With notes living in segment, there are no need for sections, so there is nothing to be stored in the shstrtab.

This patch would allow to write a simpler ELF header for an OVMF blob (which isn't an ELF) and allow it to be loaded as a PVH kernel. The header only needs to declare two program segments:
- one to tell an ELF loader where to put the blob,
- one for a Xen ELFNOTE.

The ELFNOTE is to comply to the pvh design which wants the XEN_ELFNOTE_PHYS32_ENTRY to declare a blob as compaptible with the PVH boot ABI.

Note that without the ELFNOTE, libxc will load an ELF but with the plain ELF loader, which doesn't check for shstrtab.

---
 tools/libxc/xc_dom_elfloader.c | 9 ---------
 1 file changed, 9 deletions(-)
tools/libxc/xc_dom_elfloader.c +0 -0
index 82b5f2ee79..b327db219d 100644
@@ -165,15 +165,6 @@ static elf_negerrnoval xc_dom_parse_elf_kernel(struct xc_dom_image *dom)
         return rc;

tools/libxc/xc_dom_elfloader.c static elf_negerrnoval xc_dom_parse_elf_kernel(struct xc_dom_image *dom) · line 175

Quoted 10 lines
tools/libxc/xc_dom_elfloader.c +0 -8
     }
 
-    /* Find the section-header strings table. */
-    if ( ELF_PTRVAL_INVALID(elf->sec_strtab) )
-    {
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: ELF image"
-                     " has no shstrtab", __FUNCTION__);
-        rc = -EINVAL;
-        goto out;
-    }

This might be fine for newer binaries, but you'll break older ones.

Quoted 2 lines

Instead, you should skip searching for strtab if we've already located the Xen notes.

:-(, maybe I should have gone futher on explaining why this check is useless (and probably at the wrong place, at least now).

The next thing that's done after that check is:
elf_parse_binary()
elf_xen_parse()
Those are located in "xen/common/libelf", and those are the functions that actually takes care of extracting data from the elf.

elf_xen_parse() first look for Xen ELFNOTE in the program segments (phdr, PT_NOTE) and skip reading section and strtab if found.

So, libelf already does what you asked for ;-).

The shstrtab are only used to look for legacy __xen_guest section names. Since ELFNOTEs was used, the name of section aren't looked at.

I hope that help.

Thanks,

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#5 lore raw
Quoted 60 lines · Anthony PERARD
Quoted 44 lines · Andrew Cooper
Quoted 30 lines · Anthony PERARD

This was probably useful to load ELF Note, but now ELF notes "should live in a PT_NOTE segment" (elfnote.h).

With notes living in segment, there are no need for sections, so there is nothing to be stored in the shstrtab.

This patch would allow to write a simpler ELF header for an OVMF blob (which isn't an ELF) and allow it to be loaded as a PVH kernel. The header only needs to declare two program segments:
- one to tell an ELF loader where to put the blob,
- one for a Xen ELFNOTE.

The ELFNOTE is to comply to the pvh design which wants the XEN_ELFNOTE_PHYS32_ENTRY to declare a blob as compaptible with the PVH boot ABI.

Note that without the ELFNOTE, libxc will load an ELF but with the plain ELF loader, which doesn't check for shstrtab.

---
 tools/libxc/xc_dom_elfloader.c | 9 ---------
 1 file changed, 9 deletions(-)
tools/libxc/xc_dom_elfloader.c +0 -0
index 82b5f2ee79..b327db219d 100644
@@ -165,15 +165,6 @@ static elf_negerrnoval xc_dom_parse_elf_kernel(struct xc_dom_image *dom)
         return rc;

tools/libxc/xc_dom_elfloader.c static elf_negerrnoval xc_dom_parse_elf_kernel(struct xc_dom_image *dom) · line 175

Quoted 10 lines
tools/libxc/xc_dom_elfloader.c +0 -8
     }
 
-    /* Find the section-header strings table. */
-    if ( ELF_PTRVAL_INVALID(elf->sec_strtab) )
-    {
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: ELF image"
-                     " has no shstrtab", __FUNCTION__);
-        rc = -EINVAL;
-        goto out;
-    }

This might be fine for newer binaries, but you'll break older ones.

Quoted 2 lines

Instead, you should skip searching for strtab if we've already located the Xen notes.

:-(, maybe I should have gone futher on explaining why this check is useless (and probably at the wrong place, at least now).

The next thing that's done after that check is:
elf_parse_binary()
elf_xen_parse()
Those are located in "xen/common/libelf", and those are the functions that actually takes care of extracting data from the elf.

elf_xen_parse() first look for Xen ELFNOTE in the program segments (phdr, PT_NOTE) and skip reading section and strtab if found.

Quoted 7 lines

So, libelf already does what you asked for ;-).

The shstrtab are only used to look for legacy __xen_guest section names. Since ELFNOTEs was used, the name of section aren't looked at.

I hope that help.

Andrew, do you still have concern?

Wei.

Quoted 4 lines

Thanks,

Signature · 1 line
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw
Quoted 59 lines · Wei Liu
Quoted 58 lines · Anthony PERARD
Quoted 43 lines · Andrew Cooper
Quoted 30 lines · Anthony PERARD

This was probably useful to load ELF Note, but now ELF notes "should live in a PT_NOTE segment" (elfnote.h).

With notes living in segment, there are no need for sections, so there is nothing to be stored in the shstrtab.

This patch would allow to write a simpler ELF header for an OVMF blob (which isn't an ELF) and allow it to be loaded as a PVH kernel. The header only needs to declare two program segments:
- one to tell an ELF loader where to put the blob,
- one for a Xen ELFNOTE.

The ELFNOTE is to comply to the pvh design which wants the XEN_ELFNOTE_PHYS32_ENTRY to declare a blob as compaptible with the PVH boot ABI.

Note that without the ELFNOTE, libxc will load an ELF but with the plain ELF loader, which doesn't check for shstrtab.

---
 tools/libxc/xc_dom_elfloader.c | 9 ---------
 1 file changed, 9 deletions(-)
tools/libxc/xc_dom_elfloader.c +0 -0
index 82b5f2ee79..b327db219d 100644
@@ -165,15 +165,6 @@ static elf_negerrnoval xc_dom_parse_elf_kernel(struct xc_dom_image *dom)
         return rc;

tools/libxc/xc_dom_elfloader.c static elf_negerrnoval xc_dom_parse_elf_kernel(struct xc_dom_image *dom) · line 175

Quoted 10 lines
tools/libxc/xc_dom_elfloader.c +0 -8
     }
 
-    /* Find the section-header strings table. */
-    if ( ELF_PTRVAL_INVALID(elf->sec_strtab) )
-    {
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: ELF image"
-                     " has no shstrtab", __FUNCTION__);
-        rc = -EINVAL;
-        goto out;
-    }

This might be fine for newer binaries, but you'll break older ones.

Quoted 2 lines

Instead, you should skip searching for strtab if we've already located the Xen notes.

:-(, maybe I should have gone futher on explaining why this check is useless (and probably at the wrong place, at least now).

The next thing that's done after that check is:
elf_parse_binary()
elf_xen_parse()
Those are located in "xen/common/libelf", and those are the functions that actually takes care of extracting data from the elf.

elf_xen_parse() first look for Xen ELFNOTE in the program segments (phdr, PT_NOTE) and skip reading section and strtab if found.

Quoted 8 lines
Quoted 7 lines

So, libelf already does what you asked for ;-).

The shstrtab are only used to look for legacy __xen_guest section names. Since ELFNOTEs was used, the name of section aren't looked at.

I hope that help.

Andrew, do you still have concern?

If libelf goes on to DTRT then fine, but this full explanation needs to be in the commit message.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw

PATCH v2 1/1 libxc: elf_kernel loader: Remove check for shstrtab

In reply to Anthony PERARD

This was probably useful as a sanity check when the "__xen_guest" section were not legacy. But now ELF notes are prefered and "should live in a PT_NOTE segment" (elfnote.h).

This check is unnecessary as elf_xen_parse() from xen/common/libelf will do the right thing and look for ELFNOTEs in the different places in order of preference. elf_xen_parse() will still be able to also look for the legacy "__xen_guest" section without the check in libxc.

This patch would allow to write a simpler ELF header for an OVMF blob (which isn't an ELF) and allow it to be loaded as a PVH kernel. The header only needs to declare two program segments:
- one to tell an ELF loader where to put the blob,
- one for a Xen ELFNOTE.

The ELFNOTE is to comply to the pvh design which wants the XEN_ELFNOTE_PHYS32_ENTRY to declare a blob as compaptible with the PVH boot ABI.

Note that without the ELFNOTE, libxc will load an ELF but with the plain ELF loader, which doesn't check for shstrtab.

---

Notes:
v2: Rework commit message, explain why the check is unnecessary.

 tools/libxc/xc_dom_elfloader.c | 9 ---------
 1 file changed, 9 deletions(-)
tools/libxc/xc_dom_elfloader.c +0 -9
index 82b5f2ee79..b327db219d 100644
@@ -165,15 +165,6 @@ static elf_negerrnoval xc_dom_parse_elf_kernel(struct xc_dom_image *dom)
         return rc;
     }
 
-    /* Find the section-header strings table. */
-    if ( ELF_PTRVAL_INVALID(elf->sec_strtab) )
-    {
-        xc_dom_panic(dom->xch, XC_INVALID_KERNEL, "%s: ELF image"
-                     " has no shstrtab", __FUNCTION__);
-        rc = -EINVAL;
-        goto out;
-    }
-
     /* parse binary and get xen meta info */
     elf_parse_binary(elf);
     if ( elf_xen_parse(elf, &dom->parms) != 0 )
Signature · 7 lines
Anthony PERARD


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel