// https://syzkaller.appspot.com/bug?id=dd1d56e3b757e27199f6cae72cd0e80106000d2e // 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 #ifndef __NR_bpf #define __NR_bpf 357 #endif #ifndef __NR_getsockopt #define __NR_getsockopt 365 #endif #ifndef __NR_mmap #define __NR_mmap 192 #endif #ifndef __NR_openat #define __NR_openat 295 #endif #ifndef __NR_prctl #define __NR_prctl 172 #endif #ifndef __NR_prlimit64 #define __NR_prlimit64 340 #endif #ifndef __NR_sched_setscheduler #define __NR_sched_setscheduler 156 #endif #ifndef __NR_sendmsg #define __NR_sendmsg 370 #endif #ifndef __NR_sendto #define __NR_sendto 369 #endif #ifndef __NR_setsockopt #define __NR_setsockopt 366 #endif #ifndef __NR_socket #define __NR_socket 359 #endif #ifndef __NR_writev #define __NR_writev 146 #endif #undef __NR_mmap #define __NR_mmap __NR_mmap2 static unsigned long long procid; 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 void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { int state; } event_t; static void event_init(event_t* ev) { ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { if (ev->state) exit(1); __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000); } static void event_wait(event_t* ev) { while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0); } static int event_isset(event_t* ev) { return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE); } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; for (;;) { uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts); if (__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) return 1; now = current_time_ms(); if (now - start > timeout) return 0; } } 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"); } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } int i, call, thread; for (call = 0; call < 17; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } 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_call(int call) { intptr_t res = 0; switch (call) { case 0: // openat$binderfs arguments: [ // fd: const = 0xffffffffffffff9c (4 bytes) // file: ptr[in, buffer] { // buffer: {2e 2f 62 69 6e 64 65 72 66 73 2f 62 69 6e 64 65 72 30 00} // (length 0x13) // } // flags: binder_open_flags = 0x0 (4 bytes) // mode: const = 0x0 (2 bytes) // ] // returns fd_binder memcpy((void*)0x80000380, "./binderfs/binder0\000", 19); syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x80000380, /*flags=*/0, /*mode=*/0); break; case 1: // prctl$PR_SCHED_CORE arguments: [ // option: const = 0x3e (4 bytes) // cmd: intptr = 0x1 (4 bytes) // pid: pid (resource) // type: pid_type = 0x1 (4 bytes) // uaddr: nil // ] syscall(__NR_prctl, /*option=*/0x3e, /*cmd=*/1, /*pid=*/0, /*type=PIDTYPE_TGID*/ 1, /*uaddr=*/0); break; case 2: // prlimit64 arguments: [ // pid: pid (resource) // res: rlimit_type = 0xe (4 bytes) // new: ptr[in, rlimit] { // rlimit { // soft: intptr = 0x8 (4 bytes) // hard: intptr = 0x100008b (4 bytes) // } // } // old: nil // ] *(uint32_t*)0x80000380 = 8; *(uint32_t*)0x80000384 = 0x100008b; syscall(__NR_prlimit64, /*pid=*/0, /*res=RLIMIT_RTPRIO*/ 0xe, /*new=*/0x80000380, /*old=*/0); break; case 3: // sched_setscheduler arguments: [ // pid: pid (resource) // policy: sched_policy = 0x1 (4 bytes) // prio: ptr[in, int32] { // int32 = 0x5 (4 bytes) // } // ] *(uint32_t*)0x80000200 = 5; syscall(__NR_sched_setscheduler, /*pid=*/0, /*policy=SCHED_FIFO*/ 1, /*prio=*/0x80000200); break; case 4: // openat$sequencer arguments: [ // fd: const = 0xffffffffffffff9c (4 bytes) // file: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 73 65 71 75 65 6e 63 65 72 00} (length 0xf) // } // flags: open_flags = 0x80200 (4 bytes) // mode: const = 0x0 (2 bytes) // ] // returns fd_seq memcpy((void*)0x80000300, "/dev/sequencer\000", 15); syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x80000300, /*flags=O_TRUNC|O_CLOEXEC*/ 0x80200, /*mode=*/0); break; case 5: // syz_open_dev$sndmidi arguments: [ // dev: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 73 6e 64 2f 6d 69 64 69 43 23 44 23 00} // (length 0x12) // } // id: intptr = 0x2 (4 bytes) // flags: open_flags = 0x141102 (4 bytes) // ] // returns fd_midi memcpy((void*)0x800004c0, "/dev/snd/midiC#D#\000", 18); res = -1; res = syz_open_dev(/*dev=*/0x800004c0, /*id=*/2, /*flags=O_SYNC|O_NOCTTY|O_NOATIME|O_RDWR*/ 0x141102); if (res != -1) r[0] = res; break; case 6: // writev arguments: [ // fd: fd (resource) // vec: ptr[in, array[iovec[in, array[int8]]]] { // array[iovec[in, array[int8]]] { // iovec[in, array[int8]] { // addr: ptr[in, buffer] { // buffer: {94} (length 0x1) // } // len: len = 0xf000 (4 bytes) // } // iovec[in, array[int8]] { // addr: nil // len: len = 0x0 (4 bytes) // } // } // } // vlen: len = 0x2 (4 bytes) // ] *(uint32_t*)0x80000840 = 0x800002c0; memset((void*)0x800002c0, 148, 1); *(uint32_t*)0x80000844 = 0xf000; *(uint32_t*)0x80000848 = 0; *(uint32_t*)0x8000084c = 0; syscall(__NR_writev, /*fd=*/(intptr_t)r[0], /*vec=*/0x80000840, /*vlen=*/2); break; case 7: // socket$inet_udp arguments: [ // domain: const = 0x2 (4 bytes) // type: const = 0x2 (4 bytes) // proto: const = 0x0 (4 bytes) // ] // returns sock_udp syscall(__NR_socket, /*domain=*/2, /*type=*/2, /*proto=*/0); break; case 8: // socket$inet6_sctp arguments: [ // domain: const = 0xa (4 bytes) // type: sctp_socket_type = 0x1 (4 bytes) // proto: const = 0x84 (4 bytes) // ] // returns sock_sctp6 res = syscall(__NR_socket, /*domain=*/0xa, /*type=SOCK_STREAM*/ 1, /*proto=*/0x84); if (res != -1) r[1] = res; break; case 9: // setsockopt$inet_sctp6_SCTP_SOCKOPT_BINDX_ADD arguments: [ // fd: sock_sctp6 (resource) // level: const = 0x84 (4 bytes) // opt: const = 0x64 (4 bytes) // val: ptr[in, array[sockaddr_sctp]] { // array[sockaddr_sctp] { // union sockaddr_sctp { // in: sockaddr_in { // family: const = 0x2 (2 bytes) // port: int16be = 0x4e20 (2 bytes) // addr: union ipv4_addr { // empty: const = 0x0 (4 bytes) // } // pad = 0x0 (8 bytes) // } // } // } // } // len: bytesize = 0x10 (4 bytes) // ] *(uint16_t*)0x80000080 = 2; *(uint16_t*)0x80000082 = htobe16(0x4e20); *(uint32_t*)0x80000084 = htobe32(0); syscall(__NR_setsockopt, /*fd=*/(intptr_t)r[1], /*level=*/0x84, /*opt=*/0x64, /*val=*/0x80000080, /*len=*/0x10); break; case 10: // getsockopt$inet_sctp6_SCTP_SOCKOPT_CONNECTX3 arguments: [ // fd: sock_sctp6 (resource) // level: const = 0x84 (4 bytes) // opt: const = 0x6f (4 bytes) // val: nil // len: nil // ] syscall(__NR_getsockopt, /*fd=*/(intptr_t)r[1], /*level=*/0x84, /*opt=*/0x6f, /*val=*/0, /*len=*/0); break; case 11: // setsockopt$inet_sctp6_SCTP_PEER_ADDR_THLDS arguments: [ // fd: sock_sctp6 (resource) // level: const = 0x84 (4 bytes) // opt: const = 0x85 (4 bytes) // val: ptr[in, sctp_paddrthlds] { // sctp_paddrthlds { // spt_assoc_id: assoc_id (resource) // spt_address: union sockaddr_storage_sctp { // in: sockaddr_storage_in { // addr: sockaddr_in { // family: const = 0x2 (2 bytes) // port: int16be = 0x0 (2 bytes) // addr: union ipv4_addr { // empty: const = 0x0 (4 bytes) // } // pad = 0x0 (8 bytes) // } // pad = 0x0 (112 bytes) // } // } // spt_pathmaxrxt: int16 = 0x7 (2 bytes) // spt_pathpfthld: int16 = 0x23 (2 bytes) // } // } // len: len = 0x90 (4 bytes) // ] *(uint32_t*)0x80000240 = 0; *(uint16_t*)0x80000244 = 2; *(uint16_t*)0x80000246 = htobe16(0); *(uint32_t*)0x80000248 = htobe32(0); *(uint16_t*)0x800002c4 = 7; *(uint16_t*)0x800002c6 = 0x23; syscall(__NR_setsockopt, /*fd=*/(intptr_t)r[1], /*level=*/0x84, /*opt=*/0x85, /*val=*/0x80000240, /*len=*/0x90); break; case 12: // setsockopt$inet_sctp6_SCTP_PEER_ADDR_PARAMS arguments: [ // fd: sock_sctp6 (resource) // level: const = 0x84 (4 bytes) // opt: const = 0x9 (4 bytes) // val: ptr[in, sctp_paddrparams] { // sctp_paddrparams { // spp_assoc_id: assoc_id (resource) // spp_address: union sockaddr_storage_sctp { // in6: sockaddr_storage_in6 { // addr: sockaddr_in6 { // family: const = 0xa (2 bytes) // port: int16be = 0x4e23 (2 bytes) // flow: int32be = 0xe84 (4 bytes) // addr: union ipv6_addr { // empty: ipv6_addr_empty { // a0: buffer: {00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00} (length 0x10) // } // } // scope: int32 = 0x129 (4 bytes) // } // pad = 0x0 (100 bytes) // } // } // spp_hbinterval: int32 = 0x2 (4 bytes) // spp_pathmaxrxt: int16 = 0x2 (2 bytes) // spp_pathmtu: int32 = 0x0 (4 bytes) // spp_sackdelay: int32 = 0x2 (4 bytes) // spp_flags: sctp_spp_flags = 0x5 (4 bytes) // spp_ipv6_flowlabel: int32 = 0x8 (4 bytes) // spp_dscp: int8 = 0x4 (1 bytes) // pad = 0x0 (1 bytes) // } // } // len: len = 0x9c (4 bytes) // ] *(uint32_t*)0x80000840 = 0; *(uint16_t*)0x80000844 = 0xa; *(uint16_t*)0x80000846 = htobe16(0x4e23); *(uint32_t*)0x80000848 = htobe32(0xe84); memset((void*)0x8000084c, 0, 16); *(uint32_t*)0x8000085c = 0x129; *(uint32_t*)0x800008c4 = 2; *(uint16_t*)0x800008c8 = 2; *(uint32_t*)0x800008ca = 0; *(uint32_t*)0x800008ce = 2; *(uint32_t*)0x800008d2 = 5; *(uint32_t*)0x800008d6 = 8; *(uint8_t*)0x800008da = 4; syscall(__NR_setsockopt, /*fd=*/(intptr_t)r[1], /*level=*/0x84, /*opt=*/9, /*val=*/0x80000840, /*len=*/0x9c); break; case 13: // bpf$BPF_BTF_LOAD arguments: [ // cmd: const = 0x12 (4 bytes) // arg: nil // size: len = 0x0 (4 bytes) // ] // returns fd_btf syscall(__NR_bpf, /*cmd=*/0x12, /*arg=*/0, /*size=*/0); break; case 14: // syz_open_dev$dvb_frontend arguments: [ // dev: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 64 76 62 2f 61 64 61 70 74 65 72 23 2f 66 72 // 6f 6e 74 65 6e 64 23 00} (length 0x1c) // } // id: intptr = 0x0 (4 bytes) // flags: open_flags = 0x40402 (4 bytes) // ] // returns fd_dvb_frontend memcpy((void*)0x800002c0, "/dev/dvb/adapter#/frontend#\000", 28); syz_open_dev(/*dev=*/0x800002c0, /*id=*/0, /*flags=O_NOATIME|O_APPEND|O_RDWR*/ 0x40402); break; case 15: // sendto$inet arguments: [ // fd: sock_in (resource) // buf: nil // len: len = 0x0 (4 bytes) // f: send_flags = 0x200007fd (4 bytes) // addr: ptr[in, sockaddr_in] { // sockaddr_in { // family: const = 0x2 (2 bytes) // port: int16be = 0x4e23 (2 bytes) // addr: union ipv4_addr { // local: ipv4_addr_t[const[170, int8]] { // a0: const = 0xac (1 bytes) // a1: const = 0x14 (1 bytes) // a2: const = 0x14 (1 bytes) // a3: const = 0xaa (1 bytes) // } // } // pad = 0x0 (8 bytes) // } // } // addrlen: len = 0x10 (4 bytes) // ] *(uint16_t*)0x80e68000 = 2; *(uint16_t*)0x80e68002 = htobe16(0x4e23); *(uint8_t*)0x80e68004 = 0xac; *(uint8_t*)0x80e68005 = 0x14; *(uint8_t*)0x80e68006 = 0x14; *(uint8_t*)0x80e68007 = 0xaa; syscall( __NR_sendto, /*fd=*/(intptr_t)-1, /*buf=*/0, /*len=*/0, /*f=MSG_FASTOPEN|MSG_PROBE|MSG_OOB|MSG_EOR|MSG_DONTWAIT|MSG_DONTROUTE|0x728*/ 0x200007fd, /*addr=*/0x80e68000, /*addrlen=*/0x10); break; case 16: // sendmsg$TCPDIAG_GETSOCK arguments: [ // fd: sock_diag (resource) // msg: nil // f: send_flags = 0x40000 (4 bytes) // ] syscall(__NR_sendmsg, /*fd=*/(intptr_t)-1, /*msg=*/0, /*f=MSG_BATCH*/ 0x40000); break; } } 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; for (procid = 0; procid < 4; procid++) { if (fork() == 0) { loop(); } } sleep(1000000); return 0; }