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