// https://syzkaller.appspot.com/bug?id=350547ca950aa91dab64a049382668279127f1f7 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef __NR_ioctl #define __NR_ioctl 29 #endif #ifndef __NR_mmap #define __NR_mmap 222 #endif #ifndef __NR_openat #define __NR_openat 56 #endif #ifndef __NR_write #define __NR_write 64 #endif static unsigned long long procid; 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; } } static bool write_file(const char* file, const char* what, ...) { char buf[1024]; va_list args; va_start(args, what); vsnprintf(buf, sizeof(buf), what, args); va_end(args); buf[sizeof(buf) - 1] = 0; int len = strlen(buf); int fd = open(file, O_WRONLY | O_CLOEXEC); if (fd == -1) return false; if (write(fd, buf, len) != len) { int err = errno; close(fd); errno = err; return false; } close(fd); return true; } 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 { char buf[1024]; char* hash; strncpy(buf, (char*)a0, sizeof(buf) - 1); buf[sizeof(buf) - 1] = 0; while ((hash = strchr(buf, '#'))) { *hash = '0' + (char)(a1 % 10); a1 /= 10; } return open(buf, a2, 0); } } static void kill_and_wait(int pid, int* status) { kill(-pid, SIGKILL); kill(pid, SIGKILL); for (int i = 0; i < 100; i++) { if (waitpid(-1, status, WNOHANG | __WALL) == pid) return; usleep(1000); } DIR* dir = opendir("/sys/fs/fuse/connections"); if (dir) { for (;;) { struct dirent* ent = readdir(dir); if (!ent) break; if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) continue; char abort[300]; snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort", ent->d_name); int fd = open(abort, O_WRONLY); if (fd == -1) { continue; } if (write(fd, abort, 1) < 0) { } close(fd); } closedir(dir); } else { } while (waitpid(-1, status, __WALL) != pid) { } } static void setup_test() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); write_file("/proc/self/oom_score_adj", "1000"); } 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 execute_one(void) { if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } int i, call, thread; for (call = 0; call < 6; 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); } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { int iter = 0; for (;; iter++) { int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { setup_test(); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { sleep_ms(10); if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } } } uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: memcpy((void*)0x4000000000c0, "/dev/input/event#\000", 18); res = -1; res = syz_open_dev(/*dev=*/0x4000000000c0, /*id=*/0x40, /*flags=*/0); if (res != -1) r[0] = res; break; case 1: *(uint16_t*)0x400000000300 = 0x50; *(uint16_t*)0x400000000302 = -1; *(uint16_t*)0x400000000304 = 6; *(uint16_t*)0x400000000306 = 0; *(uint16_t*)0x400000000308 = 0; *(uint16_t*)0x40000000030a = 0; *(uint16_t*)0x40000000030c = 0; *(uint16_t*)0x400000000310 = 0; *(uint16_t*)0x400000000312 = 0; *(uint16_t*)0x400000000314 = 0; *(uint16_t*)0x400000000316 = 0; *(uint16_t*)0x400000000318 = 0; *(uint16_t*)0x40000000031a = 0; *(uint16_t*)0x40000000031c = 0; *(uint16_t*)0x40000000031e = 0; *(uint16_t*)0x400000000320 = 0; *(uint16_t*)0x400000000322 = 0; *(uint16_t*)0x400000000324 = 0; *(uint16_t*)0x400000000326 = 0; syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0x40304580, /*arg=*/0x400000000300ul); break; case 2: memcpy((void*)0x400000000040, "/dev/uinput\000", 12); res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x400000000040ul, /*flags=O_RDWR_NONBLOCK*/ 0x802, /*mode=*/0); if (res != -1) r[1] = res; break; case 3: syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x4004556b, /*arg=*/0x51ul); break; case 4: memcpy((void*)0x400000000800, "syz1\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000", 80); *(uint16_t*)0x400000000850 = 0; *(uint16_t*)0x400000000852 = 0; *(uint16_t*)0x400000000854 = 0; *(uint16_t*)0x400000000856 = 0; *(uint32_t*)0x400000000858 = 0x35; *(uint32_t*)0x40000000085c = 0; *(uint32_t*)0x400000000860 = 0; *(uint32_t*)0x400000000864 = 0; *(uint32_t*)0x400000000868 = 0; *(uint32_t*)0x40000000086c = 0; *(uint32_t*)0x400000000870 = 0; *(uint32_t*)0x400000000874 = 0; *(uint32_t*)0x400000000878 = 0; *(uint32_t*)0x40000000087c = 0; *(uint32_t*)0x400000000880 = 0; *(uint32_t*)0x400000000884 = 0; *(uint32_t*)0x400000000888 = 0; *(uint32_t*)0x40000000088c = 0; *(uint32_t*)0x400000000890 = 0; *(uint32_t*)0x400000000894 = 0; *(uint32_t*)0x400000000898 = 0; *(uint32_t*)0x40000000089c = 0; *(uint32_t*)0x4000000008a0 = 0; *(uint32_t*)0x4000000008a4 = 0; *(uint32_t*)0x4000000008a8 = 0; *(uint32_t*)0x4000000008ac = 0; *(uint32_t*)0x4000000008b0 = 0; *(uint32_t*)0x4000000008b4 = 0; *(uint32_t*)0x4000000008b8 = 0; *(uint32_t*)0x4000000008bc = 0; *(uint32_t*)0x4000000008c0 = 0; *(uint32_t*)0x4000000008c4 = 0; *(uint32_t*)0x4000000008c8 = 0; *(uint32_t*)0x4000000008cc = 0; *(uint32_t*)0x4000000008d0 = 0; *(uint32_t*)0x4000000008d4 = 0; *(uint32_t*)0x4000000008d8 = 0; *(uint32_t*)0x4000000008dc = 0; *(uint32_t*)0x4000000008e0 = 1; *(uint32_t*)0x4000000008e4 = 0; *(uint32_t*)0x4000000008e8 = 0; *(uint32_t*)0x4000000008ec = 0; *(uint32_t*)0x4000000008f0 = 0; *(uint32_t*)0x4000000008f4 = 0; *(uint32_t*)0x4000000008f8 = 3; *(uint32_t*)0x4000000008fc = 0; *(uint32_t*)0x400000000900 = 0; *(uint32_t*)0x400000000904 = 0; *(uint32_t*)0x400000000908 = 0; *(uint32_t*)0x40000000090c = 0; *(uint32_t*)0x400000000910 = 0; *(uint32_t*)0x400000000914 = 0; *(uint32_t*)0x400000000918 = 0; *(uint32_t*)0x40000000091c = -1; *(uint32_t*)0x400000000920 = 0; *(uint32_t*)0x400000000924 = 0; *(uint32_t*)0x400000000928 = 0; *(uint32_t*)0x40000000092c = 0; *(uint32_t*)0x400000000930 = 0; *(uint32_t*)0x400000000934 = 0x6d37; *(uint32_t*)0x400000000938 = 0; *(uint32_t*)0x40000000093c = 0; *(uint32_t*)0x400000000940 = 0; *(uint32_t*)0x400000000944 = 0; *(uint32_t*)0x400000000948 = 0; *(uint32_t*)0x40000000094c = 0; *(uint32_t*)0x400000000950 = 0; *(uint32_t*)0x400000000954 = 0; *(uint32_t*)0x400000000958 = 0; *(uint32_t*)0x40000000095c = 0; *(uint32_t*)0x400000000960 = 0; *(uint32_t*)0x400000000964 = 0; *(uint32_t*)0x400000000968 = 0; *(uint32_t*)0x40000000096c = 0xfff; *(uint32_t*)0x400000000970 = 0; *(uint32_t*)0x400000000974 = 0; *(uint32_t*)0x400000000978 = 0; *(uint32_t*)0x40000000097c = 0; *(uint32_t*)0x400000000980 = 0; *(uint32_t*)0x400000000984 = 0; *(uint32_t*)0x400000000988 = 0; *(uint32_t*)0x40000000098c = 0; *(uint32_t*)0x400000000990 = 0; *(uint32_t*)0x400000000994 = 0; *(uint32_t*)0x400000000998 = 0; *(uint32_t*)0x40000000099c = 0; *(uint32_t*)0x4000000009a0 = 0; *(uint32_t*)0x4000000009a4 = 0; *(uint32_t*)0x4000000009a8 = 4; *(uint32_t*)0x4000000009ac = 0; *(uint32_t*)0x4000000009b0 = 0; *(uint32_t*)0x4000000009b4 = 0x800; *(uint32_t*)0x4000000009b8 = 0; *(uint32_t*)0x4000000009bc = -1; *(uint32_t*)0x4000000009c0 = 0; *(uint32_t*)0x4000000009c4 = 0; *(uint32_t*)0x4000000009c8 = 0; *(uint32_t*)0x4000000009cc = 0; *(uint32_t*)0x4000000009d0 = 0; *(uint32_t*)0x4000000009d4 = 0; *(uint32_t*)0x4000000009d8 = 0; *(uint32_t*)0x4000000009dc = 0; *(uint32_t*)0x4000000009e0 = 0; *(uint32_t*)0x4000000009e4 = 0; *(uint32_t*)0x4000000009e8 = 0; *(uint32_t*)0x4000000009ec = 0; *(uint32_t*)0x4000000009f0 = 0; *(uint32_t*)0x4000000009f4 = 0xfffffffe; *(uint32_t*)0x4000000009f8 = 0; *(uint32_t*)0x4000000009fc = 0; *(uint32_t*)0x400000000a00 = 0; *(uint32_t*)0x400000000a04 = 0; *(uint32_t*)0x400000000a08 = 0; *(uint32_t*)0x400000000a0c = 0; *(uint32_t*)0x400000000a10 = 0; *(uint32_t*)0x400000000a14 = 0; *(uint32_t*)0x400000000a18 = 0; *(uint32_t*)0x400000000a1c = 0; *(uint32_t*)0x400000000a20 = 0; *(uint32_t*)0x400000000a24 = 0; *(uint32_t*)0x400000000a28 = 0; *(uint32_t*)0x400000000a2c = 0; *(uint32_t*)0x400000000a30 = 0; *(uint32_t*)0x400000000a34 = 0; *(uint32_t*)0x400000000a38 = 0; *(uint32_t*)0x400000000a3c = 0; *(uint32_t*)0x400000000a40 = 0; *(uint32_t*)0x400000000a44 = 0; *(uint32_t*)0x400000000a48 = 0; *(uint32_t*)0x400000000a4c = 0; *(uint32_t*)0x400000000a50 = 4; *(uint32_t*)0x400000000a54 = 0; *(uint32_t*)0x400000000a58 = 0; *(uint32_t*)0x400000000a5c = 0; *(uint32_t*)0x400000000a60 = 0; *(uint32_t*)0x400000000a64 = 0; *(uint32_t*)0x400000000a68 = 0; *(uint32_t*)0x400000000a6c = 0; *(uint32_t*)0x400000000a70 = 0; *(uint32_t*)0x400000000a74 = 0; *(uint32_t*)0x400000000a78 = 0; *(uint32_t*)0x400000000a7c = 0; *(uint32_t*)0x400000000a80 = 0; *(uint32_t*)0x400000000a84 = 0; *(uint32_t*)0x400000000a88 = 0; *(uint32_t*)0x400000000a8c = 0x200000; *(uint32_t*)0x400000000a90 = 0; *(uint32_t*)0x400000000a94 = 0; *(uint32_t*)0x400000000a98 = 0; *(uint32_t*)0x400000000a9c = 0; *(uint32_t*)0x400000000aa0 = 0; *(uint32_t*)0x400000000aa4 = 7; *(uint32_t*)0x400000000aa8 = 0; *(uint32_t*)0x400000000aac = 0xfffffffd; *(uint32_t*)0x400000000ab0 = 0; *(uint32_t*)0x400000000ab4 = 0; *(uint32_t*)0x400000000ab8 = 0; *(uint32_t*)0x400000000abc = 0x20; *(uint32_t*)0x400000000ac0 = 0; *(uint32_t*)0x400000000ac4 = -1; *(uint32_t*)0x400000000ac8 = 0; *(uint32_t*)0x400000000acc = 0; *(uint32_t*)0x400000000ad0 = 0x100; *(uint32_t*)0x400000000ad4 = 0; *(uint32_t*)0x400000000ad8 = 0; *(uint32_t*)0x400000000adc = 0; *(uint32_t*)0x400000000ae0 = 0; *(uint32_t*)0x400000000ae4 = 0; *(uint32_t*)0x400000000ae8 = 0; *(uint32_t*)0x400000000aec = 0; *(uint32_t*)0x400000000af0 = 0; *(uint32_t*)0x400000000af4 = 0; *(uint32_t*)0x400000000af8 = 0; *(uint32_t*)0x400000000afc = 0xfffffffd; *(uint32_t*)0x400000000b00 = 0; *(uint32_t*)0x400000000b04 = 0; *(uint32_t*)0x400000000b08 = 0x2000; *(uint32_t*)0x400000000b0c = 0; *(uint32_t*)0x400000000b10 = 0; *(uint32_t*)0x400000000b14 = 0; *(uint32_t*)0x400000000b18 = 0; *(uint32_t*)0x400000000b1c = 0; *(uint32_t*)0x400000000b20 = 0; *(uint32_t*)0x400000000b24 = 0; *(uint32_t*)0x400000000b28 = 0; *(uint32_t*)0x400000000b2c = 0; *(uint32_t*)0x400000000b30 = 0; *(uint32_t*)0x400000000b34 = 1; *(uint32_t*)0x400000000b38 = 0; *(uint32_t*)0x400000000b3c = 0; *(uint32_t*)0x400000000b40 = 0; *(uint32_t*)0x400000000b44 = 0; *(uint32_t*)0x400000000b48 = 0; *(uint32_t*)0x400000000b4c = 0; *(uint32_t*)0x400000000b50 = 0; *(uint32_t*)0x400000000b54 = 0; *(uint32_t*)0x400000000b58 = 0; *(uint32_t*)0x400000000b5c = 0; *(uint32_t*)0x400000000b60 = 0; *(uint32_t*)0x400000000b64 = 0; *(uint32_t*)0x400000000b68 = 0; *(uint32_t*)0x400000000b6c = 0; *(uint32_t*)0x400000000b70 = 0; *(uint32_t*)0x400000000b74 = 0; *(uint32_t*)0x400000000b78 = 0; *(uint32_t*)0x400000000b7c = 0; *(uint32_t*)0x400000000b80 = 0; *(uint32_t*)0x400000000b84 = 0; *(uint32_t*)0x400000000b88 = 0xfffffffe; *(uint32_t*)0x400000000b8c = 0; *(uint32_t*)0x400000000b90 = 0; *(uint32_t*)0x400000000b94 = 5; *(uint32_t*)0x400000000b98 = 7; *(uint32_t*)0x400000000b9c = 0; *(uint32_t*)0x400000000ba0 = 0; *(uint32_t*)0x400000000ba4 = 0; *(uint32_t*)0x400000000ba8 = 0; *(uint32_t*)0x400000000bac = 7; *(uint32_t*)0x400000000bb0 = 0; *(uint32_t*)0x400000000bb4 = 0; *(uint32_t*)0x400000000bb8 = 0; *(uint32_t*)0x400000000bbc = 0; *(uint32_t*)0x400000000bc0 = 0; *(uint32_t*)0x400000000bc4 = 0; *(uint32_t*)0x400000000bc8 = 0; *(uint32_t*)0x400000000bcc = 0; *(uint32_t*)0x400000000bd0 = 0; *(uint32_t*)0x400000000bd4 = 0; *(uint32_t*)0x400000000bd8 = 0xfffffffc; *(uint32_t*)0x400000000bdc = 0; *(uint32_t*)0x400000000be0 = 3; *(uint32_t*)0x400000000be4 = 0; *(uint32_t*)0x400000000be8 = 0; *(uint32_t*)0x400000000bec = 0; *(uint32_t*)0x400000000bf0 = 0; *(uint32_t*)0x400000000bf4 = 0; *(uint32_t*)0x400000000bf8 = 0; *(uint32_t*)0x400000000bfc = 0; *(uint32_t*)0x400000000c00 = 0; *(uint32_t*)0x400000000c04 = 0; *(uint32_t*)0x400000000c08 = 0; *(uint32_t*)0x400000000c0c = 0; *(uint32_t*)0x400000000c10 = 0; *(uint32_t*)0x400000000c14 = 0; *(uint32_t*)0x400000000c18 = 0; *(uint32_t*)0x400000000c1c = 2; *(uint32_t*)0x400000000c20 = 0; *(uint32_t*)0x400000000c24 = 0; *(uint32_t*)0x400000000c28 = 0; *(uint32_t*)0x400000000c2c = 0; *(uint32_t*)0x400000000c30 = 0; *(uint32_t*)0x400000000c34 = 0; *(uint32_t*)0x400000000c38 = 0; *(uint32_t*)0x400000000c3c = 0; *(uint32_t*)0x400000000c40 = 0; *(uint32_t*)0x400000000c44 = 0; *(uint32_t*)0x400000000c48 = 0; *(uint32_t*)0x400000000c4c = 0; *(uint32_t*)0x400000000c50 = 0; *(uint32_t*)0x400000000c54 = 0; *(uint32_t*)0x400000000c58 = 0; syscall(__NR_write, /*fd=*/r[1], /*data=*/0x400000000800ul, /*len=*/0x45cul); break; case 5: syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x5501, 0); break; } } int main(void) { syscall(__NR_mmap, /*addr=*/0x3ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x400000000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x400001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, /*offset=*/0ul); const char* reason; (void)reason; for (procid = 0; procid < 5; procid++) { if (fork() == 0) { loop(); } } sleep(1000000); return 0; }