// https://syzkaller.appspot.com/bug?id=3fbc166c1cf69c513a9e388cd2cf5c6ff6aae21d // 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; } static void execute_one(); extern unsigned long long procid; void loop() { while (1) { execute_one(); } } 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 int collide; 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); if (collide && call % 2) break; 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; } } } } #ifndef __NR_bpf #define __NR_bpf 321 #endif void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000080, "./file0", 8); syscall(__NR_mkdir, 0x20000080, 0xfffffffffffffffd); break; case 1: memcpy((void*)0x20000000, "./file0", 8); memcpy((void*)0x20000280, "./file0", 8); memcpy((void*)0x20000040, "proc", 5); syscall(__NR_mount, 0x20000000, 0x20000280, 0x20000040, 0, 0x20000740); break; case 2: memcpy((void*)0x20000300, "./file0", 8); memcpy((void*)0x20000140, "./file0/bus", 12); memcpy((void*)0x20000180, "\x72\x70\x63\x5f\x70\x69\x70\x65\x66\x73\x00\x8c\x7c\x64\x7f\x03" "\x99\x28\x7d\x03\xb7\x4f\x09\xf3\xeb\xb5\x03\x00\x00\x00\x9d\xf9" "\xa5\x9c\x06\x00\x00\x00\x00\x00\x00\xf9\x0e\xf0\x78\x34\xc1\xc4", 48); write_file("/sys/kernel/debug/failslab/ignore-gfp-wait", "N"); write_file("/sys/kernel/debug/fail_futex/ignore-private", "N"); inject_fault(37); syscall(__NR_mount, 0x20000300, 0x20000140, 0x20000180, 0, 0x20000880); break; case 3: *(uint64_t*)0x20000100 = 0x200000c0; memcpy((void*)0x200000c0, "./file0", 8); *(uint32_t*)0x20000108 = 0; *(uint32_t*)0x2000010c = 0; syscall(__NR_bpf, 7, 0x20000100, 0x10); break; } } void execute_one() { execute(4); collide = 1; execute(4); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); for (;;) { loop(); } }