// https://syzkaller.appspot.com/bug?id=5735d842f7ea3ed9220aca64952ac4aba7ba741c // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #define BITMASK_LEN(type, bf_len) (type)((1ull << (bf_len)) - 1) #define BITMASK_LEN_OFF(type, bf_off, bf_len) \ (type)(BITMASK_LEN(type, (bf_len)) << (bf_off)) #define STORE_BY_BITMASK(type, addr, val, bf_off, bf_len) \ if ((bf_off) == 0 && (bf_len) == 0) { \ *(type*)(addr) = (type)(val); \ } else { \ type new_val = *(type*)(addr); \ new_val &= ~BITMASK_LEN_OFF(type, (bf_off), (bf_len)); \ new_val |= ((type)(val)&BITMASK_LEN(type, (bf_len))) << (bf_off); \ *(type*)(addr) = new_val; \ } struct csum_inet { uint32_t acc; }; static void csum_inet_init(struct csum_inet* csum) { csum->acc = 0; } static void csum_inet_update(struct csum_inet* csum, const uint8_t* data, size_t length) { if (length == 0) return; size_t i; for (i = 0; i < length - 1; i += 2) csum->acc += *(uint16_t*)&data[i]; if (length & 1) csum->acc += (uint16_t)data[length - 1]; while (csum->acc > 0xffff) csum->acc = (csum->acc & 0xffff) + (csum->acc >> 16); } static uint16_t csum_inet_digest(struct csum_inet* csum) { return ~csum->acc; } 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[1] = {0xffffffffffffffff}; void execute_call(int call) { long res; switch (call) { case 0: res = syscall(__NR_socket, 0xa, 1, 0); if (res != -1) r[0] = res; break; case 1: syscall(__NR_ioctl, r[0], 0x8912, 0x20000000); break; case 2: *(uint64_t*)0x20000000 = 0x40042f; *(uint64_t*)0x20000008 = 0xffffffffffffffe1; *(uint64_t*)0x20000010 = 0; *(uint64_t*)0x20000018 = 0; syscall(__NR_rt_sigaction, 7, 0x20000000, 0x20000200, 8, 0x20000080); break; case 3: *(uint8_t*)0x203f3fd5 = 0xaa; *(uint8_t*)0x203f3fd6 = 0xaa; *(uint8_t*)0x203f3fd7 = 0xaa; *(uint8_t*)0x203f3fd8 = 0xaa; *(uint8_t*)0x203f3fd9 = 0xaa; *(uint8_t*)0x203f3fda = 0xaa; *(uint8_t*)0x203f3fdb = -1; *(uint8_t*)0x203f3fdc = -1; *(uint8_t*)0x203f3fdd = -1; *(uint8_t*)0x203f3fde = -1; *(uint8_t*)0x203f3fdf = -1; *(uint8_t*)0x203f3fe0 = -1; *(uint16_t*)0x203f3fe1 = htobe16(0x800); STORE_BY_BITMASK(uint8_t, 0x203f3fe3, 5, 0, 4); STORE_BY_BITMASK(uint8_t, 0x203f3fe3, 4, 4, 4); STORE_BY_BITMASK(uint8_t, 0x203f3fe4, 0, 0, 2); STORE_BY_BITMASK(uint8_t, 0x203f3fe4, 0, 2, 6); *(uint16_t*)0x203f3fe5 = htobe16(0x1c); *(uint16_t*)0x203f3fe7 = htobe16(0); *(uint16_t*)0x203f3fe9 = htobe16(0); *(uint8_t*)0x203f3feb = 0; *(uint8_t*)0x203f3fec = 0; *(uint16_t*)0x203f3fed = 0; *(uint32_t*)0x203f3fef = htobe32(0); *(uint32_t*)0x203f3ff3 = htobe32(0xe0000001); *(uint16_t*)0x203f3ff7 = htobe16(0); *(uint16_t*)0x203f3ff9 = htobe16(0); *(uint16_t*)0x203f3ffb = htobe16(8); *(uint16_t*)0x203f3ffd = 0; struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x203f3fef, 4); csum_inet_update(&csum_1, (const uint8_t*)0x203f3ff3, 4); uint16_t csum_1_chunk_2 = 0x1100; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_2, 2); uint16_t csum_1_chunk_3 = 0x800; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_3, 2); csum_inet_update(&csum_1, (const uint8_t*)0x203f3ff7, 8); *(uint16_t*)0x203f3ffd = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x203f3fe3, 20); *(uint16_t*)0x203f3fed = csum_inet_digest(&csum_2); break; } } void loop() { execute(4); collide = 1; execute(4); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); loop(); return 0; }