// 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 #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 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 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(); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; unsigned long long procid; void execute_one() { long res = 0; memcpy((void*)0x20000000, "/dev/vcs#", 10); res = syz_open_dev(0x20000000, 0x7f, 0x40000); if (res != -1) r[0] = res; *(uint64_t*)0x20000040 = 0x200001c0; *(uint64_t*)0x20000048 = 0; syscall(__NR_pwritev, r[0], 0x20000040, 1, 0); syscall(__NR_setsockopt, r[0], 0x21, 0xcc, 0x20000140, 0); memcpy((void*)0x20000100, "./cgroup.net", 13); res = syscall(__NR_openat, 0xffffffffffffff9c, 0x20000100, 0x200002, 0); if (res != -1) r[1] = res; syscall(__NR_fchdir, r[1]); memcpy((void*)0x20000000, "./file0", 8); syscall(__NR_mknod, 0x20000000, 0, 0); syscall(__NR_fcntl, r[1], 4, 0x800); memcpy((void*)0x207ddff8, "./file0", 8); res = syscall(__NR_open, 0x207ddff8, 0, 0); if (res != -1) r[2] = res; syscall(__NR_ioctl, r[2], 0xc0189436, 0x20000fff); memcpy((void*)0x20000080, "./file0", 8); res = syscall(__NR_creat, 0x20000080, 0); if (res != -1) r[3] = res; 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_fallocate, r[3], 1, 0, 0x40000004); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); for (procid = 0; procid < 8; procid++) { if (fork() == 0) { for (;;) { loop(); } } } sleep(1000000); return 0; }