// https://syzkaller.appspot.com/bug?id=0b210638616bb68109e9642158d4c0072770ae1c // 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 #ifndef __NR_mmap #define __NR_mmap 222 #endif #ifndef __NR_sendmsg #define __NR_sendmsg 211 #endif #ifndef __NR_setns #define __NR_setns 268 #endif #ifndef __NR_socket #define __NR_socket 198 #endif 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; } 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[1] = {0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // setns arguments: [ // fd: fd_namespace (resource) // type: ns_type = 0x0 (8 bytes) // ] syscall(__NR_setns, /*fd=*/0xc9, /*type=*/0ul); // socket$nl_netfilter arguments: [ // domain: const = 0x10 (8 bytes) // type: const = 0x3 (8 bytes) // proto: const = 0xc (4 bytes) // ] // returns sock_nl_netfilter res = syscall(__NR_socket, /*domain=*/0x10ul, /*type=*/3ul, /*proto=*/0xc); if (res != -1) r[0] = res; // sendmsg$NFT_BATCH arguments: [ // fd: sock_nl_netfilter (resource) // msg: ptr[in, msghdr_netlink[nft_batch_msg]] { // msghdr_netlink[nft_batch_msg] { // addr: nil // addrlen: len = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // vec: ptr[in, iovec[in, nft_batch_msg]] { // iovec[in, nft_batch_msg] { // addr: ptr[in, nft_batch_msg] { // nft_batch_msg { // begin: nft_nlmsghdr[NFNL_MSG_BATCH_BEGIN] { // nlmsg_len: len = 0x14 (4 bytes) // nlmsg_type: const = 0x10 (2 bytes) // nlmsg_flags: const = 0x1 (2 bytes) // nlmsg_seq: const = 0x0 (4 bytes) // nlmsg_pid: const = 0x0 (4 bytes) // hdr: nfgenmsg_nft { // nfgen_family: families = 0x1 (1 bytes) // version: const = 0x0 (1 bytes) // res_id: const = 0xa (2 bytes) // } // } // msgs: array[nft_batch_message] { // union nft_batch_message { // NFT_MSG_NEWTABLE: // netlink_msg_netfilter_tt[NFNL_SUBSYS_NFTABLES, // NFT_MSG_NEWTABLE, array[nft_table_policy]] { // len: len = 0x20 (4 bytes) // type: const = 0x0 (1 bytes) // subsys: const = 0xa (1 bytes) // flags: netlink_netfilter_msg_flags = 0x401 (2 bytes) // seq: const = 0x0 (4 bytes) // pid: const = 0x0 (4 bytes) // hdr: nfgenmsg { // nfgen_family: nfproto = 0x1 (1 bytes) // version: const = 0x0 (1 bytes) // res_id: int16be = 0x0 (2 bytes) // } // attrs: array[nft_table_policy] { // union nft_table_policy { // NFTA_TABLE_NAME: nlattr_t[const[NFTA_TABLE_NAME, // int16], string[nft_table_name]] { // nla_len: offsetof = 0x9 (2 bytes) // nla_type: const = 0x1 (2 bytes) // payload: buffer: {73 79 7a 30 00} (length 0x5) // size: buffer: {} (length 0x0) // pad = 0x0 (3 bytes) // } // } // } // } // } // union nft_batch_message { // NFT_MSG_NEWCHAIN: // netlink_msg_netfilter_tt[NFNL_SUBSYS_NFTABLES, // NFT_MSG_NEWCHAIN, array[nft_chain_policy]] { // len: len = 0x48 (4 bytes) // type: const = 0x3 (1 bytes) // subsys: const = 0xa (1 bytes) // flags: netlink_netfilter_msg_flags = 0x401 (2 bytes) // seq: const = 0x0 (4 bytes) // pid: const = 0x0 (4 bytes) // hdr: nfgenmsg { // nfgen_family: nfproto = 0x1 (1 bytes) // version: const = 0x0 (1 bytes) // res_id: int16be = 0x0 (2 bytes) // } // attrs: array[nft_chain_policy] { // union nft_chain_policy { // NFTA_CHAIN_TABLE: nlattr_t[const[NFTA_CHAIN_TABLE, // int16], string[nft_table_name]] { // nla_len: offsetof = 0x9 (2 bytes) // nla_type: const = 0x1 (2 bytes) // payload: buffer: {73 79 7a 30 00} (length 0x5) // size: buffer: {} (length 0x0) // pad = 0x0 (3 bytes) // } // } // union nft_chain_policy { // NFTA_CHAIN_NAME: nlattr_t[const[NFTA_CHAIN_NAME, // int16], string[nft_chain_name]] { // nla_len: offsetof = 0x9 (2 bytes) // nla_type: const = 0x3 (2 bytes) // payload: buffer: {73 79 7a 31 00} (length 0x5) // size: buffer: {} (length 0x0) // pad = 0x0 (3 bytes) // } // } // union nft_chain_policy { // NFTA_CHAIN_HOOK: nlattr_tt[const[NFTA_CHAIN_HOOK, // int16:14], 0, 1, array[nft_hook_policy]] { // nla_len: offsetof = 0x14 (2 bytes) // nla_type: const = 0x4 (1 bytes) // NLA_F_NET_BYTEORDER: const = 0x0 (0 bytes) // NLA_F_NESTED: const = 0x1 (1 bytes) // payload: array[nft_hook_policy] { // union nft_hook_policy { // NFTA_HOOK_HOOKNUM: // nlattr_tt[const[NFTA_HOOK_HOOKNUM, // int16:14], 1, 0, flags[nf_inet_hooks, // int32be]] { // nla_len: offsetof = 0x8 (2 bytes) // nla_type: const = 0x1 (1 bytes) // NLA_F_NET_BYTEORDER: const = 0x1 (0 bytes) // NLA_F_NESTED: const = 0x0 (1 bytes) // payload: nf_inet_hooks = 0x4 (4 bytes) // size: buffer: {} (length 0x0) // } // } // union nft_hook_policy { // NFTA_HOOK_PRIORITY: // nlattr_tt[const[NFTA_HOOK_PRIORITY, // int16:14], 1, 0, // int32be[NF_IP_PRI_CONNTRACK:NF_IP_PRI_LAST]] // { // nla_len: offsetof = 0x8 (2 bytes) // nla_type: const = 0x2 (1 bytes) // NLA_F_NET_BYTEORDER: const = 0x1 (0 bytes) // NLA_F_NESTED: const = 0x0 (1 bytes) // payload: int32be = 0x64 (4 bytes) // size: buffer: {} (length 0x0) // } // } // } // size: buffer: {} (length 0x0) // } // } // union nft_chain_policy { // NFTA_CHAIN_TYPE: nlattr_t[const[NFTA_CHAIN_TYPE, // int16], string[nft_chain_type]] { // nla_len: offsetof = 0x8 (2 bytes) // nla_type: const = 0x7 (2 bytes) // payload: buffer: {6e 61 74 00} (length 0x4) // size: buffer: {} (length 0x0) // } // } // } // } // } // union nft_batch_message { // NFT_MSG_NEWRULE: // netlink_msg_netfilter_tt[NFNL_SUBSYS_NFTABLES, // NFT_MSG_NEWRULE, array[nft_rule_policy]] { // len: len = 0x4c (4 bytes) // type: const = 0x6 (1 bytes) // subsys: const = 0xa (1 bytes) // flags: netlink_netfilter_msg_flags = 0x401 (2 bytes) // seq: const = 0x0 (4 bytes) // pid: const = 0x0 (4 bytes) // hdr: nfgenmsg { // nfgen_family: nfproto = 0x1 (1 bytes) // version: const = 0x0 (1 bytes) // res_id: int16be = 0x0 (2 bytes) // } // attrs: array[nft_rule_policy] { // union nft_rule_policy { // NFTA_RULE_TABLE: nlattr_t[const[NFTA_RULE_TABLE, // int16], string[nft_table_name]] { // nla_len: offsetof = 0x9 (2 bytes) // nla_type: const = 0x1 (2 bytes) // payload: buffer: {73 79 7a 30 00} (length 0x5) // size: buffer: {} (length 0x0) // pad = 0x0 (3 bytes) // } // } // union nft_rule_policy { // NFTA_RULE_CHAIN: nlattr_t[const[NFTA_RULE_CHAIN, // int16], string[nft_chain_name]] { // nla_len: offsetof = 0x9 (2 bytes) // nla_type: const = 0x2 (2 bytes) // payload: buffer: {73 79 7a 31 00} (length 0x5) // size: buffer: {} (length 0x0) // pad = 0x0 (3 bytes) // } // } // union nft_rule_policy { // NFTA_RULE_EXPRESSIONS: // nlattr_tt[const[NFTA_RULE_EXPRESSIONS, int16:14], // 0, 1, array[nlnest[NFTA_LIST_ELEM, // nft_expr_policy]]] { // nla_len: offsetof = 0x20 (2 bytes) // nla_type: const = 0x4 (1 bytes) // NLA_F_NET_BYTEORDER: const = 0x0 (0 bytes) // NLA_F_NESTED: const = 0x1 (1 bytes) // payload: array[nlattr_tt[const[NFTA_LIST_ELEM, // int16:14], 0, 1, nft_expr_policy]] { // nlattr_tt[const[NFTA_LIST_ELEM, int16:14], 0, // 1, nft_expr_policy] { // nla_len: offsetof = 0x1c (2 bytes) // nla_type: const = 0x1 (1 bytes) // NLA_F_NET_BYTEORDER: const = 0x0 (0 bytes) // NLA_F_NESTED: const = 0x1 (1 bytes) // payload: union nft_expr_policy { // masq: nft_expr_policy_t["masq", // nft_masq_policy] { // NFTA_EXPR_NAME: // nlattr_t[const[NFTA_EXPR_NAME, int16], // string["masq"]] { // nla_len: offsetof = 0x9 (2 bytes) // nla_type: const = 0x1 (2 bytes) // payload: buffer: {6d 61 73 71 00} // (length 0x5) size: buffer: {} (length // 0x0) pad = 0x0 (3 bytes) // } // NFTA_EXPR_DATA: union // optional[nlnest[NFTA_EXPR_DATA, // array[nft_masq_policy]]] { // val: nlattr_tt[const[NFTA_EXPR_DATA, // int16:14], 0, 1, // array[nft_masq_policy]] { // nla_len: offsetof = 0xc (2 bytes) // nla_type: const = 0x2 (1 bytes) // NLA_F_NET_BYTEORDER: const = 0x0 (0 // bytes) NLA_F_NESTED: const = 0x1 (1 // bytes) payload: // array[nft_masq_policy] { // union nft_masq_policy { // NFTA_MASQ_FLAGS: // nlattr_tt[const[NFTA_MASQ_FLAGS, // int16:14], 1, 0, // flags[nft_nat_flags, int32be]] { // nla_len: offsetof = 0x8 (2 // bytes) nla_type: const = 0x1 // (1 bytes) NLA_F_NET_BYTEORDER: // const = 0x1 (0 bytes) // NLA_F_NESTED: const = 0x0 (1 // bytes) payload: nft_nat_flags // = 0x12 (4 bytes) size: buffer: // {} (length 0x0) // } // } // } // size: buffer: {} (length 0x0) // } // } // } // } // size: buffer: {} (length 0x0) // } // } // size: buffer: {} (length 0x0) // } // } // } // } // } // } // end: nft_nlmsghdr[NFNL_MSG_BATCH_END] { // nlmsg_len: len = 0x14 (4 bytes) // nlmsg_type: const = 0x11 (2 bytes) // nlmsg_flags: const = 0x1 (2 bytes) // nlmsg_seq: const = 0x0 (4 bytes) // nlmsg_pid: const = 0x0 (4 bytes) // hdr: nfgenmsg_nft { // nfgen_family: families = 0x1 (1 bytes) // version: const = 0x0 (1 bytes) // res_id: const = 0xa (2 bytes) // } // } // } // } // len: len = 0xdc (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 = 0x8040 (8 bytes) // ] *(uint64_t*)0x20000240 = 0; *(uint32_t*)0x20000248 = 0; *(uint64_t*)0x20000250 = 0x20000280; *(uint64_t*)0x20000280 = 0x20000000; *(uint32_t*)0x20000000 = 0x14; *(uint16_t*)0x20000004 = 0x10; *(uint16_t*)0x20000006 = 1; *(uint32_t*)0x20000008 = 0; *(uint32_t*)0x2000000c = 0; *(uint8_t*)0x20000010 = 1; *(uint8_t*)0x20000011 = 0; *(uint16_t*)0x20000012 = htobe16(0xa); *(uint32_t*)0x20000014 = 0x20; *(uint8_t*)0x20000018 = 0; *(uint8_t*)0x20000019 = 0xa; *(uint16_t*)0x2000001a = 0x401; *(uint32_t*)0x2000001c = 0; *(uint32_t*)0x20000020 = 0; *(uint8_t*)0x20000024 = 1; *(uint8_t*)0x20000025 = 0; *(uint16_t*)0x20000026 = htobe16(0); *(uint16_t*)0x20000028 = 9; *(uint16_t*)0x2000002a = 1; memcpy((void*)0x2000002c, "syz0\000", 5); *(uint32_t*)0x20000034 = 0x48; *(uint8_t*)0x20000038 = 3; *(uint8_t*)0x20000039 = 0xa; *(uint16_t*)0x2000003a = 0x401; *(uint32_t*)0x2000003c = 0; *(uint32_t*)0x20000040 = 0; *(uint8_t*)0x20000044 = 1; *(uint8_t*)0x20000045 = 0; *(uint16_t*)0x20000046 = htobe16(0); *(uint16_t*)0x20000048 = 9; *(uint16_t*)0x2000004a = 1; memcpy((void*)0x2000004c, "syz0\000", 5); *(uint16_t*)0x20000054 = 9; *(uint16_t*)0x20000056 = 3; memcpy((void*)0x20000058, "syz1\000", 5); *(uint16_t*)0x20000060 = 0x14; STORE_BY_BITMASK(uint16_t, , 0x20000062, 4, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x20000063, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x20000063, 1, 7, 1); *(uint16_t*)0x20000064 = 8; STORE_BY_BITMASK(uint16_t, , 0x20000066, 1, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x20000067, 1, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x20000067, 0, 7, 1); *(uint32_t*)0x20000068 = htobe32(4); *(uint16_t*)0x2000006c = 8; STORE_BY_BITMASK(uint16_t, , 0x2000006e, 2, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x2000006f, 1, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x2000006f, 0, 7, 1); *(uint32_t*)0x20000070 = htobe32(0x64); *(uint16_t*)0x20000074 = 8; *(uint16_t*)0x20000076 = 7; memcpy((void*)0x20000078, "nat\000", 4); *(uint32_t*)0x2000007c = 0x4c; *(uint8_t*)0x20000080 = 6; *(uint8_t*)0x20000081 = 0xa; *(uint16_t*)0x20000082 = 0x401; *(uint32_t*)0x20000084 = 0; *(uint32_t*)0x20000088 = 0; *(uint8_t*)0x2000008c = 1; *(uint8_t*)0x2000008d = 0; *(uint16_t*)0x2000008e = htobe16(0); *(uint16_t*)0x20000090 = 9; *(uint16_t*)0x20000092 = 1; memcpy((void*)0x20000094, "syz0\000", 5); *(uint16_t*)0x2000009c = 9; *(uint16_t*)0x2000009e = 2; memcpy((void*)0x200000a0, "syz1\000", 5); *(uint16_t*)0x200000a8 = 0x20; STORE_BY_BITMASK(uint16_t, , 0x200000aa, 4, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x200000ab, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x200000ab, 1, 7, 1); *(uint16_t*)0x200000ac = 0x1c; STORE_BY_BITMASK(uint16_t, , 0x200000ae, 1, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x200000af, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x200000af, 1, 7, 1); *(uint16_t*)0x200000b0 = 9; *(uint16_t*)0x200000b2 = 1; memcpy((void*)0x200000b4, "masq\000", 5); *(uint16_t*)0x200000bc = 0xc; STORE_BY_BITMASK(uint16_t, , 0x200000be, 2, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x200000bf, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x200000bf, 1, 7, 1); *(uint16_t*)0x200000c0 = 8; STORE_BY_BITMASK(uint16_t, , 0x200000c2, 1, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x200000c3, 1, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x200000c3, 0, 7, 1); *(uint32_t*)0x200000c4 = htobe32(0x12); *(uint32_t*)0x200000c8 = 0x14; *(uint16_t*)0x200000cc = 0x11; *(uint16_t*)0x200000ce = 1; *(uint32_t*)0x200000d0 = 0; *(uint32_t*)0x200000d4 = 0; *(uint8_t*)0x200000d8 = 1; *(uint8_t*)0x200000d9 = 0; *(uint16_t*)0x200000da = htobe16(0xa); *(uint64_t*)0x20000288 = 0xdc; *(uint64_t*)0x20000258 = 1; *(uint64_t*)0x20000260 = 0; *(uint64_t*)0x20000268 = 0; *(uint32_t*)0x20000270 = 0; syscall(__NR_sendmsg, /*fd=*/r[0], /*msg=*/0x20000240ul, /*f=MSG_MORE|MSG_DONTWAIT*/ 0x8040ul); } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000, /*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=*/0x21000000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); const char* reason; (void)reason; loop(); return 0; }