Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _GNU_SOURCE
- #include <endian.h>
- #include <fcntl.h>
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/stat.h>
- #include <sys/syscall.h>
- #include <sys/types.h>
- #include <unistd.h>
- static long syz_open_dev(volatile long a0, volatile long a1, volatile long a2)
- {
- if (a0 == 0xc || a0 == 0xb) {
- char buf[128];
- sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1,
- (uint8_t)a2);
- return open(buf, O_RDWR, 0);
- } else {
- unsigned long nb = a1;
- char buf[1024];
- char* hash;
- strncpy(buf, (char*)a0, sizeof(buf) - 1);
- buf[sizeof(buf) - 1] = 0;
- while ((hash = strchr(buf, '#'))) {
- *hash = '0' + (char)(nb % 10);
- nb /= 10;
- }
- return open(buf, a2, 0);
- }
- }
- uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff};
- int main(void)
- {
- syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul,
- /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
- /*fd=*/(intptr_t)-1, /*offset=*/0ul);
- syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul,
- /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul,
- /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
- /*fd=*/(intptr_t)-1, /*offset=*/0ul);
- syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul,
- /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul,
- /*fd=*/(intptr_t)-1, /*offset=*/0ul);
- const char* reason;
- (void)reason;
- intptr_t res = 0;
- if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {
- }
- // syz_open_dev$sg arguments: [
- // dev: ptr[in, buffer] {
- // buffer: {2f 64 65 76 2f 73 67 23 00} (length 0x9)
- // }
- // id: intptr = 0x0 (8 bytes)
- // flags: open_flags = 0x0 (8 bytes)
- // ]
- // returns fd_sg
- memcpy((void*)0x2000000000c0, "/dev/sg#\000", 9);
- res = -1;
- res = syz_open_dev(/*dev=*/0x2000000000c0, /*id=*/0, /*flags=*/0);
- if (res != -1)
- r[0] = res;
- // mmap arguments: [
- // addr: VMA[0x3000]
- // len: len = 0x3000 (8 bytes)
- // prot: mmap_prot = 0x3 (8 bytes)
- // flags: mmap_flags = 0x12 (8 bytes)
- // fd: fd (resource)
- // offset: intptr = 0x0 (8 bytes)
- // ]
- syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x3000ul,
- /*prot=PROT_WRITE|PROT_READ*/ 3ul,
- /*flags=MAP_FIXED|MAP_PRIVATE*/ 0x12ul, /*fd=*/r[0], /*offset=*/0ul);
- // openat$sysctl arguments: [
- // fd: const = 0xffffffffffffff9c (8 bytes)
- // file: ptr[in, buffer] {
- // buffer: {2f 70 72 6f 63 2f 73 79 73 2f 76 6d 2f 64 72 6f 70 5f 63 61
- // 63 68 65 73 00} (length 0x19)
- // }
- // flags: const = 0x1 (4 bytes)
- // mode: const = 0x0 (2 bytes)
- // ]
- // returns fd_sysctl
- memcpy((void*)0x200000001040, "/proc/sys/vm/drop_caches\000", 25);
- res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul,
- /*file=*/0x200000001040ul, /*flags=*/1, /*mode=*/0);
- if (res != -1)
- r[1] = res;
- // write$sysctl arguments: [
- // fd: fd_sysctl (resource)
- // val: ptr[in, buffer] {
- // buffer: {32 00} (length 0x2)
- // }
- // len: len = 0xfffe (8 bytes)
- // ]
- memcpy((void*)0x2000000000c0, "2\000", 2);
- syscall(__NR_write, /*fd=*/r[1], /*val=*/0x2000000000c0ul, /*len=*/0xfffeul);
- // madvise arguments: [
- // addr: VMA[0x600000]
- // len: len = 0x600000 (8 bytes)
- // advice: madvise_flags = 0x64 (8 bytes)
- // ]
- syscall(__NR_madvise, /*addr=*/0x200000000000ul, /*len=*/0x600000ul,
- /*advice=MADV_HWPOISON*/ 0x64ul);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment