// https://syzkaller.appspot.com/bug?id=bf172344c5f1d3487a4feff67c3dd30e08d5b635 // 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 static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; int skip = __atomic_load_n(&skip_segv, __ATOMIC_RELAXED) != 0; int valid = addr < prog_start || addr > prog_end; if (skip && valid) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8); syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8); memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) \ { \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } #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 long syz_open_dev(volatile long a0, volatile long a1, volatile long 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) - 1); buf[sizeof(buf) - 1] = 0; while ((hash = strchr(buf, '#'))) { *hash = '0' + (char)(a1 % 10); a1 /= 10; } return open(buf, a2, 0); } } static long syz_genetlink_get_family_id(volatile 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; } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0x0}; 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); install_segv_handler(); use_temporary_dir(); intptr_t res = 0; syscall(__NR_socket, 0x200000000000011ul, 2ul, 0); syscall(__NR_dup, -1); NONFAILING(*(uint64_t*)0x20000840 = 0x20000240); NONFAILING(*(uint16_t*)0x20000240 = 2); NONFAILING(*(uint16_t*)0x20000242 = htobe16(0x4e20)); NONFAILING(*(uint8_t*)0x20000244 = 0xac); NONFAILING(*(uint8_t*)0x20000245 = 0x14); NONFAILING(*(uint8_t*)0x20000246 = 0x14); NONFAILING(*(uint8_t*)0x20000247 = 0xaa); NONFAILING(*(uint32_t*)0x20000848 = 0x10); NONFAILING(*(uint64_t*)0x20000850 = 0x20000740); NONFAILING(*(uint64_t*)0x20000740 = 0x200002c0); NONFAILING(memcpy((void*)0x200002c0, "\x37\x56\xac\xa4\xf6\x06\x1e\x7c", 8)); NONFAILING(*(uint64_t*)0x20000748 = 8); NONFAILING(*(uint64_t*)0x20000750 = 0); NONFAILING(*(uint64_t*)0x20000758 = 0); NONFAILING(*(uint64_t*)0x20000760 = 0x20000380); NONFAILING(memcpy((void*)0x20000380, "\x5c\x08\x6d\xc3\x81\x7a\x88\x05\xfb\x3d\xf7\xb3\xd6\x3d" "\x13\x72\xd6\x12\x59\x12\xcc\xfa\x4d\x22\x61\xd2\xf8\x6f" "\xa6\x6e\x55\x30\xd5\xd5\x1c\xf4\xb9\xb9\xef\xf6\x1d\x3e" "\x78\x90\x3a\x94\xf4\xa9\xb0\x6f\x77\x64\x40\xc1\x93\xef" "\x13\x5d\xe7\x3d\xb7\x11\x51\x44\x34\xc7\x3d\xe2", 68)); NONFAILING(*(uint64_t*)0x20000768 = 0x44); NONFAILING(*(uint64_t*)0x20000770 = 0); NONFAILING(*(uint64_t*)0x20000778 = 0); NONFAILING(*(uint64_t*)0x20000780 = 0); NONFAILING(*(uint64_t*)0x20000788 = 0); NONFAILING(*(uint64_t*)0x20000790 = 0x20000640); NONFAILING(*(uint64_t*)0x20000798 = 0); NONFAILING(*(uint64_t*)0x200007a0 = 0); NONFAILING(*(uint64_t*)0x200007a8 = 0); NONFAILING(*(uint64_t*)0x200007b0 = 0x200005c0); NONFAILING(memcpy((void*)0x200005c0, "\xab\xfb\x81\xa0\xb7\x06\x47\x11\xba" "\xfc\x2b\xc4\xa7\xa2\x02\x4f\xcd\x22" "\x08\xa9\x06\x31\xb4\xe6\xb4\x2e\x6a" "\x7a\x38\xdd\x28\x74\x9c\x4c\xcf\x29" "\x8f\x0d\x6f\x62\x95\x10\x9e", 43)); NONFAILING(*(uint64_t*)0x200007b8 = 0x2b); NONFAILING(*(uint64_t*)0x20000858 = 8); NONFAILING(*(uint64_t*)0x20000860 = 0x200007c0); NONFAILING(*(uint64_t*)0x200007c0 = 0x14); NONFAILING(*(uint32_t*)0x200007c8 = 0); NONFAILING(*(uint32_t*)0x200007cc = 1); NONFAILING(*(uint32_t*)0x200007d0 = 8); NONFAILING(*(uint64_t*)0x200007d8 = 0x11); NONFAILING(*(uint32_t*)0x200007e0 = 0); NONFAILING(*(uint32_t*)0x200007e4 = 1); NONFAILING(*(uint8_t*)0x200007e8 = 0x1f); NONFAILING(*(uint64_t*)0x200007f0 = 0x1c); NONFAILING(*(uint32_t*)0x200007f8 = 0); NONFAILING(*(uint32_t*)0x200007fc = 8); NONFAILING(*(uint32_t*)0x20000800 = 0); NONFAILING(*(uint8_t*)0x20000804 = 0xac); NONFAILING(*(uint8_t*)0x20000805 = 0x14); NONFAILING(*(uint8_t*)0x20000806 = 0x14); NONFAILING(*(uint8_t*)0x20000807 = 0xaa); NONFAILING(*(uint32_t*)0x20000808 = htobe32(0x7f000001)); NONFAILING(*(uint64_t*)0x20000868 = 0x50); NONFAILING(*(uint32_t*)0x20000870 = 0); syscall(__NR_sendmsg, -1, 0x20000840ul, 0x80ul); NONFAILING(memcpy((void*)0x20000040, "/dev/bus/usb/00#/00#\000", 21)); res = -1; NONFAILING(res = syz_open_dev(0x20000040, 0x4000000000000071, 0x28081)); if (res != -1) r[0] = res; res = syscall(__NR_socket, 0x10ul, 3ul, 0x10); if (res != -1) r[1] = res; res = -1; NONFAILING(res = syz_genetlink_get_family_id(0)); if (res != -1) r[2] = res; NONFAILING(*(uint64_t*)0x200001c0 = 0); NONFAILING(*(uint32_t*)0x200001c8 = 0); NONFAILING(*(uint64_t*)0x200001d0 = 0x20000140); NONFAILING(*(uint64_t*)0x20000140 = 0x20000000); NONFAILING(*(uint32_t*)0x20000000 = 0x1c); NONFAILING(*(uint16_t*)0x20000004 = r[2]); NONFAILING(*(uint16_t*)0x20000006 = 1); NONFAILING(*(uint32_t*)0x20000008 = 0); NONFAILING(*(uint32_t*)0x2000000c = 0); NONFAILING(*(uint8_t*)0x20000010 = 0x4c); NONFAILING(*(uint8_t*)0x20000011 = 0); NONFAILING(*(uint16_t*)0x20000012 = 0); NONFAILING(*(uint16_t*)0x20000014 = 8); NONFAILING(STORE_BY_BITMASK(uint16_t, , 0x20000016, 0x11d, 0, 14)); NONFAILING(STORE_BY_BITMASK(uint16_t, , 0x20000017, 0, 6, 1)); NONFAILING(STORE_BY_BITMASK(uint16_t, , 0x20000017, 1, 7, 1)); NONFAILING(*(uint16_t*)0x20000018 = 4); NONFAILING(*(uint16_t*)0x2000001a = 1); NONFAILING(*(uint64_t*)0x20000148 = 0x1c); NONFAILING(*(uint64_t*)0x200001d8 = 1); NONFAILING(*(uint64_t*)0x200001e0 = 0); NONFAILING(*(uint64_t*)0x200001e8 = 0); NONFAILING(*(uint32_t*)0x200001f0 = 0); syscall(__NR_sendmsg, r[1], 0x200001c0ul, 0ul); NONFAILING(*(uint32_t*)0x200000c0 = 0); NONFAILING(*(uint32_t*)0x200000c4 = 0x5516); NONFAILING(*(uint64_t*)0x200000c8 = 0); syscall(__NR_ioctl, r[0], 0xc0105512, 0x200000c0ul); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x20000000, 1, 0, 7)); NONFAILING(STORE_BY_BITMASK(uint8_t, , 0x20000000, 1, 7, 1)); syscall(__NR_ioctl, r[0], 0xc0105502, 0x20000000ul); return 0; }