// https://syzkaller.appspot.com/bug?id=ddc83e209f712ce63078e146f7c0fe63e1edbc2f // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include __attribute__((noreturn)) static void doexit(int status) { volatile unsigned i; syscall(__NR_exit_group, status); for (i = 0;; i++) { } } #include #include const int kFailStatus = 67; const int kRetryStatus = 69; static void fail(const char* msg, ...) { int e = errno; va_list args; va_start(args, msg); vfprintf(stderr, msg, args); va_end(args); fprintf(stderr, " (errno %d)\n", e); doexit((e == ENOMEM || e == EAGAIN) ? kRetryStatus : kFailStatus); } static uint64_t current_time_ms() { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) fail("clock_gettime failed"); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static uintptr_t syz_open_dev(uintptr_t a0, uintptr_t a1, uintptr_t 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)); buf[sizeof(buf) - 1] = 0; while ((hash = strchr(buf, '#'))) { *hash = '0' + (char)(a1 % 10); a1 /= 10; } return open(buf, a2, 0); } } static void test(); void loop() { int iter; for (iter = 0;; iter++) { int pid = fork(); if (pid < 0) fail("loop fork failed"); if (pid == 0) { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); test(); doexit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { int res = waitpid(-1, &status, __WALL | WNOHANG); if (res == pid) break; usleep(1000); if (current_time_ms() - start > 5 * 1000) { kill(-pid, SIGKILL); kill(pid, SIGKILL); while (waitpid(-1, &status, __WALL) != pid) { } break; } } } } long r[3]; void test() { memset(r, -1, sizeof(r)); syscall(__NR_mmap, 0x20000000, 0xfff000, 3, 0x32, -1, 0); r[0] = syscall(__NR_socket, 0x18, 1, 1); r[1] = syscall(__NR_socket, 2, 2, 0); r[2] = syscall(__NR_socket, 0x18, 1, 1); *(uint16_t*)0x20e92000 = 0x18; *(uint32_t*)0x20e92002 = 1; *(uint32_t*)0x20e92006 = 0; *(uint32_t*)0x20e9200a = r[1]; *(uint16_t*)0x20e9200e = 2; *(uint16_t*)0x20e92010 = htobe16(0x4e21); *(uint8_t*)0x20e92012 = 0xac; *(uint8_t*)0x20e92013 = 0x14; *(uint8_t*)0x20e92014 = 0; *(uint8_t*)0x20e92015 = 0xbb; *(uint8_t*)0x20e92016 = 0; *(uint8_t*)0x20e92017 = 0; *(uint8_t*)0x20e92018 = 0; *(uint8_t*)0x20e92019 = 0; *(uint8_t*)0x20e9201a = 0; *(uint8_t*)0x20e9201b = 0; *(uint8_t*)0x20e9201c = 0; *(uint8_t*)0x20e9201d = 0; *(uint32_t*)0x20e9201e = 2; *(uint32_t*)0x20e92022 = 0; *(uint32_t*)0x20e92026 = 4; *(uint32_t*)0x20e9202a = 0; syscall(__NR_connect, r[2], 0x20e92000, 0x2e); syscall(__NR_close, r[1]); memcpy((void*)0x209aafee, "/dev/snd/midiC#D#", 18); syz_open_dev(0x209aafee, 1, 0x400); *(uint64_t*)0x20a7cf88 = 8; *(uint16_t*)0x20a7cf90 = 2; *(uint16_t*)0x20a7cf92 = htobe16(0x4e23); *(uint8_t*)0x20a7cf94 = 0xac; *(uint8_t*)0x20a7cf95 = 0x14; *(uint8_t*)0x20a7cf96 = 0; *(uint8_t*)0x20a7cf97 = 0xaa; *(uint8_t*)0x20a7cf98 = 0; *(uint8_t*)0x20a7cf99 = 0; *(uint8_t*)0x20a7cf9a = 0; *(uint8_t*)0x20a7cf9b = 0; *(uint8_t*)0x20a7cf9c = 0; *(uint8_t*)0x20a7cf9d = 0; *(uint8_t*)0x20a7cf9e = 0; *(uint8_t*)0x20a7cf9f = 0; *(uint16_t*)0x20a7cfa0 = 2; *(uint16_t*)0x20a7cfa2 = htobe16(0x4e22); *(uint32_t*)0x20a7cfa4 = htobe32(0xe0000002); *(uint8_t*)0x20a7cfa8 = 0; *(uint8_t*)0x20a7cfa9 = 0; *(uint8_t*)0x20a7cfaa = 0; *(uint8_t*)0x20a7cfab = 0; *(uint8_t*)0x20a7cfac = 0; *(uint8_t*)0x20a7cfad = 0; *(uint8_t*)0x20a7cfae = 0; *(uint8_t*)0x20a7cfaf = 0; *(uint16_t*)0x20a7cfb0 = 2; *(uint16_t*)0x20a7cfb2 = htobe16(0x4e21); *(uint32_t*)0x20a7cfb4 = htobe32(-1); *(uint8_t*)0x20a7cfb8 = 0; *(uint8_t*)0x20a7cfb9 = 0; *(uint8_t*)0x20a7cfba = 0; *(uint8_t*)0x20a7cfbb = 0; *(uint8_t*)0x20a7cfbc = 0; *(uint8_t*)0x20a7cfbd = 0; *(uint8_t*)0x20a7cfbe = 0; *(uint8_t*)0x20a7cfbf = 0; *(uint16_t*)0x20a7cfc0 = 0; *(uint16_t*)0x20a7cfc2 = 7; *(uint64_t*)0x20a7cfc8 = 5; *(uint64_t*)0x20a7cfd0 = 0x60aafa7f; *(uint16_t*)0x20a7cfd8 = 0xdaca; *(uint64_t*)0x20a7cfe0 = 0x20000000; *(uint64_t*)0x20a7cfe8 = 3; *(uint64_t*)0x20a7cff0 = 0x1ff; *(uint16_t*)0x20a7cff8 = 0; syscall(__NR_ioctl, r[1], 0x890b, 0x20a7cf88); *(uint16_t*)0x208adfd2 = 0x18; *(uint32_t*)0x208adfd4 = 1; *(uint32_t*)0x208adfd8 = 0; *(uint32_t*)0x208adfdc = r[1]; *(uint16_t*)0x208adfe0 = 2; *(uint16_t*)0x208adfe2 = htobe16(0x4e22); *(uint32_t*)0x208adfe4 = htobe32(2); *(uint8_t*)0x208adfe8 = 0; *(uint8_t*)0x208adfe9 = 0; *(uint8_t*)0x208adfea = 0; *(uint8_t*)0x208adfeb = 0; *(uint8_t*)0x208adfec = 0; *(uint8_t*)0x208adfed = 0; *(uint8_t*)0x208adfee = 0; *(uint8_t*)0x208adfef = 0; *(uint32_t*)0x208adff0 = 2; *(uint32_t*)0x208adff4 = 0; *(uint32_t*)0x208adff8 = 4; *(uint32_t*)0x208adffc = 1; syscall(__NR_connect, r[0], 0x208adfd2, 0x2e); } int main() { for (;;) { loop(); } }