// https://syzkaller.appspot.com/bug?id=d38ed0177151ca71af235c613ab4897461cf9ff3 // 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 #include #include #include #include #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 #include #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 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) fail("tun: snprintf failed"); if ((size_t)rv >= size) fail("tun: string '%s...' doesn't fit into buffer", str); } 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); } #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); rv = system(command); if (panic && rv != 0) fail("tun: command \"%s\" failed with code %d", &command[0], rv); va_end(args); } static int tunfd = -1; static int tun_frags_enabled; #define SYZ_TUN_MAX_PACKET_SIZE 1000 #define TUN_IFACE "syz_tun" #define LOCAL_MAC "aa:aa:aa:aa:aa:aa" #define REMOTE_MAC "aa:aa:aa:aa:aa:bb" #define LOCAL_IPV4 "172.20.20.170" #define REMOTE_IPV4 "172.20.20.187" #define LOCAL_IPV6 "fe80::aa" #define REMOTE_IPV6 "fe80::bb" #define IFF_NAPI 0x0010 #define IFF_NAPI_FRAGS 0x0020 static void initialize_tun(void) { tunfd = open("/dev/net/tun", O_RDWR | O_NONBLOCK); if (tunfd == -1) { printf("tun: can't open /dev/net/tun: please enable CONFIG_TUN=y\n"); printf("otherwise fuzzing or reproducing might not work as intended\n"); return; } const int kTunFd = 252; if (dup2(tunfd, kTunFd) < 0) fail("dup2(tunfd, kTunFd) failed"); close(tunfd); tunfd = kTunFd; struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, TUN_IFACE, IFNAMSIZ); ifr.ifr_flags = IFF_TAP | IFF_NO_PI | IFF_NAPI | IFF_NAPI_FRAGS; if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0) { ifr.ifr_flags = IFF_TAP | IFF_NO_PI; if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0) fail("tun: ioctl(TUNSETIFF) failed"); } if (ioctl(tunfd, TUNGETIFF, (void*)&ifr) < 0) fail("tun: ioctl(TUNGETIFF) failed"); tun_frags_enabled = (ifr.ifr_flags & IFF_NAPI_FRAGS) != 0; execute_command(1, "sysctl -w net.ipv6.conf.%s.accept_dad=0", TUN_IFACE); execute_command(1, "sysctl -w net.ipv6.conf.%s.router_solicitations=0", TUN_IFACE); execute_command(1, "ip link set dev %s address %s", TUN_IFACE, LOCAL_MAC); execute_command(1, "ip addr add %s/24 dev %s", LOCAL_IPV4, TUN_IFACE); execute_command(1, "ip -6 addr add %s/120 dev %s", LOCAL_IPV6, TUN_IFACE); execute_command(1, "ip neigh add %s lladdr %s dev %s nud permanent", REMOTE_IPV4, REMOTE_MAC, TUN_IFACE); execute_command(1, "ip -6 neigh add %s lladdr %s dev %s nud permanent", REMOTE_IPV6, REMOTE_MAC, TUN_IFACE); execute_command(1, "ip link set dev %s up", TUN_IFACE); } #define DEV_IPV4 "172.20.20.%d" #define DEV_IPV6 "fe80::%02hx" #define DEV_MAC "aa:aa:aa:aa:aa:%02hx" static void initialize_netdevices(void) { unsigned i; const char* devtypes[] = {"ip6gretap", "bridge", "vcan", "bond", "veth"}; const char* devnames[] = {"lo", "sit0", "bridge0", "vcan0", "tunl0", "gre0", "gretap0", "ip_vti0", "ip6_vti0", "ip6tnl0", "ip6gre0", "ip6gretap0", "erspan0", "bond0", "veth0", "veth1"}; 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 dev veth1 type veth"); 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]); } } #define MAX_FRAGS 4 struct vnet_fragmentation { uint32_t full; uint32_t count; uint32_t frags[MAX_FRAGS]; }; static uintptr_t syz_emit_ethernet(uintptr_t a0, uintptr_t a1, uintptr_t a2) { if (tunfd < 0) return (uintptr_t)-1; uint32_t length = a0; char* data = (char*)a1; struct vnet_fragmentation* frags = (struct vnet_fragmentation*)a2; struct iovec vecs[MAX_FRAGS + 1]; uint32_t nfrags = 0; if (!tun_frags_enabled || frags == NULL) { vecs[nfrags].iov_base = data; vecs[nfrags].iov_len = length; nfrags++; } else { bool full = true; uint32_t i, count = 0; full = frags->full; count = frags->count; if (count > MAX_FRAGS) count = MAX_FRAGS; for (i = 0; i < count && length != 0; i++) { uint32_t size = 0; size = frags->frags[i]; if (size > length) size = length; vecs[nfrags].iov_base = data; vecs[nfrags].iov_len = size; nfrags++; data += size; length -= size; } if (length != 0 && (full || nfrags == 0)) { vecs[nfrags].iov_base = data; vecs[nfrags].iov_len = length; nfrags++; } } return writev(tunfd, vecs, nfrags); } 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 = 128 << 20; setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 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); #define CLONE_NEWCGROUP 0x02000000 if (unshare(CLONE_NEWNS)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(CLONE_NEWCGROUP)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } } static int do_sandbox_none(void) { if (unshare(CLONE_NEWPID)) { } int pid = fork(); if (pid < 0) fail("sandbox fork failed"); if (pid) return pid; sandbox_common(); if (unshare(CLONE_NEWNET)) { } initialize_tun(); initialize_netdevices(); loop(); doexit(1); } 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[1] = {0xffffffffffffffff}; uint64_t procid; void execute_call(int call) { long res; switch (call) { case 0: res = syscall(__NR_socket, 2, 1, 0); if (res != -1) r[0] = res; break; case 1: *(uint32_t*)0x200003c0 = 1; syscall(__NR_setsockopt, r[0], 6, 0x20010000000013, 0x200003c0, 4); break; case 2: *(uint32_t*)0x20000d40 = 1; syscall(__NR_setsockopt, r[0], 6, 0x14, 0x20000d40, 4); break; case 3: *(uint16_t*)0x20303000 = 2; *(uint16_t*)0x20303002 = htobe16(0); *(uint32_t*)0x20303004 = htobe32(0x7f000001); *(uint8_t*)0x20303008 = 0; *(uint8_t*)0x20303009 = 0; *(uint8_t*)0x2030300a = 0; *(uint8_t*)0x2030300b = 0; *(uint8_t*)0x2030300c = 0; *(uint8_t*)0x2030300d = 0; *(uint8_t*)0x2030300e = 0; *(uint8_t*)0x2030300f = 0; syscall(__NR_sendto, r[0], 0x20001180, 0, 0x800000020000000, 0x20303000, 0x10); break; case 4: memcpy((void*)0x20000300, "\xbf", 1); *(uint16_t*)0x20000380 = 2; *(uint16_t*)0x20000382 = htobe16(0); *(uint32_t*)0x20000384 = htobe32(0); *(uint8_t*)0x20000388 = 0; *(uint8_t*)0x20000389 = 0; *(uint8_t*)0x2000038a = 0; *(uint8_t*)0x2000038b = 0; *(uint8_t*)0x2000038c = 0; *(uint8_t*)0x2000038d = 0; *(uint8_t*)0x2000038e = 0; *(uint8_t*)0x2000038f = 0; syscall(__NR_sendto, r[0], 0x20000300, 1, 0, 0x20000380, 0x10); break; case 5: memcpy( (void*)0x2018f000, "\xff\xff\xff\xff\xff\xff\x00\x00\x14\x00\x00\x00\x08\x00\x45\x00\x04" "\x15\x00\x00\x00\x00\x00\x11\x90\x78\x00\x00\x00\x00\xe0\x00\x00\x01" "\x4e\x20\x4e\x21\x04\x01\x90\x78\x00\xd7\x05\x02\x00\xf5\x34\x75\xb4" "\x41\xd6\x32\xcd\xbb\xcb\x21\x13\x63\x80\x7a\xec\x73\xd3\x88\x37\x62" "\xa6\x1d\xc0\x2d\x34\x9b\xfa\x3a\xc9\x74\xb9\x87\xaa\x7f\xb9\x7e\xb3" "\x24\xd5\x94\xfb\xbb\x77\xba\xb7\x59\x41\x8a\xa8\xd4\x51\xd9\x21\xe8" "\xf5\xd2\xcf\x2b\x08\x29\x21\x11\x70\x11\x92\xe9\x7c\xac\x36\x6d\xd3" "\xeb\x2e\x0f\xb0\x39\xe5\x83\x14\xef\x47\x09\xc5\xf3\x55\x6d\xb6\xa1" "\xab\x6b\x4f\xb2\xbd\xd8\x3c\xdc\x26\xe8\x39\x5e\xc4\x98\x4e\xc3\xfa" "\xf7\x1a\x61\x1d\x15\x69\x54\x5d\x65\x4c\xde\xd9\x3b\xe8\x27\xa8\x51" "\x88\xb8\x03\xc1\x9c\x1b\x56\xaa\xb5\x22\x86\x2a\x71\x8b\x81\xe5\x12" "\xb4\x96\x90\x99\x4d\x34\x25\xe3\x3b\xd9\x3f\x0e\x74\x4c\x66\xa0\x83" "\xc1\xf9\xf1\xbd\x7b\xb8\xf9\xe1\x23\xc0\x8f\x3f\x04\x1e\xd3\xfd\xc0" "\x58\x13\x6c\xf0\x07\x1a\x47\xcc\x0e\x38\x72\x0a\x12\xe1\x1e\x84\x2a" "\x7b\x5b\x26\xdf\xf0\x7f\x57\x8f\xdb\x9a\x7b\x14\x66\x2a\x62\x5c\x1e" "\xe7\x6c\x41\xcc\xb2\xb1\xfc\x63\x76\xaa\x71\x8e\x10\x67\xb9\xe4\xaf" "\x51\x1e\xf5\xb3\x60\xdb\xfa\xd3\x26\x10\x8b\xb0\x33\xdb\x19\x3d\xab" "\x27\x97\x4e\xb8\xc4\x62\x73\x9e\xae\xe5\x1d\x87\xf3\x1c\x51\x6e\x7e" "\x39\x10\x73\x77\x0d\xa3\x20\x2e\x02\xc4\x1a\x72\x77\xc8\x47\xdf\x24" "\xbd\x5b\x0a\x7a\xb6\xe2\x52\xf3\xc8\xeb\xf0\x06\x88\xcc\x55\x31\x1d" "\x88\x7e\x8b\xfd\x95\xa7\xf4\xc6\xa1\x26\xaf\x3f\xe2\x67\x14\xdd\xb8" "\x69\xc6\x6d\x18\xf8\x70\x63\x1b\xbd\x49\x7e\x8a\x06\x88\x1b\x75\x4e" "\xcd\xcd\xd0\xdc\xff\xc5\x1c\xd5\x2a\x6b\x56\x0f\x8d\x64\xb6\x3a\x16" "\x74\x74\x5e\xdc\x5f\x53\xb1\x8a\x8f\xfc\xc5\xc2\xfb\xc4\xd2\xbb\xcc" "\x2f\xaf\x3c\x18\x9d\x9b\x36\xc0\x65\x5d\x13\x94\xf5\xc1\x27\xec\x86" "\xb8\xa7\x64\xa8\x7b\x54\x6c\x2b\x6a\xc3\x7d\x0a\x8e\xc3\xed\xd7\xcd" "\xa6\xf9\x30\x57\x07\x63\xdb\xdc\x06\x40\xd2\x19\x74\x9b\xd5\x7c\x7c" "\x89\xea\xad\xfd\xae\x41\xd6\x54\xa4\x6b\x17\xbe\x06\x9a\x32\xa5\xd9" "\x4d\x29\xb6\x12\xfb\xe6\x1b\x8b\xd1\x1a\x2d\x10\xba\x5d\x4a\xc7\x01" "\x4f\xc0\x46\x5c\x3f\x14\x45\x98\xbd\x1f\x91\x33\x43\xe7\x29\x37\x11" "\x04\x0e\xee\x0a\xe8\xdf\x1e\x49\xf0\x4e\xd1\x03\x7d\x4b\x74\x2a\xed" "\x0e\x93\x21\x16\x06\x0a\xaf\x6b\x98\x52\x38\xd2\xe1\x0f\xb5\xb1\x1d" "\x19\xd7\x80\x1b\xef\xed\x48\x33\x28\x7d\x96\xa8\x5a\x7c\xdd\x9e\x21" "\x1a\x67\x27\x60\x33\x56\x55\x57\x6f\xc0\xfa\x03\x36\x62\x1c\x2b\x2b" "\x10\x18\xef\x71\xbb\x50\x77\xc6\x7e\xe5\xfa\x8d\x47\x9d\x67\x76\x01" "\x33\x63\xe9\x8b\x1f\x12\x13\x71\x2b\xe7\xe4\x75\x49\xb6\x03\x54\x59" "\x00\x8c\x50\x9f\x0f\x98\x31\x30\xa4\x51\x53\x13\x81\xee\x3c\x1a\xb9" "\xe1\xcb\xb8\xe5\x58\xb5\x6c\xa1\xa7\x09\x39\x38\x9a\xdd\xc5\xf9\x63" "\x2b\x37\xff\x3f\x63\x4a\xbb\x50\x4b\xb0\xbe\x0a\x51\x64\x96\x83\xf6" "\xe2\x95\x88\xc1\x5c\xda\x40\x25\x5e\x17\x33\x28\x68\x18\x84\xff\xef" "\x67\x29\xe9\x05\x8c\x56\x23\xe1\x40\x1f\xdc\xc7\xb8\xcb\x56\x23\xa8" "\xfd\x72\x5f\xbe\xea\x05\xfc\x41\x7c\x44\xe4\x65\x00\x61\x92\x18\xdf" "\xf7\xc7\x0a\xa0\x68\x99\x4c\x58\x88\x3c\xad\xa5\x05\xa2\xaa\x85\xb6" "\x62\x0d\xfe\x9c\x45\xb7\x07\xc9\xaa\x12\x22\xb8\x69\x72\xea\xe5\x64" "\xb2\x8a\x05\xdd\xfa\x35\x45\xdf\x23\x1f\xde\x27\x07\xd4\xbf\x67\xdc" "\x6b\xa4\x1d\xab\xa9\x1d\xee\x80\x81\xe5\xc7\xe2\xbc\xfb\xeb\xeb\xd4" "\x2d\x5a\xb8\xa3\x2d\x6e\x09\x8f\xd5\x72\x33\xe3\xb8\x13\xdc\x0d\x77" "\x21\x34\x77\x5d\xef\x45\x18\x23\xb7\xfe\xf2\xbc\x93\xda\x01\x72\x2c" "\xd6\x13\xb9\xa3\xdb\x7e\x2d\x4c\x51\xfb\x7b\x56\x00\x6e\xe9\xce\xa5" "\x3b\x62\x34\x35\x99\xa5\x61\x67\x38\x8d\x45\x24\x7f\x92\x89\xfb\x1c" "\xab\x67\xa7\xcb\x0c\x36\x65\xdd\xf1\xe1\x41\x18\x75\xb4\xde\x34\x28" "\xb3\x2f\xc6\x60\x36\x91\xa0\x23\xd8\xe4\xcb\x93\xc6\x67\xac\xb7\xb5" "\x35\xfb\x5f\x77\xaf\x9a\x49\x64\x0c\xbe\x8f\xfe\x3a\x19\x3c\xf4\xdf" "\x1b\x55\x6a\x67\xcb\x75\x3c\x60\xbd\xf9\x78\xb8\x71\xaa\x51\x3c\x07" "\x07\x4c\x66\x02\x03\x7e\xbc\x32\x19\x92\x90\xe3\xc7\xac\x6f\x10\x3a" "\xd9\x35\x89\x51\xad\x4d\xe0\xc8\xf1\xb3\x49\x51\xb0\xe6\xa4\x82\x95" "\x97\x5c\xf0\x8b\x2c\x3c\x95\x06\x48\x55\xfc\x95\x31\x7e\x38\x6f\x1c" "\x18\x60\x8d\x1d\x08\x69\x90\x03\xc9\x98\xb9\x33\x32\xcd\x31\x6f\x17" "\xa5\x13\x9d\x35\x0c\xbf\xa9\xda\xbc\x3f\x77\xc4\x19\x7a\x01\x86\xe5" "\x09\x13\x97\x8e\x98\x0a\x7a\x02\x8e\x7c\xcd\xee\xe7\x18\xaf\x02\x82" "\x00\xe9\x4a\x6b\x3a\x0e\xc9\x3b\xa1\x4b\x0c\x64\xdf\xaf\x39\x67\xe2" "\x30\xd8\xcf\x87\x6f\x26\x28\x7d\x43\x6e\xbc\x95\x88\xb5\x2b\x43\xf2" "\x38\x08\x36\xbf\xe3", 1059); syz_emit_ethernet(1, 0x2018f000, 0); break; } } void test() { execute(6); collide = 1; execute(6); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); for (procid = 0; procid < 8; procid++) { if (fork() == 0) { for (;;) { int pid = do_sandbox_none(); int status = 0; while (waitpid(pid, &status, __WALL) != pid) { } } } } sleep(1000000); return 0; }