Skip to contentSkip to conversation

libelf: allow having HYPERCALL_PAGE entry before VIRT_BASE in __xen_guest section.

PATCH Superseded [email protected] 2 participants 3 messages Oct 11, 2017

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libelf: allow having HYPERCALL_PAGE entry before VIRT_BASE in __xen_guest section.

From: Gregory Herrero <[email protected]>

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.

---
 xen/common/libelf/libelf-dominfo.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
xen/common/libelf/libelf-dominfo.c +9 -2
index a52900c00cd..b1255acc059 100644
@@ -330,14 +330,21 @@ elf_errorstatus elf_xen_parse_guest_info(struct elf_binary *elf,
 
         /* longs */
         if ( !strcmp(name, "VIRT_BASE") )
+        {
             parms->virt_base = strtoull(value, NULL, 0);
+            if ( parms->virt_hypercall != UNSET_ADDR )
+                params->virt_hypercall += params->virt_base;
+        }
         if ( !strcmp(name, "VIRT_ENTRY") )
             parms->virt_entry = strtoull(value, NULL, 0);
         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);
+            if ( parms->virt_base != UNSET_ADDR )
+                params->virt_hypercall += params->virt_base;
+        }
 
         /* other */
         if ( !strcmp(name, "FEATURES") )
Signature · 7 lines
2.14.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 11.10.17 at 14:03, <[email protected]> wrote:

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.

Do you have an example of a guest kernel that is doing this? I ask because the __xen_guest section has been deprecated for many years - everyone should be using the notes section instead nowadays.

Quoted 13 lines
xen/common/libelf/libelf-dominfo.c +4 -0
@@ -330,14 +330,21 @@ elf_errorstatus elf_xen_parse_guest_info(struct elf_binary *elf,
 
         /* longs */
         if ( !strcmp(name, "VIRT_BASE") )
+        {
             parms->virt_base = strtoull(value, NULL, 0);
+            if ( parms->virt_hypercall != UNSET_ADDR )
+                params->virt_hypercall += params->virt_base;
+        }
         if ( !strcmp(name, "VIRT_ENTRY") )
             parms->virt_entry = strtoull(value, NULL, 0);

xen/common/libelf/libelf-dominfo.c elf_errorstatus elf_xen_parse_guest_info(struct elf_binary *elf, · line 347

Quoted 10 lines
xen/common/libelf/libelf-dominfo.c +5 -2
         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);
+            if ( parms->virt_base != UNSET_ADDR )
+                params->virt_hypercall += params->virt_base;
+        }

I think you rather want to do this once after the loop. That'll then also take care of there being multiple VIRT_BASE entries.

Jan

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

#2 lore raw
Quoted 9 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 11.10.17 at 14:03, <[email protected]> wrote:

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.

Quoted 5 lines

Do you have an example of a guest kernel that is doing this? I ask because the __xen_guest section has been deprecated for many years - everyone should be using the notes section instead nowadays.

There is no public example AFAIK, I faced this issue while creating a guest locally for testing purpose.

Quoted 18 lines
Quoted 18 lines
xen/common/libelf/libelf-dominfo.c +4 -2
@@ -330,14 +330,21 @@ elf_errorstatus elf_xen_parse_guest_info(struct elf_binary *elf,
 
         /* longs */
         if ( !strcmp(name, "VIRT_BASE") )
+        {
             parms->virt_base = strtoull(value, NULL, 0);
+            if ( parms->virt_hypercall != UNSET_ADDR )
+                params->virt_hypercall += params->virt_base;
+        }
         if ( !strcmp(name, "VIRT_ENTRY") )
             parms->virt_entry = strtoull(value, NULL, 0);
         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;
Quoted 9 lines

xen/common/libelf/libelf-dominfo.c elf_errorstatus elf_xen_parse_guest_info(struct elf_binary *elf, · line 347

Quoted 5 lines
xen/common/libelf/libelf-dominfo.c +5 -0
+        {
+            parms->virt_hypercall = (strtoull(value, NULL, 0) << 12);
+            if ( parms->virt_base != UNSET_ADDR )
+                params->virt_hypercall += params->virt_base;
+        }

I think you rather want to do this once after the loop. That'll then also take care of there being multiple VIRT_BASE entries.

I will send an updated patch with your suggestion. Feel free to ignore it if usage of __xen_guest section is deprecated.

Thanks,
Gregory

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