// https://syzkaller.appspot.com/bug?id=2bf7b7983c2398ec6f0c4c6c87cb50223e8873f8 // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include __attribute__((noreturn)) static void doexit(int status) { volatile unsigned i; syscall(__NR_exit_group, status); for (i = 0;; i++) { } } #include #include const int kFailStatus = 67; const int kRetryStatus = 69; static void fail(const char* msg, ...) { int e = errno; va_list args; va_start(args, msg); vfprintf(stderr, msg, args); va_end(args); fprintf(stderr, " (errno %d)\n", e); doexit((e == ENOMEM || e == EAGAIN) ? kRetryStatus : kFailStatus); } static uint64_t current_time_ms() { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) fail("clock_gettime failed"); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void test(); void loop() { int iter; for (iter = 0;; iter++) { int pid = fork(); if (pid < 0) fail("loop fork failed"); if (pid == 0) { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); test(); doexit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { int res = waitpid(-1, &status, __WALL | WNOHANG); if (res == pid) break; usleep(1000); if (current_time_ms() - start > 5 * 1000) { kill(-pid, SIGKILL); kill(pid, SIGKILL); while (waitpid(-1, &status, __WALL) != pid) { } break; } } } } struct thread_t { int created, running, call; pthread_t th; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static int collide; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { while (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &th->running, FUTEX_WAIT, 0, 0); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); __atomic_store_n(&th->running, 0, __ATOMIC_RELEASE); syscall(SYS_futex, &th->running, FUTEX_WAKE); } return 0; } static void execute(int num_calls) { int call, thread; running = 0; for (call = 0; call < num_calls; call++) { for (thread = 0; thread < sizeof(threads) / sizeof(threads[0]); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); pthread_create(&th->th, &attr, thr, th); } if (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) { th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); __atomic_store_n(&th->running, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &th->running, FUTEX_WAKE); if (collide && call % 2) break; struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = 20 * 1000 * 1000; syscall(SYS_futex, &th->running, FUTEX_WAIT, 1, &ts); if (running) usleep((call == num_calls - 1) ? 10000 : 1000); break; } } } } long r[4]; void execute_call(int call) { switch (call) { case 0: syscall(__NR_mmap, 0x20000000, 0xfff000, 3, 0x32, -1, 0); break; case 1: memcpy((void*)0x2052dff7, "/dev/kvm", 9); r[0] = syscall(__NR_openat, 0xffffffffffffff9c, 0x2052dff7, 0, 0); break; case 2: r[1] = syscall(__NR_ioctl, r[0], 0xae01, 0); break; case 3: syscall(__NR_ioctl, r[1], 0xae47, 0); break; case 4: if (syscall(__NR_socketpair, 2, 0, 0, 0x202d7000) != -1) r[2] = *(uint32_t*)0x202d7004; break; case 5: *(uint32_t*)0x20473000 = 0x79; *(uint32_t*)0x20473004 = 0; *(uint64_t*)0x20473008 = 0; *(uint64_t*)0x20473010 = 0; *(uint64_t*)0x20473018 = 0; *(uint64_t*)0x20473020 = 0; *(uint8_t*)0x20473028 = 0; *(uint8_t*)0x20473029 = 0; *(uint8_t*)0x2047302a = 0; *(uint8_t*)0x2047302b = 0; *(uint8_t*)0x2047302c = 0; *(uint8_t*)0x2047302d = 0; *(uint8_t*)0x2047302e = 0; *(uint8_t*)0x2047302f = 0; *(uint8_t*)0x20473030 = 0; *(uint8_t*)0x20473031 = 0; *(uint8_t*)0x20473032 = 0; *(uint8_t*)0x20473033 = 0; *(uint8_t*)0x20473034 = 0; *(uint8_t*)0x20473035 = 0; *(uint8_t*)0x20473036 = 0; *(uint8_t*)0x20473037 = 0; *(uint8_t*)0x20473038 = 0; *(uint8_t*)0x20473039 = 0; *(uint8_t*)0x2047303a = 0; *(uint8_t*)0x2047303b = 0; *(uint8_t*)0x2047303c = 0; *(uint8_t*)0x2047303d = 0; *(uint8_t*)0x2047303e = 0; *(uint8_t*)0x2047303f = 0; *(uint8_t*)0x20473040 = 0; *(uint8_t*)0x20473041 = 0; *(uint8_t*)0x20473042 = 0; *(uint8_t*)0x20473043 = 0; *(uint8_t*)0x20473044 = 0; *(uint8_t*)0x20473045 = 0; *(uint8_t*)0x20473046 = 0; *(uint8_t*)0x20473047 = 0; *(uint8_t*)0x20473048 = 0; *(uint8_t*)0x20473049 = 0; *(uint8_t*)0x2047304a = 0; *(uint8_t*)0x2047304b = 0; *(uint8_t*)0x2047304c = 0; *(uint8_t*)0x2047304d = 0; *(uint8_t*)0x2047304e = 0; *(uint8_t*)0x2047304f = 0; *(uint8_t*)0x20473050 = 0; *(uint8_t*)0x20473051 = 0; *(uint8_t*)0x20473052 = 0; *(uint8_t*)0x20473053 = 0; *(uint8_t*)0x20473054 = 0; *(uint8_t*)0x20473055 = 0; *(uint8_t*)0x20473056 = 0; *(uint8_t*)0x20473057 = 0; *(uint8_t*)0x20473058 = 0; *(uint8_t*)0x20473059 = 0; *(uint8_t*)0x2047305a = 0; *(uint8_t*)0x2047305b = 0; *(uint8_t*)0x2047305c = 0; *(uint8_t*)0x2047305d = 0; *(uint8_t*)0x2047305e = 0; *(uint8_t*)0x2047305f = 0; *(uint8_t*)0x20473060 = 0; *(uint8_t*)0x20473061 = 0; *(uint8_t*)0x20473062 = 0; *(uint8_t*)0x20473063 = 0; *(uint8_t*)0x20473064 = 0; *(uint8_t*)0x20473065 = 0; *(uint8_t*)0x20473066 = 0; *(uint8_t*)0x20473067 = 0; syscall(__NR_ioctl, r[1], 0x4068aea3, 0x20473000); break; case 6: *(uint32_t*)0x20545000 = r[0]; *(uint16_t*)0x20545004 = 0xc240; *(uint16_t*)0x20545006 = 0; *(uint32_t*)0x20545008 = r[0]; *(uint16_t*)0x2054500c = 0x2000; *(uint16_t*)0x2054500e = 0; *(uint32_t*)0x20545010 = r[2]; *(uint16_t*)0x20545014 = 0x10; *(uint16_t*)0x20545016 = 0; *(uint32_t*)0x20545018 = r[2]; *(uint16_t*)0x2054501c = 2; *(uint16_t*)0x2054501e = 0; *(uint32_t*)0x20545020 = r[1]; *(uint16_t*)0x20545024 = 0x6001; *(uint16_t*)0x20545026 = 0; syscall(__NR_poll, 0x20545000, 5, 0x23a); break; case 7: r[3] = syscall(__NR_ioctl, r[1], 0xae41, 0); break; case 8: *(uint64_t*)0x205f6000 = 0xffd; syscall(__NR_ioctl, r[3], 0x4008ae93, 0x205f6000); break; case 9: memcpy( (void*)0x2057b000, "\xb3\xa6\x40\x56\x4b\x6b\x3c\x4a\x55\x2c\x1b\xf7\xa0\x97\xe2\x59\x9a" "\x7d\xce\xd9\x2e\xdc\x20\xee\xf8\x03\xca\x9a\xb9\xaa\x95\xad\xa7\x6e" "\xa3\xbe\x32\xc7\x3b\x52\xbc\x39\x10\xe9\x0c\x3c\xd9\xb0\x8f\x9f\x0c" "\x66\xc5\x97\x08\xca\x65\x7f\x5b\x2c\xd8\x5a\x00\x9f\x83\x4c\xa0\x27" "\x73\x19\xbe\xcd\xe7\xfa\x12\x82\x4b\x8c\x67\xf2\x3e\x2e\x4b\x5c\x9a" "\x5d\x70\xa0\x89\xb1\x9a\xdb\x31\x9c\x21\x3e\xca\x82\xfd\x2a\x3f\xba" "\x9e\xcd\x74\x0e\x45\x04\x8c\x23\xef\xba\xee\x09\x2f\x30\x20\x5a\x1c" "\x24\xc0\xf4\x04\x8b\xf5\xa4\xb0\xc4\xf3\xf1\x27\x87\xf1\x4e\x6a\xc5" "\x56\xaa\x27\x20\x2e\xb1\xfc\x1b\x53\x62\x90\x37\xa6\x89\x1e\x0c\x4a" "\xdb\xc0\x15\x7a\x66\xb4\xee\x4b\x05\x07\x87\x0f\x2d\x43\xb2\x2a\x43" "\x37\x11\xd0\x09\x8e\x74\x19\x6c\x34\x10\x41\x73\x32\xed\x4b\x74\x25" "\x2b\x0b\x35\xe0\xf9\x93\xc5\x0d\x1a\xc5\x61\xc8\x86\x2c\xa2\xff\x90" "\x21\xf0\x14\xd5\xa1\x7a\x6d\xa1\xa8\x5f\x43\xb1\x3b\x54\xd2\x09\x68" "\xd3\x58\x9c\x70\x23\xc5\xe5\x2e\xfc\xe2\x67\xbb\x40\x35\xcc\xfc\xaf" "\x06\xd8\xe1\x23\x8a\x43\x21\x4b\x2c\x01\x00\x01\x00\x8e\xf5\xd9\xad" "\xeb\xe5\x9d\x34\x4b\x7d\xdb\xc7\x5a\x52\x33\xf7\xe3\xbf\x29\x43\x8b" "\x9d\xc6\xb4\x29\x71\xb0\x8f\x7c\x31\x0c\xb7\x89\x30\x25\xc3\x77\xcd" "\x55\x2e\x24\x6a\xe7\xca\x3e\x3c\x3e\x2c\x57\x96\x15\x00\x01\x0d\xca" "\x5c\x05\x0f\x70\xff\xa0\xcd\x81\x6a\xaa\xc8\xff\xe4\x3a\xde\x51\xf8" "\xb2\x28\xf1\x10\x40\xbb\x05\x6a\x4d\xc0\x9e\x63\x6e\xa6\x3f\x6e\x46" "\xb9\x60\x35\x55\x53\x96\x9e\xe6\x22\x99\xd3\x91\xea\x90\x48\x4d\x7f" "\xc9\x01\x65\x9a\xb8\xca\x00\xe1\xff\xff\xff\xff\xff\xff\xff\x00\x00" "\x00\xe8\x9f\xb7\xba\xd8\x67\x91\x89\x1f\xc5\xeb\x42\x6f\xeb\x1d\x03" "\xd0\x65\x59\x8e\x98\x43\xf6\xa6\x41\xe5\x00\x06\xeb\xae\xa5\xe0\x0d" "\x55\x4e\xa1\x1b\xd1\x7a\x55\x90\x3b\x55\xa5\xbd\xdc\x1c\x41\x0d\x8f" "\xce\x7f\xbc\xf9\x31\xaf\x94\xb0\x7d\x10\x51\xc0\x7b\x63\xfb\x26\x30" "\x8a\x45\x13\x8f\x8f\x61\x71\xea\x68\xba\x25\x03\xa4\x6e\xb6\x81\x07" "\x8c\xa5\xbc\x21\x2a\xc0\x3d\x2a\x19\xae\xc1\x37\x04\x8a\xc9\xfd\xb5" "\x9b\xec\xc8\x6a\x4d\x32\x7a\x65\x8d\x6d\xb1\x95\x41\x5b\x98\xbc\x9e" "\x40\xf3\x1f\x4a\x29\x98\xf7\x0e\xfb\xf5\xb9\x36\x23\xbf\xb6\x8c\x88" "\x0f\x29\x5d\x60\xc7\x60\xf0\x14\xbd\x00\x00\x00\xff\x48\x82\x0d\x62" "\x44\x0a\x63\x72\x0f\x84\x39\x8b\x0e\xcd\x36\x6e\x33\x78\x6c\xb7\x03" "\x45\x99\x9f\x59\x2e\x25\xf9\xa6\xdd\xd1\xf3\x58\x82\xa9\x6c\x51\x17" "\x9a\x30\xa7\x98\x5a\xc3\xef\x08\x00\xb1\x9a\xbc\x81\x2d\x75\xfe\x2d" "\x1b\x72\xd4\xc3\x7b\x0b\x73\x11\x01\xb0\xe3\x6c\x55\x7b\x50\x36\xcb" "\x0f\x55\xf6\xcb\x8b\xde\x2d\xbd\x5e\xdd\xbb\x1a\x16\x15\xe7\x96\xba" "\xb2\xf5\xab\x8a\x81\x6f\x8e\x3f\x7d\x05\xf3\x6e\x0e\xb8\x6a\x76\x2a" "\x9f\xb8\xf9\x68\x64\x52\x83\x45\x79\x21\x60\x48\x2c\x4c\x3d\x63\xb5" "\x35\xc4\x9c\xb0\xa1\xc7\x15\x41\x42\x19\xbf\xd1\x52\x18\x06\xf4\xe8" "\x69\x4f\xd3\x86\x67\xf3\x43\x1c\x29\x8d\x85\x59\xbc\x04\x6d\x73\xc7" "\x07\x67\xd0\xed\xa8\x39\xfd\xff\xff\xff\xff\xff\xff\xfe\xff\xcb\xbe" "\x29\x00\x00\x00\x08\x70\x79\x16\xae\xa7\x06\x5c\x6c\x48\xd8\x0a\x6b" "\x34\x17\x69\x0f\x4a\x7d\x6b\xa1\x1a\x88\x15\x42\x27\x64\x62\xbb\x0d" "\xfd\x30\x56\x81\x15\xcd\x0e\xc4\x1c\x41\x18\x87\x8d\xae\xb1\xea\x2c" "\x67\xf2\x07\x1b\xcc\xde\x6a\x20\xef\x04\x7a\xfb\x70\x02\x71\x13\x23" "\x52\x2e\x3e\x24\x51\x94\x87\x60\x51\xae\x20\xf6\x6d\x35\x90\xbf\x1b" "\xfc\x28\x96\x91\x71\x08\xd4\x22\x02\x09\xfd\x33\xf3\xda\x7e\x62\x07" "\xf6\x0a\x18\x7e\x38\x70\x4c\xa0\xb8\xb0\xcc\xc6\x90\x23\x8d\xfb\x59" "\x7e\xb3\x3a\x48\xb9\x72\xd6\x35\xfa\xb0\xdb\x5b\x2c\xda\x45\xdd\x74" "\x12\x7f\x5f\xa3\x7a\xc2\x7e\x30\xa6\x71\xae\x4a\xc3\x59\x0e\x99\x88" "\x71\x3d\xbd\x00\x13\x75\xdc\x0b\x9f\xf6\x89\x90\x57\x3b\x19\x85\x82" "\x48\xea\x1d\xf6\x1d\xbf\xd5\x10\x7c\x87\x21\x23\xb7\xdd\xc9\x11\x07" "\x6a\x41\xec\xdc\x97\x39\x08\xbf\x65\x41\x7d\xc1\xc3\x3c\xdc\xd4\x5d" "\xf4\xdd\xf4\x38\x90\xae\xe9\x99\xf8\xbb\x2f\x2a\x25\x31\x5c\xad\x61" "\x55\x02\x46\x06\x5a\x69\xc6\xf9\x7b\x21\x6a\xb7\x84\x7b\x0a\x4c\x34" "\xa3\x6e\xba\x20\x46\x06\x57\xb1\xc3\x69\xfc\xcc\x12\x1d\x3a\xc2\xc7" "\x5e\xa6\x4d\xf3\x87\x7b\xca\x56\x24\x08\xd4\x31\x09\x1c\xb1\x57\x83" "\x89\xc4\x8d\x25\x12\xf5\xf8\x08\x20\x4a\x21\x32\x64\xcf\xe8\x90\xc4" "\x43\x9c\xa9\xf3\x2e\x0f\x69\xad\x10\x06\xa6\x18\x12\x8d\xbd\xf1\x54" "\x50\x79\xd7\x97\x66\x47\x65\xf9\x72\xc2\x21\x26\xdc\xdc\x50\x8d\xbb" "\xa6\x01\x00\x43", 1024); syscall(__NR_ioctl, r[3], 0x4400ae8f, 0x2057b000); break; case 10: syscall(__NR_ioctl, r[3], 0xae80, 0); break; } } void test() { memset(r, -1, sizeof(r)); execute(11); collide = 1; execute(11); } int main() { for (;;) { loop(); } }