Skip to contentSkip to conversation

x86: emulate lea with two register operands correctly

PATCH In review David Vrabel 3 participants 5 messages Jan 5, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: emulate lea with two register operands correctly

An lea instruction with two register operands should raise an undefined instruction exception.

Skype does such a instruction and will crash when starting if it does not get the exception.

xen/arch/x86/x86_emulate/x86_emulate.c +1 -0
diff -r efaa28639a71 -r e25b7798f13b xen/arch/x86/x86_emulate/x86_emulate.c
@@ -2240,6 +2240,7 @@ x86_emulate(
     }
 
     case 0x8d: /* lea */
+        generate_exception_if(modrm_mod == 3, EXC_UD, -1);
         dst.val = ea.mem.off;
         break;
#1 lore raw
Quoted 5 lines · David Vrabel

An lea instruction with two register operands should raise an undefined instruction exception.

Skype does such a instruction and will crash when starting if it does not get the exception.

Thanks. I think it is a little nicer to check ea.type != OP_MEM, so I made that change before committing this patch. It's now in xen-unstable staging.

It's a bit concerning that we're emulating LEA at all, perhaps. I wonder if a pagetable page has been reused as a code page and we didn't notice yet? Or is there some other reason that skype is getting emulated? :-)

-- Keir

Quoted 18 lines

diff -r efaa28639a71 -r e25b7798f13b xen/arch/x86/x86_emulate/x86_emulate.c

xen/arch/x86/x86_emulate/x86_emulate.c Thu Jan 05 14:58:56 2012 +0000 renamed from xen/arch/x86/x86_emulate/x86_emulate.c Wed Jan 04 16:12:44 2012 +0000 +1 -0
@@ -2240,6 +2240,7 @@ x86_emulate(
     }
 
     case 0x8d: /* lea */
+        generate_exception_if(modrm_mod == 3, EXC_UD, -1);
         dst.val = ea.mem.off;
         break;
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#2 lore raw
Quoted 8 lines · Keir Fraser
Quoted 5 lines · David Vrabel

An lea instruction with two register operands should raise an undefined instruction exception.

Skype does such a instruction and will crash when starting if it does not get the exception.

Quoted 6 lines

Thanks. I think it is a little nicer to check ea.type != OP_MEM, so I made that change before committing this patch. It's now in xen-unstable staging.

It's a bit concerning that we're emulating LEA at all, perhaps. I wonder if a pagetable page has been reused as a code page and we didn't notice yet? Or is there some other reason that skype is getting emulated? :-)

#UD exceptions in HVM are passed to the emulator (IIRC as part of the cross-vendor migration patches, so SYSENTER & friends could be managed).

Tim.

#3 lore raw
Quoted 12 lines · Tim Deegan
Quoted 11 lines · Keir Fraser
Quoted 5 lines · David Vrabel

An lea instruction with two register operands should raise an undefined instruction exception.

Skype does such a instruction and will crash when starting if it does not get the exception.

Thanks. I think it is a little nicer to check ea.type != OP_MEM, so I made that change before committing this patch. It's now in xen-unstable staging.

Quoted 6 lines
Quoted 3 lines

It's a bit concerning that we're emulating LEA at all, perhaps. I wonder if a pagetable page has been reused as a code page and we didn't notice yet? Or is there some other reason that skype is getting emulated? :-)

#UD exceptions in HVM are passed to the emulator (IIRC as part of the cross-vendor migration patches, so SYSENTER & friends could be managed).

Duh, good point.

-- Keir

Quoted 1 line

Tim.

#4 lore raw
In reply to Keir Fraser
Quoted 10 lines · Keir Fraser
Quoted 5 lines · David Vrabel

An lea instruction with two register operands should raise an undefined instruction exception.

Skype does such a instruction and will crash when starting if it does not get the exception.

Thanks. I think it is a little nicer to check ea.type != OP_MEM, so I made that change before committing this patch. It's now in xen-unstable staging.

That works for me, thanks.

I also think this patch should be a 4.1 candidate.

David