// https://syzkaller.appspot.com/bug?id=121015dd8a362b292ca89d5f5ffbc9cfe184e684 // 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 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[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // mkdirat arguments: [ // fd: fd_dir (resource) // path: ptr[in, buffer] { // buffer: {2e 2f 64 65 76 00} (length 0x6) // } // mode: open_mode = 0x1ff (8 bytes) // ] memcpy((void*)0x200000000040, "./dev\000", 6); syscall( __NR_mkdirat, /*fd=*/0xffffff9c, /*path=*/0x200000000040ul, /*mode=S_IXOTH|S_IWOTH|S_IROTH|S_IXGRP|S_IWGRP|S_IRGRP|S_IXUSR|S_IWUSR|0x100*/ 0x1fful); // rename arguments: [ // old: ptr[in, buffer] { // buffer: {2e 2f 64 65 76 2f 6d 64 30 00} (length 0xa) // } // new: ptr[in, buffer] { // buffer: {2e 2f 73 79 73 00} (length 0x6) // } // ] memcpy((void*)0x200000000100, "./dev/md0\000", 10); memcpy((void*)0x200000000140, "./sys\000", 6); syscall(__NR_rename, /*old=*/0x200000000100ul, /*new=*/0x200000000140ul); // mount arguments: [ // src: nil // dst: ptr[in, buffer] { // buffer: {2e 2f 64 65 76 00} (length 0x6) // } // type: ptr[in, buffer] { // buffer: {64 65 76 74 6d 70 66 73 00} (length 0x9) // } // flags: mount_flags = 0x0 (8 bytes) // data: nil // ] memcpy((void*)0x200000000080, "./dev\000", 6); memcpy((void*)0x2000000000c0, "devtmpfs\000", 9); syscall(__NR_mount, /*src=*/0ul, /*dst=*/0x200000000080ul, /*type=*/0x2000000000c0ul, /*flags=*/0ul, /*data=*/0ul); // mkdirat arguments: [ // fd: fd_dir (resource) // path: ptr[in, buffer] { // buffer: {2e 2f 73 79 73 00} (length 0x6) // } // mode: open_mode = 0x1ff (8 bytes) // ] memcpy((void*)0x200000000000, "./sys\000", 6); syscall( __NR_mkdirat, /*fd=*/0xffffff9c, /*path=*/0x200000000000ul, /*mode=S_IXOTH|S_IWOTH|S_IROTH|S_IXGRP|S_IWGRP|S_IRGRP|S_IXUSR|S_IWUSR|0x100*/ 0x1fful); // mount arguments: [ // src: nil // dst: ptr[in, buffer] { // buffer: {2e 2f 73 79 73 00} (length 0x6) // } // type: ptr[in, buffer] { // buffer: {73 79 73 66 73 00} (length 0x6) // } // flags: mount_flags = 0x0 (8 bytes) // data: nil // ] memcpy((void*)0x200000000040, "./sys\000", 6); memcpy((void*)0x200000000080, "sysfs\000", 6); syscall(__NR_mount, /*src=*/0ul, /*dst=*/0x200000000040ul, /*type=*/0x200000000080ul, /*flags=*/0ul, /*data=*/0ul); // openat arguments: [ // fd: fd_dir (resource) // file: ptr[in, buffer] { // buffer: {2e 2f 73 79 73 2f 6d 6f 64 75 6c 65 2f 6d 64 5f 6d 6f 64 2f // 70 61 72 61 6d 65 74 65 72 73 2f 6e 65 77 5f 61 72 72 61 79 00} // (length 0x29) // } // flags: open_flags = 0x1 (4 bytes) // mode: open_mode = 0x0 (2 bytes) // ] // returns fd memcpy((void*)0x200000000180, "./sys/module/md_mod/parameters/new_array\000", 41); res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000000180ul, /*flags=O_WRONLY*/ 1, /*mode=*/0); if (res != -1) r[0] = res; // write arguments: [ // fd: fd (resource) // buf: ptr[in, buffer] { // buffer: {6d 64 30} (length 0x3) // } // count: len = 0x3 (8 bytes) // ] memcpy((void*)0x200000000200, "md0", 3); syscall(__NR_write, /*fd=*/r[0], /*buf=*/0x200000000200ul, /*count=*/3ul); // openat arguments: [ // fd: fd_dir (resource) // file: ptr[in, buffer] { // buffer: {2e 2f 64 65 76 2f 6d 64 30 00} (length 0xa) // } // flags: open_flags = 0x2 (4 bytes) // mode: open_mode = 0x0 (2 bytes) // ] // returns fd memcpy((void*)0x200000000240, "./dev/md0\000", 10); res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000000240ul, /*flags=O_RDWR*/ 2, /*mode=*/0); if (res != -1) r[1] = res; // openat$vnet arguments: [ // fd: const = 0xffffffffffffff9c (8 bytes) // file: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 76 68 6f 73 74 2d 6e 65 74 00} (length 0xf) // } // flags: const = 0x2 (4 bytes) // mode: const = 0x0 (2 bytes) // ] // returns vhost_net memcpy((void*)0x200000000480, "/dev/vhost-net\000", 15); syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x200000000480ul, /*flags=*/2, /*mode=*/0); // ioctl arguments: [ // fd: fd (resource) // cmd: int32 = 0x40480923 (4 bytes) // arg: ptr[in, buffer] { // buffer: {00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 00 00 // 00 04 00 00 02 00 00 00 02 00 22 00 00 00 00 00 01 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 02 01 // 00 00 00 00 01} (length 0x47) // } // ] memcpy( (void*)0x200000000300, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0a\x00" "\x00\x00\x00\x04\x00\x00\x02\x00\x00\x00\x02\x00\x22\x00\x00\x00\x00\x00" "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x01\x00\x00\x00\x00\x01", 71); syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x40480923, /*arg=*/0x200000000300ul); // ioctl$SNDCTL_DSP_GETOSPACE arguments: [ // fd: fd_dsp (resource) // cmd: const = 0x8010500c (4 bytes) // arg: ptr[out, buffer] { // buffer: (DirOut) // } // ] syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0x8010500c, /*arg=*/0x2000000001c0ul); // ioctl arguments: [ // fd: fd (resource) // cmd: int32 = 0x40140921 (4 bytes) // arg: ptr[in, buffer] { // buffer: {00 00 00 00 01} (length 0x5) // } // ] memcpy((void*)0x200000000400, "\x00\x00\x00\x00\x01", 5); syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x40140921, /*arg=*/0x200000000400ul); // accept$alg arguments: [ // fd: sock_alg (resource) // peer: const = 0x0 (8 bytes) // peerlen: const = 0x0 (8 bytes) // ] // returns sock_algconn syscall(__NR_accept, /*fd=*/(intptr_t)-1, /*peer=*/0ul, /*peerlen=*/0ul); // 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) // pad = 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 = 0x5c (4 bytes) // type: const = 0x2 (1 bytes) // subsys: const = 0x6 (1 bytes) // flags: netlink_netfilter_msg_flags = 0x3 (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 = 0x0 (2 bytes) // } // attrs: array[ip_set_create_policy] { // 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 = 0x7 (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_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 = 0x6 (1 bytes) // size: buffer: {} (length 0x0) // pad = 0x0 (3 bytes) // } // } // } // size: buffer: {} (length 0x0) // } // } // union ip_set_create_policy { // IPSET_ATTR_TYPENAME: nlattr_t[const[IPSET_ATTR_TYPENAME, // int16], string[ipset_type]] { // nla_len: offsetof = 0x16 (2 bytes) // nla_type: const = 0x3 (2 bytes) // payload: buffer: {68 61 73 68 3a 6e 65 74 2c 70 6f 72 // 74 2c 6e 65 74 00} (length 0x12) size: buffer: {} // (length 0x0) // } // } // 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) // } // } // } // } // } // len: len = 0x5c (8 bytes) // } // } // vlen: const = 0x1 (8 bytes) // ctrl: const = 0x0 (8 bytes) // ctrllen: const = 0x0 (8 bytes) // f: send_flags = 0x8004 (4 bytes) // pad = 0x0 (4 bytes) // } // } // f: send_flags = 0x0 (8 bytes) // ] *(uint64_t*)0x200000000100 = 0; *(uint32_t*)0x200000000108 = 0; *(uint64_t*)0x200000000110 = 0x2000000000c0; *(uint64_t*)0x2000000000c0 = 0x200000000280; *(uint32_t*)0x200000000280 = 0x5c; *(uint8_t*)0x200000000284 = 2; *(uint8_t*)0x200000000285 = 6; *(uint16_t*)0x200000000286 = 3; *(uint32_t*)0x200000000288 = 0; *(uint32_t*)0x20000000028c = 0; *(uint8_t*)0x200000000290 = 0; *(uint8_t*)0x200000000291 = 0; *(uint16_t*)0x200000000292 = htobe16(0); *(uint16_t*)0x200000000294 = 5; *(uint16_t*)0x200000000296 = 1; *(uint8_t*)0x200000000298 = 7; *(uint16_t*)0x20000000029c = 9; *(uint16_t*)0x20000000029e = 2; memcpy((void*)0x2000000002a0, "syz0\000", 5); *(uint16_t*)0x2000000002a8 = 0xc; STORE_BY_BITMASK(uint16_t, , 0x2000000002aa, 7, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x2000000002ab, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x2000000002ab, 1, 7, 1); *(uint16_t*)0x2000000002ac = 5; *(uint16_t*)0x2000000002ae = 0x15; *(uint8_t*)0x2000000002b0 = 6; *(uint16_t*)0x2000000002b4 = 0x16; *(uint16_t*)0x2000000002b6 = 3; memcpy((void*)0x2000000002b8, "hash:net,port,net\000", 18); *(uint16_t*)0x2000000002cc = 5; *(uint16_t*)0x2000000002ce = 5; *(uint8_t*)0x2000000002d0 = 0xa; *(uint16_t*)0x2000000002d4 = 5; *(uint16_t*)0x2000000002d6 = 4; *(uint8_t*)0x2000000002d8 = 0; *(uint64_t*)0x2000000000c8 = 0x5c; *(uint64_t*)0x200000000118 = 1; *(uint64_t*)0x200000000120 = 0; *(uint64_t*)0x200000000128 = 0; *(uint32_t*)0x200000000130 = 0x8004; syscall(__NR_sendmsg, /*fd=*/(intptr_t)-1, /*msg=*/0x200000000100ul, /*f=*/0ul); // socket$kcm arguments: [ // domain: const = 0x2 (8 bytes) // type: kcm_socket_type = 0xa (8 bytes) // proto: const = 0x2 (4 bytes) // ] // returns sock_kcm syscall(__NR_socket, /*domain=*/2ul, /*type=SOCK_DGRAM|0x8*/ 0xaul, /*proto=*/2); // ioctl arguments: [ // fd: fd (resource) // cmd: int32 = 0x400c0930 (4 bytes) // arg: nil // ] syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x400c0930, /*arg=*/0ul); } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*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=*/0x200001000000ul, /*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; }