// https://syzkaller.appspot.com/bug?id=6dcd14a729df98f989c7b76d254226ae67084efd // 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 __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]); } } 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(); } } uint64_t r[1] = {0xffffffffffffffff}; void test() { long res; memcpy((void*)0x20005000, "/dev/sg#", 9); res = syz_open_dev(0x20005000, 0, 0x8002); if (res != -1) r[0] = res; memcpy((void*)0x20000440, "\xb6\x3d\xc0\x7f\x34\x33\x02\x00\xf6\x0c\x00\x00\x00\x72\x4a\xed\x8b" "\x27\x00\x3e\xf0\x6d\x7f\x7a\x26\x2f\x89\x4b\x4c\x3e\x37\xd5\x01\x1d" "\xcc\x60\x6a\xed\x5e\x95\xd2\xbc\x70\x18\xce\xbc\xdc\xd1\xb3\x18\x82" "\xe5\xcb\x00\x00\x01\x00\x00\x00\x00\x00\xfb\x1e\xef\x15\x87\x16\x00" "\x4f\x76\xac\xb2\xc3\x86\xe3\x24\x11\x49\xc3\x36\x48\xa6\xb1\x69\xd9" "\x79\xb6\xd5\x90\x06\x1b\xf7\xdb\x76\x70\xb4\xbe\xd1\x24\xde\x49\x08" "\xa8\xd6\xc5\x55\x74\x65\x72\x46\x44\x8a\x1b\x78\xde\xcc\x6d\x96\x39" "\x35\xdd\x7c\x57\x58\x39\xc7\x60\xa6\xf7\xf0\xbe\xcb\x0e\xe8\x79\xa6" "\x58\xb9\x10\x58\x71\x25\xff\x73\xbe\xc0\xa8\x96\x40\xb3\xe8\xe8\x54" "\xe0\x36\x7f\x4c\xf9\x80\x30\x38\x24\x72\xcf\x24\xce\xc9\x52\x02\x50" "\x67\xde\x5b\xa6\xd7\xa7\x23\x2f\x2e\x2b\xa1\x24\xb3\x12\x11\xbf\x52" "\x39\x96\xa2\xf9\xe5\x3e\xfa\x40\xf4\xdc\x84\xbe\x71\xa4\xb3\x7a\xd6" "\x91\x8d\xe4\x95\x65\x4e\x38\x0a\x1e\x5d\xeb\xc7\x37\x2b\xb2\xaa\x10" "\xd7\x5f\xce\x17\x07\x06\x62\x74\xca\xd6\x91\xd4\x24\x65\x53\x2a\x17" "\xd4\x3f\x46\x20\xcb\xc4\x78\xb3\xae\xb5\x7b\xda\x6e\x6c\xea\xac\x85" "\xcb\x18\x0e\xd5\x6b\x04\x2c\x4e\x37\x58\x3f\xd0\x8f\x35\xef\x63\xcc" "\xe5\x3c\x0e\x6c\x11\xd1\xfb\xd0\x73\xab\x5d\xbd\x7a\x74\xc0\xb2\x7b" "\xd4\x7e\x38\x30\x12\x22\x2a\x54\xf8\xc8\x4c\x22\x51\x9f\x4f\xa1\x8c" "\x32\xe8\x1a\xdd\x51\x47\x54\x71\x72\xd8\x35\x01\xa6\x30\xc9\x0a\x27" "\xf1\x7a\x9c\x9a\x79\x67\x72\xb8\x9a\x8b\xea\x8b\x7a\xe2\x59\x5f\xd3" "\xef\x7b\xdf\x1c\x5b\x73\xf1\x1c\xe2\x17\x36\xe7\xdc\xf8\xea\x27\x3f" "\xf5\x58\xf1\x6d\xa3\x23", 363); syscall(__NR_write, r[0], 0x20000440, 0x16b); *(uint64_t*)0x2085dff0 = 0x20e94000; *(uint64_t*)0x2085dff8 = 0x10295; syscall(__NR_readv, r[0], 0x2085dff0, 1); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); for (;;) { initialize_tun(); initialize_netdevices(); loop(); } }