// https://syzkaller.appspot.com/bug?id=64ddc3ca5b0483292839d44b37ddb920e05ffd30 // 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 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; for (i = 0; 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); int i; for (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) { int i, call, thread; int collide = 0; again: for (call = 0; call < 1; 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); if (collide && (call % 2) == 0) break; event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); if (!collide) { collide = 1; goto again; } } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { int iter; for (iter = 0;; 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 (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } } } #ifndef __NR_bpf #define __NR_bpf 321 #endif void execute_call(int call) { switch (call) { case 0: *(uint32_t*)0x20000080 = 3; *(uint32_t*)0x20000084 = 3; *(uint64_t*)0x20000088 = 0x20000540; memcpy( (void*)0x20000540, "\x85\x00\x00\x00\x13\x00\x00\x00\x5d\x00\x00\x00\x00\x00\x00\x00\x95" "\x00\x00\x00\x00\x00\x00\x00\x0a\x62\x1c\xf4\x34\xb9\xdb\xaf\xdc\x0a" "\x00\xe9\xbf\xde\x03\xaf\xe9\xc8\x1a\x9c\xf0\x57\x25\xca\xf1\xca\xe6" "\x35\x87\xff\x7f\x00\x00\xcd\xe5\xc0\x19\x08\x00\x96\xe2\xc4\x3f\x6b" "\x8f\xd4\x1b\x7e\x76\x66\xad\xa0\x15\x43\xb7\x18\x5a\x46\x50\x73\x2b" "\x48\x58\x8a\x84\xf8\x34\x7a\x1b\x5e\xfd\x07\x91\x37\x03\x82\x77\xbe" "\xb5\xe0\x61\x5c\x40\xdb\xb7\x00\x5f\xbd\x18\x99\x81\xfe\xb0\xa5\x14" "\xc1\x68\x64\x6e\xa7\x16\xbb\x5b\x94\xbd\x00\x00\x9b\x4f\x22\x38\x9c" "\x75\x3a\xcb\x80\x26\xfd\x80\x8f\x25\xbf\xc9\x1c\x15\xd7\xdc\x2a\xdc" "\xde\xfb\xa0\x86\x89\x42\x57\x7d\x89\x53\x19\x1e\xeb\x79\x37\x98\x29" "\x65\x2b\x10\x73\x7d\x4e\x25\xa2\x26\x95\xdf\x1c\xff\x25\x34\x0a\xf4" "\xfc\x99\x00\x00\x09\x9f\xff\x70\xb2\x4f\x82\x28\xbd\x07\x74\x1c\x71" "\x0e\xbd\xe4\xbf\x17\xdc\x8f\x32\x59\xec\x78\xe5\xb3\x95\x15\x99\x1b" "\x14\x28\xe6\x53\x01\x00\x00\x04\x39\x8f\x65\x00\x00\x00\x00\xa3\x12" "\x48\x71\xb7\x6f\x1b\x2c\x8f\xea\x54\xfb\x37\x26\x85\x03\x10\xbd\x48" "\x03\x55\x92\x1c\x9c\x0c\x12\x0d\x04\x90\x00\xb3\x19\x09\x74\xf0\x6e" "\x53\xeb\x9e\x00\x00\xcc\x4b\xd1\x2f\x5d\x44\xb1\x72\xa4\xa2\xf7\x2b" "\xb3\xfd\x26\x56\x55\x18\x81\xb9\x45\x86\x1d\x8f\x3e\xb0\xa5\x43\xde" "\x4c\x71\xe4\xf3\x06\x76\x7a\x7b\x54\x22\x58\xbe\xcc\x9f\xa5\x98\x7a" "\x70\x00\x00\x9f\xdf\x95\x54\x1c\x41\x48\xa3\xc0\x32\x2a\x5d\x2c\x53" "\x9b\x74\x94\x91\xce\x88\xe4\x7b\x14\x78\x84\xdf\x67\x6e\xb8\xa8\xf4" "\xd8\x44\xff\x1e\x3c\x21\x96\x66\x70\x3f\x30\x2c\x70\xd7\x73\xa5\x9b" "\x60\xcb\x9b\x00\x00\x00\x00\x00\xa3\x9b\xbd\x19\x34\x4c\x7c\x49\x8c" "\xe2\x55\xf7\x9f\xc8\xe7\x7e\x3b\xa3\x93\xf8\x40\x1a\xf9\x07\x7c\xca" "\x6d\x65\xa6\x3d\x47\xb5\x3a\xd6\xf1\xbe\x3a\x10\xc5\x40\xcd\xa8\xdf" "\x0b\x4e\x07\xb1\xd5\x3f\x32\xff\x3e\x2c\xe0\x3d\xd7\x07\x07\xd2\xdd" "\x1d\xb9\x1f\x84\x2e\x36\xa8\xa3\xf7\xf8\x92\x58\x94\x3e\x32\x02\x3d" "\x66\x70\x91\x0d\x1f\xdc\x9d\xb9\xd0\x3f\x84\x9c\xee\xaf\xe8\xbf\x00" "\x67\x7a\xd1\xde\xa3\xe2\xfe\xc1\x3c\xe0\xb9\x24\x89\xcb\xa7\x8d\x55" "\x17\x60\x0a\x95\x18\xb8\x11\xa8\xbf\x9d\xe0\x74\xbf\x1b\xd7\x38\x04" "\x5b\x16\x20\xe8\x3b\x90\x8d\x1e\xce\x91\x77\xc4\xb9\xb6\xf1\x22\x4a" "\x59\x80\x04\xd1\xd9\xf0\x9c\x31\x7f\x7a\x0b\xed\x45\x7e\x82\xb9\x7d" "\x41\xcc\xae\x8c\x8c\x0d\xed\x87\xdf\xe7\x08\xd5\x62\x33\xa9\x5f\x78" "\xe3\xaa\xfa\x65\x51\xeb\x8e\xaf\x62\xae\x89\x17\xa5\x6f\xb6\xa8\x2c" "\xad\xc1\x89\xf5\xe9\x8a\x5a\x30\xdf\x3e\xc4\x4e\x77\x2a\x7b\x35\x6c" "\x4c\xe3\x62\x8e\xc5\x59\xaf\xc7\xb4\xa9\x55\xfd\xc1\x50\x3f\x89\x06" "\x00\xf0\xec\x0b\xd4\x5b\x70\x93\x3c\x32\xb6\x90\x96\x44\xad\x5b\x5f" "\x4c\x20\x20\x6c\xc2\xc7\xb2\xf5\xe6\x42\x70\xd3\x0a\xaf\x2f\xe5\xda" "\xbd\xd4\x63\xb7\x05\x10\x3f\xa6\xec\x82\xd6\xd1\xd8\x7f\xe8\x85\xa4" "\x7d\x2e\x06\x96\x26\x8e\xf0\xa9\x39\xbc\xd4\xb4\xb4\x8e\x80\xfb\xfe" "\xa6\x0a\xb1\xbc\x0d\x6c\x88\x33\xc5\xbb\xbc\xc1\xeb\x12\x7f\xdd\x65" "\x83\x61\x25\x6f\x47\x0b\x37\x01\x9a\xfb\x4c\x00\x41\x19\x32\xe1\xe1" "\x60\x20\x85\xa3\x72\xf7\x6f\x22\x9c\x62\x8c\xb0\x67\x61\x74\xcb\x79" "\x6c\x71\x86\x42\x06\x63\xdc\x2d\x2f\x84\x78\xf7\xbb\xe0\x95\xcb\x5e" "\x47\xc3\xcc\x22\x3e\x11\xd5\x49\x92\x05\x82\x5f\x23\xbf\xe9\x8c\x83" "\x77\x4d\x64\x36\x3b\x78\x16\xbc\xb7\x8f\xae\xcf\x65\xca\xd2\x6a\x69" "\x71\x77\x1e\xdb\xba\xfd\x19\x61\x72\x9f\x1d\x91\x5a\x6c\x48\x76\xa6" "\xbe\xec\x2c\x98\x84\xe3\x63\x4d\x88\x87\x3d\xc0\x83\xe8\x38\xfa", 815); *(uint64_t*)0x20000090 = 0x20000000; memcpy((void*)0x20000000, "GPL\000", 4); *(uint32_t*)0x20000098 = 5; *(uint32_t*)0x2000009c = 0x487; *(uint64_t*)0x200000a0 = 0x2000cf3d; *(uint32_t*)0x200000a8 = 0; *(uint32_t*)0x200000ac = 0; *(uint8_t*)0x200000b0 = 0; *(uint8_t*)0x200000b1 = 0; *(uint8_t*)0x200000b2 = 0; *(uint8_t*)0x200000b3 = 0; *(uint8_t*)0x200000b4 = 0; *(uint8_t*)0x200000b5 = 0; *(uint8_t*)0x200000b6 = 0; *(uint8_t*)0x200000b7 = 0; *(uint8_t*)0x200000b8 = 0; *(uint8_t*)0x200000b9 = 0; *(uint8_t*)0x200000ba = 0; *(uint8_t*)0x200000bb = 0; *(uint8_t*)0x200000bc = 0; *(uint8_t*)0x200000bd = 0; *(uint8_t*)0x200000be = 0; *(uint8_t*)0x200000bf = 0; *(uint32_t*)0x200000c0 = 0; *(uint32_t*)0x200000c4 = 0; *(uint32_t*)0x200000c8 = -1; *(uint32_t*)0x200000cc = 8; *(uint64_t*)0x200000d0 = 0x20000000; *(uint32_t*)0x20000000 = 0; *(uint32_t*)0x20000004 = 0; *(uint32_t*)0x200000d8 = 0; *(uint32_t*)0x200000dc = 0x10; *(uint64_t*)0x200000e0 = 0x20000000; *(uint32_t*)0x20000000 = 0; *(uint32_t*)0x20000004 = 0; *(uint32_t*)0x20000008 = 0; *(uint32_t*)0x2000000c = 0; *(uint32_t*)0x200000e8 = 0; *(uint32_t*)0x200000ec = 0; *(uint32_t*)0x200000f0 = -1; syscall(__NR_bpf, 5ul, 0x20000080ul, 0x48ul); break; } } int main(void) { syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); loop(); return 0; }