Xen Test Framework
main.c
Go to the documentation of this file.
1 
21 #include <xtf.h>
22 
23 const char test_title[] = "XSA-451 PoC";
24 bool test_needs_fep = true;
25 
26 void test_main(void)
27 {
28  exinfo_t fault = 0;
29  unsigned int status;
30 
31  /* Enable SEE, clear and unmask all exceptions. */
33  write_mxcsr(0);
34 
35  /*
36  * As we're compiled with -mno-sse, SSE register constraints aren't
37  * tolerated. Just use %xmm0 behind the back of the compiler; it's not
38  * going to interfere with anything.
39  */
40  asm volatile ("xorps %%xmm0, %%xmm0\n\t"
41  _ASM_XEN_FEP "1: divss %%xmm0, %%xmm0\n\t"
42  "2: "
43  _ASM_EXTABLE_HANDLER(1b, 2b, %P[rec])
44  : "+a" (fault)
45  : [rec] "p" (ex_record_fault_eax));
46 
47  /*
48  * If we're still alive here, Xen didn't crash. Cross-check that the
49  * emulator did hand us back the right exception.
50  *
51  * Note: 0.0 / 0.0 yields #I (Invalid), not #Z (Zero-div).
52  */
53  if ( fault != EXINFO_SYM(XM, 0) )
54  return xtf_error("Error: expecting #XM, got %pe\n", _p(fault));
55 
56  status = read_mxcsr() & X86_MXCSR_STATUS_MASK;
57  if ( status != X86_MXCSR_IE )
58  return xtf_error("Error: expecting #I, got %#x\n", status);
59 
60  xtf_success("Success: not vulnerable to XSA-451\n");
61 }
62 
63 /*
64  * Local variables:
65  * mode: C
66  * c-file-style: "BSD"
67  * c-basic-offset: 4
68  * tab-width: 4
69  * indent-tabs-mode: nil
70  * End:
71  */
unsigned int exinfo_t
Packed exception and error code information.
Definition: exinfo.h:19
#define _ASM_XEN_FEP
Xen Forced Emulation Prefix.
Definition: xen.h:150
bool ex_record_fault_eax(struct cpu_regs *regs, const struct extable_entry *ex)
Record the current fault in %eax.
Definition: extable.c:8
#define X86_CR4_OSFXSR
Definition: processor.h:53
#define X86_MXCSR_IE
Definition: processor.h:91
#define X86_CR4_OSXMMEXCPT
Definition: processor.h:54
static uint32_t read_mxcsr(void)
Definition: lib.h:308
static void write_mxcsr(uint32_t mxcsr)
Definition: lib.h:317
void xtf_success(const char *fmt,...)
Report test success.
Definition: report.c:38
#define X86_MXCSR_STATUS_MASK
Definition: processor.h:97
void test_main(void)
To be implemented by each test, as its entry point.
Definition: main.c:137
static unsigned long read_cr4(void)
Definition: lib.h:252
bool test_needs_fep
Boolean indicating whether the test is entirely predicated on the available of the Force Emulation Pr...
Definition: main.c:34
const char test_title[]
The title of the test.
Definition: main.c:14
static void write_cr4(unsigned long cr4)
Definition: lib.h:285
#define _p(v)
Express an abitrary integer v as void *.
Definition: numbers.h:48
#define EXINFO_SYM(exc, ec)
Definition: exinfo.h:29
void xtf_error(const char *fmt,...)
Report a test error.
Definition: report.c:80
#define _ASM_EXTABLE_HANDLER(fault, fixup, handler)
Create an exception table entry with custom handler.
Definition: extable.h:38
static enum test_status status
Current status of this test.
Definition: report.c:14