Xen Test Framework
main.c
Go to the documentation of this file.
1
36#include <xtf.h>
37
38const char test_title[] = "XSA-185 PoC";
39
40void test_main(void)
41{
43
44 /*
45 * Force the use of slot 2.
46 *
47 * Slots 0 and 3 are definitely in use, and we only have 4 to choose
48 * from. Lets hope that nothing import is using the 3rd GB of virtual
49 * address space.
50 */
51 unsigned long map_slot = 2;
52
53 mmu_update_t mu =
54 {
55 .ptr = cr3_paddr + (map_slot * PAE_PTE_SIZE),
56 .val = cr3_paddr | PF_SYM(AD, U, P),
57 };
58
59 printk(" Creating recursive l3 mapping\n");
60 if ( hypercall_mmu_update(&mu, 1, NULL, DOMID_SELF) )
61 {
62 printk(" Attempt to create recursive l3 mapping was blocked\n");
63 return xtf_success("Not vulerable to XSA-185\n");
64 }
65
66 /* Construct a pointer in the linear map to l3 table. */
67 intpte_t *l3_linear = _p(map_slot << L3_PT_SHIFT |
68 map_slot << L2_PT_SHIFT |
69 map_slot << L1_PT_SHIFT);
70
71 if ( l3_linear[map_slot] & PF_SYM(RW) )
72 return xtf_failure("Fail: l3 linear mapping is RW\n");
73 else
74 return xtf_error("Error: l3 linear mapping is not RW, but wasn't blocked\n");
75}
76
77/*
78 * Local variables:
79 * mode: C
80 * c-file-style: "BSD"
81 * c-basic-offset: 4
82 * tab-width: 4
83 * indent-tabs-mode: nil
84 * End:
85 */
static unsigned long read_cr3(void)
Definition: lib.h:243
void printk(const char *fmt,...)
Definition: console.c:134
void test_main(void)
To be implemented by each test, as its entry point.
Definition: main.c:110
const char test_title[]
The title of the test.
Definition: main.c:24
static long hypercall_mmu_update(const mmu_update_t reqs[], unsigned int count, unsigned int *done, unsigned int foreigndom)
Definition: hypercall.h:60
#define _p(v)
Express an abitrary integer v as void *.
Definition: numbers.h:48
#define PAE_PTE_SIZE
PAE pagetable entries are 64 bits wide.
Definition: page-pae.h:14
#define L2_PT_SHIFT
Definition: page.h:67
uint64_t paddr_t
Definition: page.h:96
#define PAGE_SHIFT
Definition: page.h:10
unsigned long intpte_t
Definition: page.h:152
#define L1_PT_SHIFT
Definition: page.h:66
void xtf_failure(const char *fmt,...)
Report a test failure.
Definition: report.c:94
void xtf_error(const char *fmt,...)
Report a test error.
Definition: report.c:80
void xtf_success(const char *fmt,...)
Report test success.
Definition: report.c:38
#define NULL
Definition: stddef.h:12
uint64_t ptr
Definition: xen.h:249
#define PF_SYM(...)
Create pagetable entry flags based on mnemonics.
static unsigned int xen_cr3_to_pfn(unsigned int cr3)
Definition: xen-x86_32.h:72
#define DOMID_SELF
Definition: xen.h:70