All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] libelf: allow having HYPERCALL_PAGE entry before VIRT_BASE in __xen_guest section.
@ 2017-10-11 13:35 gregory.herrero
  2017-10-11 13:42 ` Jan Beulich
  0 siblings, 1 reply; 2+ messages in thread
From: gregory.herrero @ 2017-10-11 13:35 UTC (permalink / raw)
  To: xen-devel
  Cc: sstabellini, wei.liu2, konrad.wilk, George.Dunlap, ian.jackson,
	tim, jbeulich, andrew.cooper3, Gregory Herrero

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>

---
Changed since v1:
  * set virt_hypercall once after the while loop.
---
 xen/common/libelf/libelf-dominfo.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/xen/common/libelf/libelf-dominfo.c b/xen/common/libelf/libelf-dominfo.c
index a52900c00cd..eaeb774ff3d 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,22 @@ 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

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

* Re: [PATCH v2] libelf: allow having HYPERCALL_PAGE entry before VIRT_BASE in __xen_guest section.
  2017-10-11 13:35 [PATCH v2] libelf: allow having HYPERCALL_PAGE entry before VIRT_BASE in __xen_guest section gregory.herrero
@ 2017-10-11 13:42 ` Jan Beulich
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Beulich @ 2017-10-11 13:42 UTC (permalink / raw)
  To: gregory.herrero
  Cc: tim, sstabellini, wei.liu2, konrad.wilk, George.Dunlap,
	andrew.cooper3, ian.jackson, xen-devel

>>> On 11.10.17 at 15:35, <gregory.herrero@oracle.com> wrote:
> @@ -336,16 +337,22 @@ 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);

Please also drop the now pointless parentheses.

>          /* 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) &&

Please add a blank line ahead of this addition.

With those taken care of
Reviewed-by: Jan Beulich <jbeulich@suse.com>

Jan


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

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

end of thread, other threads:[~2017-10-11 13:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-11 13:35 [PATCH v2] libelf: allow having HYPERCALL_PAGE entry before VIRT_BASE in __xen_guest section gregory.herrero
2017-10-11 13:42 ` Jan Beulich

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.