// https://syzkaller.appspot.com/bug?id=ef95147925146612c0c5b3abc6a2a10cdc1797f1 // 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 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); } #define BITMASK(bf_off, bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type, htobe, addr, val, bf_off, bf_len) \ *(type*)(addr) = \ htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | \ (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) 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 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"); } static void setup_sysctl() { char mypid[32]; snprintf(mypid, sizeof(mypid), "%d", getpid()); struct { const char* name; const char* data; } files[] = { {"/sys/kernel/debug/x86/nmi_longest_ns", "10000000000"}, {"/proc/sys/kernel/hung_task_check_interval_secs", "20"}, {"/proc/sys/net/core/bpf_jit_kallsyms", "1"}, {"/proc/sys/net/core/bpf_jit_harden", "0"}, {"/proc/sys/kernel/kptr_restrict", "0"}, {"/proc/sys/kernel/softlockup_all_cpu_backtrace", "1"}, {"/proc/sys/fs/mount-max", "100"}, {"/proc/sys/vm/oom_dump_tasks", "0"}, {"/proc/sys/debug/exception-trace", "0"}, {"/proc/sys/kernel/printk", "7 4 1 3"}, {"/proc/sys/net/ipv4/ping_group_range", "0 65535"}, {"/proc/sys/kernel/keys/gc_delay", "1"}, {"/proc/sys/vm/oom_kill_allocating_task", "1"}, {"/proc/sys/kernel/ctrl-alt-del", "0"}, {"/proc/sys/kernel/cad_pid", mypid}, }; for (size_t i = 0; i < sizeof(files) / sizeof(files[0]); i++) { if (!write_file(files[i].name, files[i].data)) printf("write to %s failed: %s\n", files[i].name, strerror(errno)); } } 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) { int i, call, thread; for (call = 0; call < 3; 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 (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } } } uint64_t r[1] = {0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(__NR_socket, 0x10ul, 3ul, 0xc); if (res != -1) r[0] = res; break; case 1: *(uint64_t*)0x200001c0 = 0; *(uint32_t*)0x200001c8 = 0; *(uint64_t*)0x200001d0 = 0x20000080; *(uint64_t*)0x20000080 = 0x20000100; *(uint32_t*)0x20000100 = 0x5c; *(uint8_t*)0x20000104 = 1; *(uint8_t*)0x20000105 = 6; *(uint16_t*)0x20000106 = 5; *(uint32_t*)0x20000108 = 0; *(uint32_t*)0x2000010c = 0; *(uint8_t*)0x20000110 = 2; *(uint8_t*)0x20000111 = 0; *(uint16_t*)0x20000112 = htobe16(7); *(uint16_t*)0x20000114 = 5; *(uint16_t*)0x20000116 = 1; *(uint8_t*)0x20000118 = 7; *(uint16_t*)0x2000011c = 5; *(uint16_t*)0x2000011e = 1; *(uint8_t*)0x20000120 = 7; *(uint16_t*)0x20000124 = 5; *(uint16_t*)0x20000126 = 1; *(uint8_t*)0x20000128 = 7; *(uint16_t*)0x2000012c = 5; *(uint16_t*)0x2000012e = 1; *(uint8_t*)0x20000130 = 7; *(uint16_t*)0x20000134 = 5; *(uint16_t*)0x20000136 = 1; *(uint8_t*)0x20000138 = 7; *(uint16_t*)0x2000013c = 5; *(uint16_t*)0x2000013e = 1; *(uint8_t*)0x20000140 = 7; *(uint16_t*)0x20000144 = 5; *(uint16_t*)0x20000146 = 1; *(uint8_t*)0x20000148 = 7; *(uint16_t*)0x2000014c = 5; *(uint16_t*)0x2000014e = 1; *(uint8_t*)0x20000150 = 7; *(uint16_t*)0x20000154 = 5; *(uint16_t*)0x20000156 = 1; *(uint8_t*)0x20000158 = 7; *(uint64_t*)0x20000088 = 0x5c; *(uint64_t*)0x200001d8 = 1; *(uint64_t*)0x200001e0 = 0; *(uint64_t*)0x200001e8 = 0; *(uint32_t*)0x200001f0 = 0x20004004; syscall(__NR_sendmsg, r[0], 0x200001c0ul, 0x20040800ul); { int i; for (i = 0; i < 64; i++) { syscall(__NR_sendmsg, r[0], 0x200001c0ul, 0x20040800ul); } } break; case 2: *(uint64_t*)0x20000380 = 0; *(uint32_t*)0x20000388 = 0; *(uint64_t*)0x20000390 = 0x20000340; *(uint64_t*)0x20000340 = 0x20000240; *(uint32_t*)0x20000240 = 0xf0; *(uint8_t*)0x20000244 = 1; *(uint8_t*)0x20000245 = 2; *(uint16_t*)0x20000246 = 0x201; *(uint32_t*)0x20000248 = 0; *(uint32_t*)0x2000024c = 0; *(uint8_t*)0x20000250 = 0; *(uint8_t*)0x20000251 = 0; *(uint16_t*)0x20000252 = htobe16(6); *(uint16_t*)0x20000254 = 0xa; *(uint16_t*)0x20000256 = 6; memcpy((void*)0x20000258, "H.245\000", 6); *(uint16_t*)0x20000260 = 8; STORE_BY_BITMASK(uint16_t, , 0x20000262, 9, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x20000263, 1, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x20000263, 0, 7, 1); *(uint32_t*)0x20000264 = htobe32(6); *(uint16_t*)0x20000268 = 8; *(uint16_t*)0x2000026a = 0xb; memcpy((void*)0x2000026c, "sip\000", 4); *(uint16_t*)0x20000270 = 0xb8; STORE_BY_BITMASK(uint16_t, , 0x20000272, 2, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x20000273, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x20000273, 1, 7, 1); *(uint16_t*)0x20000274 = 0x2c; STORE_BY_BITMASK(uint16_t, , 0x20000276, 1, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x20000277, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x20000277, 1, 7, 1); *(uint16_t*)0x20000278 = 0x14; *(uint16_t*)0x2000027a = 3; *(uint8_t*)0x2000027c = 0xfe; *(uint8_t*)0x2000027d = 0x80; memset((void*)0x2000027e, 0, 13); *(uint8_t*)0x2000028b = 0xaa; *(uint16_t*)0x2000028c = 0x14; *(uint16_t*)0x2000028e = 4; *(uint8_t*)0x20000290 = 0xfc; *(uint8_t*)0x20000291 = 2; memset((void*)0x20000292, 0, 13); *(uint8_t*)0x2000029f = 0; *(uint16_t*)0x200002a0 = 6; STORE_BY_BITMASK(uint16_t, , 0x200002a2, 3, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x200002a3, 1, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x200002a3, 0, 7, 1); *(uint16_t*)0x200002a4 = htobe16(3); *(uint16_t*)0x200002a8 = 0x14; STORE_BY_BITMASK(uint16_t, , 0x200002aa, 1, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x200002ab, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x200002ab, 1, 7, 1); *(uint16_t*)0x200002ac = 8; *(uint16_t*)0x200002ae = 1; *(uint32_t*)0x200002b0 = htobe32(0); *(uint16_t*)0x200002b4 = 8; *(uint16_t*)0x200002b6 = 2; *(uint8_t*)0x200002b8 = 0xac; *(uint8_t*)0x200002b9 = 0x1e; *(uint8_t*)0x200002ba = 1; *(uint8_t*)0x200002bb = 1 + procid * 1; *(uint16_t*)0x200002bc = 6; STORE_BY_BITMASK(uint16_t, , 0x200002be, 3, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x200002bf, 1, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x200002bf, 0, 7, 1); *(uint16_t*)0x200002c0 = htobe16(0); *(uint16_t*)0x200002c4 = 0xc; STORE_BY_BITMASK(uint16_t, , 0x200002c6, 2, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x200002c7, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x200002c7, 1, 7, 1); *(uint16_t*)0x200002c8 = 5; *(uint16_t*)0x200002ca = 1; *(uint8_t*)0x200002cc = 0x88; *(uint16_t*)0x200002d0 = 0x2c; STORE_BY_BITMASK(uint16_t, , 0x200002d2, 1, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x200002d3, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x200002d3, 1, 7, 1); *(uint16_t*)0x200002d4 = 0x14; *(uint16_t*)0x200002d6 = 3; *(uint8_t*)0x200002d8 = 0xfc; *(uint8_t*)0x200002d9 = 0; memset((void*)0x200002da, 0, 13); *(uint8_t*)0x200002e7 = 1; *(uint16_t*)0x200002e8 = 0x14; *(uint16_t*)0x200002ea = 4; *(uint8_t*)0x200002ec = 0xfe; *(uint8_t*)0x200002ed = 0x88; memset((void*)0x200002ee, 0, 12); *(uint8_t*)0x200002fa = 1; *(uint8_t*)0x200002fb = 1 + procid * 1; *(uint16_t*)0x200002fc = 0x2c; STORE_BY_BITMASK(uint16_t, , 0x200002fe, 1, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x200002ff, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x200002ff, 1, 7, 1); *(uint16_t*)0x20000300 = 0x14; *(uint16_t*)0x20000302 = 3; *(uint8_t*)0x20000304 = 0xfe; *(uint8_t*)0x20000305 = 0x80; memset((void*)0x20000306, 0, 13); *(uint8_t*)0x20000313 = 0xaa; *(uint16_t*)0x20000314 = 0x14; *(uint16_t*)0x20000316 = 4; *(uint8_t*)0x20000318 = 0xfe; *(uint8_t*)0x20000319 = 0x80; memset((void*)0x2000031a, 0, 13); *(uint8_t*)0x20000327 = 0x13; *(uint16_t*)0x20000328 = 8; STORE_BY_BITMASK(uint16_t, , 0x2000032a, 8, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x2000032b, 1, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x2000032b, 0, 7, 1); *(uint32_t*)0x2000032c = htobe32(1); *(uint64_t*)0x20000348 = 0xf0; *(uint64_t*)0x20000398 = 1; *(uint64_t*)0x200003a0 = 0; *(uint64_t*)0x200003a8 = 0; *(uint32_t*)0x200003b0 = 0x800; syscall(__NR_sendmsg, r[0], 0x20000380ul, 0x2000084ul); { int i; for (i = 0; i < 64; i++) { syscall(__NR_sendmsg, r[0], 0x20000380ul, 0x2000084ul); } } break; } } int main(void) { syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); setup_sysctl(); for (procid = 0; procid < 6; procid++) { if (fork() == 0) { loop(); } } sleep(1000000); return 0; }