// autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #define BITMASK(bf_off, bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type, htobe, addr, val, bf_off, bf_len) \ *(type*)(addr) = \ htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | \ (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) 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 void setup_sysctl() { char mypid[32]; snprintf(mypid, sizeof(mypid), "%d", getpid()); struct { const char* name; const char* data; } files[] = { {"/sys/kernel/debug/x86/nmi_longest_ns", "10000000000"}, {"/proc/sys/kernel/hung_task_check_interval_secs", "20"}, {"/proc/sys/net/core/bpf_jit_kallsyms", "1"}, {"/proc/sys/net/core/bpf_jit_harden", "0"}, {"/proc/sys/kernel/kptr_restrict", "0"}, {"/proc/sys/kernel/softlockup_all_cpu_backtrace", "1"}, {"/proc/sys/fs/mount-max", "100"}, {"/proc/sys/vm/oom_dump_tasks", "0"}, {"/proc/sys/debug/exception-trace", "0"}, {"/proc/sys/kernel/printk", "7 4 1 3"}, {"/proc/sys/net/ipv4/ping_group_range", "0 65535"}, {"/proc/sys/kernel/keys/gc_delay", "1"}, {"/proc/sys/vm/oom_kill_allocating_task", "1"}, {"/proc/sys/kernel/ctrl-alt-del", "0"}, {"/proc/sys/kernel/cad_pid", mypid}, }; for (size_t i = 0; i < sizeof(files) / sizeof(files[0]); i++) { if (!write_file(files[i].name, files[i].data)) printf("write to %s failed: %s\n", files[i].name, strerror(errno)); } } int main(void) { syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); setup_sysctl(); *(uint32_t*)0x20000200 = 0; *(uint32_t*)0x20000204 = 0x80; *(uint8_t*)0x20000208 = 0; *(uint8_t*)0x20000209 = 0; *(uint8_t*)0x2000020a = 0; *(uint8_t*)0x2000020b = 0; *(uint32_t*)0x2000020c = 0; *(uint64_t*)0x20000210 = 8; *(uint64_t*)0x20000218 = 0; *(uint64_t*)0x20000220 = 0; STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 0, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 1, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 2, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 3, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 4, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 1, 5, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 6, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 7, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 8, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 9, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 1, 10, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 11, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 12, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 13, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 14, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 15, 2); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 17, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 18, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 19, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 20, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 21, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 22, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 23, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 24, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 25, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 26, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 27, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 28, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 29, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 30, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 31, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 1, 32, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 1, 33, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 34, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 35, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 1, 36, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 1, 37, 1); STORE_BY_BITMASK(uint64_t, , 0x20000228, 0, 38, 26); *(uint32_t*)0x20000230 = 0; *(uint32_t*)0x20000234 = 0; *(uint64_t*)0x20000238 = 0; *(uint64_t*)0x20000240 = 0; *(uint64_t*)0x20000248 = 0; *(uint64_t*)0x20000250 = 0; *(uint32_t*)0x20000258 = 0; *(uint32_t*)0x2000025c = 0; *(uint64_t*)0x20000260 = 0; *(uint32_t*)0x20000268 = 0; *(uint16_t*)0x2000026c = 0; *(uint16_t*)0x2000026e = 0; *(uint32_t*)0x20000270 = 0; *(uint32_t*)0x20000274 = 0; *(uint64_t*)0x20000278 = 0xd62; syscall(__NR_perf_event_open, 0x20000200ul, 0, 0ul, -1, 3ul); return 0; }