// 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_procfs(uintptr_t a0, uintptr_t a1) { char buf[128]; memset(buf, 0, sizeof(buf)); if (a0 == 0) { snprintf(buf, sizeof(buf), "/proc/self/%s", (char*)a1); } else if (a0 == (uintptr_t)-1) { snprintf(buf, sizeof(buf), "/proc/thread-self/%s", (char*)a1); } else { snprintf(buf, sizeof(buf), "/proc/self/task/%d/%s", (int)a0, (char*)a1); } int fd = open(buf, O_RDWR); if (fd == -1) fd = open(buf, O_RDONLY); return fd; } 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[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_one() { long res = 0; memcpy((void*)0x20000040, "\x6e\x65\x74\x2f\x64\x65\x76\x5f\x6d\x63\x61\x73\x74\x00\xc0\x87\xea" "\x55\x01\x1e\x14\xc9\xe3\x47\xdd\x1f\x55\xa6\x02\x6a\x1c\xb7\xe0\x67" "\xf3\xc5\x77\x98\x1c\x09\x94\xa1\xe8\x0d\x90\xd4\x9d\x68\xbd\xbc\x91" "\xfa\xb9\xc1\xc7\xf0\x63\xe6\x76\xe8\x3c\x74\x0e\x2d\x64\x75\x34\xa1" "\x04\x58\x50\xa2\x36\x65\xd8\x1c\xa0\x72\x70\x19\x3f\x5d\x00\x3c\x10" "\xe3\x42\x39\x84\x4c\x5b\x6e\x8d\x17\x21\xc0\xb5\x3a\x91\xc2\xf6\xec" "\x1e\x54\x84\x64\x5d\xb3\xdf", 109); res = syz_open_procfs(0, 0x20000040); if (res != -1) r[0] = res; memcpy((void*)0x20865ff5, "clear_refs", 11); res = syz_open_procfs(0, 0x20865ff5); if (res != -1) r[1] = res; syscall(__NR_mmap, 0x20000000, 0x8e3000, 3, 0x10, -1, 0); *(uint64_t*)0x2058f000 = 0xf; 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_sendfile, r[1], r[0], 0x2058f000, 0x100000000); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); for (;;) { loop(); } }