// https://syzkaller.appspot.com/bug?id=a64ff46f998b10b8a7af2af109474608858a1c87 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef __NR_bpf #define __NR_bpf 321 #endif static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { int state; } event_t; static void event_init(event_t* ev) { ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { if (ev->state) exit(1); __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000); } static void event_wait(event_t* ev) { while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0); } static int event_isset(event_t* ev) { return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE); } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; for (;;) { uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts); if (__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) return 1; now = current_time_ms(); if (now - start > timeout) return 0; } } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void loop(void) { if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } int i, call, thread; for (call = 0; call < 9; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } uint64_t r[2] = {0xffffffffffffffff, 0x0}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: // mkdirat arguments: [ // fd: fd_dir (resource) // path: ptr[in, buffer] { // buffer: {2e 2f 73 79 73 00} (length 0x6) // } // mode: open_mode = 0x1ff (8 bytes) // ] memcpy((void*)0x200000000000, "./sys\000", 6); syscall( __NR_mkdirat, /*fd=*/0xffffff9c, /*path=*/0x200000000000ul, /*mode=S_IXOTH|S_IWOTH|S_IROTH|S_IXGRP|S_IWGRP|S_IRGRP|S_IXUSR|S_IWUSR|0x100*/ 0x1fful); break; case 1: // mount arguments: [ // src: nil // dst: ptr[in, buffer] { // buffer: {2e 2f 73 79 73 00} (length 0x6) // } // type: ptr[in, buffer] { // buffer: {73 79 73 66 73 00} (length 0x6) // } // flags: mount_flags = 0x0 (8 bytes) // data: nil // ] memcpy((void*)0x200000000040, "./sys\000", 6); memcpy((void*)0x200000000080, "sysfs\000", 6); syscall(__NR_mount, /*src=*/0ul, /*dst=*/0x200000000040ul, /*type=*/0x200000000080ul, /*flags=*/0ul, /*data=*/0ul); break; case 2: // openat arguments: [ // fd: fd_dir (resource) // file: ptr[in, buffer] { // buffer: {2e 2f 73 79 73 2f 62 75 73 2f 70 6c 61 74 66 6f 72 6d 2f 64 // 72 69 76 65 72 73 2f 76 68 63 69 5f 68 63 64 2f 75 6e 62 69 6e 64 // 00} (length 0x2b) // } // flags: open_flags = 0x1 (4 bytes) // mode: open_mode = 0x0 (2 bytes) // ] // returns fd memcpy((void*)0x2000000000c0, "./sys/bus/platform/drivers/vhci_hcd/unbind\000", 43); res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x2000000000c0ul, /*flags=O_WRONLY*/ 1, /*mode=*/0); if (res != -1) r[0] = res; break; case 3: // write arguments: [ // fd: fd (resource) // buf: ptr[in, buffer] { // buffer: {76 68 63 69 5f 68 63 64 2e 30 00} (length 0xb) // } // count: len = 0xa (8 bytes) // ] memcpy((void*)0x200000000100, "vhci_hcd.0\000", 11); syscall(__NR_write, /*fd=*/r[0], /*buf=*/0x200000000100ul, /*count=*/0xaul); break; case 4: // bpf$PROG_LOAD arguments: [ // cmd: const = 0x5 (8 bytes) // arg: ptr[in, bpf_prog_t[flags[bpf_prog_type, int32], // bpf_prog_attach_types, bpf_btf_id[opt], fd_bpf_prog[opt]]] { // bpf_prog_t[flags[bpf_prog_type, int32], bpf_prog_attach_types, // bpf_btf_id[opt], fd_bpf_prog[opt]] { // type: bpf_prog_type = 0x10 (4 bytes) // ninsn: bytesize8 = 0x4 (4 bytes) // insns: ptr[inout, array[ANYUNION]] { // array[ANYUNION] { // union ANYUNION { // ANYBLOB: buffer: {b4 00 00 00 00 00 00 00 79 10 48 00 00 00 // 00 00 61 04 00 00 00 00 00 00 95 00 00 72} (length 0x1c) // } // } // } // license: nil // loglev: int32 = 0x2 (4 bytes) // logsize: len = 0xc3 (4 bytes) // log: ptr[out, buffer] { // buffer: (DirOut) // } // kern_version: bpf_kern_version = 0x0 (4 bytes) // flags: bpf_prog_load_flags = 0x0 (4 bytes) // prog_name: buffer: {00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00} (length 0x10) prog_ifindex: ifindex (resource) // expected_attach_type: union bpf_prog_attach_types { // sk_msg: sk_msg_attach_types = 0x0 (4 bytes) // } // btf_fd: fd_btf (resource) // func_info_rec_size: const = 0x8 (4 bytes) // func_info: nil // func_info_cnt: len = 0x0 (4 bytes) // line_info_rec_size: const = 0x10 (4 bytes) // line_info: nil // line_info_cnt: len = 0x0 (4 bytes) // attach_btf_id: bpf_btf_id (resource) // attach_prog_fd: fd_bpf_prog (resource) // core_relo_cnt: len = 0x0 (4 bytes) // fd_array: nil // core_relos: nil // core_relo_rec_size: const = 0x10 (4 bytes) // log_true_size: int32 = 0x0 (4 bytes) // prog_token_fd: union _bpf_prog_t[flags[bpf_prog_type, int32], // bpf_prog_attach_types, bpf_btf_id[opt], // fd_bpf_prog[opt]]_prog_token_fd_wrapper { // void: buffer: {} (length 0x0) // } // pad: union _bpf_prog_t[flags[bpf_prog_type, int32], // bpf_prog_attach_types, bpf_btf_id[opt], // fd_bpf_prog[opt]]_pad_wrapper { // value: const = 0x0 (4 bytes) // } // } // } // size: len = 0x94 (8 bytes) // ] // returns fd_bpf_prog *(uint32_t*)0x20000000e000 = 0x10; *(uint32_t*)0x20000000e004 = 4; *(uint64_t*)0x20000000e008 = 0x200000000040; memcpy((void*)0x200000000040, "\xb4\x00\x00\x00\x00\x00\x00\x00\x79\x10\x48\x00\x00\x00\x00\x00" "\x61\x04\x00\x00\x00\x00\x00\x00\x95\x00\x00\x72", 28); *(uint64_t*)0x20000000e010 = 0; *(uint32_t*)0x20000000e018 = 2; *(uint32_t*)0x20000000e01c = 0xc3; *(uint64_t*)0x20000000e020 = 0x20000000cf3d; *(uint32_t*)0x20000000e028 = 0; *(uint32_t*)0x20000000e02c = 0; memset((void*)0x20000000e030, 0, 16); *(uint32_t*)0x20000000e040 = 0; *(uint32_t*)0x20000000e044 = 0; *(uint32_t*)0x20000000e048 = -1; *(uint32_t*)0x20000000e04c = 8; *(uint64_t*)0x20000000e050 = 0; *(uint32_t*)0x20000000e058 = 0; *(uint32_t*)0x20000000e05c = 0x10; *(uint64_t*)0x20000000e060 = 0; *(uint32_t*)0x20000000e068 = 0; *(uint32_t*)0x20000000e06c = 0; *(uint32_t*)0x20000000e070 = -1; *(uint32_t*)0x20000000e074 = 0; *(uint64_t*)0x20000000e078 = 0; *(uint64_t*)0x20000000e080 = 0; *(uint32_t*)0x20000000e088 = 0x10; *(uint32_t*)0x20000000e08c = 0; *(uint32_t*)0x20000000e090 = 0; syscall(__NR_bpf, /*cmd=*/5ul, /*arg=*/0x20000000e000ul, /*size=*/0x94ul); break; case 5: // timer_create arguments: [ // id: clock_id = 0x0 (8 bytes) // ev: ptr[in, sigevent] { // sigevent { // val: const = 0x0 (8 bytes) // signo: int32 = 0x21 (4 bytes) // notify: sigev_notify = 0x2 (4 bytes) // u: union sigevent_u { // thr: sigevent_thread { // func: nil // attr: nil // } // } // pad = 0x0 (32 bytes) // } // } // timerid: ptr[out, timerid] { // timerid (resource) // } // ] *(uint64_t*)0x2000000000c0 = 0; *(uint32_t*)0x2000000000c8 = 0x21; *(uint32_t*)0x2000000000cc = 2; *(uint64_t*)0x2000000000d0 = 0; *(uint64_t*)0x2000000000d8 = 0; res = syscall(__NR_timer_create, /*id=*/0ul, /*ev=*/0x2000000000c0ul, /*timerid=*/0x200000000300ul); if (res != -1) r[1] = *(uint32_t*)0x200000000300; break; case 6: // fcntl$lock arguments: [ // fd: fd (resource) // cmd: fcntl_lock = 0x24 (8 bytes) // lock: ptr[in, flock] { // flock { // type: flock_type = 0x0 (2 bytes) // whence: seek_whence = 0x0 (2 bytes) // pad = 0x0 (4 bytes) // start: intptr = 0x10001 (8 bytes) // len: intptr = 0x5 (8 bytes) // pid: pid (resource) // pad = 0x0 (4 bytes) // } // } // ] *(uint16_t*)0x200000000040 = 0; *(uint16_t*)0x200000000042 = 0; *(uint64_t*)0x200000000048 = 0x10001; *(uint64_t*)0x200000000050 = 5; *(uint32_t*)0x200000000058 = 0; syscall(__NR_fcntl, /*fd=*/(intptr_t)-1, /*cmd=F_OFD_GETLK*/ 0x24ul, /*lock=*/0x200000000040ul); break; case 7: // mprotect arguments: [ // addr: VMA[0xf000] // len: len = 0xf000 (8 bytes) // prot: mmap_prot = 0x1 (8 bytes) // ] syscall(__NR_mprotect, /*addr=*/0x200000000000ul, /*len=*/0xf000ul, /*prot=PROT_READ*/ 1ul); break; case 8: // timer_settime arguments: [ // timerid: timerid (resource) // flags: timer_flags = 0x1 (8 bytes) // new: ptr[in, itimerspec] { // itimerspec { // interv: timespec { // sec: time_sec (resource) // nsec: time_nsec (resource) // } // value: timespec { // sec: time_sec (resource) // nsec: time_nsec (resource) // } // } // } // old: nil // ] *(uint64_t*)0x200000000040 = 0; *(uint64_t*)0x200000000048 = 0; *(uint64_t*)0x200000000050 = 0; *(uint64_t*)0x200000000058 = 0x989680; syscall(__NR_timer_settime, /*timerid=*/r[1], /*flags=TIMER_ABSTIME*/ 1ul, /*new=*/0x200000000040ul, /*old=*/0ul); break; } } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000, /*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=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); const char* reason; (void)reason; loop(); return 0; }