Skip to contentSkip to conversation

Restore memory used for IP computation

PATCH Superseded Frediano Ziglio 2 participants 2 messages Aug 21, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Restore memory used for IP computation

We need to write in some location but no reasons to not trying to restore what we potentially overwrote.

---
 xen/arch/x86/boot/head.S | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
xen/arch/x86/boot/head.S +10 -2
index d8ac0f0494..3e1e9e05b6 100644
@@ -418,13 +418,17 @@ __pvh_start:
          * absolute stack address as the native path, for lack of a better
          * alternative.
          */
-        mov     $0x1000, %esp
+        mov     $0xffc, %esp
+        pop     %edx
 
         /* Calculate the load base address. */
         call    1f
 1:      pop     %esi
         sub     $sym_offs(1b), %esi
 
+        /* Restore clobbered stack */
+        push    %edx
+
         /* Set up stack. */
         lea     STACK_SIZE - CPUINFO_sizeof + sym_esi(cpu0_stack), %esp
 
@@ -468,13 +472,17 @@ __start:
          * this page for a temporary stack, being one of the safest locations
          * to clobber.
          */
-        mov     $0x1000, %esp
+        mov     $0xffc, %esp
+        pop     %edx
 
         /* Calculate the load base address. */
         call    1f
 1:      pop     %esi
         sub     $sym_offs(1b), %esi
 
+        /* Restore clobbered stack */
+        push    %edx
+
         /* Set up stack. */
         lea     STACK_SIZE - CPUINFO_sizeof + sym_esi(cpu0_stack), %esp
 
Signature · 1 line
2.46.0
#1 lore raw
Quoted 4 lines · Frediano Ziglio

We need to write in some location but no reasons to not trying to restore what we potentially overwrote.

Please follow how Linux does this.

e.g.
https://lore.kernel.org/xen-devel/[email protected]/

Specifically, ...

xen/arch/x86/boot/head.S __pvh_start: · line 420

Quoted 12 lines
---
 xen/arch/x86/boot/head.S | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
xen/arch/x86/boot/head.S +0 -0
index d8ac0f0494..3e1e9e05b6 100644
@@ -418,13 +418,17 @@ __pvh_start:
          * absolute stack address as the native path, for lack of a better
          * alternative.
          */

... the reasoning in this comment here is incorrect for non-BIOS systems, and causes memory corruption for Coreboot based boot.

I've been meaning to fix it for ages, but seeing as you're changing it... :)

The first field under %ebx in a boot ABI we recognise is a much better choice that an arbitrary location in the first page of memory.

~Andrew