// https://syzkaller.appspot.com/bug?id=401730da81cc65b97da6fa48aa9c0d392463f1b5 // 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 #include __attribute__((noreturn)) static void doexit(int status) { volatile unsigned i; syscall(__NR_exit_group, status); for (i = 0;; i++) { } } #include #include #include #include #include const int kFailStatus = 67; const int kRetryStatus = 69; static void exitf(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(kRetryStatus); } 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 int inject_fault(int nth) { int fd; char buf[16]; fd = open("/proc/thread-self/fail-nth", O_RDWR); if (fd == -1) exitf("failed to open /proc/thread-self/fail-nth"); sprintf(buf, "%d", nth + 1); if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) exitf("failed to write /proc/thread-self/fail-nth"); return fd; } struct thread_t { int created, running, call; pthread_t th; }; 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 (;;) { while (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &th->running, FUTEX_WAIT, 0, 0); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); __atomic_store_n(&th->running, 0, __ATOMIC_RELEASE); syscall(SYS_futex, &th->running, FUTEX_WAKE); } return 0; } static void execute(int num_calls) { int call, thread; running = 0; for (call = 0; call < num_calls; call++) { for (thread = 0; thread < sizeof(threads) / sizeof(threads[0]); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); pthread_create(&th->th, &attr, thr, th); } if (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) { th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); __atomic_store_n(&th->running, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &th->running, FUTEX_WAKE); struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = 20 * 1000 * 1000; syscall(SYS_futex, &th->running, FUTEX_WAIT, 1, &ts); if (running) usleep((call == num_calls - 1) ? 10000 : 1000); break; } } } } uint64_t r[1] = {0xffffffffffffffff}; void execute_call(int call) { long res; switch (call) { case 0: res = syscall(__NR_socket, 0x1e, 2, 0); if (res != -1) r[0] = res; break; case 1: *(uint16_t*)0x20d80f80 = 0x1e; memcpy((void*)0x20d80f82, "\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x09\xa9\x79\xf3\x21\xb3\x0c\x7b\xc8\x79\x04\x05\xc7\xba\xd6\x2e" "\x0a\x43\xa6\x32\xed\x49\x38\xd3\x6d\x73\xfb\x8f\x84\x01\xa3\xff" "\x59\x82\x9a\x2b\x0a\xfe\x7c\xe4\x3a\x4b\x24\x70\xa0\xc5\x21\x66" "\x69\xca\x02\x1f\x6f\x65\xdc\xf1\x60\xe7\xe5\x8f\x35\x8c\x00\x02" "\xf0\x00\x01\x58\xd1\x9b\xcb\x31\xf1\x31\x4a\x8e\xf1\x51\x62\x2c" "\xa5\xbd\xb9\xc8\xea\xd2\x00\x00\x77\xae\xb8\x1c\x90\x00\x1d\x6d" "\x7c\x98\x0e\xe5\x90\xc8\xb9\xf7\x0d\xc1\x36\xcb\x18\x4a", 126); syscall(__NR_bind, r[0], 0x20d80f80, 0x80); break; case 2: *(uint16_t*)0x20afb000 = 0x1e; memcpy((void*)0x20afb002, "\x01\x03\x00\x00\x00\x00\x00\xb9\x00\x00\x00\x00\x47\x00\x00\x00" "\x00\xa9\x79\xf3\x21\xb3\x0c\x7b\xc8\x79\x04\x05\xc7\xba\xd6\x2e" "\x0a\x63\xa6\x32\xed\x49\x38\xd3\x6d\x73\xfb\x8f\x84\x01\xa3\xff" "\x59\x82\x9a\x2b\x0a\xfe\x7c\xe4\x3a\x4b\x24\x70\xa0\xc5\x21\x66" "\x69\xca\x02\x1f\x6f\x65\xdc\xf1\x60\xe7\xe5\x8f\x35\x8c\x00\x02" "\xf0\x00\x01\x58\xd1\x9b\xcb\x31\x51\xd2\x4a\xce\xf1\xf1\x62\x2c" "\xa5\xbd\xb9\xc8\xea\x31\x00\x00\x77\xae\xb8\x1c\x90\x00\x1d\x6d" "\x7c\x98\x04\x00\x00\x00\x00\xf7\x0d\xc1\x36\xcb\x18\x4a", 126); write_file("/sys/kernel/debug/failslab/ignore-gfp-wait", "N"); write_file("/sys/kernel/debug/fail_futex/ignore-private", "N"); inject_fault(0); syscall(__NR_bind, r[0], 0x20afb000, 0x80); break; } } void loop() { execute(3); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); loop(); return 0; }