// https://syzkaller.appspot.com/bug?id=139f57528e83bd37af23a2327fed7a6f356b52ef // 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 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 void netlink_nest(struct nlmsg* nlmsg, int typ) { struct nlattr* attr = (struct nlattr*)nlmsg->pos; attr->nla_type = typ; nlmsg->pos += sizeof(*attr); nlmsg->nested[nlmsg->nesting++] = attr; } static void netlink_done(struct nlmsg* nlmsg) { struct nlattr* attr = nlmsg->nested[--nlmsg->nesting]; attr->nla_len = nlmsg->pos - (char*)attr; } 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_send(struct nlmsg* nlmsg, int sock) { return netlink_send_ext(nlmsg, sock, 0, NULL, true); } 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 void netlink_add_device_impl(struct nlmsg* nlmsg, const char* type, const char* name, bool up) { struct ifinfomsg hdr; memset(&hdr, 0, sizeof(hdr)); if (up) hdr.ifi_flags = hdr.ifi_change = IFF_UP; netlink_init(nlmsg, RTM_NEWLINK, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr)); if (name) netlink_attr(nlmsg, IFLA_IFNAME, name, strlen(name)); netlink_nest(nlmsg, IFLA_LINKINFO); netlink_attr(nlmsg, IFLA_INFO_KIND, type, strlen(type)); } static void netlink_device_change(struct nlmsg* nlmsg, int sock, const char* name, bool up, const char* master, const void* mac, int macsize, const char* new_name) { struct ifinfomsg hdr; memset(&hdr, 0, sizeof(hdr)); if (up) hdr.ifi_flags = hdr.ifi_change = IFF_UP; hdr.ifi_index = if_nametoindex(name); netlink_init(nlmsg, RTM_NEWLINK, 0, &hdr, sizeof(hdr)); if (new_name) netlink_attr(nlmsg, IFLA_IFNAME, new_name, strlen(new_name)); if (master) { int ifindex = if_nametoindex(master); netlink_attr(nlmsg, IFLA_MASTER, &ifindex, sizeof(ifindex)); } if (macsize) netlink_attr(nlmsg, IFLA_ADDRESS, mac, macsize); int err = netlink_send(nlmsg, sock); if (err < 0) { } } static struct nlmsg nlmsg; static long syz_open_dev(volatile long a0, volatile long a1, volatile 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 { unsigned long nb = a1; char buf[1024]; char* hash; strncpy(buf, (char*)a0, sizeof(buf) - 1); buf[sizeof(buf) - 1] = 0; while ((hash = strchr(buf, '#'))) { *hash = '0' + (char)(nb % 10); nb /= 10; } return open(buf, a2 & ~O_CREAT, 0); } } #define NL802154_CMD_SET_SHORT_ADDR 11 #define NL802154_ATTR_IFINDEX 3 #define NL802154_ATTR_SHORT_ADDR 10 static const char* setup_802154() { const char* error = NULL; int sock_generic = -1; int sock_route = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock_route == -1) { error = "socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE) failed"; goto fail; } sock_generic = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); if (sock_generic == -1) { error = "socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC) failed"; goto fail; } { int nl802154_family_id = netlink_query_family_id(&nlmsg, sock_generic, "nl802154", true); if (nl802154_family_id < 0) { error = "netlink_query_family_id failed"; goto fail; } for (int i = 0; i < 2; i++) { char devname[] = "wpan0"; devname[strlen(devname) - 1] += i; uint64_t hwaddr = 0xaaaaaaaaaaaa0002 + (i << 8); uint16_t shortaddr = 0xaaa0 + i; int ifindex = if_nametoindex(devname); struct genlmsghdr genlhdr; memset(&genlhdr, 0, sizeof(genlhdr)); genlhdr.cmd = NL802154_CMD_SET_SHORT_ADDR; netlink_init(&nlmsg, nl802154_family_id, 0, &genlhdr, sizeof(genlhdr)); netlink_attr(&nlmsg, NL802154_ATTR_IFINDEX, &ifindex, sizeof(ifindex)); netlink_attr(&nlmsg, NL802154_ATTR_SHORT_ADDR, &shortaddr, sizeof(shortaddr)); if (netlink_send(&nlmsg, sock_generic) < 0) { error = "NL802154_CMD_SET_SHORT_ADDR failed"; goto fail; } netlink_device_change(&nlmsg, sock_route, devname, true, 0, &hwaddr, sizeof(hwaddr), 0); if (i == 0) { netlink_add_device_impl(&nlmsg, "lowpan", "lowpan0", false); netlink_done(&nlmsg); netlink_attr(&nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex)); if (netlink_send(&nlmsg, sock_route) < 0) { error = "netlink: adding device lowpan0 type lowpan link wpan0"; goto fail; } } } } fail: close(sock_route); close(sock_generic); return error; } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); const char* reason; (void)reason; if ((reason = setup_802154())) printf("the reproducer may not work as expected: 802154 injection setup " "failed: %s\n", reason); intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // openat$sysfs arguments: [ // fd: const = 0xffffffffffffff9c (8 bytes) // dir: ptr[in, buffer] { // buffer: {2f 73 79 73 2f 70 6f 77 65 72 2f 72 65 73 75 6d 65} (length // 0x11) // } // flags: open_flags = 0x141a82 (4 bytes) // mode: open_mode = 0x0 (2 bytes) // ] // returns fd memcpy((void*)0x2000000002c0, "/sys/power/resume", 17); res = syscall( __NR_openat, /*fd=*/0xffffffffffffff9cul, /*dir=*/0x2000000002c0ul, /*flags=O_TRUNC|O_SYNC|O_NONBLOCK|O_NOATIME|O_EXCL|O_RDWR*/ 0x141a82, /*mode=*/0); if (res != -1) r[0] = res; // write$cgroup_int arguments: [ // fd: fd_cgroup_int (resource) // buf: ptr[in, int64] { // int64 = 0x900 (18 bytes) // } // len: bytesize = 0x12 (8 bytes) // ] sprintf((char*)0x200000000040, "0x%016llx", (long long)0x900); syscall(__NR_write, /*fd=*/r[0], /*buf=*/0x200000000040ul, /*len=*/0x12ul); // syz_open_dev$loop arguments: [ // dev: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 6c 6f 6f 70 23 00} (length 0xb) // } // id: intptr = 0x7 (8 bytes) // flags: open_flags = 0x180862 (8 bytes) // ] // returns fd_loop memcpy((void*)0x200000000240, "/dev/loop#\000", 11); res = -1; res = syz_open_dev( /*dev=*/0x200000000240, /*id=*/7, /*flags=O_NONBLOCK|O_CREAT|O_CLOEXEC|O_RDWR|0x100020*/ 0x180862); if (res != -1) r[1] = res; // openat$sysfs arguments: [ // fd: const = 0xffffffffffffff9c (8 bytes) // dir: ptr[in, buffer] { // buffer: {2f 73 79 73 2f 70 6f 77 65 72 2f 70 6d 5f 66 72 65 65 7a 65 // 5f 74 69 6d 65 6f 75 74} (length 0x1c) // } // flags: open_flags = 0x82802 (4 bytes) // mode: open_mode = 0xf (2 bytes) // ] // returns fd memcpy((void*)0x200000000000, "/sys/power/pm_freeze_timeout", 28); res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*dir=*/0x200000000000ul, /*flags=O_NONBLOCK|O_CLOEXEC|FASYNC|O_RDWR*/ 0x82802, /*mode=S_IXOTH|S_IWOTH|S_IROTH|S_IXGRP*/ 0xf); if (res != -1) r[2] = res; // ioctl$LOOP_CONFIGURE arguments: [ // fd: fd_loop (resource) // cmd: const = 0x4c0a (4 bytes) // arg: ptr[in, loop_config] { // loop_config { // fd: fd_loop (resource) // block_size: int32 = 0x0 (4 bytes) // info: loop_info64 { // lo_device: const = 0x0 (8 bytes) // lo_inode: const = 0x0 (8 bytes) // lo_rdevice: const = 0x0 (8 bytes) // lo_offset: int64 = 0x6 (8 bytes) // lo_sizelimit: int64 = 0x4000000000000ffd (8 bytes) // lo_number: const = 0x0 (4 bytes) // lo_enc_type: lo_encrypt_type = 0x0 (4 bytes) // lo_enc_key_size: int32 = 0x1e (4 bytes) // lo_flags: lo_flags = 0xc (4 bytes) // lo_file_name: buffer: {fa f9 83 17 e5 a1 14 99 89 fc 8d be 43 ea // 6a cc 96 e3 a2 50 3d c3 bd 3f e3 7d 58 12 8b ba d0 09 9c eb dc 25 // f5 ab 60 c9 e6 d6 80 f9 85 88 1a 7b ed a9 d6 90 98 c8 b5 34 46 4c // 51 6b dd 8a 0f 35} (length 0x40) lo_crypt_name: buffer: {32 d8 cc // 26 f7 06 1a 74 df 2c fc 06 c8 9f 3d 9e 23 4b 30 c5 09 97 d3 be f4 // 09 ff 21 76 ff 7b fe 55 cd 4a 5d 83 cd 4a 52 4b d3 ff e7 0c 7f 3f // 80 0b 2f 7b 6a a5 4c c5 0a 1f ca ed 1e 83 1f a7 9a} (length 0x40) // lo_enc_key: buffer: {67 52 37 60 fd 40 f7 8d 2c fc 03 d8 1a 8c a5 // 5b a1 39 c0 18 02 c4 da e4 16 2e 43 ac 61 b7 ad 33} (length 0x20) // lo_init: array[int64] { // int64 = 0x2 (8 bytes) // int64 = 0x7 (8 bytes) // } // } // reserved: buffer: {00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00} (length 0x40) // } // } // ] *(uint32_t*)0x200000000080 = r[2]; *(uint32_t*)0x200000000084 = 0; *(uint64_t*)0x200000000088 = 0; *(uint64_t*)0x200000000090 = 0; *(uint64_t*)0x200000000098 = 0; *(uint64_t*)0x2000000000a0 = 6; *(uint64_t*)0x2000000000a8 = 0x4000000000000ffd; *(uint32_t*)0x2000000000b0 = 0; *(uint32_t*)0x2000000000b4 = 0; *(uint32_t*)0x2000000000b8 = 0x1e; *(uint32_t*)0x2000000000bc = 0xc; memcpy((void*)0x2000000000c0, "\xfa\xf9\x83\x17\xe5\xa1\x14\x99\x89\xfc\x8d\xbe\x43\xea\x6a\xcc\x96" "\xe3\xa2\x50\x3d\xc3\xbd\x3f\xe3\x7d\x58\x12\x8b\xba\xd0\x09\x9c\xeb" "\xdc\x25\xf5\xab\x60\xc9\xe6\xd6\x80\xf9\x85\x88\x1a\x7b\xed\xa9\xd6" "\x90\x98\xc8\xb5\x34\x46\x4c\x51\x6b\xdd\x8a\x0f\x35", 64); memcpy((void*)0x200000000100, "\x32\xd8\xcc\x26\xf7\x06\x1a\x74\xdf\x2c\xfc\x06\xc8\x9f\x3d\x9e\x23" "\x4b\x30\xc5\x09\x97\xd3\xbe\xf4\x09\xff\x21\x76\xff\x7b\xfe\x55\xcd" "\x4a\x5d\x83\xcd\x4a\x52\x4b\xd3\xff\xe7\x0c\x7f\x3f\x80\x0b\x2f\x7b" "\x6a\xa5\x4c\xc5\x0a\x1f\xca\xed\x1e\x83\x1f\xa7\x9a", 64); memcpy((void*)0x200000000140, "\x67\x52\x37\x60\xfd\x40\xf7\x8d\x2c\xfc\x03\xd8\x1a\x8c\xa5\x5b\xa1" "\x39\xc0\x18\x02\xc4\xda\xe4\x16\x2e\x43\xac\x61\xb7\xad\x33", 32); *(uint64_t*)0x200000000160 = 2; *(uint64_t*)0x200000000168 = 7; memset((void*)0x200000000170, 0, 64); syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x4c0a, /*arg=*/0x200000000080ul); return 0; }