// https://syzkaller.appspot.com/bug?id=8f063539d4ecf1faf3132624b57a641e923ee25a // 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 static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } 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); } } 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 = 240; if (dup2(tunfd, kTunFd) < 0) exit(1); 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) exit(1); } if (ioctl(tunfd, TUNGETIFF, (void*)&ifr) < 0) exit(1); tun_frags_enabled = (ifr.ifr_flags & IFF_NAPI_FRAGS) != 0; execute_command(0, "sysctl -w net.ipv6.conf.%s.accept_dad=0", TUN_IFACE); execute_command(0, "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 neigh add %s lladdr %s dev %s nud permanent", REMOTE_IPV4, REMOTE_MAC, TUN_IFACE); execute_command(0, "ip -6 addr add %s/120 dev %s", LOCAL_IPV6, TUN_IFACE); execute_command(0, "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 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 long syz_open_dev(long a0, long a1, long 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) - 1); buf[sizeof(buf) - 1] = 0; while ((hash = strchr(buf, '#'))) { *hash = '0' + (char)(a1 % 10); a1 /= 10; } return open(buf, a2, 0); } } 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_tun(); initialize_netdevices(); loop(); exit(1); } uint64_t r[5] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void loop(void) { long res = 0; syscall(__NR_clone, 0x820002102013fff, 0, 0x9999999999999999, 0x20000000, -1); res = syscall(__NR_socket, 0x2b, 1, 0); if (res != -1) r[0] = res; res = syscall(__NR_dup3, r[0], -1, 0); if (res != -1) r[1] = res; syscall(__NR_fcntl, r[1], 0, -1); syscall(__NR_getpid); memcpy((void*)0x20000080, "./file0", 8); syscall(__NR_fchmodat, -1, 0x20000080, 0x10); memcpy((void*)0x20000000, "/dev/kvm", 9); res = syscall(__NR_openat, 0xffffffffffffff9c, 0x20000000, 0, 0); if (res != -1) r[2] = res; res = syscall(__NR_ioctl, r[2], 0xae01, 0); if (res != -1) r[3] = res; res = syscall(__NR_ioctl, r[3], 0xae41, 0); if (res != -1) r[4] = res; *(uint32_t*)0x20000100 = 1; *(uint32_t*)0x20000104 = 0; *(uint32_t*)0x20000108 = 0x40000108; *(uint32_t*)0x2000010c = 0; *(uint64_t*)0x20000110 = 0; syscall(__NR_ioctl, r[4], 0x4080aebf, 0x20000100); syscall(__NR_getpid); *(uint16_t*)0x20000300 = 0; *(uint16_t*)0x20000302 = 0; *(uint16_t*)0x20000304 = 0; *(uint16_t*)0x20000306 = 0; memcpy((void*)0x20000308, "\x73\x79\x7a\x30\x00\x00\x00\x00\x00\x00\x00\xe1\xff\xff\xff\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00", 80); *(uint32_t*)0x20000358 = 0; syscall(__NR_ioctl, -1, 0x5501, 0x20000300); syscall(__NR_getpid); *(uint16_t*)0x200000c0 = 8; *(uint16_t*)0x200000c2 = 6; *(uint16_t*)0x200000c4 = 1; *(uint16_t*)0x200000c6 = 0x58; memcpy((void*)0x200000c8, "\x73\x79\x7a\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 80); *(uint32_t*)0x20000118 = 0x53; syscall(__NR_ioctl, -1, 0x405c5503, 0x200000c0); syscall(__NR_pipe, 0x20000180); *(uint16_t*)0x20000040 = 0xa; *(uint16_t*)0x20000042 = htobe16(0); *(uint32_t*)0x20000044 = 0; *(uint8_t*)0x20000048 = 0xfe; *(uint8_t*)0x20000049 = 0x80; *(uint8_t*)0x2000004a = 0; *(uint8_t*)0x2000004b = 0; *(uint8_t*)0x2000004c = 0; *(uint8_t*)0x2000004d = 0; *(uint8_t*)0x2000004e = 0; *(uint8_t*)0x2000004f = 0; *(uint8_t*)0x20000050 = 0; *(uint8_t*)0x20000051 = 0; *(uint8_t*)0x20000052 = 0; *(uint8_t*)0x20000053 = 0; *(uint8_t*)0x20000054 = 0; *(uint8_t*)0x20000055 = 0; *(uint8_t*)0x20000056 = 0; *(uint8_t*)0x20000057 = 0xbb; *(uint32_t*)0x20000058 = 0; syscall(__NR_connect, -1, 0x20000040, 0); memcpy((void*)0x20000940, "/dev/ptmx", 10); syscall(__NR_openat, 0xffffffffffffff9c, 0x20000940, 0, 0); memcpy((void*)0x200001c0, "/dev/net/tun", 13); syscall(__NR_openat, 0xffffffffffffff9c, 0x200001c0, 0, 0); *(uint8_t*)0x20000240 = 1; *(uint8_t*)0x20000241 = 0; syscall(__NR_write, -1, 0x20000240, 2); *(uint16_t*)0x200008c0 = 0xa; *(uint16_t*)0x200008c2 = htobe16(0x4e20); *(uint32_t*)0x200008c4 = 4; *(uint8_t*)0x200008c8 = -1; *(uint8_t*)0x200008c9 = 1; *(uint8_t*)0x200008ca = 0; *(uint8_t*)0x200008cb = 0; *(uint8_t*)0x200008cc = 0; *(uint8_t*)0x200008cd = 0; *(uint8_t*)0x200008ce = 0; *(uint8_t*)0x200008cf = 0; *(uint8_t*)0x200008d0 = 0; *(uint8_t*)0x200008d1 = 0; *(uint8_t*)0x200008d2 = 0; *(uint8_t*)0x200008d3 = 0; *(uint8_t*)0x200008d4 = 0; *(uint8_t*)0x200008d5 = 0; *(uint8_t*)0x200008d6 = 0; *(uint8_t*)0x200008d7 = 1; *(uint32_t*)0x200008d8 = 3; syscall(__NR_sendto, -1, 0x200007c0, 0, 0x4c000, 0x200008c0, 0x1c); memcpy((void*)0x20000940, "/dev/ptmx", 10); syscall(__NR_openat, 0xffffffffffffff9c, 0x20000940, 0, 0); syscall(__NR_socket, 0xa, 0, 0); syscall(__NR_ioctl, -1, 0x89ff, 0x20000300); memcpy((void*)0x20000240, "/dev/snd/pcmC#D#p", 18); syz_open_dev(0x20000240, 5, 0x40040); *(uint64_t*)0x20000380 = 0x2000; *(uint64_t*)0x20000388 = 0x20000280; *(uint32_t*)0x20000390 = 8; *(uint32_t*)0x20000394 = -1; *(uint32_t*)0x20000398 = 2; *(uint8_t*)0x2000039c = 0; *(uint8_t*)0x2000039d = 0; *(uint8_t*)0x2000039e = 0; *(uint8_t*)0x2000039f = 0; *(uint8_t*)0x200003a0 = 0; *(uint8_t*)0x200003a1 = 0; *(uint8_t*)0x200003a2 = 0; *(uint8_t*)0x200003a3 = 0; *(uint8_t*)0x200003a4 = 0; *(uint8_t*)0x200003a5 = 0; *(uint8_t*)0x200003a6 = 0; *(uint8_t*)0x200003a7 = 0; *(uint8_t*)0x200003a8 = 0; *(uint8_t*)0x200003a9 = 0; *(uint8_t*)0x200003aa = 0; *(uint8_t*)0x200003ab = 0; *(uint8_t*)0x200003ac = 0; *(uint8_t*)0x200003ad = 0; *(uint8_t*)0x200003ae = 0; *(uint8_t*)0x200003af = 0; *(uint8_t*)0x200003b0 = 0; *(uint8_t*)0x200003b1 = 0; *(uint8_t*)0x200003b2 = 0; *(uint8_t*)0x200003b3 = 0; *(uint8_t*)0x200003b4 = 0; *(uint8_t*)0x200003b5 = 0; *(uint8_t*)0x200003b6 = 0; *(uint8_t*)0x200003b7 = 0; *(uint8_t*)0x200003b8 = 0; *(uint8_t*)0x200003b9 = 0; *(uint8_t*)0x200003ba = 0; *(uint8_t*)0x200003bb = 0; *(uint8_t*)0x200003bc = 0; *(uint8_t*)0x200003bd = 0; *(uint8_t*)0x200003be = 0; *(uint8_t*)0x200003bf = 0; syscall(__NR_ioctl, -1, 0x4040ae79, 0x20000380); *(uint64_t*)0x20000140 = 0x200000c0; *(uint16_t*)0x200000c0 = 0x10; *(uint16_t*)0x200000c2 = 0; *(uint32_t*)0x200000c4 = 0; *(uint32_t*)0x200000c8 = 0; *(uint32_t*)0x20000148 = 0xc; *(uint64_t*)0x20000150 = 0x20000100; *(uint64_t*)0x20000100 = 0x20000180; *(uint32_t*)0x20000180 = 0x28; *(uint16_t*)0x20000184 = 0x10; *(uint16_t*)0x20000186 = 0xba5f; *(uint32_t*)0x20000188 = 0; *(uint32_t*)0x2000018c = 0; *(uint8_t*)0x20000190 = 0; *(uint8_t*)0x20000191 = 0; *(uint16_t*)0x20000192 = 0; *(uint32_t*)0x20000194 = 0; *(uint32_t*)0x20000198 = 3; *(uint32_t*)0x2000019c = 0; *(uint16_t*)0x200001a0 = 8; *(uint16_t*)0x200001a2 = 0x1b; *(uint32_t*)0x200001a4 = 0; *(uint64_t*)0x20000108 = 0x28; *(uint64_t*)0x20000158 = 1; *(uint64_t*)0x20000160 = 0; *(uint64_t*)0x20000168 = 0; *(uint32_t*)0x20000170 = 0; syscall(__NR_sendmsg, -1, 0x20000140, 0); } int main(void) { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); use_temporary_dir(); do_sandbox_none(); return 0; }