Skip to contentSkip to conversation

x86/emul: Reject LGDT/LIDT attempts with non-canonical base addresses

PATCH In review Andrew Cooper 3 participants 4 messages Nov 2, 2016 – Nov 3, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/emul: Reject LGDT/LIDT attempts with non-canonical base addresses

No sane OS would deliberately try this, but make Xen's emulation match real hardware by delivering #GP(0), rather than suffering a VMEntry failure.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/arch/x86/x86_emulate/x86_emulate.c | 2 ++
 1 file changed, 2 insertions(+)
xen/arch/x86/x86_emulate/x86_emulate.c +2 -0
index 7a707dc..6b940c4 100644
@@ -4443,6 +4443,8 @@ x86_emulate(
                  (rc = read_ulong(ea.mem.seg, ea.mem.off+2,
                                   &base, mode_64bit() ? 8 : 4, ctxt, ops)) )
                 goto done;
+            generate_exception_if(mode_64bit() &&
+                                  !is_canonical_address(base), EXC_GP, 0);
             sreg.base = base;
             sreg.limit = limit;
             if ( op_bytes == 2 )
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 02.11.16 at 15:52, <[email protected]> wrote:

No sane OS would deliberately try this, but make Xen's emulation match real hardware by delivering #GP(0), rather than suffering a VMEntry failure.

albeit ...

xen/arch/x86/x86_emulate/x86_emulate.c x86_emulate( · line 4447

Quoted 8 lines
xen/arch/x86/x86_emulate/x86_emulate.c +2 -0
@@ -4443,6 +4443,8 @@ x86_emulate(
                  (rc = read_ulong(ea.mem.seg, ea.mem.off+2,
                                   &base, mode_64bit() ? 8 : 4, ctxt, ops)) )
                 goto done;
+            generate_exception_if(mode_64bit() &&
+                                  !is_canonical_address(base), EXC_GP, 0);

... I don't think the mode_64bit() part is needed.

Jan

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

#2 lore raw
Quoted 8 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 02.11.16 at 15:52, <[email protected]> wrote:

No sane OS would deliberately try this, but make Xen's emulation match real hardware by delivering #GP(0), rather than suffering a VMEntry failure.

albeit ...

Quoted 9 lines

xen/arch/x86/x86_emulate/x86_emulate.c x86_emulate( · line 4447

Quoted 8 lines
xen/arch/x86/x86_emulate/x86_emulate.c +2 -0
@@ -4443,6 +4443,8 @@ x86_emulate(
                  (rc = read_ulong(ea.mem.seg, ea.mem.off+2,
                                   &base, mode_64bit() ? 8 : 4, ctxt, ops)) )
                 goto done;
+            generate_exception_if(mode_64bit() &&
+                                  !is_canonical_address(base), EXC_GP, 0);

... I don't think the mode_64bit() part is needed.

True - as we explicitly zero sreg to start with, the canonical base check is safe in all modes. I will drop it from v2.

~Andrew

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

#3 lore raw
In reply to Jan Beulich
Quoted 7 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 02.11.16 at 15:52, <[email protected]> wrote:

No sane OS would deliberately try this, but make Xen's emulation match real hardware by delivering #GP(0), rather than suffering a VMEntry failure.

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