// https://syzkaller.appspot.com/bug?id=9f27e880d757d8e1b7bebd36a4c391fccb92f134 // 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 #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); if (pthread_create(&th, &attr, fn, arg)) exit(1); pthread_attr_destroy(&attr); } 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); } 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_RELAXED)) return 1; now = current_time_ms(); if (now - start > timeout) return 0; } } static void vsnprintf_check(char* str, size_t size, const char* format, va_list args) { int rv; rv = vsnprintf(str, size, format, args); if (rv < 0) exit(1); if ((size_t)rv >= size) exit(1); } #define COMMAND_MAX_LEN 128 #define PATH_PREFIX \ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin " #define PATH_PREFIX_LEN (sizeof(PATH_PREFIX) - 1) static void execute_command(bool panic, const char* format, ...) { va_list args; char command[PATH_PREFIX_LEN + COMMAND_MAX_LEN]; int rv; va_start(args, format); memcpy(command, PATH_PREFIX, PATH_PREFIX_LEN); vsnprintf_check(command + PATH_PREFIX_LEN, COMMAND_MAX_LEN, format, args); va_end(args); rv = system(command); if (rv) { if (panic) exit(1); } } #define DEV_IPV4 "172.20.20.%d" #define DEV_IPV6 "fe80::%02hx" #define DEV_MAC "aa:aa:aa:aa:aa:%02hx" static void snprintf_check(char* str, size_t size, const char* format, ...) { va_list args; va_start(args, format); vsnprintf_check(str, size, format, args); va_end(args); } static void initialize_netdevices(void) { unsigned i; const char* devtypes[] = {"ip6gretap", "bridge", "vcan", "bond", "team"}; const char* devnames[] = {"lo", "sit0", "bridge0", "vcan0", "tunl0", "gre0", "gretap0", "ip_vti0", "ip6_vti0", "ip6tnl0", "ip6gre0", "ip6gretap0", "erspan0", "bond0", "veth0", "veth1", "team0", "veth0_to_bridge", "veth1_to_bridge", "veth0_to_bond", "veth1_to_bond", "veth0_to_team", "veth1_to_team"}; const char* devmasters[] = {"bridge", "bond", "team"}; for (i = 0; i < sizeof(devtypes) / (sizeof(devtypes[0])); i++) execute_command(0, "ip link add dev %s0 type %s", devtypes[i], devtypes[i]); execute_command(0, "ip link add type veth"); for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) { execute_command( 0, "ip link add name %s_slave_0 type veth peer name veth0_to_%s", devmasters[i], devmasters[i]); execute_command( 0, "ip link add name %s_slave_1 type veth peer name veth1_to_%s", devmasters[i], devmasters[i]); execute_command(0, "ip link set %s_slave_0 master %s0", devmasters[i], devmasters[i]); execute_command(0, "ip link set %s_slave_1 master %s0", devmasters[i], devmasters[i]); execute_command(0, "ip link set veth0_to_%s up", devmasters[i]); execute_command(0, "ip link set veth1_to_%s up", devmasters[i]); } execute_command(0, "ip link set bridge_slave_0 up"); execute_command(0, "ip link set bridge_slave_1 up"); for (i = 0; i < sizeof(devnames) / (sizeof(devnames[0])); i++) { char addr[32]; snprintf_check(addr, sizeof(addr), DEV_IPV4, i + 10); execute_command(0, "ip -4 addr add %s/24 dev %s", addr, devnames[i]); snprintf_check(addr, sizeof(addr), DEV_IPV6, i + 10); execute_command(0, "ip -6 addr add %s/120 dev %s", addr, devnames[i]); snprintf_check(addr, sizeof(addr), DEV_MAC, i + 10); execute_command(0, "ip link set dev %s address %s", devnames[i], addr); execute_command(0, "ip link set dev %s up", devnames[i]); } } static void setup_common() { if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) { } } static void loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); setsid(); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 160 << 20; setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 136 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); if (unshare(CLONE_NEWNS)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(0x02000000)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } } int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, __WALL) != pid) { } return WEXITSTATUS(status); } static int do_sandbox_none(void) { if (unshare(CLONE_NEWPID)) { } int pid = fork(); if (pid != 0) return wait_for_loop(pid); setup_common(); sandbox_common(); if (unshare(CLONE_NEWNET)) { } initialize_netdevices(); loop(); exit(1); } 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 loop(void) { int i, call, thread; int collide = 0; again: for (call = 0; call < 10; 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; } } 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*)0x20000000 = 0xa; *(uint16_t*)0x20000002 = htobe16(0x4e20); *(uint32_t*)0x20000004 = 0; *(uint8_t*)0x20000008 = 0; *(uint8_t*)0x20000009 = 0; *(uint8_t*)0x2000000a = 0; *(uint8_t*)0x2000000b = 0; *(uint8_t*)0x2000000c = 0; *(uint8_t*)0x2000000d = 0; *(uint8_t*)0x2000000e = 0; *(uint8_t*)0x2000000f = 0; *(uint8_t*)0x20000010 = 0; *(uint8_t*)0x20000011 = 0; *(uint8_t*)0x20000012 = 0; *(uint8_t*)0x20000013 = 0; *(uint8_t*)0x20000014 = 0; *(uint8_t*)0x20000015 = 0; *(uint8_t*)0x20000016 = 0; *(uint8_t*)0x20000017 = 0; *(uint32_t*)0x20000018 = 0; syscall(__NR_bind, r[0], 0x20000000, 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*)0x201c9fff, "\x03", 1); syscall(__NR_setsockopt, r[1], 0x10d, 0xd, 0x201c9fff, 1); break; case 5: *(uint16_t*)0x20e5c000 = 2; *(uint16_t*)0x20e5c002 = htobe16(0x4e20); *(uint8_t*)0x20e5c004 = 0xac; *(uint8_t*)0x20e5c005 = 0x14; *(uint8_t*)0x20e5c006 = 0x14; *(uint8_t*)0x20e5c007 = 0x20; *(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*)0x20000080 = 0; res = syscall(__NR_accept, r[0], 0, 0x20000080); if (res != -1) r[2] = res; break; case 7: *(uint64_t*)0x200004c0 = 0x20000200; *(uint16_t*)0x20000200 = 0x10; *(uint16_t*)0x20000202 = 0; *(uint32_t*)0x20000204 = 0; *(uint32_t*)0x20000208 = 0x20000000; *(uint32_t*)0x200004c8 = 0xc; *(uint64_t*)0x200004d0 = 0x20000480; *(uint64_t*)0x20000480 = 0x20000340; *(uint32_t*)0x20000340 = 0x10c; *(uint16_t*)0x20000344 = 0; *(uint16_t*)0x20000346 = 0x410; *(uint32_t*)0x20000348 = 0; *(uint32_t*)0x2000034c = 0x25dfdbfc; *(uint8_t*)0x20000350 = 0xd; *(uint8_t*)0x20000351 = 0; *(uint16_t*)0x20000352 = 0; *(uint16_t*)0x20000354 = 8; *(uint16_t*)0x20000356 = 5; *(uint32_t*)0x20000358 = 0; *(uint16_t*)0x2000035c = 8; *(uint16_t*)0x2000035e = 5; *(uint32_t*)0x20000360 = 6; *(uint16_t*)0x20000364 = 0x60; *(uint16_t*)0x20000366 = 3; *(uint16_t*)0x20000368 = 8; *(uint16_t*)0x2000036a = 5; *(uint32_t*)0x2000036c = htobe32(0x7f000001); *(uint16_t*)0x20000370 = 8; *(uint16_t*)0x20000372 = 7; *(uint16_t*)0x20000374 = htobe16(0x4e20); *(uint16_t*)0x20000378 = 0x14; *(uint16_t*)0x2000037a = 6; *(uint8_t*)0x2000037c = 0; *(uint8_t*)0x2000037d = 0; *(uint8_t*)0x2000037e = 0; *(uint8_t*)0x2000037f = 0; *(uint8_t*)0x20000380 = 0; *(uint8_t*)0x20000381 = 0; *(uint8_t*)0x20000382 = 0; *(uint8_t*)0x20000383 = 0; *(uint8_t*)0x20000384 = 0; *(uint8_t*)0x20000385 = 0; *(uint8_t*)0x20000386 = -1; *(uint8_t*)0x20000387 = -1; *(uint32_t*)0x20000388 = htobe32(-1); *(uint16_t*)0x2000038c = 8; *(uint16_t*)0x2000038e = 4; *(uint16_t*)0x20000390 = -1; *(uint16_t*)0x20000394 = 8; *(uint16_t*)0x20000396 = 3; *(uint32_t*)0x20000398 = 1; *(uint16_t*)0x2000039c = 8; *(uint16_t*)0x2000039e = 1; *(uint32_t*)0x200003a0 = 0; *(uint16_t*)0x200003a4 = 8; *(uint16_t*)0x200003a6 = 7; *(uint16_t*)0x200003a8 = htobe16(0x4e22); *(uint16_t*)0x200003ac = 8; *(uint16_t*)0x200003ae = 3; *(uint32_t*)0x200003b0 = 0; *(uint16_t*)0x200003b4 = 8; *(uint16_t*)0x200003b6 = 4; *(uint16_t*)0x200003b8 = 0xfffe; *(uint16_t*)0x200003bc = 8; *(uint16_t*)0x200003be = 7; *(uint16_t*)0x200003c0 = htobe16(0x4e20); *(uint16_t*)0x200003c4 = 8; *(uint16_t*)0x200003c6 = 6; *(uint32_t*)0x200003c8 = 2; *(uint16_t*)0x200003cc = 0x50; *(uint16_t*)0x200003ce = 1; *(uint16_t*)0x200003d0 = 8; *(uint16_t*)0x200003d2 = 2; *(uint16_t*)0x200003d4 = 0x45f6; *(uint16_t*)0x200003d8 = 8; *(uint16_t*)0x200003da = 2; *(uint16_t*)0x200003dc = 0xbe; *(uint16_t*)0x200003e0 = 8; *(uint16_t*)0x200003e2 = 2; *(uint16_t*)0x200003e4 = 0x3f; *(uint16_t*)0x200003e8 = 8; *(uint16_t*)0x200003ea = 2; *(uint16_t*)0x200003ec = 0x33; *(uint16_t*)0x200003f0 = 8; *(uint16_t*)0x200003f2 = 9; *(uint32_t*)0x200003f4 = 0x6e; *(uint16_t*)0x200003f8 = 8; *(uint16_t*)0x200003fa = 8; *(uint32_t*)0x200003fc = 1; *(uint16_t*)0x20000400 = 8; *(uint16_t*)0x20000402 = 8; *(uint32_t*)0x20000404 = 3; *(uint16_t*)0x20000408 = 0xc; *(uint16_t*)0x2000040a = 7; *(uint32_t*)0x2000040c = 0x14; *(uint32_t*)0x20000410 = 0x2a; *(uint16_t*)0x20000414 = 8; *(uint16_t*)0x20000416 = 0xb; memcpy((void*)0x20000418, "sip", 4); *(uint16_t*)0x2000041c = 0x28; *(uint16_t*)0x2000041e = 1; *(uint16_t*)0x20000420 = 8; *(uint16_t*)0x20000422 = 8; *(uint32_t*)0x20000424 = 4; *(uint16_t*)0x20000428 = 8; *(uint16_t*)0x2000042a = 9; *(uint32_t*)0x2000042c = 0x14; *(uint16_t*)0x20000430 = 0xc; *(uint16_t*)0x20000432 = 7; *(uint32_t*)0x20000434 = 0x10; *(uint32_t*)0x20000438 = 2; *(uint16_t*)0x2000043c = 8; *(uint16_t*)0x2000043e = 8; *(uint32_t*)0x20000440 = 0x80; *(uint16_t*)0x20000444 = 8; *(uint16_t*)0x20000446 = 6; *(uint32_t*)0x20000448 = 0; *(uint64_t*)0x20000488 = 0x10c; *(uint64_t*)0x200004d8 = 1; *(uint64_t*)0x200004e0 = 0; *(uint64_t*)0x200004e8 = 0; *(uint32_t*)0x200004f0 = 0x4000810; syscall(__NR_sendmsg, r[2], 0x200004c0, 0x800); break; case 8: *(uint64_t*)0x20000140 = 0; *(uint32_t*)0x20000148 = 0; *(uint64_t*)0x20000150 = 0x200000c0; *(uint64_t*)0x200000c0 = 0x20000780; memcpy( (void*)0x20000780, "\x00\xff\xff\xff\xff\xff\xff\xff\x1c\x89\x80\xdb\xd7\xa9\x99\x27\x51" "\x95\x94\xca\x46\x70\x11\x38\xd9\x09\x24\x6d\x95\x72\x65\x56\xb4\xac" "\x2d\x62\xa9\xc4\x73\x61\x15\x81\xfa\xfe\x74\xac\x28\x73\x47\x08\x60" "\xc8\xdc\x75\xaf\x40\x99\x49\x09\x44\x9a\x1f\xf0\x5e\x28\xd9\x3f\xd8" "\xcc\xba\xcb\x24\x75\x04\xda\x7a\x8f\x08\xc8\xdd\x5a\x6f\x86\x2a\xcc" "\xf9\x3c\x88\xee\x8a\xc6\x8d\x91\x18\x68\xdf\x3d\x3a\xe6\xed\x5e\x32" "\x1a\x2e\x5b\x43\x89\xf0\x12\x8c\x1e\x04\xd0\xe6\x28\x51\xbb\x3d\x2a" "\xcc\x78\x34\xfc\x52\x72\x20\xa5\xcb\x40\x8d\x42\x4e\x27\x67\xee\x63" "\x0e\x47\x0f\x88\xc2\xa0\x71\x88\xa0\xa9\x03\x41\x7e\x6e\xec\x6b\x08" "\x53\x50\x4b\x24\x03\x3f\x0f\x7d\x41\xbf\x87\x2a\x33\xdc\xa2\xa5\x9a" "\x57\xdb\x78\x6a\x82\xa8\xb9\x64\x90\xd3\xb1\x5c\xe4\xaf\xaa\xcc\xa7" "\x62\xb7\xe1\xec\xc3\x87\xfa\xcc\x3e\xb0\xe4\xbe\x3c\x33\x24\x8d\x40" "\x0a\x12\xf5\x30\x60\xc2\x33\xe2\x48\x91\x80\xad\x27\x9e\x88\x1b\xe4" "\x2e\xfc\xe2\x62\x58\xec\xa0\xb7\x15\x55\x5d\xc2\xfc\xda\x94\xa3\x25" "\xc7\xa9\x68\xd0\xf5\x6b\xe1\x43\x5f\x0a\xe1\x31\xbe\x93\x7f\x1f\xe7" "\xeb\x23\xbd\xd6\x3e\x01\xf9\x83\x91\x43\x12\xac\x58\x06\xae\x3a\x78" "\x12\x30\x7e\x19\x86\x9f\xe2\x1f\x3a\x81\x43\x60\xc9\x83\x6a\x75\x70" "\x13\x85\x5f\x7d\x5b\xc9\xd3\x14\xf1\xfc\xea\xa2\x40\x58\xdd\x28\xad" "\x97\x02\x01\x75\x7f\x08\xcb\x92\xf5\xb5\x1d\x02\xb7\xa6\x0e\xa4\xaa" "\xc0\xd0\x87\xa6\xf0\x39\xfa\x5f\xfb\xc2\x43\x40\xb1\x56\x30\xe2\x0e" "\x11\x23\x41\x5d\x64\x24\x1c\xf7\x29\xdd\x32\xfe\xaf\x6d\x68\xd2\x02" "\xfe\x6a\xc1\x90\xf7\x43\x2b\x19\x1c\xbb\xc8\x5d\xea\x3e\x14\x6c\x1b" "\x05\xb2\x9c\x5a\xca\xdf\x8b\x01\x3c\xc7\xb0\xa7\x6a\x6c\xf0\xac\x71" "\x7c\x81\x1d\xd8\xea\xc6\xce\xbe\x01\x10\xc1\x53\xb8\xb1\x65\x6a\xba" "\x40\xaa\x2c\xfd\x77\x5a\x18\x8e\x83\x56\xb0\x82\xe6\xba\xa7\xe0\x68" "\x4b\x23\xf3\x85\x97\xe7\xbd\x54\x2d\x9c\x3b\xbd\x90\x68\x91\xda\x52" "\x71\x1f\xda\x87\x7e\x3a\xe7\xad\x53\x23\x6e\x73\x38\xd6\x52\xd8\x92" "\x6a\x46\xae\x0c\x99\x6d\x25\xc1\x0d\xeb\xcd\x7e\xce\x46\xf6\x52\xeb" "\x66\xb7\xe2\x2f\xa2\x05\x0b\xb3\x67\x98\xb1\x67\x7e\x9a\xb9\xde\x7e" "\xef\x69\x50\xfd\x4e\xa0\x89\xab\xa7\x6d\x26\x83\x19\x22\xf9\x7c\x79" "\x78\x2b\x1e\xeb\x01\xb6\xa3\xab\xef\xc7\x8a\x52\x4f\x79\x72\xaf\x37" "\xf0\xcf\xa5\x1d\xe9\xdd\xe6\x6e\x1a\x47\xfc\xd8\x83\xde\xa4\x4d\xe4" "\x68\x2f\x7d\x38\xd6\x5a\x09\x58\xed", 553); *(uint64_t*)0x200000c8 = 0x229; *(uint64_t*)0x20000158 = 1; *(uint64_t*)0x20000160 = 0; *(uint64_t*)0x20000168 = 0; *(uint32_t*)0x20000170 = 0; syscall(__NR_sendmsg, r[2], 0x20000140, 0); break; case 9: *(uint64_t*)0x20005700 = 0x20003900; *(uint16_t*)0x20003900 = 0x18; *(uint32_t*)0x20003902 = 2; *(uint16_t*)0x20003906 = htobe16(0); *(uint32_t*)0x2000390a = htobe32(0); *(uint32_t*)0x20005708 = 0x80; *(uint64_t*)0x20005710 = 0x20003b80; *(uint64_t*)0x20005718 = 0x3a5; *(uint64_t*)0x20005720 = 0x20003bc0; *(uint64_t*)0x20005728 = 0; *(uint32_t*)0x20005730 = 0; *(uint32_t*)0x20005738 = 0; syscall(__NR_sendmmsg, r[1], 0x20005700, 0x3a6, 0); break; } } int main(void) { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); do_sandbox_none(); return 0; }