// https://syzkaller.appspot.com/bug?id=baff5bfd0c148e6a6552e815fba942c1ac5e61b0 // 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 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 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 < 7; 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$auto_kernfs_file_fops_kernfs_internal arguments: [ // fd: const = 0xffffffffffffff9c (8 bytes) // file: ptr[in, buffer] { // buffer: {2f 73 79 73 2f 64 65 76 69 63 65 73 2f 73 79 73 74 65 6d 2f // 63 70 75 2f 63 70 75 31 2f 6f 6e 6c 69 6e 65 00} (length 0x24) // } // flags: open_flags = 0x62 (4 bytes) // mode: const = 0x0 (2 bytes) // ] // returns fd_kernfs_file_fops_kernfs_internal memcpy((void*)0x200000000080, "/sys/devices/system/cpu/cpu1/online\000", 36); res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x200000000080ul, /*flags=O_CREAT|O_RDWR|0x20*/ 0x62, /*mode=*/0); if (res != -1) r[0] = res; break; case 1: // write$auto arguments: [ // fd: fd (resource) // buf: ptr[in, buffer] { // buffer: {30 00 a6 cc 0d 91 51 55 9d 49 da 1b ad b1 9e c8 54 74 a8 94 // 9c 8a e2 c7 63 4f 4d b6 a3 2c 21 6f 9e b0 ad 54 fb 52 a1 59 94 56 5b // 38 04 63 df 3a 5d d9 94 f8 46 bb a2 bb 3e ad 65 18 bd e2 1c 89 4f 4f // 5d 65 5b da ac dd 1a dd dd b9 6f 1a ab d5 ef 60 d8 9c f7 3f 3a 1a c6 // 32 91 31 65 fd 15 88 0f 9a d5 a7 14 08 7d 3b ab 74 d1 61 6b e5 98 ea // e3 7d 10 ab 0c 5f 19 9b 11 b2 35 56 55 4b 93 cd 64 17 e4 ac 41 a5 5b // 08 b8 3b 02 74 63 66 06 fb 44 91 ca 47 da 61 3a 6b 5b 72 06 eb f0 c4 // cb 10 ae c8 e9 75 9f de 4b a5 8e ff 7f d0 55 56 11 cb dd 81 be de 0c // 2f 06 28 1d a5 c5 9b b2 96 05 60 e7 d5 59 07 c1 e9 28 95 df 48 f4 0b // f3 43 52 6e 7a c2 13 3c f0 0b 1f 14 f3 d0 f2 d1 4c 21 81 ea 83 a0 0d // 7c 25 bf 02 74 72 67 9a e7 00 85 5a 06 3f 12 98 0f 29 07 f4 aa 05 c0 // a0 72 d2 85 8d 48 d0 3e ca fc 35 01 95 4f 34 ca 95 1d 83 ec 0a 44 8e // fb ce d1 77 15 3a e9 81 2f 42 23 c6 a1 fa 2d 1b 8c 72 92 6e 4d a1 3b // e4 70 64 24 d7 1b 0b 82 0d 0c d0 48 71 d9 0d 88 23 89 8d cd 1e 87 4e // ee 4f 8d 4f e9 fc 91 a1 a8 48 52 2b 07 b7 52 09 0a 2b 7f d5 48 90 47 // 3d 9a 0d b1 30 17 6e 1b f8 0b 11 0b bb c8 5e a4 e2 05 91 7c 12 33 c3 // 3a fd ee 04 61 c8 12 ce a2 12 cb 8c 87 66 eb 47 51 e9 96 d5 45 13 61 // b7 05 37 3c 26 e0 94 a7 fb 9d 3b fa b1 1b 34 61 2c 27 b2 59 6d e1 3a // bf 8c 73 06 a3 75 8d 21 0a 80 2d 9a bb 3b f4 f3 e1 97 fc 38 ff a7 5c // 8b f9 95 10 24 ef 1a 20 23 62 fb fe e9 06 66 4b 30 dd 84 54 2c fa b5 // 00 83 64 bb 61 d7 0a 92 6c df 41 4e 9d cb 96 c7 e8 e6 8b 43 eb c7 45 // 5a c8 1a 81 6e 66 09 5a 2d 73 5a 13 6e ec a9 bf d0 24 b9 d8 00 00 00 // 00 00 00 00} (length 0x1fb) // } // count: intptr = 0x5 (8 bytes) // ] memcpy((void*)0x2000000002c0, "0\000\246\314\r\221QU\235I\332\033\255\261\236\310Tt\250\224\234" "\212\342\307cOM\266\243,!o\236\260\255T\373R\241Y\224V[8\004c\337:]" "\331\224\370F\273\242\273>\255e\030\275\342\034\211OO]e[" "\332\254\335\032\335\335\271o\032\253\325\357`\330\234\367?:" "\032\3062\2211e\375\025\210\017\232\325\247\024\b};" "\253t\321ak\345\230\352\343}\020\253\f_" "\031\233\021\2625VUK\223\315d\027\344\254A\245[\b\270;" "\002tcf\006\373D\221\312G\332a:k[" "r\006\353\360\304\313\020\256\310\351u\237\336K\245\216\377\177\320" "UV\021\313\335\201\276\336\f/" "\006(\035\245\305\233\262\226\005`\347\325Y\a\301\351(" "\225\337H\364\v\363CRnz\302\023<\360\v\037\024\363\320\362\321L!" "\201\352\203\240\r|%\277\002trg\232\347\000\205Z\006?\022\230\017)" "\a\364\252\005\300\240r\322\205\215H\320>" "\312\3745\001\225O4\312\225\035\203\354\nD\216\373\316\321w\025:" "\351\201/" "B#\306\241\372-\033\214r\222nM\241;\344pd$" "\327\033\v\202\r\f\320Hq\331\r\210#" "\211\215\315\036\207N\356O\215O\351\374\221\241\250HR+\a\267R\t\n+" "\177\325H\220G=\232\r\2610\027n\033\370\v\021\v\273\310^" "\244\342\005\221|\0223\303:" "\375\356\004a\310\022\316\242\022\313\214\207f\353GQ\351\226\325E" "\023a\267\0057<&\340\224\247\373\235;\372\261\0334a,\'\262Ym\341:" "\277\214s\006\243u\215!\n\200-\232\273;" "\364\363\341\227\3748\377\247\\\213\371\225\020$\357\032 " "#b\373\376\351\006fK0\335\204T," "\372\265\000\203d\273a\327\n\222l\337AN\235\313\226\307\350\346\213" "C\353\307EZ\310\032\201nf\tZ-sZ\023n\354\251\277\320$" "\271\330\000\000\000\000\000\000\000", 507); syscall(__NR_write, /*fd=*/r[0], /*buf=*/0x2000000002c0ul, /*count=*/5ul); break; case 2: // mmap$auto arguments: [ // addr: intptr = 0x0 (8 bytes) // len: intptr = 0x2020009 (8 bytes) // prot: intptr = 0x3 (8 bytes) // flags: intptr = 0xeb1 (8 bytes) // fd: fd (resource) // off: intptr = 0x8000 (8 bytes) // ] syscall(__NR_mmap, /*addr=*/0ul, /*len=*/0x2020009ul, /*prot=*/3ul, /*flags=*/0xeb1ul, /*fd=*/0xfffffffa, /*off=*/0x8000ul); break; case 3: // openat$auto_proc_oom_adj_operations_base arguments: [ // fd: const = 0xffffffffffffff9c (8 bytes) // file: ptr[in, buffer] { // buffer: {2f 70 72 6f 63 2f 73 65 6c 66 2f 6f 6f 6d 5f 61 64 6a 00} // (length 0x13) // } // flags: open_flags = 0x48402 (4 bytes) // mode: const = 0x0 (2 bytes) // ] // returns fd_proc_oom_adj_operations_base memcpy((void*)0x200000000000, "/proc/self/oom_adj\000", 19); res = syscall( __NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x200000000000ul, /*flags=O_NOATIME|O_LARGEFILE|O_APPEND|O_RDWR*/ 0x48402, /*mode=*/0); if (res != -1) r[1] = res; break; case 4: // read$auto arguments: [ // fd: fd (resource) // buf: nil // count: intptr = 0x1f40 (8 bytes) // ] syscall(__NR_read, /*fd=*/r[1], /*buf=*/0ul, /*count=*/0x1f40ul); break; case 5: // writev$auto arguments: [ // fd: fd (resource) // vec: ptr[in, iovec$auto] { // iovec$auto { // iov_base: nil // iov_len: intptr = 0x7111 (8 bytes) // } // } // vlen: intptr = 0x8 (8 bytes) // ] *(uint64_t*)0x200000000100 = 0; *(uint64_t*)0x200000000108 = 0x7111; syscall(__NR_writev, /*fd=*/3, /*vec=*/0x200000000100ul, /*vlen=*/8ul); break; case 6: // prctl$auto arguments: [ // option: int32 = 0x3e (4 bytes) // arg2: intptr = 0x1 (8 bytes) // arg3: pid (resource) // arg4: intptr = 0x1 (8 bytes) // arg5: intptr = 0x0 (8 bytes) // ] // returns fd syscall(__NR_prctl, /*option=*/0x3e, /*arg2=*/1ul, /*arg3=*/0, /*arg4=*/1ul, /*arg5=*/0ul); break; } } 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; for (procid = 0; procid < 4; procid++) { if (fork() == 0) { loop(); } } sleep(1000000); return 0; }