xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libelf: Handle PVH kernels lacking ENTRY elfnote
@ 2020-10-14 15:31 Jason Andryuk
  2020-10-14 15:52 ` Wei Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Jason Andryuk @ 2020-10-14 15:31 UTC (permalink / raw)
  To: xen-devel
  Cc: Jason Andryuk, Andrew Cooper, George Dunlap, Ian Jackson,
	Jan Beulich, Julien Grall, Stefano Stabellini, Wei Liu

Linux kernels only have an ENTRY elfnote when built with CONFIG_PV.  A
kernel build CONFIG_PVH=y CONFIG_PV=n lacks the note.  In this case,
virt_entry will be UNSET_ADDR, overwritten by the ELF header e_entry,
and fail the check against the virt address range.

Change the code to only check virt_entry against the virtual address
range if it was set upon entry to the function.

Signed-off-by: Jason Andryuk <jandryuk@gmail.com>

---
Maybe the overwriting of virt_entry could be removed, but I don't know
if there would be unintended consequences where (old?) kernels don't
have an elfnote, but do have an in-range e_entry?  The failing kernel I
just looked at has an e_entry of 0x1000000.

Oh, it looks like Mini-OS doesn't set the entry ELFNOTE and relies on
e_entry (of 0) to pass these checks.

---
 xen/common/libelf/libelf-dominfo.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/xen/common/libelf/libelf-dominfo.c b/xen/common/libelf/libelf-dominfo.c
index 508f08db42..1ecf35166b 100644
--- a/xen/common/libelf/libelf-dominfo.c
+++ b/xen/common/libelf/libelf-dominfo.c
@@ -416,6 +416,7 @@ static elf_errorstatus elf_xen_note_check(struct elf_binary *elf,
 static elf_errorstatus elf_xen_addr_calc_check(struct elf_binary *elf,
                                    struct elf_dom_parms *parms)
 {
+    bool check_virt_entry = true;
     uint64_t virt_offset;
 
     if ( (parms->elf_paddr_offset != UNSET_ADDR) &&
@@ -456,8 +457,10 @@ static elf_errorstatus elf_xen_addr_calc_check(struct elf_binary *elf,
     parms->virt_kstart = elf->pstart + virt_offset;
     parms->virt_kend   = elf->pend   + virt_offset;
 
-    if ( parms->virt_entry == UNSET_ADDR )
+    if ( parms->virt_entry == UNSET_ADDR ) {
         parms->virt_entry = elf_uval(elf, elf->ehdr, e_entry);
+        check_virt_entry = false;
+    }
 
     if ( parms->bsd_symtab )
     {
@@ -476,11 +479,17 @@ static elf_errorstatus elf_xen_addr_calc_check(struct elf_binary *elf,
     elf_msg(elf, "    p2m_base         = 0x%" PRIx64 "\n", parms->p2m_base);
 
     if ( (parms->virt_kstart > parms->virt_kend) ||
-         (parms->virt_entry < parms->virt_kstart) ||
-         (parms->virt_entry > parms->virt_kend) ||
          (parms->virt_base > parms->virt_kstart) )
     {
-        elf_err(elf, "ERROR: ELF start or entries are out of bounds\n");
+        elf_err(elf, "ERROR: ELF start is out of bounds\n");
+        return -1;
+    }
+
+    if ( check_virt_entry &&
+         ( (parms->virt_entry < parms->virt_kstart) ||
+           (parms->virt_entry > parms->virt_kend) ) )
+    {
+        elf_err(elf, "ERROR: ELF entry is out of bounds\n");
         return -1;
     }
 
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2020-10-19 15:37 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-14 15:31 [PATCH] libelf: Handle PVH kernels lacking ENTRY elfnote Jason Andryuk
2020-10-14 15:52 ` Wei Liu
2020-10-14 16:02 ` Jan Beulich
2020-10-14 16:27   ` Jason Andryuk
2020-10-15  7:00     ` Jan Beulich
2020-10-15 14:50       ` Jason Andryuk
2020-10-15 15:14         ` Jan Beulich
2020-10-15 17:27           ` Andrew Cooper
2020-10-16 16:28           ` Jason Andryuk
2020-10-19  7:38             ` Jan Beulich
2020-10-19 15:26               ` Jason Andryuk
2020-10-19 15:36                 ` Jan Beulich
2020-10-15 15:03       ` Roger Pau Monné
2020-10-14 16:12 ` Jürgen Groß
2020-10-14 16:27   ` Jason Andryuk
2020-10-15  4:17     ` Jürgen Groß

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).