// https://syzkaller.appspot.com/bug?id=e43426047c6a30d7adbeed0f6fd67c3192490998 // 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 192 #endif #ifndef __NR_openat #define __NR_openat 295 #endif #ifndef __NR_sendmsg #define __NR_sendmsg 370 #endif #ifndef __NR_write #define __NR_write 4 #endif #undef __NR_mmap #define __NR_mmap __NR_mmap2 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)) { } // openat$uhid arguments: [ // fd: const = 0xffffffffffffff9c (4 bytes) // file: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 75 68 69 64 00} (length 0xa) // } // flags: uhid_open_flags = 0x2 (4 bytes) // mode: const = 0x0 (2 bytes) // ] // returns fd_uhid memcpy((void*)0x80000000, "/dev/uhid\000", 10); res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x80000000, /*flags=O_RDWR*/ 2, /*mode=*/0); if (res != -1) r[0] = res; // sendmsg$IPSET_CMD_CREATE arguments: [ // fd: sock_nl_netfilter (resource) // msg: ptr[in, msghdr_netlink[netlink_msg_netfilter_t[NFNL_SUBSYS_IPSET, // IPSET_CMD_CREATE, ip_set_create_policy]]] { // msghdr_netlink[netlink_msg_netfilter_t[NFNL_SUBSYS_IPSET, // IPSET_CMD_CREATE, ip_set_create_policy]] { // addr: nil // addrlen: len = 0x0 (4 bytes) // vec: ptr[in, iovec[in, netlink_msg_netfilter_t[NFNL_SUBSYS_IPSET, // IPSET_CMD_CREATE, ip_set_create_policy]]] { // iovec[in, netlink_msg_netfilter_t[NFNL_SUBSYS_IPSET, // IPSET_CMD_CREATE, ip_set_create_policy]] { // addr: ptr[in, netlink_msg_netfilter_tt[NFNL_SUBSYS_IPSET, // IPSET_CMD_CREATE, array[ip_set_create_policy]]] { // netlink_msg_netfilter_tt[NFNL_SUBSYS_IPSET, IPSET_CMD_CREATE, // array[ip_set_create_policy]] { // len: len = 0x58 (4 bytes) // type: const = 0x2 (1 bytes) // subsys: const = 0x6 (1 bytes) // flags: netlink_netfilter_msg_flags = 0x801 (2 bytes) // seq: const = 0x0 (4 bytes) // pid: const = 0x0 (4 bytes) // hdr: nfgenmsg { // nfgen_family: nfproto = 0x0 (1 bytes) // version: const = 0x0 (1 bytes) // res_id: int16be = 0x2 (2 bytes) // } // attrs: array[ip_set_create_policy] { // union ip_set_create_policy { // IPSET_ATTR_DATA: nlattr_tt[const[IPSET_ATTR_DATA, // int16:14], 0, 1, array[ip_set_type_create_policy]] { // nla_len: offsetof = 0xc (2 bytes) // nla_type: const = 0x7 (1 bytes) // NLA_F_NET_BYTEORDER: const = 0x0 (0 bytes) // NLA_F_NESTED: const = 0x1 (1 bytes) // payload: array[ip_set_type_create_policy] { // union ip_set_type_create_policy { // IPSET_ATTR_BUCKETSIZE: // nlattr_t[const[IPSET_ATTR_BUCKETSIZE, int16], // int8] { // nla_len: offsetof = 0x5 (2 bytes) // nla_type: const = 0x15 (2 bytes) // payload: int8 = 0x7 (1 bytes) // size: buffer: {} (length 0x0) // pad = 0x0 (3 bytes) // } // } // } // size: buffer: {} (length 0x0) // } // } // union ip_set_create_policy { // IPSET_ATTR_PROTOCOL: nlattr_t[const[IPSET_ATTR_PROTOCOL, // int16], const[IPSET_PROTOCOL, int8]] { // nla_len: offsetof = 0x5 (2 bytes) // nla_type: const = 0x1 (2 bytes) // payload: const = 0x6 (1 bytes) // size: buffer: {} (length 0x0) // pad = 0x0 (3 bytes) // } // } // union ip_set_create_policy { // IPSET_ATTR_FAMILY: nlattr_t[const[IPSET_ATTR_FAMILY, // int16], flags[nfproto, int8]] { // nla_len: offsetof = 0x5 (2 bytes) // nla_type: const = 0x5 (2 bytes) // payload: nfproto = 0xa (1 bytes) // size: buffer: {} (length 0x0) // pad = 0x0 (3 bytes) // } // } // union ip_set_create_policy { // IPSET_ATTR_REVISION: nlattr_t[const[IPSET_ATTR_REVISION, // int16], int8[0:3]] { // nla_len: offsetof = 0x5 (2 bytes) // nla_type: const = 0x4 (2 bytes) // payload: int8 = 0x0 (1 bytes) // size: buffer: {} (length 0x0) // pad = 0x0 (3 bytes) // } // } // union ip_set_create_policy { // IPSET_ATTR_SETNAME: nlattr_t[const[IPSET_ATTR_SETNAME, // int16], string[ipset_name]] { // nla_len: offsetof = 0x9 (2 bytes) // nla_type: const = 0x2 (2 bytes) // payload: buffer: {73 79 7a 30 00} (length 0x5) // size: buffer: {} (length 0x0) // pad = 0x0 (3 bytes) // } // } // union ip_set_create_policy { // IPSET_ATTR_TYPENAME: nlattr_t[const[IPSET_ATTR_TYPENAME, // int16], string[ipset_type]] { // nla_len: offsetof = 0x13 (2 bytes) // nla_type: const = 0x3 (2 bytes) // payload: buffer: {68 61 73 68 3a 6e 65 74 2c 69 66 61 // 63 65 00} (length 0xf) size: buffer: {} (length 0x0) // } // } // } // } // } // len: len = 0x58 (4 bytes) // } // } // vlen: const = 0x1 (4 bytes) // ctrl: const = 0x0 (4 bytes) // ctrllen: const = 0x0 (4 bytes) // f: send_flags = 0x0 (4 bytes) // } // } // f: send_flags = 0x80 (4 bytes) // ] *(uint32_t*)0x800000c0 = 0; *(uint32_t*)0x800000c4 = 0; *(uint32_t*)0x800000c8 = 0x800001c0; *(uint32_t*)0x800001c0 = 0x800002c0; *(uint32_t*)0x800002c0 = 0x58; *(uint8_t*)0x800002c4 = 2; *(uint8_t*)0x800002c5 = 6; *(uint16_t*)0x800002c6 = 0x801; *(uint32_t*)0x800002c8 = 0; *(uint32_t*)0x800002cc = 0; *(uint8_t*)0x800002d0 = 0; *(uint8_t*)0x800002d1 = 0; *(uint16_t*)0x800002d2 = htobe16(2); *(uint16_t*)0x800002d4 = 0xc; STORE_BY_BITMASK(uint16_t, , 0x800002d6, 7, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x800002d7, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x800002d7, 1, 7, 1); *(uint16_t*)0x800002d8 = 5; *(uint16_t*)0x800002da = 0x15; *(uint8_t*)0x800002dc = 7; *(uint16_t*)0x800002e0 = 5; *(uint16_t*)0x800002e2 = 1; *(uint8_t*)0x800002e4 = 6; *(uint16_t*)0x800002e8 = 5; *(uint16_t*)0x800002ea = 5; *(uint8_t*)0x800002ec = 0xa; *(uint16_t*)0x800002f0 = 5; *(uint16_t*)0x800002f2 = 4; *(uint8_t*)0x800002f4 = 0; *(uint16_t*)0x800002f8 = 9; *(uint16_t*)0x800002fa = 2; memcpy((void*)0x800002fc, "syz0\000", 5); *(uint16_t*)0x80000304 = 0x13; *(uint16_t*)0x80000306 = 3; memcpy((void*)0x80000308, "hash:net,iface\000", 15); *(uint32_t*)0x800001c4 = 0x58; *(uint32_t*)0x800000cc = 1; *(uint32_t*)0x800000d0 = 0; *(uint32_t*)0x800000d4 = 0; *(uint32_t*)0x800000d8 = 0; syscall(__NR_sendmsg, /*fd=*/(intptr_t)-1, /*msg=*/0x800000c0, /*f=MSG_EOR*/ 0x80); // write$UHID_CREATE2 arguments: [ // fd: fd_uhid (resource) // data: ptr[in, uhid_req[UHID_CREATE2, uhid_create2_req]] { // uhid_req[UHID_CREATE2, uhid_create2_req] { // type: const = 0xb (4 bytes) // data: uhid_create2_req { // name: buffer: {73 79 7a 30 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 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 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 00 00 00 00 00 00 // 00} (length 0x80) phys: buffer: {73 79 7a 30 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 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00} (length 0x40) uniq: buffer: {73 79 7a // 30 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 00 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00} (length 0x40) // rd_size: len = 0x1d (2 bytes) // bus: int16 = 0x3 (2 bytes) // vendor: int32 = 0x56a (4 bytes) // product: int32 = 0x3f (4 bytes) // version: int32 = 0x0 (4 bytes) // country: int32 = 0x0 (4 bytes) // rd_data: buffer: {05 01 09 05 a1 01 05 09 19 01 29 0a 15 00 25 01 // 75 01 95 0a 81 02 95 01 75 06 81 03 c0} (length 0x1d) // } // } // } // len: len = 0x135 (4 bytes) // ] *(uint32_t*)0x80001000 = 0xb; memcpy( (void*)0x80001004, "syz0\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\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\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\000\000\000\000\000\000\000", 128); memcpy((void*)0x80001084, "syz0\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\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000", 64); memcpy((void*)0x800010c4, "syz0\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\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000", 64); *(uint16_t*)0x80001104 = 0x1d; *(uint16_t*)0x80001106 = 3; *(uint32_t*)0x80001108 = 0x56a; *(uint32_t*)0x8000110c = 0x3f; *(uint32_t*)0x80001110 = 0; *(uint32_t*)0x80001114 = 0; memcpy((void*)0x80001118, "\x05\x01\x09\x05\xa1\x01\x05\x09\x19\x01\x29\x0a\x15\x00\x25\x01\x75" "\x01\x95\x0a\x81\x02\x95\x01\x75\x06\x81\x03\xc0", 29); syscall(__NR_write, /*fd=*/(intptr_t)r[0], /*data=*/0x80001000, /*len=*/0x135); // write$UHID_INPUT2 arguments: [ // fd: fd_uhid (resource) // data: ptr[inout, array[ANYUNION]] { // array[ANYUNION] { // union ANYUNION { // ANYBLOB: buffer: {0c 00 00 00 0a 17} (length 0x6) // } // } // } // len: len = 0x10 (4 bytes) // ] memcpy((void*)0x80000300, "\x0c\x00\x00\x00\x0a\x17", 6); syscall(__NR_write, /*fd=*/(intptr_t)r[0], /*data=*/0x80000300, /*len=*/0x10); } int main(void) { syscall(__NR_mmap, /*addr=*/0x7ffff000, /*len=*/0x1000, /*prot=*/0, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32, /*fd=*/(intptr_t)-1, /*offset=*/0); syscall(__NR_mmap, /*addr=*/0x80000000, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32, /*fd=*/(intptr_t)-1, /*offset=*/0); syscall(__NR_mmap, /*addr=*/0x81000000, /*len=*/0x1000, /*prot=*/0, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32, /*fd=*/(intptr_t)-1, /*offset=*/0); const char* reason; (void)reason; loop(); return 0; }