// https://syzkaller.appspot.com/bug?id=286166aa4744abfe4a5d2b5f6eb4796575004992 // 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 unsigned long long procid; 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; } static long syz_genetlink_get_family_id(long name) { char buf[512] = {0}; struct nlmsghdr* hdr = (struct nlmsghdr*)buf; struct genlmsghdr* genlhdr = (struct genlmsghdr*)NLMSG_DATA(hdr); struct nlattr* attr = (struct nlattr*)(genlhdr + 1); hdr->nlmsg_len = sizeof(*hdr) + sizeof(*genlhdr) + sizeof(*attr) + GENL_NAMSIZ; hdr->nlmsg_type = GENL_ID_CTRL; hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; genlhdr->cmd = CTRL_CMD_GETFAMILY; attr->nla_type = CTRL_ATTR_FAMILY_NAME; attr->nla_len = sizeof(*attr) + GENL_NAMSIZ; strncpy((char*)(attr + 1), (char*)name, GENL_NAMSIZ); struct iovec iov = {hdr, hdr->nlmsg_len}; struct sockaddr_nl addr = {0}; addr.nl_family = AF_NETLINK; int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); if (fd == -1) { return -1; } struct msghdr msg = {&addr, sizeof(addr), &iov, 1, NULL, 0, 0}; if (sendmsg(fd, &msg, 0) == -1) { close(fd); return -1; } ssize_t n = recv(fd, buf, sizeof(buf), 0); close(fd); if (n <= 0) { return -1; } if (hdr->nlmsg_type != GENL_ID_CTRL) { return -1; } for (; (char*)attr < buf + n; attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) { if (attr->nla_type == CTRL_ATTR_FAMILY_ID) return *(uint16_t*)(attr + 1); } return -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[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { long res = 0; syscall(__NR_ioctl, -1, 0x400454d4, 0); res = syscall(__NR_socket, 2, 2, 0); if (res != -1) r[0] = res; memcpy((void*)0x20000900, "\x6d\x61\x6e\x67\x6c\x65\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x9b\x97\x9c\xd5\x03\x05\x12\xa0\x00\x00\x00\x00\x00\x00\x1f\x00" "\x00\x00\x06\x00\x00\x00\xf8\xe3\xff\xff\xff\xff\xff\xff\xf7\x00\x00" "\x00\xb0\x02\x00\x00\x70\x03\x00\x00\x00\x00\x00\x00\x90\x05\x00\x00" "\x90\x05\x00\x00\x90\x05\x00\x00\x90\x05\x00\x00\x90\x05\x00\x00\x06" "\x00\x08\x00", 88); *(uint64_t*)0x20000958 = 0; syscall(__NR_setsockopt, r[0], 0, 0x40, 0x20000900, 3); syscall(__NR_socketpair, 1, 0, 0, 0x20000240); syscall(__NR_openat, 0xffffffffffffff9c, 0, 0x100, 0); memcpy((void*)0x20000100, "/dev/net/tun\x00", 13); syscall(__NR_openat, 0xffffffffffffff9c, 0x20000100, 0, 0); syscall(__NR_clone, 0x8860000, 0, 0, 0, 0); syscall(__NR_socket, 0x10, 3, 0); res = syscall(__NR_accept4, -1, 0, 0, 0); if (res != -1) r[1] = res; memcpy((void*)0x20000400, "IPVS\x00", 5); syz_genetlink_get_family_id(0x20000400); syscall(__NR_write, r[1], 0, 0); *(uint8_t*)0x20000680 = 0; *(uint8_t*)0x20000681 = 0xfb; *(uint8_t*)0x20000682 = 0x15; *(uint8_t*)0x20000683 = 0; *(uint8_t*)0x20000684 = 0xa; memcpy((void*)0x20000685, "\xb0\x53\x24\x50\xd9\xc8\x64\x8c\x27\x91\x1f\x4d\x32\x76\x0a\xd5", 16); syscall(__NR_lsetxattr, 0, 0, 0x20000680, 0x15, 0); syscall(__NR_openat, 0xffffffffffffff9c, 0, 0, 0); syscall(__NR_clone, 0x2102001ffc, 0, 0x9999999999999999, 0x20000640, -1); syscall(__NR_ioctl, -1, 0xc018620b, 0); } int main(void) { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); for (procid = 0; procid < 6; procid++) { if (fork() == 0) { loop(); } } sleep(1000000); return 0; }