// https://syzkaller.appspot.com/bug?id=61d80cc45077fcc43cec63681f58a989ec08dbf2 // 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 #include unsigned long long procid; static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) && (addr < prog_start || addr > prog_end)) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8); syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8); memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) \ { \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ } 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; for (i = 0; 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); } 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_RELAXED)) 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; NONFAILING(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 long syz_open_procfs(volatile long a0, volatile long a1) { char buf[128]; memset(buf, 0, sizeof(buf)); if (a0 == 0) { NONFAILING(snprintf(buf, sizeof(buf), "/proc/self/%s", (char*)a1)); } else if (a0 == -1) { NONFAILING(snprintf(buf, sizeof(buf), "/proc/thread-self/%s", (char*)a1)); } else { NONFAILING(snprintf(buf, sizeof(buf), "/proc/self/task/%d/%s", (int)a0, (char*)a1)); } int fd = open(buf, O_RDWR); if (fd == -1) fd = open(buf, O_RDONLY); return fd; } static void kill_and_wait(int pid, int* status) { kill(-pid, SIGKILL); kill(pid, SIGKILL); int i; for (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) { int i, call, thread; int collide = 0; again: for (call = 0; call < 11; 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); if (collide && (call % 2) == 0) break; event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); if (!collide) { collide = 1; goto again; } } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { int iter; for (iter = 0;; 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 < 5 * 1000) continue; kill_and_wait(pid, &status); break; } } } #ifndef __NR_clock_getres #define __NR_clock_getres 266 #endif #ifndef __NR_clone #define __NR_clone 120 #endif #ifndef __NR_ioctl #define __NR_ioctl 54 #endif #ifndef __NR_mmap #define __NR_mmap 192 #endif #ifndef __NR_openat #define __NR_openat 295 #endif #ifndef __NR_pipe #define __NR_pipe 42 #endif #ifndef __NR_read #define __NR_read 3 #endif #ifndef __NR_socket #define __NR_socket 359 #endif #ifndef __NR_write #define __NR_write 4 #endif #undef __NR_mmap #define __NR_mmap __NR_mmap2 uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res; switch (call) { case 0: syscall(__NR_socket, 2, 2, 3); break; case 1: syscall(__NR_ioctl, -1, 0x5432, 0x20000040); break; case 2: syscall(__NR_clock_getres, 0xf, 0); break; case 3: syscall(__NR_openat, 0xffffff9c, 0, 0xc0000, 0); break; case 4: syscall(__NR_ioctl, -1, 0x7003, 0); break; case 5: syscall(__NR_clone, 0x207ffd, 0, 0x99999999, 0, -1); break; case 6: NONFAILING(memcpy((void*)0x20000280, "/dev/loop#\000", 11)); syz_open_dev(0x20000280, 6, 0x105082); break; case 7: res = syscall(__NR_pipe, 0x20000080); if (res != -1) { NONFAILING(r[0] = *(uint32_t*)0x20000080); NONFAILING(r[1] = *(uint32_t*)0x20000084); } break; case 8: NONFAILING(memcpy( (void*)0x20000a00, "\x8b\x62\x5c\xc3\xc7\x3c\x49\xd7\x00\x00\x00\x00\x00\x00\xed\xd3\xa4" "\x4a\xb3\xb1\xdf\x5e\x98\x68\x3a\x40\xb6\xd1\xa9\x65\x82\xee\x68\x62" "\x79\x71\x3f\xb6\x8c\x1e\x4d\xd8\x56\x47\x8a\x2f\x46\x71\x09\xf2\xb7" "\xf0\x08\x7f\x24\x78\x61\x37\xf0\x7a\x6e\x14\xb9\xac\xae\x26\xef\x60" "\xe6\x0b\x0c\x30\x01\x39\x36\xc5\x47\x1c\x08\x32\x8e\x45\x71\x06\x00" "\x10\x6b\x19\x8a\x76\x5c\xf9\x8c\x8c\x07\x46\xb6\x30\xb0\xda\x7f\x8b" "\xfe\x85\xf2\x7d\x53\x5d\xee\x3e\xe8\xc6\xe0\x74\x02\x00\xdf\x8a\xf3" "\x7d\xf2\xbe\x3f\xee\x83\x3b\x03\xbe\x78\xf8\x04\xe8\x6f\xab\xad\x81" "\x57\x5e\xd3\xc1\x96\x97\x85\x9e\x6f\xa4\x03\xad\x7f\x1b\x1f\xf2\xb6" "\x83\xbd\x8b\x6f\x9a\xce\xe9\xc7\xcd\x2c\xfe\x84\xfe\xc8\x46\x13\x75" "\x74\x08\x51\x1e\xb2\xef\xe9\xe9\xcb\xf6\x01\xf7\xa5\x7d\x1e\xc5\x5a" "\xfd\xb9\xb1\xd2\xf3\x05\x24\x8e\x32\x64\x0f\xf4\x72\xb5\x58\x87\x14" "\xb7\x3e\xb3\x7b\x5f\xf2\x9b\x7b\xad\x90\x08\xaa\x80\x1a\xb9\xee\xec" "\x7b\xfb\x2f\x8d\x57\xfb\x3f\x97\x16\xff\xbd\xd8\x92\x15\xff\x86\x67" "\x28\x4a\x6c\x31\x95\x1a\x43\xfe\x0a\x60\x6d\xbb\xe4\xd7\x71\x22\x21" "\xf1\x48\xef\xdf\xcb\x76\xda\xfd\x4f\x37\x00\xd6\x39\x84\xa7\x83\xbe" "\x3e\x52\x00\x2d\xb8\x69\x1a\xf0\x3a\x0b\x5f\x66\xfe\xaa\xf1\x8c\x50" "\xd9\xf4\xe4\x25\x27\x10\x64\x90\xd7\x39\xf6\x70\xc2\x0d\xf9\xe6\xe7" "\x0f\x0f\xd0\xcd\x4d\xea\xe0\x2c\x8e\xf0\x48\x88\x73\xd6\x7c\xfa\x61" "\x9b\x80\x28\x95\x31\xcb\xd1\x67\x62\x9f\x2f\xdd\x35\x40\xa5\x23\x3b" "\x9f\x80\x03\xc3\x3f\x79\xd7\xc0\x93\xc5\xb9\x6b\xd9\x41\xd9\x60\x1e" "\xa1\x18\xd4\x21\x96\x01\x8e\x04\x68\x90\x70\x8b\xc1\x5d\x75\x36\xd0" "\x5c\xb0\x15\x93\xf9\xcf\x2a\xc4\x09\x82\x29\xcf\xc6\x9d\x0d\x49\x69" "\x46\x5d\x45\x75\x99\x01\xa6\xac\xbb\x53\xbf\x23\x90\xfc\xb4\xc5\x30" "\x4d\x47\xf5\xc7\x49\xa2\x07\x10\x59\x4b\x06\x7b\x41\xd4\xcf\x69\x19" "\x62\xb3\xfa\x09\x8f\x14\x31\x47\xfb\xc4\x4f\x7d\xd0\xaf\xe4\x08\x01" "\x25\x80\x4f\x3a\x95\x74\x13\x91\xf2\xaf\x68\x93\x18\xac\x69\x67\xfb" "\xcf\x19\x32\xf5\x69\x2b\x1c\xf8\x0d\xd5\x42\x9d\xcb\x0a\x5e\x94\xba" "\x96\x61\xe5\xa4\x63", 481)); syscall(__NR_write, (intptr_t)r[1], 0x20000a00, 0xffffff5d); break; case 9: syscall(__NR_read, (intptr_t)r[0], 0x20000340, 0x151c3a26); break; case 10: NONFAILING(memcpy((void*)0x200000c0, "net/tcp6\000", 9)); syz_open_procfs(0, 0x200000c0); break; } } int main(void) { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); install_segv_handler(); for (procid = 0; procid < 6; procid++) { if (fork() == 0) { loop(); } } sleep(1000000); return 0; }