[PATCH] xen/kexec: Clear unused registers before jumping into an image

Daniel Kiper daniel.kiper at oracle.com
Fri Nov 15 10:56:14 EST 2013


Clear unused registers before jumping into an image. This way
loaded image could not assume that any register has an specific
info about earlier running Xen hypervisor. However, it also
does not mean that the image may expect that a given register
is zeroed. The image MUST assume that every register has a random
value or in other words it is uninitialized or has undefined state.

Signed-off-by: Daniel Kiper <daniel.kiper at oracle.com>
---
 xen/arch/x86/x86_64/kexec_reloc.S |   37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/xen/arch/x86/x86_64/kexec_reloc.S b/xen/arch/x86/x86_64/kexec_reloc.S
index 7a16c85..e7eef79 100644
--- a/xen/arch/x86/x86_64/kexec_reloc.S
+++ b/xen/arch/x86/x86_64/kexec_reloc.S
@@ -71,6 +71,29 @@ identity_mapped:
         jnz     call_32_bit
 
 call_64_bit:
+        /*
+         * Clear unused registers before jumping into an image. This way
+         * loaded image could not assume that any register has an specific
+         * info about earlier running Xen hypervisor. However, it also
+         * does not mean that the image may expect that a given register
+         * is zeroed. The image MUST assume that every register has a random
+         * value or in other words it is uninitialized or has undefined state.
+         */
+        xorl    %eax, %eax
+        xorl    %ebx, %ebx
+        xorl    %ecx, %ecx
+        xorl    %edx, %edx
+        xorl    %esi, %esi
+        xorl    %edi, %edi
+        xorl    %r8d, %r8d
+        xorl    %r9d, %r9d
+        xorl    %r10d, %r10d
+        xorl    %r11d, %r11d
+        xorl    %r12d, %r12d
+        xorl    %r13d, %r13d
+        xorl    %r14d, %r14d
+        xorl    %r15d, %r15d
+
         /* Call the image entry point.  This should never return. */
         callq   *%rbp
         ud2
@@ -164,6 +187,20 @@ compatibility_mode:
         xorl    %eax, %eax
         movl    %eax, %cr4
 
+        /*
+         * Clear unused registers before jumping into an image. This way
+         * loaded image could not assume that any register has an specific
+         * info about earlier running Xen hypervisor. However, it also
+         * does not mean that the image may expect that a given register
+         * is zeroed. The image MUST assume that every register has a random
+         * value or in other words it is uninitialized or has undefined state.
+         */
+        xorl    %ebx, %ebx
+        xorl    %ecx, %ecx
+        xorl    %edx, %edx
+        xorl    %esi, %esi
+        xorl    %edi, %edi
+
         /* Call the image entry point.  This should never return. */
         call    *%ebp
         ud2
-- 
1.7.10.4




More information about the kexec mailing list