All of lore.kernel.org
 help / color / mirror / Atom feed
From: gregory.herrero@oracle.com
To: xen-devel@lists.xen.org
Cc: sstabellini@kernel.org, wei.liu2@citrix.com,
	konrad.wilk@oracle.com, George.Dunlap@eu.citrix.com,
	ian.jackson@eu.citrix.com, tim@xen.org, jbeulich@suse.com,
	andrew.cooper3@citrix.com,
	Gregory Herrero <gregory.herrero@oracle.com>
Subject: [PATCH v3] libelf: allow having HYPERCALL_PAGE entry before VIRT_BASE in __xen_guest section.
Date: Wed, 11 Oct 2017 15:52:15 +0200	[thread overview]
Message-ID: <20171011135215.2037-1-gregory.herrero@oracle.com> (raw)

From: Gregory Herrero <gregory.herrero@oracle.com>

When filling __xen_guest section of a guest, user may define
HYPERCALL_PAGE earlier than VIRT_BASE in the section leading to an
incorrect hypercall page address since an undefined virt_base could be
used to compute hypercall page address.
If there is no VIRT_BASE entry in __xen_guest section, default value of
0 is used for virt_base. Thus, setting hypercall page address to
HYPERCALL_PAGE value is correct in this case too.

Signed-off-by: Gregory Herrero <gregory.herrero@oracle.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
Changed since v1:
  * set virt_hypercall once after the while loop.
  * Correct coding style.
---
 xen/common/libelf/libelf-dominfo.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/xen/common/libelf/libelf-dominfo.c b/xen/common/libelf/libelf-dominfo.c
index a52900c00cd..829d5176a91 100644
--- a/xen/common/libelf/libelf-dominfo.c
+++ b/xen/common/libelf/libelf-dominfo.c
@@ -269,6 +269,7 @@ elf_errorstatus elf_xen_parse_guest_info(struct elf_binary *elf,
     elf_ptrval h;
     unsigned char name[32], value[128];
     unsigned len;
+    elf_errorstatus ret = 0;
 
     h = parms->guest_info;
 #define STAR(h) (elf_access_unsigned(elf, (h), 0, 1))
@@ -336,16 +337,23 @@ elf_errorstatus elf_xen_parse_guest_info(struct elf_binary *elf,
         if ( !strcmp(name, "ELF_PADDR_OFFSET") )
             parms->elf_paddr_offset = strtoull(value, NULL, 0);
         if ( !strcmp(name, "HYPERCALL_PAGE") )
-            parms->virt_hypercall = (strtoull(value, NULL, 0) << 12) +
-                parms->virt_base;
+            parms->virt_hypercall = strtoull(value, NULL, 0) << 12;
 
         /* other */
         if ( !strcmp(name, "FEATURES") )
             if ( elf_xen_parse_features(value, parms->f_supported,
                                         parms->f_required) )
-                return -1;
+            {
+                ret = -1;
+                break;
+            }
     }
-    return 0;
+
+    if ( (parms->virt_base != UNSET_ADDR) &&
+         (parms->virt_hypercall != UNSET_ADDR) )
+        parms->virt_hypercall += parms->virt_base;
+
+    return ret;
 }
 
 /* ------------------------------------------------------------------------ */
-- 
2.14.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

                 reply	other threads:[~2017-10-11 13:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171011135215.2037-1-gregory.herrero@oracle.com \
    --to=gregory.herrero@oracle.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=konrad.wilk@oracle.com \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.