// https://syzkaller.appspot.com/bug?id=5608eec6b6533ced4380191fb86d41f55285b6cd // 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 #ifndef __NR_memfd_create #define __NR_memfd_create 319 #endif static unsigned long long procid; static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } 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 thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { int state; } event_t; static void event_init(event_t* ev) { ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { if (ev->state) exit(1); __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000); } static void event_wait(event_t* ev) { while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0); } static int event_isset(event_t* ev) { return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE); } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; for (;;) { uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts); if (__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) return 1; now = current_time_ms(); if (now - start > timeout) return 0; } } 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; } #define MAX_FDS 30 #define USB_MAX_IFACE_NUM 4 #define USB_MAX_EP_NUM 32 #define USB_MAX_FDS 6 struct usb_endpoint_index { struct usb_endpoint_descriptor desc; int handle; }; struct usb_iface_index { struct usb_interface_descriptor* iface; uint8_t bInterfaceNumber; uint8_t bAlternateSetting; uint8_t bInterfaceClass; struct usb_endpoint_index eps[USB_MAX_EP_NUM]; int eps_num; }; struct usb_device_index { struct usb_device_descriptor* dev; struct usb_config_descriptor* config; uint8_t bDeviceClass; uint8_t bMaxPower; int config_length; struct usb_iface_index ifaces[USB_MAX_IFACE_NUM]; int ifaces_num; int iface_cur; }; struct usb_info { int fd; struct usb_device_index index; }; static struct usb_info usb_devices[USB_MAX_FDS]; static struct usb_device_index* lookup_usb_index(int fd) { for (int i = 0; i < USB_MAX_FDS; i++) { if (__atomic_load_n(&usb_devices[i].fd, __ATOMIC_ACQUIRE) == fd) return &usb_devices[i].index; } return NULL; } static int usb_devices_num; static bool parse_usb_descriptor(const char* buffer, size_t length, struct usb_device_index* index) { if (length < sizeof(*index->dev) + sizeof(*index->config)) return false; memset(index, 0, sizeof(*index)); index->dev = (struct usb_device_descriptor*)buffer; index->config = (struct usb_config_descriptor*)(buffer + sizeof(*index->dev)); index->bDeviceClass = index->dev->bDeviceClass; index->bMaxPower = index->config->bMaxPower; index->config_length = length - sizeof(*index->dev); index->iface_cur = -1; size_t offset = 0; while (true) { if (offset + 1 >= length) break; uint8_t desc_length = buffer[offset]; uint8_t desc_type = buffer[offset + 1]; if (desc_length <= 2) break; if (offset + desc_length > length) break; if (desc_type == USB_DT_INTERFACE && index->ifaces_num < USB_MAX_IFACE_NUM) { struct usb_interface_descriptor* iface = (struct usb_interface_descriptor*)(buffer + offset); index->ifaces[index->ifaces_num].iface = iface; index->ifaces[index->ifaces_num].bInterfaceNumber = iface->bInterfaceNumber; index->ifaces[index->ifaces_num].bAlternateSetting = iface->bAlternateSetting; index->ifaces[index->ifaces_num].bInterfaceClass = iface->bInterfaceClass; index->ifaces_num++; } if (desc_type == USB_DT_ENDPOINT && index->ifaces_num > 0) { struct usb_iface_index* iface = &index->ifaces[index->ifaces_num - 1]; if (iface->eps_num < USB_MAX_EP_NUM) { memcpy(&iface->eps[iface->eps_num].desc, buffer + offset, sizeof(iface->eps[iface->eps_num].desc)); iface->eps_num++; } } offset += desc_length; } return true; } static struct usb_device_index* add_usb_index(int fd, const char* dev, size_t dev_len) { int i = __atomic_fetch_add(&usb_devices_num, 1, __ATOMIC_RELAXED); if (i >= USB_MAX_FDS) return NULL; if (!parse_usb_descriptor(dev, dev_len, &usb_devices[i].index)) return NULL; __atomic_store_n(&usb_devices[i].fd, fd, __ATOMIC_RELEASE); return &usb_devices[i].index; } struct vusb_connect_string_descriptor { uint32_t len; char* str; } __attribute__((packed)); struct vusb_connect_descriptors { uint32_t qual_len; char* qual; uint32_t bos_len; char* bos; uint32_t strs_len; struct vusb_connect_string_descriptor strs[0]; } __attribute__((packed)); static const char default_string[] = {8, USB_DT_STRING, 's', 0, 'y', 0, 'z', 0}; static const char default_lang_id[] = {4, USB_DT_STRING, 0x09, 0x04}; static bool lookup_connect_response_in(int fd, const struct vusb_connect_descriptors* descs, const struct usb_ctrlrequest* ctrl, struct usb_qualifier_descriptor* qual, char** response_data, uint32_t* response_length) { struct usb_device_index* index = lookup_usb_index(fd); uint8_t str_idx; if (!index) return false; switch (ctrl->bRequestType & USB_TYPE_MASK) { case USB_TYPE_STANDARD: switch (ctrl->bRequest) { case USB_REQ_GET_DESCRIPTOR: switch (ctrl->wValue >> 8) { case USB_DT_DEVICE: *response_data = (char*)index->dev; *response_length = sizeof(*index->dev); return true; case USB_DT_CONFIG: *response_data = (char*)index->config; *response_length = index->config_length; return true; case USB_DT_STRING: str_idx = (uint8_t)ctrl->wValue; if (descs && str_idx < descs->strs_len) { *response_data = descs->strs[str_idx].str; *response_length = descs->strs[str_idx].len; return true; } if (str_idx == 0) { *response_data = (char*)&default_lang_id[0]; *response_length = default_lang_id[0]; return true; } *response_data = (char*)&default_string[0]; *response_length = default_string[0]; return true; case USB_DT_BOS: *response_data = descs->bos; *response_length = descs->bos_len; return true; case USB_DT_DEVICE_QUALIFIER: if (!descs->qual) { qual->bLength = sizeof(*qual); qual->bDescriptorType = USB_DT_DEVICE_QUALIFIER; qual->bcdUSB = index->dev->bcdUSB; qual->bDeviceClass = index->dev->bDeviceClass; qual->bDeviceSubClass = index->dev->bDeviceSubClass; qual->bDeviceProtocol = index->dev->bDeviceProtocol; qual->bMaxPacketSize0 = index->dev->bMaxPacketSize0; qual->bNumConfigurations = index->dev->bNumConfigurations; qual->bRESERVED = 0; *response_data = (char*)qual; *response_length = sizeof(*qual); return true; } *response_data = descs->qual; *response_length = descs->qual_len; return true; default: break; } break; default: break; } break; default: break; } return false; } typedef bool (*lookup_connect_out_response_t)( int fd, const struct vusb_connect_descriptors* descs, const struct usb_ctrlrequest* ctrl, bool* done); static bool lookup_connect_response_out_generic( int fd, const struct vusb_connect_descriptors* descs, const struct usb_ctrlrequest* ctrl, bool* done) { switch (ctrl->bRequestType & USB_TYPE_MASK) { case USB_TYPE_STANDARD: switch (ctrl->bRequest) { case USB_REQ_SET_CONFIGURATION: *done = true; return true; default: break; } break; } return false; } #define UDC_NAME_LENGTH_MAX 128 struct usb_raw_init { __u8 driver_name[UDC_NAME_LENGTH_MAX]; __u8 device_name[UDC_NAME_LENGTH_MAX]; __u8 speed; }; enum usb_raw_event_type { USB_RAW_EVENT_INVALID = 0, USB_RAW_EVENT_CONNECT = 1, USB_RAW_EVENT_CONTROL = 2, }; struct usb_raw_event { __u32 type; __u32 length; __u8 data[0]; }; struct usb_raw_ep_io { __u16 ep; __u16 flags; __u32 length; __u8 data[0]; }; #define USB_RAW_EPS_NUM_MAX 30 #define USB_RAW_EP_NAME_MAX 16 #define USB_RAW_EP_ADDR_ANY 0xff struct usb_raw_ep_caps { __u32 type_control : 1; __u32 type_iso : 1; __u32 type_bulk : 1; __u32 type_int : 1; __u32 dir_in : 1; __u32 dir_out : 1; }; struct usb_raw_ep_limits { __u16 maxpacket_limit; __u16 max_streams; __u32 reserved; }; struct usb_raw_ep_info { __u8 name[USB_RAW_EP_NAME_MAX]; __u32 addr; struct usb_raw_ep_caps caps; struct usb_raw_ep_limits limits; }; struct usb_raw_eps_info { struct usb_raw_ep_info eps[USB_RAW_EPS_NUM_MAX]; }; #define USB_RAW_IOCTL_INIT _IOW('U', 0, struct usb_raw_init) #define USB_RAW_IOCTL_RUN _IO('U', 1) #define USB_RAW_IOCTL_EVENT_FETCH _IOR('U', 2, struct usb_raw_event) #define USB_RAW_IOCTL_EP0_WRITE _IOW('U', 3, struct usb_raw_ep_io) #define USB_RAW_IOCTL_EP0_READ _IOWR('U', 4, struct usb_raw_ep_io) #define USB_RAW_IOCTL_EP_ENABLE _IOW('U', 5, struct usb_endpoint_descriptor) #define USB_RAW_IOCTL_EP_DISABLE _IOW('U', 6, __u32) #define USB_RAW_IOCTL_EP_WRITE _IOW('U', 7, struct usb_raw_ep_io) #define USB_RAW_IOCTL_EP_READ _IOWR('U', 8, struct usb_raw_ep_io) #define USB_RAW_IOCTL_CONFIGURE _IO('U', 9) #define USB_RAW_IOCTL_VBUS_DRAW _IOW('U', 10, __u32) #define USB_RAW_IOCTL_EPS_INFO _IOR('U', 11, struct usb_raw_eps_info) #define USB_RAW_IOCTL_EP0_STALL _IO('U', 12) #define USB_RAW_IOCTL_EP_SET_HALT _IOW('U', 13, __u32) #define USB_RAW_IOCTL_EP_CLEAR_HALT _IOW('U', 14, __u32) #define USB_RAW_IOCTL_EP_SET_WEDGE _IOW('U', 15, __u32) static int usb_raw_open() { return open("/dev/raw-gadget", O_RDWR); } static int usb_raw_init(int fd, uint32_t speed, const char* driver, const char* device) { struct usb_raw_init arg; strncpy((char*)&arg.driver_name[0], driver, sizeof(arg.driver_name)); strncpy((char*)&arg.device_name[0], device, sizeof(arg.device_name)); arg.speed = speed; return ioctl(fd, USB_RAW_IOCTL_INIT, &arg); } static int usb_raw_run(int fd) { return ioctl(fd, USB_RAW_IOCTL_RUN, 0); } static int usb_raw_configure(int fd) { return ioctl(fd, USB_RAW_IOCTL_CONFIGURE, 0); } static int usb_raw_vbus_draw(int fd, uint32_t power) { return ioctl(fd, USB_RAW_IOCTL_VBUS_DRAW, power); } static int usb_raw_ep0_write(int fd, struct usb_raw_ep_io* io) { return ioctl(fd, USB_RAW_IOCTL_EP0_WRITE, io); } static int usb_raw_ep0_read(int fd, struct usb_raw_ep_io* io) { return ioctl(fd, USB_RAW_IOCTL_EP0_READ, io); } static int usb_raw_event_fetch(int fd, struct usb_raw_event* event) { return ioctl(fd, USB_RAW_IOCTL_EVENT_FETCH, event); } static int usb_raw_ep_enable(int fd, struct usb_endpoint_descriptor* desc) { return ioctl(fd, USB_RAW_IOCTL_EP_ENABLE, desc); } static int usb_raw_ep_disable(int fd, int ep) { return ioctl(fd, USB_RAW_IOCTL_EP_DISABLE, ep); } static int usb_raw_ep0_stall(int fd) { return ioctl(fd, USB_RAW_IOCTL_EP0_STALL, 0); } #define USB_MAX_PACKET_SIZE 4096 struct usb_raw_control_event { struct usb_raw_event inner; struct usb_ctrlrequest ctrl; char data[USB_MAX_PACKET_SIZE]; }; struct usb_raw_ep_io_data { struct usb_raw_ep_io inner; char data[USB_MAX_PACKET_SIZE]; }; static void set_interface(int fd, int n) { struct usb_device_index* index = lookup_usb_index(fd); if (!index) return; if (index->iface_cur >= 0 && index->iface_cur < index->ifaces_num) { for (int ep = 0; ep < index->ifaces[index->iface_cur].eps_num; ep++) { int rv = usb_raw_ep_disable( fd, index->ifaces[index->iface_cur].eps[ep].handle); if (rv < 0) { } else { } } } if (n >= 0 && n < index->ifaces_num) { for (int ep = 0; ep < index->ifaces[n].eps_num; ep++) { int rv = usb_raw_ep_enable(fd, &index->ifaces[n].eps[ep].desc); if (rv < 0) { } else { index->ifaces[n].eps[ep].handle = rv; } } index->iface_cur = n; } } static int configure_device(int fd) { struct usb_device_index* index = lookup_usb_index(fd); if (!index) return -1; int rv = usb_raw_vbus_draw(fd, index->bMaxPower); if (rv < 0) { return rv; } rv = usb_raw_configure(fd); if (rv < 0) { return rv; } set_interface(fd, 0); return 0; } static volatile long syz_usb_connect_impl(uint64_t speed, uint64_t dev_len, const char* dev, const struct vusb_connect_descriptors* descs, lookup_connect_out_response_t lookup_connect_response_out) { if (!dev) { return -1; } int fd = usb_raw_open(); if (fd < 0) { return fd; } if (fd >= MAX_FDS) { close(fd); return -1; } struct usb_device_index* index = add_usb_index(fd, dev, dev_len); if (!index) { return -1; } char device[32]; sprintf(&device[0], "dummy_udc.%llu", procid); int rv = usb_raw_init(fd, speed, "dummy_udc", &device[0]); if (rv < 0) { return rv; } rv = usb_raw_run(fd); if (rv < 0) { return rv; } bool done = false; while (!done) { struct usb_raw_control_event event; event.inner.type = 0; event.inner.length = sizeof(event.ctrl); rv = usb_raw_event_fetch(fd, (struct usb_raw_event*)&event); if (rv < 0) { return rv; } if (event.inner.type != USB_RAW_EVENT_CONTROL) continue; char* response_data = NULL; uint32_t response_length = 0; struct usb_qualifier_descriptor qual; if (event.ctrl.bRequestType & USB_DIR_IN) { if (!lookup_connect_response_in(fd, descs, &event.ctrl, &qual, &response_data, &response_length)) { usb_raw_ep0_stall(fd); continue; } } else { if (!lookup_connect_response_out(fd, descs, &event.ctrl, &done)) { usb_raw_ep0_stall(fd); continue; } response_data = NULL; response_length = event.ctrl.wLength; } if ((event.ctrl.bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD && event.ctrl.bRequest == USB_REQ_SET_CONFIGURATION) { rv = configure_device(fd); if (rv < 0) { return rv; } } struct usb_raw_ep_io_data response; response.inner.ep = 0; response.inner.flags = 0; if (response_length > sizeof(response.data)) response_length = 0; if (event.ctrl.wLength < response_length) response_length = event.ctrl.wLength; response.inner.length = response_length; if (response_data) memcpy(&response.data[0], response_data, response_length); else memset(&response.data[0], 0, response_length); if (event.ctrl.bRequestType & USB_DIR_IN) { rv = usb_raw_ep0_write(fd, (struct usb_raw_ep_io*)&response); } else { rv = usb_raw_ep0_read(fd, (struct usb_raw_ep_io*)&response); } if (rv < 0) { return rv; } } sleep_ms(200); return fd; } static volatile long syz_usb_connect(volatile long a0, volatile long a1, volatile long a2, volatile long a3) { uint64_t speed = a0; uint64_t dev_len = a1; const char* dev = (const char*)a2; const struct vusb_connect_descriptors* descs = (const struct vusb_connect_descriptors*)a3; return syz_usb_connect_impl(speed, dev_len, dev, descs, &lookup_connect_response_out_generic); } //% This code is derived from puff.{c,h}, found in the zlib development. The //% original files come with the following copyright notice: //% Copyright (C) 2002-2013 Mark Adler, all rights reserved //% version 2.3, 21 Jan 2013 //% This software is provided 'as-is', without any express or implied //% warranty. In no event will the author be held liable for any damages //% arising from the use of this software. //% Permission is granted to anyone to use this software for any purpose, //% including commercial applications, and to alter it and redistribute it //% freely, subject to the following restrictions: //% 1. The origin of this software must not be misrepresented; you must not //% claim that you wrote the original software. If you use this software //% in a product, an acknowledgment in the product documentation would be //% appreciated but is not required. //% 2. Altered source versions must be plainly marked as such, and must not be //% misrepresented as being the original software. //% 3. This notice may not be removed or altered from any source distribution. //% Mark Adler madler@alumni.caltech.edu //% BEGIN CODE DERIVED FROM puff.{c,h} #define MAXBITS 15 #define MAXLCODES 286 #define MAXDCODES 30 #define MAXCODES (MAXLCODES + MAXDCODES) #define FIXLCODES 288 struct puff_state { unsigned char* out; unsigned long outlen; unsigned long outcnt; const unsigned char* in; unsigned long inlen; unsigned long incnt; int bitbuf; int bitcnt; jmp_buf env; }; static int puff_bits(struct puff_state* s, int need) { long val = s->bitbuf; while (s->bitcnt < need) { if (s->incnt == s->inlen) longjmp(s->env, 1); val |= (long)(s->in[s->incnt++]) << s->bitcnt; s->bitcnt += 8; } s->bitbuf = (int)(val >> need); s->bitcnt -= need; return (int)(val & ((1L << need) - 1)); } static int puff_stored(struct puff_state* s) { s->bitbuf = 0; s->bitcnt = 0; if (s->incnt + 4 > s->inlen) return 2; unsigned len = s->in[s->incnt++]; len |= s->in[s->incnt++] << 8; if (s->in[s->incnt++] != (~len & 0xff) || s->in[s->incnt++] != ((~len >> 8) & 0xff)) return -2; if (s->incnt + len > s->inlen) return 2; if (s->outcnt + len > s->outlen) return 1; for (; len--; s->outcnt++, s->incnt++) { if (s->in[s->incnt]) s->out[s->outcnt] = s->in[s->incnt]; } return 0; } struct puff_huffman { short* count; short* symbol; }; static int puff_decode(struct puff_state* s, const struct puff_huffman* h) { int first = 0; int index = 0; int bitbuf = s->bitbuf; int left = s->bitcnt; int code = first = index = 0; int len = 1; short* next = h->count + 1; while (1) { while (left--) { code |= bitbuf & 1; bitbuf >>= 1; int count = *next++; if (code - count < first) { s->bitbuf = bitbuf; s->bitcnt = (s->bitcnt - len) & 7; return h->symbol[index + (code - first)]; } index += count; first += count; first <<= 1; code <<= 1; len++; } left = (MAXBITS + 1) - len; if (left == 0) break; if (s->incnt == s->inlen) longjmp(s->env, 1); bitbuf = s->in[s->incnt++]; if (left > 8) left = 8; } return -10; } static int puff_construct(struct puff_huffman* h, const short* length, int n) { int len; for (len = 0; len <= MAXBITS; len++) h->count[len] = 0; int symbol; for (symbol = 0; symbol < n; symbol++) (h->count[length[symbol]])++; if (h->count[0] == n) return 0; int left = 1; for (len = 1; len <= MAXBITS; len++) { left <<= 1; left -= h->count[len]; if (left < 0) return left; } short offs[MAXBITS + 1]; offs[1] = 0; for (len = 1; len < MAXBITS; len++) offs[len + 1] = offs[len] + h->count[len]; for (symbol = 0; symbol < n; symbol++) if (length[symbol] != 0) h->symbol[offs[length[symbol]]++] = symbol; return left; } static int puff_codes(struct puff_state* s, const struct puff_huffman* lencode, const struct puff_huffman* distcode) { static const short lens[29] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258}; static const short lext[29] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0}; static const short dists[30] = { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577}; static const short dext[30] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13}; int symbol; do { symbol = puff_decode(s, lencode); if (symbol < 0) return symbol; if (symbol < 256) { if (s->outcnt == s->outlen) return 1; if (symbol) s->out[s->outcnt] = symbol; s->outcnt++; } else if (symbol > 256) { symbol -= 257; if (symbol >= 29) return -10; int len = lens[symbol] + puff_bits(s, lext[symbol]); symbol = puff_decode(s, distcode); if (symbol < 0) return symbol; unsigned dist = dists[symbol] + puff_bits(s, dext[symbol]); if (dist > s->outcnt) return -11; if (s->outcnt + len > s->outlen) return 1; while (len--) { if (dist <= s->outcnt && s->out[s->outcnt - dist]) s->out[s->outcnt] = s->out[s->outcnt - dist]; s->outcnt++; } } } while (symbol != 256); return 0; } static int puff_fixed(struct puff_state* s) { static int virgin = 1; static short lencnt[MAXBITS + 1], lensym[FIXLCODES]; static short distcnt[MAXBITS + 1], distsym[MAXDCODES]; static struct puff_huffman lencode, distcode; if (virgin) { lencode.count = lencnt; lencode.symbol = lensym; distcode.count = distcnt; distcode.symbol = distsym; short lengths[FIXLCODES]; int symbol; for (symbol = 0; symbol < 144; symbol++) lengths[symbol] = 8; for (; symbol < 256; symbol++) lengths[symbol] = 9; for (; symbol < 280; symbol++) lengths[symbol] = 7; for (; symbol < FIXLCODES; symbol++) lengths[symbol] = 8; puff_construct(&lencode, lengths, FIXLCODES); for (symbol = 0; symbol < MAXDCODES; symbol++) lengths[symbol] = 5; puff_construct(&distcode, lengths, MAXDCODES); virgin = 0; } return puff_codes(s, &lencode, &distcode); } static int puff_dynamic(struct puff_state* s) { static const short order[19] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; int nlen = puff_bits(s, 5) + 257; int ndist = puff_bits(s, 5) + 1; int ncode = puff_bits(s, 4) + 4; if (nlen > MAXLCODES || ndist > MAXDCODES) return -3; short lengths[MAXCODES]; int index; for (index = 0; index < ncode; index++) lengths[order[index]] = puff_bits(s, 3); for (; index < 19; index++) lengths[order[index]] = 0; short lencnt[MAXBITS + 1], lensym[MAXLCODES]; struct puff_huffman lencode = {lencnt, lensym}; int err = puff_construct(&lencode, lengths, 19); if (err != 0) return -4; index = 0; while (index < nlen + ndist) { int symbol; int len; symbol = puff_decode(s, &lencode); if (symbol < 0) return symbol; if (symbol < 16) lengths[index++] = symbol; else { len = 0; if (symbol == 16) { if (index == 0) return -5; len = lengths[index - 1]; symbol = 3 + puff_bits(s, 2); } else if (symbol == 17) symbol = 3 + puff_bits(s, 3); else symbol = 11 + puff_bits(s, 7); if (index + symbol > nlen + ndist) return -6; while (symbol--) lengths[index++] = len; } } if (lengths[256] == 0) return -9; err = puff_construct(&lencode, lengths, nlen); if (err && (err < 0 || nlen != lencode.count[0] + lencode.count[1])) return -7; short distcnt[MAXBITS + 1], distsym[MAXDCODES]; struct puff_huffman distcode = {distcnt, distsym}; err = puff_construct(&distcode, lengths + nlen, ndist); if (err && (err < 0 || ndist != distcode.count[0] + distcode.count[1])) return -8; return puff_codes(s, &lencode, &distcode); } static int puff(unsigned char* dest, unsigned long* destlen, const unsigned char* source, unsigned long sourcelen) { struct puff_state s = { .out = dest, .outlen = *destlen, .outcnt = 0, .in = source, .inlen = sourcelen, .incnt = 0, .bitbuf = 0, .bitcnt = 0, }; int err; if (setjmp(s.env) != 0) err = 2; else { int last; do { last = puff_bits(&s, 1); int type = puff_bits(&s, 2); err = type == 0 ? puff_stored(&s) : (type == 1 ? puff_fixed(&s) : (type == 2 ? puff_dynamic(&s) : -1)); if (err != 0) break; } while (!last); } *destlen = s.outcnt; return err; } //% END CODE DERIVED FROM puff.{c,h} #define ZLIB_HEADER_WIDTH 2 static int puff_zlib_to_file(const unsigned char* source, unsigned long sourcelen, int dest_fd) { if (sourcelen < ZLIB_HEADER_WIDTH) return 0; source += ZLIB_HEADER_WIDTH; sourcelen -= ZLIB_HEADER_WIDTH; const unsigned long max_destlen = 132 << 20; void* ret = mmap(0, max_destlen, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0); if (ret == MAP_FAILED) return -1; unsigned char* dest = (unsigned char*)ret; unsigned long destlen = max_destlen; int err = puff(dest, &destlen, source, sourcelen); if (err) { munmap(dest, max_destlen); errno = -err; return -1; } if (write(dest_fd, dest, destlen) != (ssize_t)destlen) { munmap(dest, max_destlen); return -1; } return munmap(dest, max_destlen); } static int setup_loop_device(unsigned char* data, unsigned long size, const char* loopname, int* loopfd_p) { int err = 0, loopfd = -1; int memfd = syscall(__NR_memfd_create, "syzkaller", 0); if (memfd == -1) { err = errno; goto error; } if (puff_zlib_to_file(data, size, memfd)) { err = errno; goto error_close_memfd; } loopfd = open(loopname, O_RDWR); if (loopfd == -1) { err = errno; goto error_close_memfd; } if (ioctl(loopfd, LOOP_SET_FD, memfd)) { if (errno != EBUSY) { err = errno; goto error_close_loop; } ioctl(loopfd, LOOP_CLR_FD, 0); usleep(1000); if (ioctl(loopfd, LOOP_SET_FD, memfd)) { err = errno; goto error_close_loop; } } close(memfd); *loopfd_p = loopfd; return 0; error_close_loop: close(loopfd); error_close_memfd: close(memfd); error: errno = err; return -1; } static void reset_loop_device(const char* loopname) { int loopfd = open(loopname, O_RDWR); if (loopfd == -1) { return; } if (ioctl(loopfd, LOOP_CLR_FD, 0)) { } close(loopfd); } static long syz_mount_image(volatile long fsarg, volatile long dir, volatile long flags, volatile long optsarg, volatile long change_dir, volatile unsigned long size, volatile long image) { unsigned char* data = (unsigned char*)image; int res = -1, err = 0, need_loop_device = !!size; char* mount_opts = (char*)optsarg; char* target = (char*)dir; char* fs = (char*)fsarg; char* source = NULL; char loopname[64]; if (need_loop_device) { int loopfd; memset(loopname, 0, sizeof(loopname)); snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid); if (setup_loop_device(data, size, loopname, &loopfd) == -1) return -1; close(loopfd); source = loopname; } mkdir(target, 0777); char opts[256]; memset(opts, 0, sizeof(opts)); if (strlen(mount_opts) > (sizeof(opts) - 32)) { } strncpy(opts, mount_opts, sizeof(opts) - 32); if (strcmp(fs, "iso9660") == 0) { flags |= MS_RDONLY; } else if (strncmp(fs, "ext", 3) == 0) { bool has_remount_ro = false; char* remount_ro_start = strstr(opts, "errors=remount-ro"); if (remount_ro_start != NULL) { char after = *(remount_ro_start + strlen("errors=remount-ro")); char before = remount_ro_start == opts ? '\0' : *(remount_ro_start - 1); has_remount_ro = ((before == '\0' || before == ',') && (after == '\0' || after == ',')); } if (strstr(opts, "errors=panic") || !has_remount_ro) strcat(opts, ",errors=continue"); } else if (strcmp(fs, "xfs") == 0) { strcat(opts, ",nouuid"); } res = mount(source, target, fs, flags, opts); if (res == -1) { err = errno; goto error_clear_loop; } res = open(target, O_RDONLY | O_DIRECTORY); if (res == -1) { err = errno; goto error_clear_loop; } if (change_dir) { res = chdir(target); if (res == -1) { err = errno; } } error_clear_loop: if (need_loop_device) reset_loop_device(loopname); errno = err; return res; } static void setup_sysctl() { int cad_pid = fork(); if (cad_pid < 0) exit(1); if (cad_pid == 0) { for (;;) sleep(100); } char tmppid[32]; snprintf(tmppid, sizeof(tmppid), "%d", cad_pid); struct { const char* name; const char* data; } files[] = { {"/sys/kernel/debug/x86/nmi_longest_ns", "10000000000"}, {"/proc/sys/kernel/hung_task_check_interval_secs", "20"}, {"/proc/sys/net/core/bpf_jit_kallsyms", "1"}, {"/proc/sys/net/core/bpf_jit_harden", "0"}, {"/proc/sys/kernel/kptr_restrict", "0"}, {"/proc/sys/kernel/softlockup_all_cpu_backtrace", "1"}, {"/proc/sys/fs/mount-max", "100"}, {"/proc/sys/vm/oom_dump_tasks", "0"}, {"/proc/sys/debug/exception-trace", "0"}, {"/proc/sys/kernel/printk", "7 4 1 3"}, {"/proc/sys/kernel/keys/gc_delay", "1"}, {"/proc/sys/vm/oom_kill_allocating_task", "1"}, {"/proc/sys/kernel/ctrl-alt-del", "0"}, {"/proc/sys/kernel/cad_pid", tmppid}, }; for (size_t i = 0; i < sizeof(files) / sizeof(files[0]); i++) { if (!write_file(files[i].name, files[i].data)) { } } kill(cad_pid, SIGKILL); while (waitpid(cad_pid, NULL, 0) != cad_pid) ; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void loop(void) { if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } int i, call, thread; for (call = 0; call < 10; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50 + (call == 0 ? 4000 : 0) + (call == 8 ? 3000 : 0)); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: memcpy((void*)0x200000000180, "udf\000", 4); memcpy((void*)0x200000000100, "./bus\000", 6); memcpy((void*)0x2000000002c0, "iocharset", 9); *(uint8_t*)0x2000000002c9 = 0x3d; memcpy((void*)0x2000000002ca, "iso8859-4", 9); *(uint8_t*)0x2000000002d3 = 0x2c; memcpy((void*)0x2000000002d4, "partition", 9); *(uint8_t*)0x2000000002dd = 0x3d; sprintf((char*)0x2000000002de, "%020llu", (long long)6); *(uint8_t*)0x2000000002f2 = 0x2c; memcpy((void*)0x2000000002f3, "gid=forget", 10); *(uint8_t*)0x2000000002fd = 0x2c; memcpy((void*)0x2000000002fe, "session", 7); *(uint8_t*)0x200000000305 = 0x3d; sprintf((char*)0x200000000306, "%020llu", (long long)0xfe8); *(uint8_t*)0x20000000031a = 0x2c; memcpy((void*)0x20000000031b, "noadinicb", 9); *(uint8_t*)0x200000000324 = 0x2c; memcpy((void*)0x200000000325, "anchor", 6); *(uint8_t*)0x20000000032b = 0x3d; sprintf((char*)0x20000000032c, "%020llu", (long long)0); *(uint8_t*)0x200000000340 = 0x2c; memcpy((void*)0x200000000341, "uid=forget", 10); *(uint8_t*)0x20000000034b = 0x2c; *(uint8_t*)0x20000000034c = 0; memcpy( (void*)0x200000001480, "\x78\x9c\xec\xdd\x41\x6c\x1c\xd7\x7d\x07\xe0\xff\x1b\x2e\x45\xca\x6e" "\x2b\x26\x4e\x54\xbb\x8d\x8b\x4d\x5b\xa4\x32\x63\xb9\xb2\xa4\x98\x8a" "\x55\xb8\xab\x9a\x66\x1b\x40\x96\x89\x50\xcc\x2d\x00\x57\xe4\x4a\x5d" "\x98\x5a\x12\x24\xd5\xc8\x46\xda\xd0\xbd\xf4\xd0\x43\x80\xa2\xe8\x21" "\x27\x02\xad\x51\x20\x45\x03\xa3\x29\x82\x1e\xd9\xd6\x05\x92\x8b\x0f" "\x45\x4e\x3d\x11\x2d\x6c\x04\x45\x0f\x6c\x11\x20\xa7\x80\xc5\xcc\xbe" "\x95\x96\x34\x65\xc9\xa6\x48\x51\xf6\xf7\xd9\xd4\x6f\x39\xf3\xde\xec" "\x7b\x6f\x96\x33\x92\xa0\x37\x2f\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\x80\x88\xdf\x7b\xe9\xc2\xa9\x67\xd3\x83\x6e\x05" "\x00\x70\x90\x2e\x4d\x7d\xf5\xd4\x69\xf7\x7f\x00\xf8\x44\xb9\xec\xcf" "\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\xd8\xa5\x28\xe2" "\xb1\x48\xb1\x78\x69\x33\xcd\x54\xdf\x77\x0d\x5f\x6c\x77\x6e\xdc\x9c" "\x1e\x9f\xd8\xbd\xda\xd1\x54\xd5\x1c\xa8\xca\x97\x5f\xc3\xcf\x9e\x3e" "\x73\xf6\x4b\xcf\x8d\x9d\xeb\xe5\x07\xd7\xbf\xdf\x9e\x88\x57\xa6\x2e" "\x5f\xa8\xbf\xb8\x70\x7d\x71\xa9\xb5\xbc\xdc\x9a\xab\x4f\x77\xda\xb3" "\x0b\x73\xad\x7b\x3e\xc2\x5e\xeb\xef\x34\x5a\x0d\x40\xfd\xfa\xab\x37" "\xe6\xae\x5e\x5d\xae\x9f\x7e\xe6\xcc\xb6\xdd\x37\x47\xde\x1b\x7a\xf4" "\xf8\xc8\xf9\xb1\xa7\x4e\x3e\xd9\x2b\x3b\x3d\x3e\x31\x31\xd5\x57\xa6" "\x36\xf8\x91\xdf\xfd\x7d\xee\x34\xc3\xe3\x48\x14\x71\x32\x52\x3c\xfd" "\xbd\x9f\xa4\x66\x44\x14\xb1\xf7\xb1\xb8\xcb\x67\x67\xbf\x1d\xad\x3a" "\x31\x5a\x75\x62\x7a\x7c\xa2\xea\xc8\x7c\xbb\xd9\x59\x29\x77\x4e\xf6" "\x06\xa2\x88\xa8\xf7\x55\x6a\xf4\xc6\xe8\x00\xce\xc5\x9e\x34\x22\x56" "\xcb\xe6\x97\x0d\x1e\x2d\xbb\x37\xb5\xd8\x5c\x6a\x5e\x99\x6f\xd5\x27" "\x9b\x4b\x2b\xed\x95\xf6\x42\x67\x32\x75\x5b\x5b\xf6\xa7\x1e\x45\x9c" "\x4b\x11\x6b\x11\xb1\x31\xf4\xfe\xc3\x0d\x46\x11\xb5\x48\xf1\x9d\x63" "\x9b\xe9\x4a\x44\x0c\xf4\xc6\xe1\x8b\xd5\xc4\xe0\x3b\xb7\xa3\xd8\xc7" "\x3e\xde\x83\xb2\x9d\xf5\xc1\x88\xb5\xe2\x21\x38\x67\x87\xd8\x50\x14" "\xf1\x72\xa4\xf8\xe9\xdb\x45\xcc\x96\x63\x96\xbf\xe2\x0b\x11\x2f\x97" "\xf9\x83\x88\x37\xcb\x7c\x21\x22\x95\x1f\x8c\xb3\x11\xef\xee\xf2\x39" "\xe2\xe1\x54\x8b\x22\xfe\xbc\x3c\xff\xe7\x37\xd3\x5c\x75\x3d\xe8\x5d" "\x57\x2e\x7e\xad\xfe\x95\xce\xd5\x85\xbe\xb2\xbd\xeb\xca\x43\x7f\x7f" "\x38\x48\x87\xfc\xda\x34\x1c\x45\x34\xab\x2b\xfe\x66\xfa\xe8\xbf\xd9" "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe0\x7e\x3b\x1a" "\x45\x3c\x11\x29\x5e\xfa\xf7\x3f\xaa\xe6\x15\x47\x35\x2f\xfd\xd8\xf9" "\xb1\xdf\x1f\xf9\xc5\xfe\x39\xe3\x8f\xdf\xe5\x38\x65\xd9\x67\x22\x62" "\xb5\xb8\xb7\x39\xb9\x47\xf2\x14\xe2\xc9\x34\x99\xd2\x03\x9e\x4b\xfc" "\x49\x36\x1c\x45\xfc\x71\x9e\xff\xf7\xc6\x83\x6e\x0c\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc0\x27\xdc\x8f\x23\xc5\xf3" "\xef\x9c\x48\x6b\xd1\xbf\xa6\x78\xbb\x73\xad\x7e\xb9\x79\x65\xbe\xbb" "\x2a\x6c\x6f\xed\xdf\xde\x9a\xe9\x5b\x5b\x5b\x5b\xf5\xd4\xcd\x46\xce" "\x99\x9c\xab\x39\xd7\x72\xae\xe7\xdc\xc8\x19\x45\xae\x9f\xb3\x91\x73" "\x26\xe7\x6a\xce\xb5\x9c\xeb\x39\x37\x72\xc6\x40\xae\x9f\xb3\x91\x73" "\x26\xe7\x6a\xce\xb5\x9c\xeb\x39\x37\x72\x46\x2d\xd7\xcf\xd9\xc8\x39" "\x93\x73\x35\xe7\x5a\xce\xf5\x9c\x1b\x39\xe3\x90\xac\xdd\x0b\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\xf0\x71\x52\x44\x11\x3f\x8f" "\x14\xdf\xfe\xc6\x66\x8a\x14\x11\x8d\x88\x99\xe8\xe6\xfa\x50\xaf\x0c" "\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\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\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\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\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\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\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\xf0\x20\x0d\xa5" "\x22\xbe\x1f\x29\xea\x7f\xd0\xb8\xb5\xad\x16\x11\xa9\xfa\xbf\xeb\x44" "\xf9\xcb\xd9\x68\x1c\x29\xf3\xd3\xd1\x18\x2b\xf3\x85\x68\x5c\xc8\xd9" "\xac\xb2\xd6\x78\xe3\x01\xb4\x9f\xbd\x19\x4c\x45\xfc\x28\x52\x0c\x0d" "\xbf\x75\xeb\x84\xe7\xf3\x3f\xd8\xfd\xee\xd6\xc7\x20\xde\xfc\xe6\xed" "\xef\x7e\xa5\xd6\xcd\x81\xde\xce\x91\xf7\x86\x1e\x3d\x7e\xec\xfc\xd8" "\xc4\xaf\x3d\x7e\xa7\xd7\x69\xb7\x06\x8c\x5e\x6c\x77\x6e\xdc\xac\x4f" "\x8f\x4f\x4c\x4c\xf5\x6d\xae\xe5\x77\xff\x74\xdf\xb6\x91\xfc\xbe\xc5" "\xfd\xe9\x3a\x11\xb1\xfc\xda\xeb\xaf\x36\xe7\xe7\x5b\x4b\x9f\x98\x17" "\x45\x1c\x8a\x66\x3c\xa8\x17\xb5\xee\x8b\x5a\x1c\x92\xf6\x1c\xd4\x8b" "\x7c\xbd\x8a\x5d\x76\x15\x87\xe1\xa7\xa0\x71\x58\x06\xaa\xf7\xe2\x01" "\x5f\x98\x38\x10\xe5\xfd\xff\xdd\x48\xf1\xdb\xef\xfc\x47\xef\x86\xdf" "\xbb\xff\xff\x42\xf7\xbb\x5b\x77\xf8\xf8\xd9\x9f\xdc\xbe\xff\x3f\xbf" "\xf3\x40\xfb\x74\xff\x7f\xac\x6f\xdb\xf3\xf9\x77\x23\x83\xb5\x88\xe1" "\x95\xeb\x8b\x83\xc7\x23\x86\x97\x5f\x7b\xfd\x64\xfb\x7a\xf3\x5a\xeb" "\x5a\xab\x73\xf6\xd4\xa9\x2f\x8f\x8d\x7d\xf9\xcc\xa9\xc1\x23\x11\xc3" "\x57\xdb\xf3\xad\xbe\x57\x7b\x1e\x2a\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x80\x83\x95\x8a\xf8\xdd\x48\xd1\xfc\xd1\x66\xaa\x47" "\xc4\xcd\x6a\xbe\xd6\xc8\xf9\xb1\xa7\x4e\x3e\x39\x10\x03\xd5\x7c\xab" "\x6d\xf3\xb6\x5e\x99\xba\x7c\xa1\xfe\xe2\xc2\xf5\xc5\xa5\xd6\xf2\x72" "\x6b\xae\x3e\xdd\x69\xcf\x2e\xcc\xb5\xee\xf5\xed\x86\xab\xe9\x5e\xd3" "\xe3\x13\xfb\xd2\x99\xbb\x3a\xba\xcf\xed\x3f\x3a\xfc\xe2\xc2\xe2\x6b" "\x4b\xed\x6b\x7f\xb8\xb2\xeb\xfe\x47\x86\x2f\x5c\x59\x5e\x59\x6a\xce" "\xee\xbe\x3b\x8e\x46\x11\xd1\xe8\xdf\x32\x5a\x35\x78\x7a\x7c\xa2\x6a" "\xf4\x7c\xbb\xd9\xa9\xaa\x4e\xee\x3a\x99\xee\xc3\x1b\x4c\x45\xfc\x67" "\xa4\x98\x3d\x5b\x3f\xd2\xdb\x96\xe7\xff\xed\x9c\xe1\xbf\x6d\xfe\xff" "\xea\xce\x03\xed\xd3\xfc\xbf\x4f\xf5\x6d\x2b\xdf\x33\xa5\x22\x7e\x16" "\x29\x7e\xeb\x2f\x1e\x8f\xcf\x57\xed\x7c\x24\xde\x37\x66\xb9\xdc\xdf" "\x44\x8a\xd1\x73\x9f\xcb\xe5\xe2\x48\x59\xae\xd7\x86\xee\x73\x05\xba" "\x33\x03\xcb\xb2\xff\x1b\x29\xfe\xe1\xe7\xdb\xcb\xf6\xe6\x43\x3e\x76" "\xbb\xec\xb3\xf7\x3a\xae\x0f\x8b\xf2\xfc\x1f\x8b\x14\xdf\xff\xb3\xef" "\xc6\xaf\xe7\x6d\xdb\x9f\xff\xb0\xfb\xf9\x7f\x64\xe7\x81\xf6\xe9\xfc" "\x7f\xa6\x6f\xdb\x23\xdb\x9e\x57\xb0\xe7\xae\x93\xcf\xff\xc9\x48\xf1" "\xc2\x63\x6f\xc5\x6f\xe4\x6d\x1f\xf4\xfc\x8f\x22\xb6\xb6\xb6\xbe\x15" "\x71\x22\x17\xbe\xf5\x7c\x8e\x7d\x3a\xff\x9f\xed\xdb\x36\x12\xdd\xf7" "\xfd\xcd\xfb\xd7\x7d\x00\x00\x00\x00\x00\x00\x00\x00\x80\x87\xd6\x60" "\x2a\xe2\x6f\x23\xc5\x93\x13\xb5\xf4\x5c\xde\x76\x2f\xff\xfe\x6f\x6e" "\xe7\x81\xf6\xe9\xdf\x7f\xfd\x72\xdf\xb6\xb9\x03\x5a\xaf\x68\xcf\x83" "\x0a\x00\x00\x00\x00\x87\xc4\x60\x2a\xe2\xc7\x91\xe2\xda\xca\x5b\xb7" "\xe6\x50\x6f\x9f\xff\xdd\x37\xff\xf3\x77\x6e\xaf\xbd\x3e\x9e\x76\xec" "\xad\xfe\x9e\xef\x97\xaa\xe7\x06\xdc\xcf\xbf\xff\xeb\x37\x92\xdf\x77" "\x66\xef\xdd\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x80\x43\x25\xa5\x22\x9e\xcb\xeb\xa9\xcf\xdc\x65\x3d\xf5\xf5\x48" "\xf1\xd2\x7f\x3f\x9d\xcb\xa5\xe3\x65\xb9\xde\x3a\xf0\x23\xd5\xaf\xc3" "\x97\x16\x3a\x27\x2f\xcc\xcf\x2f\xcc\x36\x57\x9a\x57\xe6\x5b\xf5\xa9" "\xc5\xe6\x6c\xab\xac\xfb\x99\x48\xb1\xf9\xd7\x9f\xcb\x75\x8b\x6a\x7d" "\xf5\xcf\xe7\xba\xdd\x35\xde\x87\xb7\x7a\x6b\xb1\x2f\x45\x8a\x89\xbf" "\xeb\x95\xed\xae\xc5\xde\x5b\x9b\xbc\xbb\x1e\x78\x77\x2d\xf6\xb2\xec" "\xa7\x22\xc5\x7f\xfd\xfd\xf6\xb2\xbd\x75\xac\x3f\x7b\xbb\xec\xe9\xb2" "\xec\x5f\x45\x8a\xaf\xff\xd3\xee\x65\x8f\xdf\x2e\x7b\xa6\x2c\xfb\xdd" "\x48\xf1\xc3\xaf\xd7\x7b\x65\x1f\x29\xcb\xf6\x9e\x8f\xda\x7d\x26\xe9" "\x70\x2d\xe6\x5b\xcf\xcc\x2e\xcc\xbf\xef\x51\xa8\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\x61\x0d\xa6\x22\xfe\x34" "\x52\xfc\xcf\xf5\xb5\x58\xad\xa6\xfd\xbf\x71\x6b\x57\xce\x5a\x6f\xc3" "\x9b\xdf\xec\x5b\xef\x7f\x87\x9b\xd5\x3a\xff\x23\xd5\xfa\xff\x77\x7a" "\xfd\x51\xd6\xff\x1f\xb9\x2f\xbd\x04\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" "\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\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\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\x80\x87\x4b\x8a\x22\x5e\x8f\x14\x8b\x97\x36\xd3" "\xfa\x50\xf9\x7d\xd7\xf0\xc5\x76\xe7\xc6\xcd\xe9\xf1\x89\xdd\xab\x1d" "\x4d\x55\xcd\x81\xaa\x7c\xf9\x35\xfc\xec\xe9\x33\x67\xbf\xf4\xdc\xd8" "\xb9\x5e\x7e\x70\xfd\xfb\xed\x89\x78\x65\xea\xf2\x85\xfa\x8b\x0b\xd7" "\x17\x97\x5a\xcb\xcb\xad\xb9\xfa\x74\xa7\x3d\xbb\x30\xd7\xba\xe7\x23" "\xec\xb5\xfe\xed\xa1\xeb\x1a\xad\x06\xa0\x7e\xfd\xd5\x1b\x73\x57\xaf" "\x2e\xd7\x4f\x3f\x73\x66\xdb\xee\x9b\x23\xef\x0d\x3d\x7a\x7c\xe4\xfc" "\xd8\x53\x27\x9f\xec\x95\x9d\x1e\x9f\x98\x98\xea\x2b\x53\x1b\xfc\x10" "\xef\xfe\xa1\x1a\x77\xdb\x91\x28\xe2\x2f\x23\xc5\xd3\xdf\xfb\x49\xfa" "\xe7\xa1\x88\x22\xf6\x3e\x16\x77\xf9\xec\xec\xb7\xa3\x55\x27\x46\xab" "\x4e\x4c\x8f\x4f\x54\x1d\x99\x6f\x37\x3b\x2b\xe5\xce\xc9\xde\x40\x14" "\x11\xf5\xbe\x4a\x8d\xde\x18\x1d\xc0\xb9\xd8\x93\x46\xc4\x6a\xd9\xfc" "\xb2\xc1\xa3\x65\xf7\xa6\x16\x9b\x4b\xcd\x2b\xf3\xad\xfa\x64\x73\x69" "\xa5\xbd\xd2\x5e\xe8\x4c\xa6\x6e\x6b\xcb\xfe\xd4\xa3\x88\x73\x29\x62" "\x2d\x22\x36\x86\xfa\x0f\x74\x24\x67\x11\xaf\x46\x8a\xef\x1c\xdb\x4c" "\xff\x32\x14\x31\xd0\x1b\x87\x2f\x5e\x9a\xfa\xea\xa9\xd3\x77\x6e\x47" "\xb1\xaf\xbd\xbc\x8b\x6f\x55\xed\xac\x0f\x46\xac\x15\x0f\xc1\x39\x3b" "\xc4\x86\xa2\x88\x7f\x8c\x14\x3f\x7d\xfb\x44\xfc\xeb\x50\x44\x2d\xba" "\x5f\xf1\x85\x88\x97\xcb\xfc\x41\xc4\x9b\x65\xbe\x10\x91\xca\x0f\xc6" "\xd9\x88\x77\x87\x1e\x74\xab\xb9\x5f\x6a\x51\xc4\xff\x95\xe7\xff\xfc" "\x66\x7a\x7b\x28\xa2\xfa\x91\xa9\xae\x2b\x17\xbf\x56\xff\x4a\xe7\xea" "\x42\x5f\xd9\xde\x75\x65\xe7\xfd\x61\x2b\x22\x1e\xaa\xfb\xc3\x41\x3a" "\xe4\xd7\xa6\xe1\x28\xe2\x87\xd5\x15\x7f\x33\xfd\x9b\x9f\x6b\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x43\xa4\x88\x5f\x8d\x14" "\xcf\xbf\x73\x22\x55\xf3\x83\x6f\xcd\x29\x6e\x77\xae\xd5\x2f\x37\xaf" "\xcc\x77\xa7\xf5\xf5\xe6\xfe\xf5\xe6\x4c\x6f\x6d\x6d\x6d\xd5\x53\x37" "\x1b\x39\x67\x72\xae\xe6\x5c\xcb\xb9\x9e\x73\x23\x67\x14\xb9\x7e\xce" "\x46\xce\x99\x9c\xab\x39\xd7\x72\xae\xe7\xdc\xc8\x19\x03\xb9\x7e\xce" "\x46\xce\x99\x9c\xab\x39\xd7\x72\xae\xe7\xdc\xc8\x19\xb5\x5c\x3f\x67" "\x23\xe7\x4c\xce\xd5\x9c\x6b\x39\xd7\x73\x6e\xe4\x8c\x43\x32\x77\x0f" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf8\x78\x29" "\xaa\xff\x52\x7c\xfb\x1b\x9b\x69\x6b\xa8\xbb\xbe\xf4\x4c\x74\x73\xdd" "\x7a\xa0\x1f\x7b\xff\x1f\x00\x00\xff\xff\x70\x9f\xfb\xe4", 3108); syz_mount_image( /*fs=*/0x200000000180, /*dir=*/0x200000000100, /*flags=MS_POSIXACL|MS_REC|MS_SYNCHRONOUS|MS_STRICTATIME|MS_NODEV|0x480*/ 0x1014494, /*opts=*/0x2000000002c0, /*chdir=*/0xfe, /*size=*/0xc24, /*img=*/0x200000001480); break; case 1: memcpy((void*)0x200000000240, "./file1\000", 8); res = syscall( __NR_open, /*file=*/0x200000000240ul, /*flags=O_SYNC|O_NOCTTY|O_NOATIME|O_DIRECT|O_CREAT|0x2*/ 0x145142ul, /*mode=*/0ul); if (res != -1) r[0] = res; break; case 2: syscall(__NR_ftruncate, /*fd=*/r[0], /*len=*/0x2007ffcul); break; case 3: syscall(__NR_sendfile, /*fdout=*/r[0], /*fdin=*/r[0], /*off=*/0ul, /*count=*/0x800000009ul); break; case 4: memcpy((void*)0x200000000000, "./bus\000", 6); res = syscall( __NR_open, /*file=*/0x200000000000ul, /*flags=O_NOFOLLOW|O_NOCTTY|O_NOATIME|O_CREAT|O_RDWR*/ 0x60142ul, /*mode=*/0ul); if (res != -1) r[1] = res; break; case 5: memcpy((void*)0x200000000080, "./bus\000", 6); res = syscall(__NR_open, /*file=*/0x200000000080ul, /*flags=O_SYNC|O_NOCTTY|O_DIRECT|O_CLOEXEC|O_RDWR*/ 0x185102ul, /*mode=*/0ul); if (res != -1) r[2] = res; break; case 6: syscall(__NR_ftruncate, /*fd=*/r[2], /*len=*/0x2007ffbul); break; case 7: syscall(__NR_sendfile, /*fdout=*/r[1], /*fdin=*/r[2], /*off=*/0ul, /*count=*/0x1000000201005ul); break; case 8: syz_usb_connect(/*speed=*/0, /*dev_len=*/0, /*dev=*/0, /*conn_descs=*/0); break; case 9: memcpy((void*)0x200000000040, "./file1\000", 8); syscall(__NR_truncate, /*file=*/0x200000000040ul, /*len=*/0x7ffful); break; } } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-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=*/-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, /*offset=*/0ul); setup_sysctl(); const char* reason; (void)reason; use_temporary_dir(); loop(); return 0; }