// https://syzkaller.appspot.com/bug?id=fb750a9bd66a7111b69a9f7518dc93600ae60006 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } #define BITMASK_LEN(type, bf_len) (type)((1ull << (bf_len)) - 1) #define BITMASK_LEN_OFF(type, bf_off, bf_len) \ (type)(BITMASK_LEN(type, (bf_len)) << (bf_off)) #define STORE_BY_BITMASK(type, addr, val, bf_off, bf_len) \ if ((bf_off) == 0 && (bf_len) == 0) { \ *(type*)(addr) = (type)(val); \ } else { \ type new_val = *(type*)(addr); \ new_val &= ~BITMASK_LEN_OFF(type, (bf_off), (bf_len)); \ new_val |= ((type)(val)&BITMASK_LEN(type, (bf_len))) << (bf_off); \ *(type*)(addr) = new_val; \ } static void vsnprintf_check(char* str, size_t size, const char* format, va_list args) { int rv; rv = vsnprintf(str, size, format, args); if (rv < 0) exit(1); if ((size_t)rv >= size) exit(1); } #define COMMAND_MAX_LEN 128 #define PATH_PREFIX \ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin " #define PATH_PREFIX_LEN (sizeof(PATH_PREFIX) - 1) static void execute_command(bool panic, const char* format, ...) { va_list args; char command[PATH_PREFIX_LEN + COMMAND_MAX_LEN]; int rv; va_start(args, format); memcpy(command, PATH_PREFIX, PATH_PREFIX_LEN); vsnprintf_check(command + PATH_PREFIX_LEN, COMMAND_MAX_LEN, format, args); va_end(args); rv = system(command); if (rv) { if (panic) exit(1); } } #define DEV_IPV4 "172.20.20.%d" #define DEV_IPV6 "fe80::%02hx" #define DEV_MAC "aa:aa:aa:aa:aa:%02hx" static void snprintf_check(char* str, size_t size, const char* format, ...) { va_list args; va_start(args, format); vsnprintf_check(str, size, format, args); va_end(args); } static void initialize_netdevices(void) { unsigned i; const char* devtypes[] = {"ip6gretap", "bridge", "vcan", "bond", "team"}; const char* devnames[] = {"lo", "sit0", "bridge0", "vcan0", "tunl0", "gre0", "gretap0", "ip_vti0", "ip6_vti0", "ip6tnl0", "ip6gre0", "ip6gretap0", "erspan0", "bond0", "veth0", "veth1", "team0", "veth0_to_bridge", "veth1_to_bridge", "veth0_to_bond", "veth1_to_bond", "veth0_to_team", "veth1_to_team"}; const char* devmasters[] = {"bridge", "bond", "team"}; for (i = 0; i < sizeof(devtypes) / (sizeof(devtypes[0])); i++) execute_command(0, "ip link add dev %s0 type %s", devtypes[i], devtypes[i]); execute_command(0, "ip link add type veth"); for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) { execute_command( 0, "ip link add name %s_slave_0 type veth peer name veth0_to_%s", devmasters[i], devmasters[i]); execute_command( 0, "ip link add name %s_slave_1 type veth peer name veth1_to_%s", devmasters[i], devmasters[i]); execute_command(0, "ip link set %s_slave_0 master %s0", devmasters[i], devmasters[i]); execute_command(0, "ip link set %s_slave_1 master %s0", devmasters[i], devmasters[i]); execute_command(0, "ip link set veth0_to_%s up", devmasters[i]); execute_command(0, "ip link set veth1_to_%s up", devmasters[i]); } execute_command(0, "ip link set bridge_slave_0 up"); execute_command(0, "ip link set bridge_slave_1 up"); for (i = 0; i < sizeof(devnames) / (sizeof(devnames[0])); i++) { char addr[32]; snprintf_check(addr, sizeof(addr), DEV_IPV4, i + 10); execute_command(0, "ip -4 addr add %s/24 dev %s", addr, devnames[i]); snprintf_check(addr, sizeof(addr), DEV_IPV6, i + 10); execute_command(0, "ip -6 addr add %s/120 dev %s", addr, devnames[i]); snprintf_check(addr, sizeof(addr), DEV_MAC, i + 10); execute_command(0, "ip link set dev %s address %s", devnames[i], addr); execute_command(0, "ip link set dev %s up", devnames[i]); } } static long syz_open_procfs(long a0, long a1) { char buf[128]; memset(buf, 0, sizeof(buf)); if (a0 == 0) { snprintf(buf, sizeof(buf), "/proc/self/%s", (char*)a1); } else if (a0 == -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 void setup_common() { if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) { } } static void loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); setsid(); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 160 << 20; setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 136 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); if (unshare(CLONE_NEWNS)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(0x02000000)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } } int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, __WALL) != pid) { } return WEXITSTATUS(status); } static int do_sandbox_none(void) { if (unshare(CLONE_NEWPID)) { } int pid = fork(); if (pid != 0) return wait_for_loop(pid); setup_common(); sandbox_common(); if (unshare(CLONE_NEWNET)) { } initialize_netdevices(); loop(); exit(1); } static void kill_and_wait(int pid, int* status) { kill(-pid, SIGKILL); kill(pid, SIGKILL); int i; for (i = 0; i < 100; i++) { if (waitpid(-1, status, WNOHANG | __WALL) == pid) return; usleep(1000); } DIR* dir = opendir("/sys/fs/fuse/connections"); if (dir) { for (;;) { struct dirent* ent = readdir(dir); if (!ent) break; if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) continue; char abort[300]; snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort", ent->d_name); int fd = open(abort, O_WRONLY); if (fd == -1) { continue; } if (write(fd, abort, 1) < 0) { } close(fd); } closedir(dir); } else { } while (waitpid(-1, status, __WALL) != pid) { } } #define SYZ_HAVE_SETUP_TEST 1 static void setup_test() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); } #define SYZ_HAVE_RESET_TEST 1 static void reset_test() { int fd; for (fd = 3; fd < 30; fd++) close(fd); } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { int iter; for (iter = 0;; iter++) { int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { setup_test(); execute_one(); reset_test(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } } } uint64_t r[5] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { long res = 0; memcpy((void*)0x20000040, "/dev/infiniband/rdma_cm", 24); res = syscall(__NR_openat, 0xffffffffffffff9c, 0x20000040, 2, 0); if (res != -1) r[0] = res; *(uint32_t*)0x200000c0 = 0; *(uint16_t*)0x200000c4 = 0x18; *(uint16_t*)0x200000c6 = 0xfa00; *(uint64_t*)0x200000c8 = 0; *(uint64_t*)0x200000d0 = 0x20000080; *(uint16_t*)0x200000d8 = 0x111; *(uint8_t*)0x200000da = 0; *(uint8_t*)0x200000db = 0; *(uint8_t*)0x200000dc = 0; *(uint8_t*)0x200000dd = 0; *(uint8_t*)0x200000de = 0; *(uint8_t*)0x200000df = 0; res = syscall(__NR_write, r[0], 0x200000c0, 0x20); if (res != -1) r[1] = *(uint32_t*)0x20000080; *(uint32_t*)0x20000180 = 0xe; *(uint16_t*)0x20000184 = 0x18; *(uint16_t*)0x20000186 = 0xfa00; *(uint64_t*)0x20000188 = 0x20000000; *(uint32_t*)0x20000000 = 0; *(uint32_t*)0x20000190 = r[1]; *(uint32_t*)0x20000194 = 0; *(uint32_t*)0x20000198 = 2; *(uint32_t*)0x2000019c = 4; syscall(__NR_write, r[0], 0x20000180, 0x20); *(uint32_t*)0x20000100 = 3; *(uint16_t*)0x20000104 = 0x40; *(uint16_t*)0x20000106 = 0xfa00; *(uint16_t*)0x20000108 = 0; *(uint16_t*)0x2000010a = htobe16(0); *(uint32_t*)0x2000010c = 0; *(uint8_t*)0x20000110 = 0xfe; *(uint8_t*)0x20000111 = 0x80; *(uint8_t*)0x20000112 = 0; *(uint8_t*)0x20000113 = 0; *(uint8_t*)0x20000114 = 0; *(uint8_t*)0x20000115 = 0; *(uint8_t*)0x20000116 = 0; *(uint8_t*)0x20000117 = 0; *(uint8_t*)0x20000118 = 0; *(uint8_t*)0x20000119 = 0; *(uint8_t*)0x2000011a = 0; *(uint8_t*)0x2000011b = 0; *(uint8_t*)0x2000011c = 0; *(uint8_t*)0x2000011d = 0; *(uint8_t*)0x2000011e = 0; *(uint8_t*)0x2000011f = 0xbb; *(uint32_t*)0x20000120 = 0; *(uint16_t*)0x20000124 = 0xa; *(uint16_t*)0x20000126 = htobe16(0); *(uint32_t*)0x20000128 = 0; *(uint8_t*)0x2000012c = 0; *(uint8_t*)0x2000012d = 0; *(uint8_t*)0x2000012e = 0; *(uint8_t*)0x2000012f = 0; *(uint8_t*)0x20000130 = 0; *(uint8_t*)0x20000131 = 0; *(uint8_t*)0x20000132 = 0; *(uint8_t*)0x20000133 = 0; *(uint8_t*)0x20000134 = 0; *(uint8_t*)0x20000135 = 0; *(uint8_t*)0x20000136 = 0; *(uint8_t*)0x20000137 = 0; *(uint8_t*)0x20000138 = 0xc0; *(uint8_t*)0x20000139 = 0; *(uint8_t*)0x2000013a = 0; *(uint8_t*)0x2000013b = 0; *(uint32_t*)0x2000013c = 0; *(uint32_t*)0x20000140 = r[1]; *(uint32_t*)0x20000144 = 0; syscall(__NR_write, r[0], 0x20000100, 0x48); *(uint32_t*)0x20000040 = 1; *(uint32_t*)0x20000044 = 0x70; *(uint8_t*)0x20000048 = 0; *(uint8_t*)0x20000049 = 0; *(uint8_t*)0x2000004a = 0; *(uint8_t*)0x2000004b = 0; *(uint32_t*)0x2000004c = 0; *(uint64_t*)0x20000050 = 0x50d; *(uint64_t*)0x20000058 = 0; *(uint64_t*)0x20000060 = 0; STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 0, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 1, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 2, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 3, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 4, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 5, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 6, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 7, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 8, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 9, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 10, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 11, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 12, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 13, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 14, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 15, 2); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 17, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 18, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 19, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 20, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 21, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 22, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 23, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 24, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 25, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 26, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 27, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 28, 1); STORE_BY_BITMASK(uint64_t, 0x20000068, 0, 29, 35); *(uint32_t*)0x20000070 = 0; *(uint32_t*)0x20000074 = 0; *(uint64_t*)0x20000078 = 0x20000000; *(uint64_t*)0x20000080 = 0; *(uint64_t*)0x20000088 = 0; *(uint64_t*)0x20000090 = 0; *(uint32_t*)0x20000098 = 0; *(uint32_t*)0x2000009c = 0; *(uint64_t*)0x200000a0 = 0; *(uint32_t*)0x200000a8 = 0; *(uint16_t*)0x200000ac = 0; *(uint16_t*)0x200000ae = 0; syscall(__NR_perf_event_open, 0x20000040, 0, 0, -1, 0); *(uint32_t*)0x20000400 = 0; syscall(__NR_setsockopt, -1, 0x10e, 1, 0x20000400, 4); memcpy((void*)0x20000140, "oom_score_adj", 14); res = syz_open_procfs(0, 0x20000140); if (res != -1) r[2] = res; *(uint64_t*)0x20000240 = 0x5d; syscall(__NR_sendfile, r[2], -1, 0x20000240, 0x239ffffffffffff); *(uint64_t*)0x20000140 = 0x40000000000009; syscall(__NR_sched_setaffinity, 0, 8, 0x20000140); *(uint32_t*)0x20000400 = 0; syscall(__NR_setsockopt, -1, 0x10e, 1, 0x20000400, 4); memcpy((void*)0x20000140, "oom_score_adj", 14); res = syz_open_procfs(0, 0x20000140); if (res != -1) r[3] = res; *(uint64_t*)0x20000240 = 0x5d; syscall(__NR_sendfile, r[3], -1, 0x20000240, 0x239ffffffffffff); res = syscall(__NR_socket, 0x10, 2, 0); if (res != -1) r[4] = res; *(uint64_t*)0x20000100 = 0x20000080; *(uint16_t*)0x20000080 = 0x10; *(uint16_t*)0x20000082 = 0x7003; *(uint32_t*)0x20000084 = 0; *(uint32_t*)0x20000088 = 0; *(uint32_t*)0x20000108 = 0x80; *(uint64_t*)0x20000110 = 0x20000200; *(uint64_t*)0x20000200 = 0x20000240; memcpy((void*)0x20000240, "\x55\x00\x00\x00\x18\x00\x7f\x5e\x00\xfe\x01\xb2\xa4\xa2\x80\x93\x0a" "\x60\x08\x00\xff\xa8\x43\x02\x91\x00\x00\x00\x2d\x00\x09\x00\x23\x00" "\x0c\x00\x0b\x00\x00\x00\x0d\x00\x05\x00\xfe\x80\x00\x00\x00\x00\xc7" "\x8b\x80\x08\x23\x14\xe9\x03\x0b\x9d\x56\x68\x85\xb1\x67\x32\x0b\x00" "\xdc\x13\x38\xd5\x44\x00\x00\x9b\x84\x13\x6e\xf7\x5a\xfb\x83\xde\x44", 85); *(uint64_t*)0x20000208 = 0x55; *(uint64_t*)0x20000118 = 1; *(uint64_t*)0x20000120 = 0x20000080; *(uint64_t*)0x20000128 = 0; *(uint32_t*)0x20000130 = 0; syscall(__NR_sendmsg, r[4], 0x20000100, 0); } int main(void) { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); do_sandbox_none(); return 0; }