// https://syzkaller.appspot.com/bug?id=2b5c671149637e40918f4b5e8cc0a78d3f13e169 // 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 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; } 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 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 { unsigned long nb = a1; char buf[1024]; char* hash; strncpy(buf, (char*)a0, sizeof(buf) - 1); buf[sizeof(buf) - 1] = 0; while ((hash = strchr(buf, '#'))) { *hash = '0' + (char)(nb % 10); nb /= 10; } return open(buf, a2 & ~O_CREAT, 0); } } 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[5] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // syz_open_dev$loop arguments: [ // dev: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 6c 6f 6f 70 23 00} (length 0xb) // } // id: intptr = 0xffffffff7ffffffd (8 bytes) // flags: open_flags = 0x160862 (8 bytes) // ] // returns fd_loop memcpy((void*)0x200000000240, "/dev/loop#\000", 11); res = -1; res = syz_open_dev( /*dev=*/0x200000000240, /*id=*/0xffffffff7ffffffd, /*flags=O_NONBLOCK|O_NOFOLLOW|O_NOATIME|O_CREAT|O_RDWR|0x100020*/ 0x160862); if (res != -1) r[0] = res; // openat$sysfs arguments: [ // fd: const = 0xffffffffffffff9c (8 bytes) // dir: ptr[in, buffer] { // buffer: {2f 73 79 73 2f 70 6f 77 65 72 2f 70 6d 5f 70 72 69 6e 74 5f // 74 69 6d 65 73} (length 0x19) // } // flags: open_flags = 0x82802 (4 bytes) // mode: open_mode = 0xf (2 bytes) // ] // returns fd memcpy((void*)0x200000000340, "/sys/power/pm_print_times", 25); res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*dir=*/0x200000000340ul, /*flags=O_NONBLOCK|O_CLOEXEC|FASYNC|O_RDWR*/ 0x82802, /*mode=S_IXOTH|S_IWOTH|S_IROTH|S_IXGRP*/ 0xf); if (res != -1) r[1] = res; // ioctl$LOOP_CONFIGURE arguments: [ // fd: fd_loop (resource) // cmd: const = 0x4c0a (4 bytes) // arg: ptr[in, loop_config] { // loop_config { // fd: fd_loop (resource) // block_size: int32 = 0x0 (4 bytes) // info: loop_info64 { // lo_device: const = 0x0 (8 bytes) // lo_inode: const = 0x0 (8 bytes) // lo_rdevice: const = 0x0 (8 bytes) // lo_offset: int64 = 0x1 (8 bytes) // lo_sizelimit: int64 = 0x4000000000000ffd (8 bytes) // lo_number: const = 0x0 (4 bytes) // lo_enc_type: lo_encrypt_type = 0x0 (4 bytes) // lo_enc_key_size: int32 = 0x1e (4 bytes) // lo_flags: lo_flags = 0x4 (4 bytes) // lo_file_name: buffer: {fa f9 00 00 00 80 14 d9 89 fc 8d be 43 ea // 6a cc 96 e3 a2 50 3d c3 bd 3f e3 7d 58 12 8b ba d0 09 0f 00 dc 25 // f5 ab 60 c9 e6 ea 65 f9 85 88 1a 35 00 00 dd ff ff ff 00 00 00 00 // 00 00 00 00 00 00} (length 0x40) lo_crypt_name: buffer: {32 d8 cc // 26 f7 06 1a 74 df 2c fc 06 c8 9f 3d 9e 23 4b 30 c5 09 97 d3 be f4 // 09 ff 21 76 ff 7b 02 55 cd 4a 7f 3f 80 0b 2f 7b 6a a5 4c c5 0a 1f // ca ed 29 83 1f a7 9a 00 00 00 00 fe 01 f1 00 00 00} (length 0x40) // lo_enc_key: buffer: {71 52 37 60 1a 8c a5 b0 7d cc 14 18 02 c4 da // cf 16 2e 43 ac 61 f7 ad 33 00 00 00 00 00 a0 41 00} (length 0x20) // lo_init: array[int64] { // int64 = 0xfffffffffffffce8 (8 bytes) // int64 = 0xa (8 bytes) // } // } // reserved: buffer: {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 0x40) // } // } // ] *(uint32_t*)0x200000000080 = r[1]; *(uint32_t*)0x200000000084 = 0; *(uint64_t*)0x200000000088 = 0; *(uint64_t*)0x200000000090 = 0; *(uint64_t*)0x200000000098 = 0; *(uint64_t*)0x2000000000a0 = 1; *(uint64_t*)0x2000000000a8 = 0x4000000000000ffd; *(uint32_t*)0x2000000000b0 = 0; *(uint32_t*)0x2000000000b4 = 0; *(uint32_t*)0x2000000000b8 = 0x1e; *(uint32_t*)0x2000000000bc = 4; memcpy((void*)0x2000000000c0, "\xfa\xf9\x00\x00\x00\x80\x14\xd9\x89\xfc\x8d\xbe\x43\xea\x6a\xcc\x96" "\xe3\xa2\x50\x3d\xc3\xbd\x3f\xe3\x7d\x58\x12\x8b\xba\xd0\x09\x0f\x00" "\xdc\x25\xf5\xab\x60\xc9\xe6\xea\x65\xf9\x85\x88\x1a\x35\x00\x00\xdd" "\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 64); memcpy((void*)0x200000000100, "\x32\xd8\xcc\x26\xf7\x06\x1a\x74\xdf\x2c\xfc\x06\xc8\x9f\x3d\x9e\x23" "\x4b\x30\xc5\x09\x97\xd3\xbe\xf4\x09\xff\x21\x76\xff\x7b\x02\x55\xcd" "\x4a\x7f\x3f\x80\x0b\x2f\x7b\x6a\xa5\x4c\xc5\x0a\x1f\xca\xed\x29\x83" "\x1f\xa7\x9a\x00\x00\x00\x00\xfe\x01\xf1\x00\x00\x00", 64); memcpy((void*)0x200000000140, "\x71\x52\x37\x60\x1a\x8c\xa5\xb0\x7d\xcc\x14\x18\x02\xc4\xda\xcf\x16" "\x2e\x43\xac\x61\xf7\xad\x33\x00\x00\x00\x00\x00\xa0\x41\x00", 32); *(uint64_t*)0x200000000160 = 0xfffffffffffffce8; *(uint64_t*)0x200000000168 = 0xa; memset((void*)0x200000000170, 0, 64); syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0x4c0a, /*arg=*/0x200000000080ul); // madvise arguments: [ // addr: VMA[0x800000] // len: len = 0x800000 (8 bytes) // advice: madvise_flags = 0x17 (8 bytes) // ] syscall(__NR_madvise, /*addr=*/0x2000000ec000ul, /*len=*/0x800000ul, /*advice=MADV_POPULATE_WRITE*/ 0x17ul); // socket$can_bcm arguments: [ // domain: const = 0x1d (8 bytes) // type: const = 0x2 (8 bytes) // proto: const = 0x2 (4 bytes) // ] // returns sock_can_bcm res = syscall(__NR_socket, /*domain=*/0x1dul, /*type=*/2ul, /*proto=*/2); if (res != -1) r[2] = res; // ioctl$ifreq_SIOCGIFINDEX_vcan arguments: [ // fd: sock (resource) // cmd: const = 0x8933 (4 bytes) // arg: nil // ] syscall(__NR_ioctl, /*fd=*/r[2], /*cmd=*/0x8933, /*arg=*/0ul); // connect$can_bcm arguments: [ // fd: sock_can_bcm (resource) // addr: nil // len: bytesize = 0x0 (8 bytes) // ] syscall(__NR_connect, /*fd=*/r[2], /*addr=*/0ul, /*len=*/0ul); // sendmsg$can_bcm arguments: [ // fd: sock_can_bcm (resource) // msg: nil // f: send_flags = 0x20000000 (8 bytes) // ] syscall(__NR_sendmsg, /*fd=*/r[2], /*msg=*/0ul, /*f=MSG_FASTOPEN*/ 0x20000000ul); // ioctl$SNDCTL_DSP_SYNC arguments: [ // fd: fd_dsp (resource) // cmd: const = 0x5001 (4 bytes) // arg: const = 0x0 (8 bytes) // ] syscall(__NR_ioctl, /*fd=*/(intptr_t)-1, /*cmd=*/0x5001, /*arg=*/0ul); // ioctl$SNDCTL_DSP_SETFMT arguments: [ // fd: fd_dsp (resource) // cmd: const = 0x40045010 (4 bytes) // arg: nil // ] syscall(__NR_ioctl, /*fd=*/(intptr_t)-1, /*cmd=*/0x40045010, /*arg=*/0ul); // recvmmsg arguments: [ // fd: sock (resource) // mmsg: nil // vlen: len = 0x0 (8 bytes) // f: recv_flags = 0x2 (8 bytes) // timeout: nil // ] syscall(__NR_recvmmsg, /*fd=*/(intptr_t)-1, /*mmsg=*/0ul, /*vlen=*/0ul, /*f=MSG_PEEK*/ 2ul, /*timeout=*/0ul); // prctl$PR_SCHED_CORE arguments: [ // option: const = 0x3e (8 bytes) // cmd: intptr = 0x1 (8 bytes) // pid: pid (resource) // type: pid_type = 0x2 (8 bytes) // uaddr: nil // ] syscall(__NR_prctl, /*option=*/0x3eul, /*cmd=*/1ul, /*pid=*/0, /*type=PIDTYPE_PGID*/ 2ul, /*uaddr=*/0ul); // ioctl$sock_SIOCGIFINDEX arguments: [ // fd: sock (resource) // cmd: const = 0x8933 (4 bytes) // arg: nil // ] syscall(__NR_ioctl, /*fd=*/(intptr_t)-1, /*cmd=*/0x8933, /*arg=*/0ul); // socket arguments: [ // domain: socket_domain = 0xa (8 bytes) // type: socket_type = 0x3 (8 bytes) // proto: int32 = 0x3e (4 bytes) // ] // returns sock syscall(__NR_socket, /*domain=AF_INET6*/ 0xaul, /*type=SOCK_RAW*/ 3ul, /*proto=*/0x3e); // setsockopt$XDP_UMEM_REG arguments: [ // fd: sock_xdp (resource) // level: const = 0x11b (4 bytes) // opt: const = 0x4 (4 bytes) // val: nil // len: bytesize = 0x0 (8 bytes) // ] syscall(__NR_setsockopt, /*fd=*/(intptr_t)-1, /*level=*/0x11b, /*opt=*/4, /*val=*/0ul, /*len=*/0ul); // openat$audio arguments: [ // fd: const = 0xffffffffffffff9c (8 bytes) // file: nil // flags: open_flags = 0x40000000080201 (4 bytes) // mode: const = 0x0 (2 bytes) // ] // returns fd_dsp res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0ul, /*flags=O_TRUNC|O_CLOEXEC|O_WRONLY*/ 0x80201, /*mode=*/0); if (res != -1) r[3] = res; // write$apparmor_current arguments: [ // fd: fd_apparmor_current (resource) // data: ptr[in, apparmor_current_attr] { // union apparmor_current_attr { // hat: apparmor_current_hat { // cmd: buffer: {70 65 72 6d 68 61 74 20} (length 0x8) // token: int64 = 0x1 (18 bytes) // delim: const = 0x5e (1 bytes) // hats: array[buffer] { // } // } // } // } // len: len = 0x1b (8 bytes) // ] memcpy((void*)0x200000000180, "permhat ", 8); sprintf((char*)0x200000000188, "0x%016llx", (long long)1); *(uint8_t*)0x20000000019a = 0x5e; syscall(__NR_write, /*fd=*/(intptr_t)-1, /*data=*/0x200000000180ul, /*len=*/0x1bul); // write$RDMA_USER_CM_CMD_CREATE_ID arguments: [ // fd: fd_rdma_cm (resource) // data: nil // len: bytesize = 0x0 (8 bytes) // ] syscall(__NR_write, /*fd=*/r[3], /*data=*/0ul, /*len=*/0ul); // openat$sysfs arguments: [ // fd: const = 0xffffffffffffff9c (8 bytes) // dir: ptr[in, buffer] { // buffer: {2f 73 79 73 2f 70 6f 77 65 72 2f 72 65 73 75 6d 65} (length // 0x11) // } // flags: open_flags = 0x149a82 (4 bytes) // mode: open_mode = 0x0 (2 bytes) // ] // returns fd memcpy((void*)0x2000000002c0, "/sys/power/resume", 17); res = syscall( __NR_openat, /*fd=*/0xffffffffffffff9cul, /*dir=*/0x2000000002c0ul, /*flags=O_TRUNC|O_SYNC|O_NONBLOCK|O_NOATIME|O_LARGEFILE|O_EXCL|0x2*/ 0x149a82, /*mode=*/0); if (res != -1) r[4] = res; // write$cgroup_int arguments: [ // fd: fd_cgroup_int (resource) // buf: ptr[in, int64] { // int64 = 0xfe8e (18 bytes) // } // len: bytesize = 0x12 (8 bytes) // ] sprintf((char*)0x200000000040, "0x%016llx", (long long)0xfe8e); syscall(__NR_write, /*fd=*/r[4], /*buf=*/0x200000000040ul, /*len=*/0x12ul); // ioctl$TIOCPKT arguments: [ // fd: fd_tty (resource) // cmd: const = 0x5420 (4 bytes) // arg: nil // ] syscall(__NR_ioctl, /*fd=*/(intptr_t)-1, /*cmd=*/0x5420, /*arg=*/0ul); } 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; }