// https://syzkaller.appspot.com/bug?id=2431068eb52548f20447545f1948b727e87e720a // 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 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() { 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() { 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 long syz_open_dev(long a0, long a1, 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 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) { } } #define SYZ_HAVE_SETUP_TEST 1 static void setup_test() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); } #define SYZ_HAVE_RESET_TEST 1 static void reset_test() { int fd; for (fd = 3; fd < 30; fd++) close(fd); } static void execute_one(); #define WAIT_FLAGS __WALL static void loop() { int iter; for (iter = 0;; iter++) { int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { setup_test(); execute_one(); reset_test(); 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; } } } uint64_t r[1] = {0xffffffffffffffff}; void execute_one() { long res = 0; res = syscall(__NR_socket, 2, 1, 0); if (res != -1) r[0] = res; NONFAILING(memcpy( (void*)0x20000800, "\x66\x69\x6c\x74\x65\x72\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00" "\x04\x00\x00\x40\x58\x04\x00\x00\x00\x00\x00\x00\x30\x02\x00\x00\x00\x00" "\x00\x00\x55\x03\x00\x00\x70\x03\x00\x00\x70\x03\x00\x00\x04\x00\x00\x00" "\xc3\x02\x62\x2c\xd0\xc2\x1f\xe5\x52\xfa\x54\xd5\x31\x3e\xf3\x34\xdc\xae" "\x98\xff\xa7\xaa\x4c\x8c\x68\xa7\x31\x35\x6e\xca\x1b\xb4\x91\xaa\xcf\x66" "\xdf\x03\x73\x2f\x0f\x23\xe4\x09\xb0\xef\x7d\x65\xa8\x07\x1f\x62\x6b\xe2" "\x40\xf2\x51\xea\xf4\x33\x26\xd3\x0a\x0c\x9f\x94\x1d\xc5\x67\xa2\x5d\x74" "\xdc\xa7\x96\xea\x15\xd6\x7d\x10\xa1\x3f\x3e\x35\x58\xaf\x94\x0c\x80\x58" "\x5f\x62\x5a\x72\x67\xeb\xda\x73\x24\x0c\x67\x9a\xff\x7b\x6b\x3a\x09\x4a" "\xc1\x75\x65\x67\x02\x40\x86\xdc\x99\x8f\xe9\x23\xf4\xbd\x3b\x04\xc1\x35" "\x92\xf2\x65\xeb\xb1\x4b\x17\x8a\x23\x4d\xc6\x97\x0d\xfa\xc4\x05\x58\x31" "\xea", 217)); NONFAILING(*(uint64_t*)0x200008d9 = 0x20000000); syscall(__NR_setsockopt, r[0], 0, 0x60, 0x20000800, 3); NONFAILING(memcpy((void*)0x20000040, "/dev/snd/seq", 13)); syz_open_dev(0x20000040, 0, 0x101801); NONFAILING(*(uint32_t*)0x20000340 = 0); NONFAILING(*(uint32_t*)0x20000344 = 0); NONFAILING(*(uint32_t*)0x20000348 = 0); NONFAILING(memcpy((void*)0x2000034c, "\x71\x75\x65\x75\x65\x31\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00", 64)); NONFAILING(*(uint32_t*)0x2000038c = 0); NONFAILING(*(uint8_t*)0x20000390 = 0); NONFAILING(*(uint8_t*)0x20000391 = 0); NONFAILING(*(uint8_t*)0x20000392 = 0); NONFAILING(*(uint8_t*)0x20000393 = 0); NONFAILING(*(uint8_t*)0x20000394 = 0); NONFAILING(*(uint8_t*)0x20000395 = 0); NONFAILING(*(uint8_t*)0x20000396 = 0); NONFAILING(*(uint8_t*)0x20000397 = 0); NONFAILING(*(uint8_t*)0x20000398 = 0); NONFAILING(*(uint8_t*)0x20000399 = 0); NONFAILING(*(uint8_t*)0x2000039a = 0); NONFAILING(*(uint8_t*)0x2000039b = 0); NONFAILING(*(uint8_t*)0x2000039c = 0); NONFAILING(*(uint8_t*)0x2000039d = 0); NONFAILING(*(uint8_t*)0x2000039e = 0); NONFAILING(*(uint8_t*)0x2000039f = 0); NONFAILING(*(uint8_t*)0x200003a0 = 0); NONFAILING(*(uint8_t*)0x200003a1 = 0); NONFAILING(*(uint8_t*)0x200003a2 = 0); NONFAILING(*(uint8_t*)0x200003a3 = 0); NONFAILING(*(uint8_t*)0x200003a4 = 0); NONFAILING(*(uint8_t*)0x200003a5 = 0); NONFAILING(*(uint8_t*)0x200003a6 = 0); NONFAILING(*(uint8_t*)0x200003a7 = 0); NONFAILING(*(uint8_t*)0x200003a8 = 0); NONFAILING(*(uint8_t*)0x200003a9 = 0); NONFAILING(*(uint8_t*)0x200003aa = 0); NONFAILING(*(uint8_t*)0x200003ab = 0); NONFAILING(*(uint8_t*)0x200003ac = 0); NONFAILING(*(uint8_t*)0x200003ad = 0); NONFAILING(*(uint8_t*)0x200003ae = 0); NONFAILING(*(uint8_t*)0x200003af = 0); NONFAILING(*(uint8_t*)0x200003b0 = 0); NONFAILING(*(uint8_t*)0x200003b1 = 0); NONFAILING(*(uint8_t*)0x200003b2 = 0); NONFAILING(*(uint8_t*)0x200003b3 = 0); NONFAILING(*(uint8_t*)0x200003b4 = 0); NONFAILING(*(uint8_t*)0x200003b5 = 0); NONFAILING(*(uint8_t*)0x200003b6 = 0); NONFAILING(*(uint8_t*)0x200003b7 = 0); NONFAILING(*(uint8_t*)0x200003b8 = 0); NONFAILING(*(uint8_t*)0x200003b9 = 0); NONFAILING(*(uint8_t*)0x200003ba = 0); NONFAILING(*(uint8_t*)0x200003bb = 0); NONFAILING(*(uint8_t*)0x200003bc = 0); NONFAILING(*(uint8_t*)0x200003bd = 0); NONFAILING(*(uint8_t*)0x200003be = 0); NONFAILING(*(uint8_t*)0x200003bf = 0); NONFAILING(*(uint8_t*)0x200003c0 = 0); NONFAILING(*(uint8_t*)0x200003c1 = 0); NONFAILING(*(uint8_t*)0x200003c2 = 0); NONFAILING(*(uint8_t*)0x200003c3 = 0); NONFAILING(*(uint8_t*)0x200003c4 = 0); NONFAILING(*(uint8_t*)0x200003c5 = 0); NONFAILING(*(uint8_t*)0x200003c6 = 0); NONFAILING(*(uint8_t*)0x200003c7 = 0); NONFAILING(*(uint8_t*)0x200003c8 = 0); NONFAILING(*(uint8_t*)0x200003c9 = 0); NONFAILING(*(uint8_t*)0x200003ca = 0); NONFAILING(*(uint8_t*)0x200003cb = 0); syscall(__NR_ioctl, -1, 0x408c5333, 0x20000340); NONFAILING(memcpy((void*)0x200000c0, "/dev/snapshot", 14)); syscall(__NR_openat, 0xffffffffffffff9c, 0x200000c0, 0x80800, 0); NONFAILING(memcpy((void*)0x20000100, "./file0", 8)); syscall(__NR_lstat, 0x20000100, 0x20000140); NONFAILING(memcpy((void*)0x200001c0, "/selinux/create", 16)); syscall(__NR_openat, 0xffffffffffffff9c, 0x200001c0, 2, 0); syscall(__NR_timer_delete, 0); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); install_segv_handler(); for (procid = 0; procid < 8; procid++) { if (fork() == 0) { loop(); } } sleep(1000000); return 0; }