// https://syzkaller.appspot.com/bug?id=126dddfb53abe3a4547711c138d313eb0c1ffad2 // 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 #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(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; } struct nlmsg { char* pos; int nesting; struct nlattr* nested[8]; char buf[4096]; }; static void netlink_init(struct nlmsg* nlmsg, int typ, int flags, const void* data, int size) { memset(nlmsg, 0, sizeof(*nlmsg)); struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf; hdr->nlmsg_type = typ; hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | flags; memcpy(hdr + 1, data, size); nlmsg->pos = (char*)(hdr + 1) + NLMSG_ALIGN(size); } static void netlink_attr(struct nlmsg* nlmsg, int typ, const void* data, int size) { struct nlattr* attr = (struct nlattr*)nlmsg->pos; attr->nla_len = sizeof(*attr) + size; attr->nla_type = typ; if (size > 0) memcpy(attr + 1, data, size); nlmsg->pos += NLMSG_ALIGN(attr->nla_len); } static int netlink_send_ext(struct nlmsg* nlmsg, int sock, uint16_t reply_type, int* reply_len, bool dofail) { if (nlmsg->pos > nlmsg->buf + sizeof(nlmsg->buf) || nlmsg->nesting) exit(1); struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf; hdr->nlmsg_len = nlmsg->pos - nlmsg->buf; struct sockaddr_nl addr; memset(&addr, 0, sizeof(addr)); addr.nl_family = AF_NETLINK; ssize_t n = sendto(sock, nlmsg->buf, hdr->nlmsg_len, 0, (struct sockaddr*)&addr, sizeof(addr)); if (n != (ssize_t)hdr->nlmsg_len) { if (dofail) exit(1); return -1; } n = recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0); if (reply_len) *reply_len = 0; if (n < 0) { if (dofail) exit(1); return -1; } if (n < (ssize_t)sizeof(struct nlmsghdr)) { errno = EINVAL; if (dofail) exit(1); return -1; } if (hdr->nlmsg_type == NLMSG_DONE) return 0; if (reply_len && hdr->nlmsg_type == reply_type) { *reply_len = n; return 0; } if (n < (ssize_t)(sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr))) { errno = EINVAL; if (dofail) exit(1); return -1; } if (hdr->nlmsg_type != NLMSG_ERROR) { errno = EINVAL; if (dofail) exit(1); return -1; } errno = -((struct nlmsgerr*)(hdr + 1))->error; return -errno; } static int netlink_query_family_id(struct nlmsg* nlmsg, int sock, const char* family_name, bool dofail) { struct genlmsghdr genlhdr; memset(&genlhdr, 0, sizeof(genlhdr)); genlhdr.cmd = CTRL_CMD_GETFAMILY; netlink_init(nlmsg, GENL_ID_CTRL, 0, &genlhdr, sizeof(genlhdr)); netlink_attr(nlmsg, CTRL_ATTR_FAMILY_NAME, family_name, strnlen(family_name, GENL_NAMSIZ - 1) + 1); int n = 0; int err = netlink_send_ext(nlmsg, sock, GENL_ID_CTRL, &n, dofail); if (err < 0) { return -1; } uint16_t id = 0; struct nlattr* attr = (struct nlattr*)(nlmsg->buf + NLMSG_HDRLEN + NLMSG_ALIGN(sizeof(genlhdr))); for (; (char*)attr < nlmsg->buf + n; attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) { if (attr->nla_type == CTRL_ATTR_FAMILY_ID) { id = *(uint16_t*)(attr + 1); break; } } if (!id) { errno = EINVAL; return -1; } recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0); return id; } static long syz_genetlink_get_family_id(volatile long name, volatile long sock_arg) { int fd = sock_arg; if (fd < 0) { fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); if (fd == -1) { return -1; } } struct nlmsg nlmsg_tmp; int ret = netlink_query_family_id(&nlmsg_tmp, fd, (char*)name, false); if ((int)sock_arg < 0) close(fd); if (ret < 0) { return -1; } return ret; } static void kill_and_wait(int pid, int* status) { kill(-pid, SIGKILL); kill(pid, SIGKILL); for (int 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) { } } static void setup_test() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); write_file("/proc/self/oom_score_adj", "1000"); } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { int iter = 0; for (;; iter++) { int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { setup_test(); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { sleep_ms(10); if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0x0}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // socket$alg arguments: [ // domain: const = 0x26 (8 bytes) // type: const = 0x5 (8 bytes) // proto: const = 0x0 (4 bytes) // ] // returns sock_alg res = syscall(__NR_socket, /*domain=*/0x26ul, /*type=*/5ul, /*proto=*/0); if (res != -1) r[0] = res; // bind$alg arguments: [ // fd: sock_alg (resource) // addr: ptr[in, sockaddr_alg] { // sockaddr_alg { // family: const = 0x26 (2 bytes) // type: buffer: {61 65 61 64 00 00 00 00 00 00 00 00 00 00} (length // 0xe) feat: af_alg_type = 0x0 (4 bytes) mask: af_alg_type = 0x0 (4 // bytes) name: buffer: {70 63 72 79 70 74 28 67 65 6e 65 72 69 63 2d // 67 63 6d 2d 61 65 73 6e 69 29 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00} (length 0x40) // } // } // addrlen: len = 0x58 (8 bytes) // ] *(uint16_t*)0x200000000040 = 0x26; memcpy((void*)0x200000000042, "aead\000\000\000\000\000\000\000\000\000\000", 14); *(uint32_t*)0x200000000050 = 0; *(uint32_t*)0x200000000054 = 0; memcpy((void*)0x200000000058, "pcrypt(generic-gcm-aesni)" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000", 64); syscall(__NR_bind, /*fd=*/r[0], /*addr=*/0x200000000040ul, /*addrlen=*/0x58ul); // socket$nl_generic arguments: [ // domain: const = 0x10 (8 bytes) // type: const = 0x3 (8 bytes) // proto: const = 0x10 (4 bytes) // ] // returns sock_nl_generic res = syscall(__NR_socket, /*domain=*/0x10ul, /*type=*/3ul, /*proto=*/0x10); if (res != -1) r[1] = res; // socket$nl_generic arguments: [ // domain: const = 0x10 (8 bytes) // type: const = 0x3 (8 bytes) // proto: const = 0x10 (4 bytes) // ] // returns sock_nl_generic res = syscall(__NR_socket, /*domain=*/0x10ul, /*type=*/3ul, /*proto=*/0x10); if (res != -1) r[2] = res; // syz_genetlink_get_family_id$tipc2 arguments: [ // name: ptr[in, buffer] { // buffer: {54 49 50 43 76 32 00} (length 0x7) // } // fd: sock_nl_generic (resource) // ] // returns genl_tipc2_family_id memcpy((void*)0x200000000100, "TIPCv2\000", 7); res = -1; res = syz_genetlink_get_family_id(/*name=*/0x200000000100, /*fd=*/-1); if (res != -1) r[3] = res; // sendmsg$TIPC_NL_BEARER_ENABLE arguments: [ // fd: sock_nl_generic (resource) // msg: ptr[in, msghdr_netlink[netlink_msg_t[genl_tipc2_family_id, // genlmsghdr_t[TIPC_NL_BEARER_ENABLE], tipc_nl_policy]]] { // msghdr_netlink[netlink_msg_t[genl_tipc2_family_id, // genlmsghdr_t[TIPC_NL_BEARER_ENABLE], tipc_nl_policy]] { // addr: nil // addrlen: len = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // vec: ptr[in, iovec[in, netlink_msg_t[genl_tipc2_family_id, // genlmsghdr_t[TIPC_NL_BEARER_ENABLE], tipc_nl_policy]]] { // iovec[in, netlink_msg_t[genl_tipc2_family_id, // genlmsghdr_t[TIPC_NL_BEARER_ENABLE], tipc_nl_policy]] { // addr: ptr[in, netlink_msg_t[genl_tipc2_family_id, // genlmsghdr_t[TIPC_NL_BEARER_ENABLE], tipc_nl_policy]] { // netlink_msg_t[genl_tipc2_family_id, // genlmsghdr_t[TIPC_NL_BEARER_ENABLE], tipc_nl_policy] { // len: len = 0x54 (4 bytes) // type: genl_tipc2_family_id (resource) // flags: netlink_msg_flags = 0x1 (2 bytes) // seq: int32 = 0x0 (4 bytes) // pid: int32 = 0x0 (4 bytes) // payload: genlmsghdr_t[TIPC_NL_BEARER_ENABLE] { // cmd: const = 0x3 (1 bytes) // version: const = 0x0 (1 bytes) // reserved: const = 0x0 (2 bytes) // } // attrs: array[tipc_nl_policy] { // union tipc_nl_policy { // TIPC_NLA_BEARER: nlattr_tt[const[TIPC_NLA_BEARER, // int16:14], 0, 1, array[tipc_nl_bearer_policy]] { // nla_len: offsetof = 0x40 (2 bytes) // nla_type: const = 0x1 (1 bytes) // NLA_F_NET_BYTEORDER: const = 0x0 (0 bytes) // NLA_F_NESTED: const = 0x1 (1 bytes) // payload: array[tipc_nl_bearer_policy] { // union tipc_nl_bearer_policy { // TIPC_NLA_BEARER_UDP_OPTS: // nlattr_t[const[TIPC_NLA_BEARER_UDP_OPTS, int16], // tipc_nl_udp_policy] { // nla_len: offsetof = 0x2c (2 bytes) // nla_type: const = 0x4 (2 bytes) // payload: tipc_nl_udp_policy { // TIPC_NLA_UDP_LOCAL: // nlattr_t[const[TIPC_NLA_UDP_LOCAL, int16], // sockaddr_tipc_udp] { // nla_len: offsetof = 0x14 (2 bytes) // nla_type: const = 0x1 (2 bytes) // payload: union sockaddr_tipc_udp { // in: sockaddr_in { // family: const = 0x2 (2 bytes) // port: int16be = 0x0 (2 bytes) // addr: union ipv4_addr { // loopback: const = 0x7f000001 (4 bytes) // } // pad = 0x0 (8 bytes) // } // } // size: buffer: {} (length 0x0) // } // TIPC_NLA_UDP_REMOTE: // nlattr_t[const[TIPC_NLA_UDP_REMOTE, int16], // sockaddr_tipc_udp] { // nla_len: offsetof = 0x14 (2 bytes) // nla_type: const = 0x2 (2 bytes) // payload: union sockaddr_tipc_udp { // in: sockaddr_in { // family: const = 0x2 (2 bytes) // port: int16be = 0x0 (2 bytes) // addr: union ipv4_addr { // multicast2: const = 0xe0000002 (4 // bytes) // } // pad = 0x0 (8 bytes) // } // } // size: buffer: {} (length 0x0) // } // } // size: buffer: {} (length 0x0) // } // } // union tipc_nl_bearer_policy { // TIPC_NLA_BEARER_NAME: // nlattr_t[const[TIPC_NLA_BEARER_NAME, int16], // tipc_bearer_name] { // nla_len: offsetof = 0xd (2 bytes) // nla_type: const = 0x1 (2 bytes) // payload: union tipc_bearer_name { // udp: buffer: {75 64 70 3a 73 79 7a 32 00} // (length 0x9) // } // size: buffer: {} (length 0x0) // } // } // } // size: buffer: {} (length 0x0) // } // } // } // } // } // len: len = 0x54 (8 bytes) // } // } // vlen: const = 0x1 (8 bytes) // ctrl: const = 0x0 (8 bytes) // ctrllen: const = 0x0 (8 bytes) // f: send_flags = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // } // } // f: send_flags = 0x0 (8 bytes) // ] *(uint64_t*)0x2000000001c0 = 0; *(uint32_t*)0x2000000001c8 = 0; *(uint64_t*)0x2000000001d0 = 0x200000000180; *(uint64_t*)0x200000000180 = 0x200000000080; *(uint32_t*)0x200000000080 = 0x54; *(uint16_t*)0x200000000084 = r[3]; *(uint16_t*)0x200000000086 = 1; *(uint32_t*)0x200000000088 = 0; *(uint32_t*)0x20000000008c = 0; *(uint8_t*)0x200000000090 = 3; *(uint8_t*)0x200000000091 = 0; *(uint16_t*)0x200000000092 = 0; *(uint16_t*)0x200000000094 = 0x40; STORE_BY_BITMASK(uint16_t, , 0x200000000096, 1, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x200000000097, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x200000000097, 1, 7, 1); *(uint16_t*)0x200000000098 = 0x2c; *(uint16_t*)0x20000000009a = 4; *(uint16_t*)0x20000000009c = 0x14; *(uint16_t*)0x20000000009e = 1; *(uint16_t*)0x2000000000a0 = 2; *(uint16_t*)0x2000000000a2 = htobe16(0); *(uint32_t*)0x2000000000a4 = htobe32(0x7f000001); *(uint16_t*)0x2000000000b0 = 0x14; *(uint16_t*)0x2000000000b2 = 2; *(uint16_t*)0x2000000000b4 = 2; *(uint16_t*)0x2000000000b6 = htobe16(0); *(uint32_t*)0x2000000000b8 = htobe32(0xe0000002); *(uint16_t*)0x2000000000c4 = 0xd; *(uint16_t*)0x2000000000c6 = 1; memcpy((void*)0x2000000000c8, "udp:syz2\000", 9); *(uint64_t*)0x200000000188 = 0x54; *(uint64_t*)0x2000000001d8 = 1; *(uint64_t*)0x2000000001e0 = 0; *(uint64_t*)0x2000000001e8 = 0; *(uint32_t*)0x2000000001f0 = 0; syscall(__NR_sendmsg, /*fd=*/r[2], /*msg=*/0x2000000001c0ul, /*f=*/0ul); // sendmsg$TIPC_NL_KEY_SET arguments: [ // fd: sock_nl_generic (resource) // msg: ptr[in, msghdr_netlink[netlink_msg_t[genl_tipc2_family_id, // genlmsghdr_t[TIPC_NL_KEY_SET], tipc_nl_policy]]] { // msghdr_netlink[netlink_msg_t[genl_tipc2_family_id, // genlmsghdr_t[TIPC_NL_KEY_SET], tipc_nl_policy]] { // addr: nil // addrlen: len = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // vec: ptr[in, iovec[in, netlink_msg_t[genl_tipc2_family_id, // genlmsghdr_t[TIPC_NL_KEY_SET], tipc_nl_policy]]] { // iovec[in, netlink_msg_t[genl_tipc2_family_id, // genlmsghdr_t[TIPC_NL_KEY_SET], tipc_nl_policy]] { // addr: ptr[in, netlink_msg_t[genl_tipc2_family_id, // genlmsghdr_t[TIPC_NL_KEY_SET], tipc_nl_policy]] { // netlink_msg_t[genl_tipc2_family_id, // genlmsghdr_t[TIPC_NL_KEY_SET], tipc_nl_policy] { // len: len = 0x58 (4 bytes) // type: genl_tipc2_family_id (resource) // flags: netlink_msg_flags = 0x1 (2 bytes) // seq: int32 = 0x0 (4 bytes) // pid: int32 = 0x0 (4 bytes) // payload: genlmsghdr_t[TIPC_NL_KEY_SET] { // cmd: const = 0x17 (1 bytes) // version: const = 0x0 (1 bytes) // reserved: const = 0x0 (2 bytes) // } // attrs: array[tipc_nl_policy] { // union tipc_nl_policy { // TIPC_NLA_NODE: nlattr_tt[const[TIPC_NLA_NODE, int16:14], // 0, 1, array[tipc_nl_node_policy]] { // nla_len: offsetof = 0x44 (2 bytes) // nla_type: const = 0x6 (1 bytes) // NLA_F_NET_BYTEORDER: const = 0x0 (0 bytes) // NLA_F_NESTED: const = 0x1 (1 bytes) // payload: array[tipc_nl_node_policy] { // union tipc_nl_node_policy { // TIPC_NLA_NODE_KEY: // nlattr_t[const[TIPC_NLA_NODE_KEY, int16], // tipc_aead_key] { // nla_len: offsetof = 0x3c (2 bytes) // nla_type: const = 0x4 (2 bytes) // payload: tipc_aead_key { // alg_name: buffer: {67 63 6d 28 61 65 73 29 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00 00 00} (length 0x20) keylen: // len = 0x14 (4 bytes) key: buffer: {e3 de 3d 7b // 4c d0 7e c3 ee 77 7d e7 74 fc 79 87 cc a4 19 // 89} (length 0x14) // } // size: buffer: {} (length 0x0) // } // } // union tipc_nl_node_policy { // TIPC_NLA_NODE_KEY_MASTER: // nlattr_t[const[TIPC_NLA_NODE_KEY_MASTER, int16], // void] { // nla_len: offsetof = 0x4 (2 bytes) // nla_type: const = 0x5 (2 bytes) // payload: buffer: {} (length 0x0) // size: buffer: {} (length 0x0) // } // } // } // size: buffer: {} (length 0x0) // } // } // } // } // } // len: len = 0x58 (8 bytes) // } // } // vlen: const = 0x1 (8 bytes) // ctrl: const = 0x0 (8 bytes) // ctrllen: const = 0x0 (8 bytes) // f: send_flags = 0x4 (4 bytes) // pad = 0x0 (4 bytes) // } // } // f: send_flags = 0x4000004 (8 bytes) // ] *(uint64_t*)0x200000000100 = 0; *(uint32_t*)0x200000000108 = 0; *(uint64_t*)0x200000000110 = 0x200000000000; *(uint64_t*)0x200000000000 = 0x200000000200; *(uint32_t*)0x200000000200 = 0x58; *(uint16_t*)0x200000000204 = r[3]; *(uint16_t*)0x200000000206 = 1; *(uint32_t*)0x200000000208 = 0; *(uint32_t*)0x20000000020c = 0; *(uint8_t*)0x200000000210 = 0x17; *(uint8_t*)0x200000000211 = 0; *(uint16_t*)0x200000000212 = 0; *(uint16_t*)0x200000000214 = 0x44; STORE_BY_BITMASK(uint16_t, , 0x200000000216, 6, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x200000000217, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x200000000217, 1, 7, 1); *(uint16_t*)0x200000000218 = 0x3c; *(uint16_t*)0x20000000021a = 4; memcpy((void*)0x20000000021c, "gcm(aes)" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000", 32); *(uint32_t*)0x20000000023c = 0x14; memcpy((void*)0x200000000240, "\xe3\xde\x3d\x7b\x4c\xd0\x7e\xc3\xee\x77\x7d\xe7\x74\xfc\x79\x87\xcc" "\xa4\x19\x89", 20); *(uint16_t*)0x200000000254 = 4; *(uint16_t*)0x200000000256 = 5; *(uint64_t*)0x200000000008 = 0x58; *(uint64_t*)0x200000000118 = 1; *(uint64_t*)0x200000000120 = 0; *(uint64_t*)0x200000000128 = 0; *(uint32_t*)0x200000000130 = 4; syscall(__NR_sendmsg, /*fd=*/r[1], /*msg=*/0x200000000100ul, /*f=MSG_ZEROCOPY|MSG_DONTROUTE*/ 0x4000004ul); } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); const char* reason; (void)reason; loop(); return 0; }