// https://syzkaller.appspot.com/bug?id=9f27e880d757d8e1b7bebd36a4c391fccb92f134 // 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[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { long res; switch (call) { case 0: res = syscall(__NR_socket, 0xa, 6, 0); if (res != -1) r[0] = res; break; case 1: *(uint16_t*)0x20000340 = 0xa; *(uint16_t*)0x20000342 = htobe16(0x4e20); *(uint32_t*)0x20000344 = 6; *(uint8_t*)0x20000348 = 0; *(uint8_t*)0x20000349 = 0; *(uint8_t*)0x2000034a = 0; *(uint8_t*)0x2000034b = 0; *(uint8_t*)0x2000034c = 0; *(uint8_t*)0x2000034d = 0; *(uint8_t*)0x2000034e = 0; *(uint8_t*)0x2000034f = 0; *(uint8_t*)0x20000350 = 0; *(uint8_t*)0x20000351 = 0; *(uint8_t*)0x20000352 = 0; *(uint8_t*)0x20000353 = 0; *(uint8_t*)0x20000354 = 0; *(uint8_t*)0x20000355 = 0; *(uint8_t*)0x20000356 = 0; *(uint8_t*)0x20000357 = 0; *(uint32_t*)0x20000358 = 0xfffffffc; syscall(__NR_bind, r[0], 0x20000340, 0x1c); break; case 2: res = syscall(__NR_socket, 2, 6, 0); if (res != -1) r[1] = res; break; case 3: syscall(__NR_listen, r[0], 6); break; case 4: memcpy((void*)0x20000080, "\x03", 1); syscall(__NR_setsockopt, r[1], 0x10d, 0xd, 0x20000080, 1); break; case 5: *(uint16_t*)0x20e5c000 = 2; *(uint16_t*)0x20e5c002 = htobe16(0x4e20); *(uint32_t*)0x20e5c004 = htobe32(0x7f000001); *(uint8_t*)0x20e5c008 = 0; *(uint8_t*)0x20e5c009 = 0; *(uint8_t*)0x20e5c00a = 0; *(uint8_t*)0x20e5c00b = 0; *(uint8_t*)0x20e5c00c = 0; *(uint8_t*)0x20e5c00d = 0; *(uint8_t*)0x20e5c00e = 0; *(uint8_t*)0x20e5c00f = 0; syscall(__NR_connect, r[1], 0x20e5c000, 0x10); break; case 6: *(uint32_t*)0x20000040 = 0x80; res = syscall(__NR_accept, r[0], 0x20000240, 0x20000040); if (res != -1) r[2] = res; break; case 7: *(uint64_t*)0x20000800 = 0x20000380; *(uint16_t*)0x20000380 = 1; *(uint8_t*)0x20000382 = 0; *(uint32_t*)0x20000384 = 0x4e21; *(uint32_t*)0x20000808 = 0x6e; *(uint64_t*)0x20000810 = 0x20000740; *(uint64_t*)0x20000740 = 0x20000400; *(uint64_t*)0x20000748 = 0; *(uint64_t*)0x20000750 = 0x20000500; *(uint64_t*)0x20000758 = 0; *(uint64_t*)0x20000760 = 0x200006c0; memcpy((void*)0x200006c0, "\x70\x7c\x28\x7f\x30\xba\x64\x2d\x38\xf7\xa6\x7c\x0d\xb8\x0c\x5f" "\xd1\x4b\x3a\x11\x7d\xbf\xc1\x45\xe1\xa0\xd0\x1f\xa6\xb2\x18\x56" "\xfb\x64\x70\x57\xe1\x8b\xda\xa6\x43\x75\xa4\xb5\x71\x1c\x00\x43" "\x05\xb0\x82\x29\x38\x59\xec\xe3\x6b\x0d\x8b\x5b\x79\xdc\xf9\x60" "\xfb\xfe\xa5\x14\x72\x7a\x06\xf1\x61\x0c\x85\xf3\x42\xda\x61", 79); *(uint64_t*)0x20000768 = 0x4f; *(uint64_t*)0x20000818 = 3; *(uint64_t*)0x20000820 = 0x200007c0; *(uint64_t*)0x20000828 = 0; *(uint32_t*)0x20000830 = 0x8000; syscall(__NR_sendmmsg, r[2], 0x20000800, 1, 0x8000); break; case 8: *(uint64_t*)0x20000200 = 0x200000c0; *(uint16_t*)0x200000c0 = 0x10; *(uint16_t*)0x200000c2 = 0; *(uint32_t*)0x200000c4 = 0; *(uint32_t*)0x200000c8 = 0; *(uint32_t*)0x20000208 = 0xc; *(uint64_t*)0x20000210 = 0x200001c0; *(uint64_t*)0x200001c0 = 0x20001840; *(uint64_t*)0x200001c8 = 1; *(uint64_t*)0x20000218 = 1; *(uint64_t*)0x20000220 = 0; *(uint64_t*)0x20000228 = 0; *(uint32_t*)0x20000230 = 0; syscall(__NR_sendmsg, r[2], 0x20000200, 0); break; case 9: *(uint64_t*)0x20000600 = 0x20000300; *(uint16_t*)0x20000300 = 0x10; *(uint16_t*)0x20000302 = 0; *(uint32_t*)0x20000304 = 0; *(uint32_t*)0x20000308 = 0x40000002; *(uint32_t*)0x20000608 = 0xc; *(uint64_t*)0x20000610 = 0x200005c0; *(uint64_t*)0x200005c0 = 0x200004c0; *(uint32_t*)0x200004c0 = 0x14; *(uint16_t*)0x200004c4 = 0; *(uint16_t*)0x200004c6 = 0x908; *(uint32_t*)0x200004c8 = 0x70bd2c; *(uint32_t*)0x200004cc = 0x25dfdbfb; *(uint8_t*)0x200004d0 = 3; *(uint8_t*)0x200004d1 = 0; *(uint16_t*)0x200004d2 = 0; *(uint64_t*)0x200005c8 = 0x14; *(uint64_t*)0x20000618 = 1; *(uint64_t*)0x20000620 = 0; *(uint64_t*)0x20000628 = 0; *(uint32_t*)0x20000630 = 0xb167f2fa; syscall(__NR_sendmsg, r[1], 0x20000600, 0x4000); break; case 10: *(uint8_t*)0x20000040 = 0xaa; *(uint8_t*)0x20000041 = 0xaa; *(uint8_t*)0x20000042 = 0xaa; *(uint8_t*)0x20000043 = 0xaa; *(uint8_t*)0x20000044 = 0xaa; *(uint8_t*)0x20000045 = 0xaa; *(uint8_t*)0x20000046 = -1; *(uint8_t*)0x20000047 = -1; *(uint8_t*)0x20000048 = -1; *(uint8_t*)0x20000049 = -1; *(uint8_t*)0x2000004a = -1; *(uint8_t*)0x2000004b = -1; *(uint16_t*)0x2000004c = htobe16(0x800); STORE_BY_BITMASK(uint8_t, 0x2000004e, 7, 0, 4); STORE_BY_BITMASK(uint8_t, 0x2000004e, 4, 4, 4); STORE_BY_BITMASK(uint8_t, 0x2000004f, 0, 0, 2); STORE_BY_BITMASK(uint8_t, 0x2000004f, 0, 2, 6); *(uint16_t*)0x20000050 = htobe16(0x30); *(uint16_t*)0x20000052 = htobe16(0); *(uint16_t*)0x20000054 = htobe16(0); *(uint8_t*)0x20000056 = 0; *(uint8_t*)0x20000057 = 0; *(uint16_t*)0x20000058 = 0; *(uint8_t*)0x2000005a = 0xac; *(uint8_t*)0x2000005b = 0x14; *(uint8_t*)0x2000005c = 0x14; *(uint8_t*)0x2000005d = 0xbb; *(uint8_t*)0x2000005e = 0xac; *(uint8_t*)0x2000005f = 0x23; *(uint8_t*)0x20000060 = 0x14; *(uint8_t*)0x20000061 = 0xaa; *(uint8_t*)0x20000062 = 7; *(uint8_t*)0x20000063 = 7; *(uint8_t*)0x20000064 = 4; *(uint32_t*)0x20000065 = htobe32(0); *(uint16_t*)0x2000006a = htobe16(0); *(uint16_t*)0x2000006c = htobe16(0); *(uint32_t*)0x2000006e = 0x41424344; *(uint32_t*)0x20000072 = 0x41424344; STORE_BY_BITMASK(uint8_t, 0x20000076, 0, 0, 1); STORE_BY_BITMASK(uint8_t, 0x20000076, 0, 1, 3); STORE_BY_BITMASK(uint8_t, 0x20000076, 5, 4, 4); *(uint8_t*)0x20000077 = 0; *(uint16_t*)0x20000078 = htobe16(0); *(uint16_t*)0x2000007a = 0; *(uint16_t*)0x2000007c = htobe16(0); *(uint32_t*)0x20000000 = 0; *(uint32_t*)0x20000004 = 0; *(uint32_t*)0x20000008 = 0; *(uint32_t*)0x2000000c = 0; *(uint32_t*)0x20000010 = 0; *(uint32_t*)0x20000014 = 0; struct csum_inet csum_1; csum_inet_init(&csum_1); csum_inet_update(&csum_1, (const uint8_t*)0x2000005a, 4); csum_inet_update(&csum_1, (const uint8_t*)0x2000005e, 4); uint16_t csum_1_chunk_2 = 0x600; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_2, 2); uint16_t csum_1_chunk_3 = 0x1400; csum_inet_update(&csum_1, (const uint8_t*)&csum_1_chunk_3, 2); csum_inet_update(&csum_1, (const uint8_t*)0x2000006a, 20); *(uint16_t*)0x2000007a = csum_inet_digest(&csum_1); struct csum_inet csum_2; csum_inet_init(&csum_2); csum_inet_update(&csum_2, (const uint8_t*)0x2000004e, 28); *(uint16_t*)0x20000058 = csum_inet_digest(&csum_2); break; } } void loop() { execute(11); collide = 1; execute(11); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); loop(); return 0; }