// https://syzkaller.appspot.com/bug?id=556e390bf27cfe4ab863fa16072c21c1a0d19227 // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include static uintptr_t syz_open_dev(uintptr_t a0, uintptr_t a1, uintptr_t 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 { char buf[1024]; char* hash; strncpy(buf, (char*)a0, sizeof(buf)); buf[sizeof(buf) - 1] = 0; while ((hash = strchr(buf, '#'))) { *hash = '0' + (char)(a1 % 10); a1 /= 10; } return open(buf, a2, 0); } } static void test(); void loop() { while (1) { test(); } } 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; } } } } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffff}; void execute_call(int call) { long res; switch (call) { case 0: memcpy((void*)0x20000080, "/dev/vcsa#", 11); res = syz_open_dev(0x20000080, 4, 0x200); if (res != -1) r[0] = res; break; case 1: *(uint16_t*)0x20000140 = 0xa; *(uint16_t*)0x20000142 = htobe16(0x4e22); *(uint32_t*)0x20000144 = 4; *(uint8_t*)0x20000148 = 0xfe; *(uint8_t*)0x20000149 = 0x80; *(uint8_t*)0x2000014a = 0; *(uint8_t*)0x2000014b = 0; *(uint8_t*)0x2000014c = 0; *(uint8_t*)0x2000014d = 0; *(uint8_t*)0x2000014e = 0; *(uint8_t*)0x2000014f = 0; *(uint8_t*)0x20000150 = 0; *(uint8_t*)0x20000151 = 0; *(uint8_t*)0x20000152 = 0; *(uint8_t*)0x20000153 = 0; *(uint8_t*)0x20000154 = 0; *(uint8_t*)0x20000155 = 0; *(uint8_t*)0x20000156 = 0; *(uint8_t*)0x20000157 = 0xaa; *(uint32_t*)0x20000158 = 3; *(uint16_t*)0x2000015c = 2; *(uint16_t*)0x2000015e = htobe16(0x4e23); *(uint32_t*)0x20000160 = htobe32(0); *(uint8_t*)0x20000164 = 0; *(uint8_t*)0x20000165 = 0; *(uint8_t*)0x20000166 = 0; *(uint8_t*)0x20000167 = 0; *(uint8_t*)0x20000168 = 0; *(uint8_t*)0x20000169 = 0; *(uint8_t*)0x2000016a = 0; *(uint8_t*)0x2000016b = 0; *(uint16_t*)0x2000016c = 2; *(uint16_t*)0x2000016e = htobe16(0x4e20); *(uint8_t*)0x20000170 = 0xac; *(uint8_t*)0x20000171 = 0x14; *(uint8_t*)0x20000172 = 0x14; *(uint8_t*)0x20000173 = 0xaa; *(uint8_t*)0x20000174 = 0; *(uint8_t*)0x20000175 = 0; *(uint8_t*)0x20000176 = 0; *(uint8_t*)0x20000177 = 0; *(uint8_t*)0x20000178 = 0; *(uint8_t*)0x20000179 = 0; *(uint8_t*)0x2000017a = 0; *(uint8_t*)0x2000017b = 0; *(uint16_t*)0x2000017c = 2; *(uint16_t*)0x2000017e = htobe16(0x4e23); *(uint32_t*)0x20000180 = htobe32(-1); *(uint8_t*)0x20000184 = 0; *(uint8_t*)0x20000185 = 0; *(uint8_t*)0x20000186 = 0; *(uint8_t*)0x20000187 = 0; *(uint8_t*)0x20000188 = 0; *(uint8_t*)0x20000189 = 0; *(uint8_t*)0x2000018a = 0; *(uint8_t*)0x2000018b = 0; *(uint16_t*)0x2000018c = 2; *(uint16_t*)0x2000018e = htobe16(0x4e23); *(uint8_t*)0x20000190 = 0xac; *(uint8_t*)0x20000191 = 0x14; *(uint8_t*)0x20000192 = 0x14; *(uint8_t*)0x20000193 = 0x13; *(uint8_t*)0x20000194 = 0; *(uint8_t*)0x20000195 = 0; *(uint8_t*)0x20000196 = 0; *(uint8_t*)0x20000197 = 0; *(uint8_t*)0x20000198 = 0; *(uint8_t*)0x20000199 = 0; *(uint8_t*)0x2000019a = 0; *(uint8_t*)0x2000019b = 0; *(uint16_t*)0x2000019c = 2; *(uint16_t*)0x2000019e = htobe16(0x4e22); *(uint8_t*)0x200001a0 = 0xac; *(uint8_t*)0x200001a1 = 0x14; *(uint8_t*)0x200001a2 = 0x14; *(uint8_t*)0x200001a3 = 0xbb; *(uint8_t*)0x200001a4 = 0; *(uint8_t*)0x200001a5 = 0; *(uint8_t*)0x200001a6 = 0; *(uint8_t*)0x200001a7 = 0; *(uint8_t*)0x200001a8 = 0; *(uint8_t*)0x200001a9 = 0; *(uint8_t*)0x200001aa = 0; *(uint8_t*)0x200001ab = 0; *(uint16_t*)0x200001ac = 2; *(uint16_t*)0x200001ae = htobe16(0x4e23); *(uint32_t*)0x200001b0 = htobe32(0); *(uint8_t*)0x200001b4 = 0; *(uint8_t*)0x200001b5 = 0; *(uint8_t*)0x200001b6 = 0; *(uint8_t*)0x200001b7 = 0; *(uint8_t*)0x200001b8 = 0; *(uint8_t*)0x200001b9 = 0; *(uint8_t*)0x200001ba = 0; *(uint8_t*)0x200001bb = 0; *(uint16_t*)0x200001bc = 0xa; *(uint16_t*)0x200001be = htobe16(0x4e24); *(uint32_t*)0x200001c0 = 0x3f; *(uint8_t*)0x200001c4 = 0xfe; *(uint8_t*)0x200001c5 = 0x80; *(uint8_t*)0x200001c6 = 0; *(uint8_t*)0x200001c7 = 0; *(uint8_t*)0x200001c8 = 0; *(uint8_t*)0x200001c9 = 0; *(uint8_t*)0x200001ca = 0; *(uint8_t*)0x200001cb = 0; *(uint8_t*)0x200001cc = 0; *(uint8_t*)0x200001cd = 0; *(uint8_t*)0x200001ce = 0; *(uint8_t*)0x200001cf = 0; *(uint8_t*)0x200001d0 = 0; *(uint8_t*)0x200001d1 = 0; *(uint8_t*)0x200001d2 = 0; *(uint8_t*)0x200001d3 = 0xbb; *(uint32_t*)0x200001d4 = 0x8e; *(uint16_t*)0x200001d8 = 0xa; *(uint16_t*)0x200001da = htobe16(0x4e20); *(uint32_t*)0x200001dc = 1; *(uint8_t*)0x200001e0 = 0xfe; *(uint8_t*)0x200001e1 = 0x80; *(uint8_t*)0x200001e2 = 0; *(uint8_t*)0x200001e3 = 0; *(uint8_t*)0x200001e4 = 0; *(uint8_t*)0x200001e5 = 0; *(uint8_t*)0x200001e6 = 0; *(uint8_t*)0x200001e7 = 0; *(uint8_t*)0x200001e8 = 0; *(uint8_t*)0x200001e9 = 0; *(uint8_t*)0x200001ea = 0; *(uint8_t*)0x200001eb = 0; *(uint8_t*)0x200001ec = 0; *(uint8_t*)0x200001ed = 0; *(uint8_t*)0x200001ee = 0; *(uint8_t*)0x200001ef = 0xf; *(uint32_t*)0x200001f0 = 6; *(uint16_t*)0x200001f4 = 0xa; *(uint16_t*)0x200001f6 = htobe16(0x4e21); *(uint32_t*)0x200001f8 = 0xa6; *(uint8_t*)0x200001fc = 0xfe; *(uint8_t*)0x200001fd = 0x80; *(uint8_t*)0x200001fe = 0; *(uint8_t*)0x200001ff = 0; *(uint8_t*)0x20000200 = 0; *(uint8_t*)0x20000201 = 0; *(uint8_t*)0x20000202 = 0; *(uint8_t*)0x20000203 = 0; *(uint8_t*)0x20000204 = 0; *(uint8_t*)0x20000205 = 0; *(uint8_t*)0x20000206 = 0; *(uint8_t*)0x20000207 = 0; *(uint8_t*)0x20000208 = 0; *(uint8_t*)0x20000209 = 0; *(uint8_t*)0x2000020a = 0; *(uint8_t*)0x2000020b = 0xbb; *(uint32_t*)0x2000020c = 5; syscall(__NR_setsockopt, r[0], 0x84, 0x65, 0x20000140, 0xd0); break; case 2: memcpy((void*)0x20000100, "/dev/infiniband/rdma_cm", 24); res = syscall(__NR_openat, 0xffffffffffffff9c, 0x20000100, 2, 0); if (res != -1) r[1] = res; break; case 3: *(uint32_t*)0x20004140 = 0; *(uint16_t*)0x20004144 = 0x18; *(uint16_t*)0x20004146 = 0xfa00; *(uint64_t*)0x20004148 = 0; *(uint64_t*)0x20004150 = 0x20004100; *(uint16_t*)0x20004158 = 0x13f; *(uint8_t*)0x2000415a = 0; *(uint8_t*)0x2000415b = 0; *(uint8_t*)0x2000415c = 0; *(uint8_t*)0x2000415d = 0; *(uint8_t*)0x2000415e = 0; *(uint8_t*)0x2000415f = 0; res = syscall(__NR_write, r[1], 0x20004140, 0x20); if (res != -1) r[2] = *(uint32_t*)0x20004100; break; case 4: *(uint32_t*)0x20000040 = 1; *(uint16_t*)0x20000044 = 0x10; *(uint16_t*)0x20000046 = 0xfa00; *(uint64_t*)0x20000048 = 0x20000000; *(uint32_t*)0x20000050 = r[2]; *(uint32_t*)0x20000054 = 0; syscall(__NR_write, r[1], 0x20000040, 0x18); break; } } void test() { execute(5); collide = 1; execute(5); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); for (;;) { loop(); } }