tags 652146 patch
thanks

Michael Prokop wrote...

> Problem doesn't seem to be present on 32bit systems,
> but on amd64 it's definitely reproducable.

The most likely culprit is

    "push %%rbx\n\t"

in src/hd/hd.c:hd_is_xen, in combination with the compiler and perhaps
libc.

As the compiler makes the strcmp call inline, hd_is_xen becomes a leaf
function. Hence the compiler optimizes the frame pointer handling,
therefore %rsp is not decremented and may not be used for push/pop
operations - at least not without tampering data, probably somewhere
in the caller's domain.

Suggested solution:

Instead of pushing, save %rbp in another register and mark that one
clobbered:

--- src/hd/hd.c.orig    2009-05-12 17:49:52.000000000 +0200
+++ src/hd/hd.c 2012-01-16 00:57:35.600532496 +0100
@@ -3245,16 +3257,16 @@
     "mov %%edx,8(%%esi)\n\t"
     "pop %%ebx"
 #else
-    "push %%rbx\n\t"
+    "mov %%ebx,%%edi\n\t"
     "cpuid\n\t"
     "mov %%ebx,(%%rsi)\n\t"
     "mov %%ecx,4(%%rsi)\n\t"
     "mov %%edx,8(%%rsi)\n\t"
-    "pop %%rbx"
+    "mov %%edi,%%ebx\n\t"
 #endif
     : "=a" (u), "=c" (foo)
     : "a" (0x40000000), "c" (0), "S" (signature)
-    : "%edx"
+    : "%edx", "%edi"
   );
 
   signature[12] = 0;


Other solutions:

* Mark %ebx clobbered. This appears to create the regular frameing but
  I wouldn't rely on that.
* Use some kind of pragma that disables frame optimization. Ditto.

Still unexplained: Why does this not happen on i386? Avoiding push/pop
there too would at least do not harm.

    Christoph

Attachment: signature.asc
Description: Digital signature

Reply via email to