// https://syzkaller.appspot.com/bug?id=4acb2aa300d1adc7695b387fb986b9ef00680908 // 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 #include #include #define BITMASK(bf_off, bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type, htobe, addr, val, bf_off, bf_len) \ *(type*)(addr) = \ htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | \ (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static bool write_file(const char* file, const char* what, ...) { char buf[1024]; va_list args; va_start(args, what); vsnprintf(buf, sizeof(buf), what, args); va_end(args); buf[sizeof(buf) - 1] = 0; int len = strlen(buf); int fd = open(file, O_WRONLY | O_CLOEXEC); if (fd == -1) return false; if (write(fd, buf, len) != len) { int err = errno; close(fd); errno = err; return false; } close(fd); return true; } struct nlmsg { char* pos; int nesting; struct nlattr* nested[8]; char buf[4096]; }; static void netlink_init(struct nlmsg* nlmsg, int typ, int flags, const void* data, int size) { memset(nlmsg, 0, sizeof(*nlmsg)); struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf; hdr->nlmsg_type = typ; hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | flags; memcpy(hdr + 1, data, size); nlmsg->pos = (char*)(hdr + 1) + NLMSG_ALIGN(size); } static void netlink_attr(struct nlmsg* nlmsg, int typ, const void* data, int size) { struct nlattr* attr = (struct nlattr*)nlmsg->pos; attr->nla_len = sizeof(*attr) + size; attr->nla_type = typ; if (size > 0) memcpy(attr + 1, data, size); nlmsg->pos += NLMSG_ALIGN(attr->nla_len); } static int netlink_send_ext(struct nlmsg* nlmsg, int sock, uint16_t reply_type, int* reply_len, bool dofail) { if (nlmsg->pos > nlmsg->buf + sizeof(nlmsg->buf) || nlmsg->nesting) exit(1); struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf; hdr->nlmsg_len = nlmsg->pos - nlmsg->buf; struct sockaddr_nl addr; memset(&addr, 0, sizeof(addr)); addr.nl_family = AF_NETLINK; ssize_t n = sendto(sock, nlmsg->buf, hdr->nlmsg_len, 0, (struct sockaddr*)&addr, sizeof(addr)); if (n != (ssize_t)hdr->nlmsg_len) { if (dofail) exit(1); return -1; } n = recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0); if (reply_len) *reply_len = 0; if (n < 0) { if (dofail) exit(1); return -1; } if (n < (ssize_t)sizeof(struct nlmsghdr)) { errno = EINVAL; if (dofail) exit(1); return -1; } if (hdr->nlmsg_type == NLMSG_DONE) return 0; if (reply_len && hdr->nlmsg_type == reply_type) { *reply_len = n; return 0; } if (n < (ssize_t)(sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr))) { errno = EINVAL; if (dofail) exit(1); return -1; } if (hdr->nlmsg_type != NLMSG_ERROR) { errno = EINVAL; if (dofail) exit(1); return -1; } errno = -((struct nlmsgerr*)(hdr + 1))->error; return -errno; } static int netlink_query_family_id(struct nlmsg* nlmsg, int sock, const char* family_name, bool dofail) { struct genlmsghdr genlhdr; memset(&genlhdr, 0, sizeof(genlhdr)); genlhdr.cmd = CTRL_CMD_GETFAMILY; netlink_init(nlmsg, GENL_ID_CTRL, 0, &genlhdr, sizeof(genlhdr)); netlink_attr(nlmsg, CTRL_ATTR_FAMILY_NAME, family_name, strnlen(family_name, GENL_NAMSIZ - 1) + 1); int n = 0; int err = netlink_send_ext(nlmsg, sock, GENL_ID_CTRL, &n, dofail); if (err < 0) { return -1; } uint16_t id = 0; struct nlattr* attr = (struct nlattr*)(nlmsg->buf + NLMSG_HDRLEN + NLMSG_ALIGN(sizeof(genlhdr))); for (; (char*)attr < nlmsg->buf + n; attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) { if (attr->nla_type == CTRL_ATTR_FAMILY_ID) { id = *(uint16_t*)(attr + 1); break; } } if (!id) { errno = EINVAL; return -1; } recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0); return id; } static long syz_genetlink_get_family_id(volatile long name, volatile long sock_arg) { int fd = sock_arg; if (fd < 0) { fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); if (fd == -1) { return -1; } } struct nlmsg nlmsg_tmp; int ret = netlink_query_family_id(&nlmsg_tmp, fd, (char*)name, false); if ((int)sock_arg < 0) close(fd); if (ret < 0) { return -1; } return ret; } static void setup_common() { if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) { } } static void setup_binderfs() { if (mkdir("/dev/binderfs", 0777)) { } if (mount("binder", "/dev/binderfs", "binder", 0, NULL)) { } if (symlink("/dev/binderfs", "./binderfs")) { } } static void loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setsid(); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = (200 << 20); setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 32 << 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 (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(0x02000000)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } typedef struct { const char* name; const char* value; } sysctl_t; static const sysctl_t sysctls[] = { {"/proc/sys/kernel/shmmax", "16777216"}, {"/proc/sys/kernel/shmall", "536870912"}, {"/proc/sys/kernel/shmmni", "1024"}, {"/proc/sys/kernel/msgmax", "8192"}, {"/proc/sys/kernel/msgmni", "1024"}, {"/proc/sys/kernel/msgmnb", "1024"}, {"/proc/sys/kernel/sem", "1024 1048576 500 1024"}, }; unsigned i; for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++) write_file(sysctls[i].name, sysctls[i].value); } static int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, __WALL) != pid) { } return WEXITSTATUS(status); } static void drop_caps(void) { struct __user_cap_header_struct cap_hdr = {}; struct __user_cap_data_struct cap_data[2] = {}; cap_hdr.version = _LINUX_CAPABILITY_VERSION_3; cap_hdr.pid = getpid(); if (syscall(SYS_capget, &cap_hdr, &cap_data)) exit(1); const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE); cap_data[0].effective &= ~drop; cap_data[0].permitted &= ~drop; cap_data[0].inheritable &= ~drop; if (syscall(SYS_capset, &cap_hdr, &cap_data)) exit(1); } 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(); drop_caps(); if (unshare(CLONE_NEWNET)) { } write_file("/proc/sys/net/ipv4/ping_group_range", "0 65535"); setup_binderfs(); loop(); exit(1); } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0x0}; void loop(void) { intptr_t res = 0; res = syscall(__NR_socket, 0x10ul, 3ul, 0); if (res != -1) r[0] = res; res = syscall(__NR_socket, 0x10ul, 3ul, 0); if (res != -1) r[1] = res; res = syscall(__NR_socket, 0x10ul, 0x803ul, 0); if (res != -1) r[2] = res; memcpy((void*)0x200000c0, "mptcp_pm\000", 9); syz_genetlink_get_family_id(0x200000c0, r[2]); *(uint32_t*)0x20000080 = 0x14; res = syscall(__NR_getsockname, r[2], 0x20000100ul, 0x20000080ul); if (res != -1) r[3] = *(uint32_t*)0x20000104; *(uint64_t*)0x20005840 = 0; *(uint32_t*)0x20005848 = 0; *(uint64_t*)0x20005850 = 0x200005c0; *(uint64_t*)0x200005c0 = 0x20001240; *(uint32_t*)0x20001240 = 0x48; *(uint16_t*)0x20001244 = 0x24; *(uint16_t*)0x20001246 = 0x8651; *(uint32_t*)0x20001248 = 0; *(uint32_t*)0x2000124c = 0; *(uint8_t*)0x20001250 = 0; *(uint8_t*)0x20001251 = 0; *(uint16_t*)0x20001252 = 0; *(uint32_t*)0x20001254 = r[3]; *(uint16_t*)0x20001258 = 0; *(uint16_t*)0x2000125a = 0; *(uint16_t*)0x2000125c = -1; *(uint16_t*)0x2000125e = -1; *(uint16_t*)0x20001260 = 0; *(uint16_t*)0x20001262 = 0; *(uint16_t*)0x20001264 = 8; *(uint16_t*)0x20001266 = 1; memcpy((void*)0x20001268, "htb\000", 4); *(uint16_t*)0x2000126c = 0x1c; *(uint16_t*)0x2000126e = 2; *(uint16_t*)0x20001270 = 0x18; *(uint16_t*)0x20001272 = 2; *(uint32_t*)0x20001274 = 3; *(uint32_t*)0x20001278 = 0; *(uint32_t*)0x2000127c = 0; *(uint32_t*)0x20001280 = 0; *(uint32_t*)0x20001284 = 0; *(uint64_t*)0x200005c8 = 0x48; *(uint64_t*)0x20005858 = 1; *(uint64_t*)0x20005860 = 0; *(uint64_t*)0x20005868 = 0; *(uint32_t*)0x20005870 = 0; syscall(__NR_sendmsg, r[1], 0x20005840ul, 0ul); *(uint64_t*)0x20000140 = 0; *(uint32_t*)0x20000148 = 0; *(uint64_t*)0x20000150 = 0x20000180; *(uint64_t*)0x20000180 = 0x20000ac0; *(uint32_t*)0x20000ac0 = 0x70; *(uint16_t*)0x20000ac4 = 0x2c; *(uint16_t*)0x20000ac6 = 0xd27; *(uint32_t*)0x20000ac8 = 0; *(uint32_t*)0x20000acc = 0; *(uint8_t*)0x20000ad0 = 0; *(uint8_t*)0x20000ad1 = 0; *(uint16_t*)0x20000ad2 = 0; *(uint32_t*)0x20000ad4 = r[3]; *(uint16_t*)0x20000ad8 = 0; *(uint16_t*)0x20000ada = 0; *(uint16_t*)0x20000adc = 0; *(uint16_t*)0x20000ade = 0; *(uint16_t*)0x20000ae0 = 2; *(uint16_t*)0x20000ae2 = 0; *(uint16_t*)0x20000ae4 = 0xa; *(uint16_t*)0x20000ae6 = 1; memcpy((void*)0x20000ae8, "basic\000", 6); *(uint16_t*)0x20000af0 = 0x40; *(uint16_t*)0x20000af2 = 2; *(uint16_t*)0x20000af4 = 0x3c; STORE_BY_BITMASK(uint16_t, , 0x20000af6, 2, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x20000af7, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x20000af7, 1, 7, 1); *(uint16_t*)0x20000af8 = 0x30; STORE_BY_BITMASK(uint16_t, , 0x20000afa, 2, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x20000afb, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x20000afb, 1, 7, 1); *(uint16_t*)0x20000afc = 0x2c; STORE_BY_BITMASK(uint16_t, , 0x20000afe, 1, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x20000aff, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x20000aff, 0, 7, 1); *(uint16_t*)0x20000b00 = 0; *(uint16_t*)0x20000b02 = 9; *(uint16_t*)0x20000b04 = 0; *(uint16_t*)0x20000b06 = 0; *(uint16_t*)0x20000b08 = 8; *(uint16_t*)0x20000b0a = 1; *(uint32_t*)0x20000b0c = 0; *(uint16_t*)0x20000b10 = 5; *(uint16_t*)0x20000b12 = 4; *(uint8_t*)0x20000b14 = 0xe; *(uint16_t*)0x20000b18 = 0xb; *(uint16_t*)0x20000b1a = 2; memcpy((void*)0x20000b1c, "policy\000", 7); *(uint16_t*)0x20000b24 = 4; *(uint16_t*)0x20000b26 = 5; *(uint16_t*)0x20000b28 = 8; *(uint16_t*)0x20000b2a = 1; *(uint16_t*)0x20000b2c = 2; *(uint16_t*)0x20000b2e = 0; *(uint64_t*)0x20000188 = 0x70; *(uint64_t*)0x20000158 = 1; *(uint64_t*)0x20000160 = 0; *(uint64_t*)0x20000168 = 0; *(uint32_t*)0x20000170 = 0; syscall(__NR_sendmsg, r[0], 0x20000140ul, 0ul); } int main(void) { syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); do_sandbox_none(); return 0; }