| 0/0 |
2026/07/15 21:16 |
flow |
assessment-security |
24m
Results: map[DenialOfService:true Explanation:The bug is a memory leak in the `uss720` USB-to-parallel port driver,
specifically in the `get_1284_register` function.
### Root Cause Analysis
When the driver communicates with the USB device, it submits an asynchronous
control transfer URB via `submit_async_request()`. This function allocates a
request structure (`rq`) and initializes its reference count to 1, then
increments it to 2 before submitting the URB (one reference for the URB
completion handler, one for the caller).
In `get_1284_register()`, the driver waits for the URB to complete using
`wait_for_completion_timeout()`.
If the device responds in time, the function correctly drops its reference by
calling `kref_put(&rq->ref_count, destroy_async)`.
However, if the device fails to respond and the wait times out, the function
executes the timeout path:
```c
if (wait_for_completion_timeout(&rq->compl, HZ)) {
// ... normal completion ...
kref_put(&rq->ref_count, destroy_async);
return ret;
}
printk(KERN_WARNING "get_1284_register timeout\n");
kill_all_async_requests_priv(priv);
return -EIO;
```
In the timeout path, the driver calls `kill_all_async_requests_priv()` to unlink
the pending URBs but **forgets to drop its reference** to `rq`. When the
unlinked URB eventually completes, the completion handler (`async_complete`)
drops its own reference, leaving the `rq` reference count at 1 forever.
Because `rq` also holds a reference to the driver's private data structure
(`priv`), this single missing `kref_put` causes a cascade of memory leaks,
leaking the `rq` structure, the URB, the DMA buffer, and the `priv` structure
itself. This perfectly matches the 4 unreferenced objects shown in the
KASAN/kmemleak report.
### Impact and Exploitability
- **Exploitable**: **False**. This is a pure memory leak. The reference counting
logic ensures that the objects are never freed prematurely, so there is no
use-after-free or memory corruption.
- **Denial of Service**: **True**. A malicious USB device that intentionally
ignores control requests can cause the driver to repeatedly hit the timeout
path, leaking memory on every attempt. This can eventually exhaust system memory
(OOM).
- **Peripheral Trigger**: **True**. Triggering this bug requires a USB device
that times out on specific control requests. Thus, it requires physical access
to plug in a malicious USB device (or root privileges to emulate one via
software like `raw-gadget`).
- **Unprivileged / User Namespaces**: **False**. Unprivileged users cannot
emulate USB devices, nor can they force a legitimate hardware device to time
out. Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/07/15 21:16 |
action |
syz-repro-to-c-repro |
0m
Results: map[SimplifiedCRepro:// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <linux/loop.h>
#include <linux/usb/ch9.h>
#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);
}
#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");
} else if (strncmp(fs, "gfs2", 4) == 0 && (strstr(opts, "errors=panic") || strstr(opts, "debug"))) {
strcat(opts, ",errors=withdraw");
}
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;
}
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000, /*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=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
const char* reason;
(void)reason;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// syz_usb_connect arguments: [
// speed: usb_device_speed = 0x0 (8 bytes)
// dev_len: len = 0x5a (8 bytes)
// dev: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// union ANYUNION {
// ANYBLOB: buffer: {12 01 00 00 60 f9 4d 10 0d 05 02 00 27 23 01 02 03 01 09 02 48 40 02 00 00 00 00 09 04 7d 04 03 1d 5a bf 00 09 05 04 00 00 55 39 00 00 09 05 0b 00 00 00 00 00 00 09 05 02 00 00 00 05 00 00 09 04 7d 01 01 34 81 af 00 09 a0 0e 00 23 00 00 69 00 09 04 7d be} (length 0x55)
// }
// }
// }
// conn_descs: nil
// ]
// returns fd_usb
memcpy((void*)0x200000000080, "... [truncated large byte array] ...", 85);
syz_usb_connect(/*speed=*/0, /*dev_len=*/0x5a, /*dev=*/0x200000000080, /*conn_descs=*/0);
// syz_mount_image$f2fs arguments: [
// fs: ptr[in, buffer] {
// buffer: {66 32 66 73 00} (length 0x5)
// }
// dir: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8)
// }
// flags: mount_flags = 0x8 (8 bytes)
// opts: ptr[in, fs_options[f2fs_options]] {
// fs_options[f2fs_options] {
// elems: array[fs_opt_elem[f2fs_options]] {
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// nodiscard: buffer: {6e 6f 64 69 73 63 61 72 64} (length 0x9)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// nocheckpoint_merge: buffer: {6e 6f 63 68 65 63 6b 70 6f 69 6e 74 5f 6d 65 72 67 65} (length 0x12)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// alloc_mode_def: buffer: {61 6c 6c 6f 63 5f 6d 6f 64 65 3d 64 65 66 61 75 6c 74} (length 0x12)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// six_active_logs: buffer: {61 63 74 69 76 65 5f 6c 6f 67 73 3d 36} (length 0xd)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// flush_merge: buffer: {66 6c 75 73 68 5f 6d 65 72 67 65} (length 0xb)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// fault_injection: fs_opt["fault_injection", fmt[dec, int32]] {
// name: buffer: {66 61 75 6c 74 5f 69 6e 6a 65 63 74 69 6f 6e} (length 0xf)
// eq: const = 0x3d (1 bytes)
// val: int32 = 0x4ee (20 bytes)
// }
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// acl: buffer: {61 63 6c} (length 0x3)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// noacl: buffer: {6e 6f 61 63 6c} (length 0x5)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// compress_cache: buffer: {63 6f 6d 70 72 65 73 73 5f 63 61 63 68 65} (length 0xe)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// alloc_mode_def: buffer: {61 6c 6c 6f 63 5f 6d 6f 64 65 3d 64 65 66 61 75 6c 74} (length 0x12)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// nodiscard: buffer: {6e 6f 64 69 73 63 61 72 64} (length 0x9)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// compress_cache: buffer: {63 6f 6d 70 72 65 73 73 5f 63 61 63 68 65} (length 0xe)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// fault_type: fs_opt["fault_type", fmt[dec, int32]] {
// name: buffer: {66 61 75 6c 74 5f 74 79 70 65} (length 0xa)
// eq: const = 0x3d (1 bytes)
// val: int32 = 0x4 (20 bytes)
// }
// }
// comma: const = 0x2c (1 bytes)
// }
// }
// common: array[fs_opt_elem[fs_options_common]] {
// }
// null: const = 0x0 (1 bytes)
// }
// }
// chdir: int8 = 0x1 (1 bytes)
// size: len = 0x5505 (8 bytes)
// img: ptr[in, buffer] {
// buffer: (compressed buffer with length 0x5505)
// }
// ]
// returns fd_dir
memcpy((void*)0x200000000000, "f2fs\000", 5);
memcpy((void*)0x200000000040, "./file0\000", 8);
memcpy((void*)0x200000000400, "nodiscard", 9);
*(uint8_t*)0x200000000409 = 0x2c;
memcpy((void*)0x20000000040a, "nocheckpoint_merge", 18);
*(uint8_t*)0x20000000041c = 0x2c;
memcpy((void*)0x20000000041d, "alloc_mode=default", 18);
*(uint8_t*)0x20000000042f = 0x2c;
memcpy((void*)0x200000000430, "active_logs=6", 13);
*(uint8_t*)0x20000000043d = 0x2c;
memcpy((void*)0x20000000043e, "flush_merge", 11);
*(uint8_t*)0x200000000449 = 0x2c;
memcpy((void*)0x20000000044a, "fault_injection", 15);
*(uint8_t*)0x200000000459 = 0x3d;
sprintf((char*)0x20000000045a, "%020llu", (long long)0x4ee);
*(uint8_t*)0x20000000046e = 0x2c;
memcpy((void*)0x20000000046f, "acl", 3);
*(uint8_t*)0x200000000472 = 0x2c;
memcpy((void*)0x200000000473, "noacl", 5);
*(uint8_t*)0x200000000478 = 0x2c;
memcpy((void*)0x200000000479, "compress_cache", 14);
*(uint8_t*)0x200000000487 = 0x2c;
memcpy((void*)0x200000000488, "alloc_mode=default", 18);
*(uint8_t*)0x20000000049a = 0x2c;
memcpy((void*)0x20000000049b, "nodiscard", 9);
*(uint8_t*)0x2000000004a4 = 0x2c;
memcpy((void*)0x2000000004a5, "compress_cache", 14);
*(uint8_t*)0x2000000004b3 = 0x2c;
memcpy((void*)0x2000000004b4, "fault_type", 10);
*(uint8_t*)0x2000000004be = 0x3d;
sprintf((char*)0x2000000004bf, "%020llu", (long long)4);
*(uint8_t*)0x2000000004d3 = 0x2c;
*(uint8_t*)0x2000000004d4 = 0;
memcpy((void*)0x2000000079c0, "... [truncated large byte array] ...", 21765);
syz_mount_image(/*fs=*/0x200000000000, /*dir=*/0x200000000040, /*flags=MS_NOEXEC*/8, /*opts=*/0x200000000400, /*chdir=*/1, /*size=*/0x5505, /*img=*/0x2000000079c0);
return 0;
}
]
|
| 2/1 |
2026/07/15 21:16 |
action |
kernel-checkouter |
1m
Results: map[KernelSrc:/app/workdir/cache/src/616ad0bb7fd0e57794f58b6a8b531efba9cc084f]
|
| 3/1 |
2026/07/15 21:17 |
action |
kernel-builder |
11m
Results: map[KernelObj:/app/workdir/cache/build/1bd80176b65eb8555d626b4570c1c18db51c93fa]
|
| 4/1 |
2026/07/15 21:28 |
action |
codesearch-prepare |
8m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/07/15 21:37 |
agent |
expert |
2m
Model:
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Instruction: You are an experienced Linux kernel security engineer. Your task is to analyze given kernel bug report
and determine its security impact based on the following dimensions.
Use the provided tools to examine the source code, check for capability checks (e.g., capable(), ns_capable()),
and understand the nature of the bug. Analyze the given kernel build and configuration.
You can check the kernel config by grepping ".config" file; you can check kernel cmdline by grepping
".config" file for "CONFIG_CMDLINE=". Assume sysctl parameters have default values.
But analyze for the corresponding production build w/o debugging tools enabled (like KASAN, KMSAN, UBSAN).
Try different strategies when analyzing the bug:
- think of ways in which the vulnerable code is unreachable
- or the other way around: try to come up with different ideas of how an unprivileged user can reach the bug
If still unsure err on the side of the bug being non-exploitable/not-accessible.
In the final reply, provide a reasoning for your assessment.
Analysis dimensions:
* Exploitable:
Determine if the bug can result in memory corruption, elevated privileges, or an information leak.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a completely wild pointer access
(e.g. user-space address, or non-canonical address, but not on NULL or address corresponding to KASAN shadow
for NULL address), including both data accesses and control transfers, that also usually implies possibility
of exploitation. Such reports usually say "unable to handle kernel paging request".
Uses of uninitialized values detected by KMSAN may be exploitable b/c attacker frequently can affect uninit
values with spraying techniques. However, for these exploitability depends on how exactly the uninit value
is used in the code, and what it affects.
Information leaks are exploitable on their own and should be classified as such. A bug that copies kernel
memory contents to userspace (e.g. an out-of-bounds read whose result is returned to the caller, or
uninitialized stack/heap bytes written to a user buffer) is exploitable: it can reveal kernel pointer
values and defeat KASLR, expose sensitive data such as cryptographic keys or other processes' memory, and
serves as a necessary building block in most modern kernel privilege-escalation exploit chains. Do not classify
an information leak as non-exploitable solely because it does not directly cause a memory write or control-flow
hijack; the leak itself is the exploit primitive.
Think of what happens after the bug is triggered. Some bugs cause kernel panic and halt execution,
they are harder to exploit. For example, BUG reports halts the kernel. However, WARNING reports don't halt
execution in production builds. Debug bug detection tools (like KASAN, KMSAN, KCSAN, UBSAN) are also not enabled
in production builds, so attacker can freely exploit these bugs w/o being detected by these tools.
If you see an integer overflow, think how the overflowed value used later (if it's used as allocation size,
or an array index). If you see an out-of-bounds read, think if it's followed by an out-of-bounds write as well.
Some KCSAN data-races may be exploitable by skilled attackers as well. Think what data structures got corrupted
as the result of data races and how. However, note that kernel has lots of "benign" data races that don't lead
to any runtime misbehavior at all.
* Denial Of Service:
Determine if the bug can result in denial-of-service. Most bugs can, since they cause system crash,
hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash
in production. For these think what will be consequences of the violation of the kernel assumptions flagged
by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow
(e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled,
then it may or may not cause denial-of-service.
* Accessible From Unprivileged Processes:
Determine if the bug can be reached from a typical (non-root) user process that does NOT have any special capabilities
(like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON) or access to device nodes restricted to root.
Assume that unprivileged_bpf_disabled=1, that is eBPF loading is not accessible. However, cBPF (classical BPF)
is still accessible to non-root processes.
Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even
within a new user namespace (checked by ns_capable() function in the kernel sources).
* Accessible From User Namespaces:
Determine if the bug can be reached within a user-namespace where the process has all capabilities
(including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON). Such capabilities are checked with ns_capable()
function in the kernel sources.
* VM Guest Trigger:
Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM).
Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.),
and handling of VM exits in the KVM code.
* VM Host Trigger in The Confidential Computing Context:
Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host.
Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).
* Ethernet Network Trigger:
Determine if the bug can be triggered by processing ingress network Ethernet traffic, either directly (network stack)
or via drivers exposed to network data.
* Other Remote Trigger:
Determine if the bug can be triggered by processing remote traffic other than Ethernet (Wifi, Bluetooth, NFC, etc).
* Peripheral Trigger:
Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged
into a system, such as a USB device or a niche hardware driver handling external hardware inputs.
This is particularly important for mobile and desktop environments where users can plug in unknown devices.
* Malicious Filesystem Trigger:
Determine if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
This is highly critical for Desktop and Mobile environments where external media or downloaded images
might be auto-mounted.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The kernel bug report is:
BUG: memory leak
unreferenced object 0xffff88812c0e34c0 (size 64):
comm "kworker/0:0", pid 9, jiffies 4294942439
hex dump (first 32 bytes):
00 b8 b6 05 81 88 ff ff 00 00 00 00 00 00 00 00 ................
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace (crc 7291ab94):
kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
slab_post_alloc_hook mm/slub.c:4625 [inline]
slab_alloc_node mm/slub.c:4945 [inline]
__kmalloc_cache_noprof+0x356/0x440 mm/slub.c:5511
_kmalloc_noprof include/linux/slab.h:969 [inline]
_kzalloc_noprof include/linux/slab.h:1290 [inline]
uss720_probe+0xf6/0x330 drivers/usb/misc/uss720.c:702
usb_probe_interface+0x210/0x480 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:628 [inline]
really_probe+0x12f/0x3a0 drivers/base/dd.c:706
__driver_probe_device+0xe9/0x1a0 drivers/base/dd.c:868
driver_probe_device+0x28/0xf0 drivers/base/dd.c:898
__device_attach_driver+0x10f/0x170 drivers/base/dd.c:1026
bus_for_each_drv+0xd2/0x130 drivers/base/bus.c:500
__device_attach+0xf9/0x290 drivers/base/dd.c:1098
device_initial_probe+0x6f/0x80 drivers/base/dd.c:1153
bus_probe_device+0x3e/0xb0 drivers/base/bus.c:620
device_add+0x99f/0xc80 drivers/base/core.c:3772
usb_set_configuration+0x8f5/0xb80 drivers/usb/core/message.c:2268
usb_generic_driver_probe+0x73/0xb0 drivers/usb/core/generic.c:250
usb_probe_device+0x78/0x1f0 drivers/usb/core/driver.c:291
call_driver_probe drivers/base/dd.c:628 [inline]
really_probe+0x12f/0x3a0 drivers/base/dd.c:706
BUG: memory leak
unreferenced object 0xffff88812d350b40 (size 96):
comm "kworker/0:0", pid 9, jiffies 4294942439
hex dump (first 32 bytes):
c0 34 0e 2c 81 88 ff ff 01 00 00 00 00 00 00 00 .4.,............
e0 34 0e 2c 81 88 ff ff e0 34 0e 2c 81 88 ff ff .4.,.....4.,....
backtrace (crc 519c4231):
kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
slab_post_alloc_hook mm/slub.c:4625 [inline]
slab_alloc_node mm/slub.c:4945 [inline]
__kmalloc_cache_noprof+0x356/0x440 mm/slub.c:5511
_kmalloc_noprof include/linux/slab.h:969 [inline]
_kzalloc_noprof include/linux/slab.h:1290 [inline]
submit_async_request.constprop.0+0x6b/0x440 drivers/usb/misc/uss720.c:137
get_1284_register+0x4a/0x1a0 drivers/usb/misc/uss720.c:205
uss720_probe+0x205/0x330 drivers/usb/misc/uss720.c:733
usb_probe_interface+0x210/0x480 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:628 [inline]
really_probe+0x12f/0x3a0 drivers/base/dd.c:706
__driver_probe_device+0xe9/0x1a0 drivers/base/dd.c:868
driver_probe_device+0x28/0xf0 drivers/base/dd.c:898
__device_attach_driver+0x10f/0x170 drivers/base/dd.c:1026
bus_for_each_drv+0xd2/0x130 drivers/base/bus.c:500
__device_attach+0xf9/0x290 drivers/base/dd.c:1098
device_initial_probe+0x6f/0x80 drivers/base/dd.c:1153
bus_probe_device+0x3e/0xb0 drivers/base/bus.c:620
device_add+0x99f/0xc80 drivers/base/core.c:3772
usb_set_configuration+0x8f5/0xb80 drivers/usb/core/message.c:2268
usb_generic_driver_probe+0x73/0xb0 drivers/usb/core/generic.c:250
BUG: memory leak
unreferenced object 0xffff88812d277180 (size 192):
comm "kworker/0:0", pid 9, jiffies 4294942439
hex dump (first 32 bytes):
01 00 00 00 98 ff ff ff 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 98 71 27 2d 81 88 ff ff .........q'-....
backtrace (crc 26b7be33):
kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
slab_post_alloc_hook mm/slub.c:4625 [inline]
slab_alloc_node mm/slub.c:4945 [inline]
__do_kmalloc_node mm/slub.c:5361 [inline]
__kmalloc_noprof+0x3bf/0x550 mm/slub.c:5387
_kmalloc_noprof include/linux/slab.h:973 [inline]
usb_alloc_urb+0x66/0xa0 drivers/usb/core/urb.c:75
submit_async_request.constprop.0+0x11c/0x440 drivers/usb/misc/uss720.c:145
get_1284_register+0x4a/0x1a0 drivers/usb/misc/uss720.c:205
uss720_probe+0x205/0x330 drivers/usb/misc/uss720.c:733
usb_probe_interface+0x210/0x480 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:628 [inline]
really_probe+0x12f/0x3a0 drivers/base/dd.c:706
__driver_probe_device+0xe9/0x1a0 drivers/base/dd.c:868
driver_probe_device+0x28/0xf0 drivers/base/dd.c:898
__device_attach_driver+0x10f/0x170 drivers/base/dd.c:1026
bus_for_each_drv+0xd2/0x130 drivers/base/bus.c:500
__device_attach+0xf9/0x290 drivers/base/dd.c:1098
device_initial_probe+0x6f/0x80 drivers/base/dd.c:1153
bus_probe_device+0x3e/0xb0 drivers/base/bus.c:620
device_add+0x99f/0xc80 drivers/base/core.c:3772
usb_set_configuration+0x8f5/0xb80 drivers/usb/core/message.c:2268
BUG: memory leak
unreferenced object 0xffff888111cfec80 (size 8):
comm "kworker/0:0", pid 9, jiffies 4294942439
hex dump (first 8 bytes):
c0 03 00 00 00 00 07 00 ........
backtrace (crc 40fcb6d):
kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
slab_post_alloc_hook mm/slub.c:4625 [inline]
slab_alloc_node mm/slub.c:4945 [inline]
__kmalloc_cache_noprof+0x356/0x440 mm/slub.c:5511
_kmalloc_noprof include/linux/slab.h:969 [inline]
submit_async_request.constprop.0+0x143/0x440 drivers/usb/misc/uss720.c:150
get_1284_register+0x4a/0x1a0 drivers/usb/misc/uss720.c:205
uss720_probe+0x205/0x330 drivers/usb/misc/uss720.c:733
usb_probe_interface+0x210/0x480 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:628 [inline]
really_probe+0x12f/0x3a0 drivers/base/dd.c:706
__driver_probe_device+0xe9/0x1a0 drivers/base/dd.c:868
driver_probe_device+0x28/0xf0 drivers/base/dd.c:898
__device_attach_driver+0x10f/0x170 drivers/base/dd.c:1026
bus_for_each_drv+0xd2/0x130 drivers/base/bus.c:500
__device_attach+0xf9/0x290 drivers/base/dd.c:1098
device_initial_probe+0x6f/0x80 drivers/base/dd.c:1153
bus_probe_device+0x3e/0xb0 drivers/base/bus.c:620
device_add+0x99f/0xc80 drivers/base/core.c:3772
usb_set_configuration+0x8f5/0xb80 drivers/usb/core/message.c:2268
usb_generic_driver_probe+0x73/0xb0 drivers/usb/core/generic.c:250
connection error: failed to recv *flatrpc.ExecutorMessageRawT: EOF
It is reproducible with the followint program.
Keep in mind that it may lack the precise threading, sandboxing, and some arguments of a working reproducer.
But it should give an idea of the involved syscalls.
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <linux/loop.h>
#include <linux/usb/ch9.h>
#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);
}
#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");
} else if (strncmp(fs, "gfs2", 4) == 0 && (strstr(opts, "errors=panic") || strstr(opts, "debug"))) {
strcat(opts, ",errors=withdraw");
}
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;
}
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000, /*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=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
const char* reason;
(void)reason;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// syz_usb_connect arguments: [
// speed: usb_device_speed = 0x0 (8 bytes)
// dev_len: len = 0x5a (8 bytes)
// dev: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// union ANYUNION {
// ANYBLOB: buffer: {12 01 00 00 60 f9 4d 10 0d 05 02 00 27 23 01 02 03 01 09 02 48 40 02 00 00 00 00 09 04 7d 04 03 1d 5a bf 00 09 05 04 00 00 55 39 00 00 09 05 0b 00 00 00 00 00 00 09 05 02 00 00 00 05 00 00 09 04 7d 01 01 34 81 af 00 09 a0 0e 00 23 00 00 69 00 09 04 7d be} (length 0x55)
// }
// }
// }
// conn_descs: nil
// ]
// returns fd_usb
memcpy((void*)0x200000000080, "... [truncated large byte array] ...", 85);
syz_usb_connect(/*speed=*/0, /*dev_len=*/0x5a, /*dev=*/0x200000000080, /*conn_descs=*/0);
// syz_mount_image$f2fs arguments: [
// fs: ptr[in, buffer] {
// buffer: {66 32 66 73 00} (length 0x5)
// }
// dir: ptr[in, buffer] {
// buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8)
// }
// flags: mount_flags = 0x8 (8 bytes)
// opts: ptr[in, fs_options[f2fs_options]] {
// fs_options[f2fs_options] {
// elems: array[fs_opt_elem[f2fs_options]] {
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// nodiscard: buffer: {6e 6f 64 69 73 63 61 72 64} (length 0x9)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// nocheckpoint_merge: buffer: {6e 6f 63 68 65 63 6b 70 6f 69 6e 74 5f 6d 65 72 67 65} (length 0x12)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// alloc_mode_def: buffer: {61 6c 6c 6f 63 5f 6d 6f 64 65 3d 64 65 66 61 75 6c 74} (length 0x12)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// six_active_logs: buffer: {61 63 74 69 76 65 5f 6c 6f 67 73 3d 36} (length 0xd)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// flush_merge: buffer: {66 6c 75 73 68 5f 6d 65 72 67 65} (length 0xb)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// fault_injection: fs_opt["fault_injection", fmt[dec, int32]] {
// name: buffer: {66 61 75 6c 74 5f 69 6e 6a 65 63 74 69 6f 6e} (length 0xf)
// eq: const = 0x3d (1 bytes)
// val: int32 = 0x4ee (20 bytes)
// }
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// acl: buffer: {61 63 6c} (length 0x3)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// noacl: buffer: {6e 6f 61 63 6c} (length 0x5)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// compress_cache: buffer: {63 6f 6d 70 72 65 73 73 5f 63 61 63 68 65} (length 0xe)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// alloc_mode_def: buffer: {61 6c 6c 6f 63 5f 6d 6f 64 65 3d 64 65 66 61 75 6c 74} (length 0x12)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// nodiscard: buffer: {6e 6f 64 69 73 63 61 72 64} (length 0x9)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// compress_cache: buffer: {63 6f 6d 70 72 65 73 73 5f 63 61 63 68 65} (length 0xe)
// }
// comma: const = 0x2c (1 bytes)
// }
// fs_opt_elem[f2fs_options] {
// elem: union f2fs_options {
// fault_type: fs_opt["fault_type", fmt[dec, int32]] {
// name: buffer: {66 61 75 6c 74 5f 74 79 70 65} (length 0xa)
// eq: const = 0x3d (1 bytes)
// val: int32 = 0x4 (20 bytes)
// }
// }
// comma: const = 0x2c (1 bytes)
// }
// }
// common: array[fs_opt_elem[fs_options_common]] {
// }
// null: const = 0x0 (1 bytes)
// }
// }
// chdir: int8 = 0x1 (1 bytes)
// size: len = 0x5505 (8 bytes)
// img: ptr[in, buffer] {
// buffer: (compressed buffer with length 0x5505)
// }
// ]
// returns fd_dir
memcpy((void*)0x200000000000, "f2fs\000", 5);
memcpy((void*)0x200000000040, "./file0\000", 8);
memcpy((void*)0x200000000400, "nodiscard", 9);
*(uint8_t*)0x200000000409 = 0x2c;
memcpy((void*)0x20000000040a, "nocheckpoint_merge", 18);
*(uint8_t*)0x20000000041c = 0x2c;
memcpy((void*)0x20000000041d, "alloc_mode=default", 18);
*(uint8_t*)0x20000000042f = 0x2c;
memcpy((void*)0x200000000430, "active_logs=6", 13);
*(uint8_t*)0x20000000043d = 0x2c;
memcpy((void*)0x20000000043e, "flush_merge", 11);
*(uint8_t*)0x200000000449 = 0x2c;
memcpy((void*)0x20000000044a, "fault_injection", 15);
*(uint8_t*)0x200000000459 = 0x3d;
sprintf((char*)0x20000000045a, "%020llu", (long long)0x4ee);
*(uint8_t*)0x20000000046e = 0x2c;
memcpy((void*)0x20000000046f, "acl", 3);
*(uint8_t*)0x200000000472 = 0x2c;
memcpy((void*)0x200000000473, "noacl", 5);
*(uint8_t*)0x200000000478 = 0x2c;
memcpy((void*)0x200000000479, "compress_cache", 14);
*(uint8_t*)0x200000000487 = 0x2c;
memcpy((void*)0x200000000488, "alloc_mode=default", 18);
*(uint8_t*)0x20000000049a = 0x2c;
memcpy((void*)0x20000000049b, "nodiscard", 9);
*(uint8_t*)0x2000000004a4 = 0x2c;
memcpy((void*)0x2000000004a5, "compress_cache", 14);
*(uint8_t*)0x2000000004b3 = 0x2c;
memcpy((void*)0x2000000004b4, "fault_type", 10);
*(uint8_t*)0x2000000004be = 0x3d;
sprintf((char*)0x2000000004bf, "%020llu", (long long)4);
*(uint8_t*)0x2000000004d3 = 0x2c;
*(uint8_t*)0x2000000004d4 = 0;
memcpy((void*)0x2000000079c0, "... [truncated large byte array] ...", 21765);
syz_mount_image(/*fs=*/0x200000000000, /*dir=*/0x200000000040, /*flags=MS_NOEXEC*/8, /*opts=*/0x200000000400, /*chdir=*/1, /*size=*/0x5505, /*img=*/0x2000000079c0);
return 0;
}
Reply: The bug is a memory leak in the `uss720` USB-to-parallel port driver, specifically in the `get_1284_register` function.
### Root Cause Analysis
When the driver communicates with the USB device, it submits an asynchronous control transfer URB via `submit_async_request()`. This function allocates a request structure (`rq`) and initializes its reference count to 1, then increments it to 2 before submitting the URB (one reference for the URB completion handler, one for the caller).
In `get_1284_register()`, the driver waits for the URB to complete using `wait_for_completion_timeout()`.
If the device responds in time, the function correctly drops its reference by calling `kref_put(&rq->ref_count, destroy_async)`.
However, if the device fails to respond and the wait times out, the function executes the timeout path:
```c
if (wait_for_completion_timeout(&rq->compl, HZ)) {
// ... normal completion ...
kref_put(&rq->ref_count, destroy_async);
return ret;
}
printk(KERN_WARNING "get_1284_register timeout\n");
kill_all_async_requests_priv(priv);
return -EIO;
```
In the timeout path, the driver calls `kill_all_async_requests_priv()` to unlink the pending URBs but **forgets to drop its reference** to `rq`. When the unlinked URB eventually completes, the completion handler (`async_complete`) drops its own reference, leaving the `rq` reference count at 1 forever.
Because `rq` also holds a reference to the driver's private data structure (`priv`), this single missing `kref_put` causes a cascade of memory leaks, leaking the `rq` structure, the URB, the DMA buffer, and the `priv` structure itself. This perfectly matches the 4 unreferenced objects shown in the KASAN/kmemleak report.
### Impact and Exploitability
- **Exploitable**: **False**. This is a pure memory leak. The reference counting logic ensures that the objects are never freed prematurely, so there is no use-after-free or memory corruption.
- **Denial of Service**: **True**. A malicious USB device that intentionally ignores control requests can cause the driver to repeatedly hit the timeout path, leaking memory on every attempt. This can eventually exhaust system memory (OOM).
- **Peripheral Trigger**: **True**. Triggering this bug requires a USB device that times out on specific control requests. Thus, it requires physical access to plug in a malicious USB device (or root privileges to emulate one via software like `raw-gadget`).
- **Unprivileged / User Namespaces**: **False**. Unprivileged users cannot emulate USB devices, nor can they force a legitimate hardware device to time out.
|
| 6/2 |
2026/07/15 21:37 |
llm |
expert |
0m
Model:
Tokens:
input: 23463
output: 42
thoughts: 450
Thoughts: **Memory Leak Investigation: uss720 Driver**
Okay, so I've got a memory leak report for the `uss720` driver, specifically in `drivers/usb/misc/uss720.c`. The leak is pinpointed within the `uss720_probe` function. The backtrace they've provided is pretty straightforward, showing calls to allocation functions that are triggering the kernel memory leak detection: `kmemleak_alloc_recursive`, `slab_post_alloc_hook`, `slab_alloc_node`, eventually leading to `__kmalloc_cache_noprof` and its related functions, and ultimately ending in `uss720_probe`.
The backtraces also show some interactions within `uss720_probe`:
* It seems like there are multiple allocations happening in `uss720_probe` itself.
* One path goes through `submit_async_request` -> `get_1284_register` -> `uss720_probe`.
* Another path goes through `submit_async_request` again, but this time allocating an `urb` via `usb_alloc_urb`.
Therefore, I'll need to focus my attention on `uss720_probe` itself and the `submit_async_request` function within `drivers/usb/misc/uss720.c` to understand where these allocations are happening and, crucially, where they're *not* being freed. Time to dive into the code...
|
| 7/2 |
2026/07/15 21:37 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/usb/misc/uss720.c Name:uss720_probe]
Results: map[SourceCode: 671: static int uss720_probe(struct usb_interface *intf,
672: const struct usb_device_id *id)
673: {
674: struct usb_device *usbdev = usb_get_dev(interface_to_usbdev(intf));
675: struct usb_host_interface *interface;
676: struct usb_endpoint_descriptor *epd;
677: struct parport_uss720_private *priv;
678: struct parport *pp;
679: unsigned char reg;
680: int ret = -ENODEV;
681:
682: dev_dbg(&intf->dev, "probe: vendor id 0x%x, device id 0x%x\n",
683: le16_to_cpu(usbdev->descriptor.idVendor),
684: le16_to_cpu(usbdev->descriptor.idProduct));
685:
686: /* our known interfaces have 3 alternate settings */
687: if (intf->num_altsetting != 3)
688: goto bail_out_early;
689:
690: ret = usb_set_interface(usbdev, intf->altsetting->desc.bInterfaceNumber, 2);
691: dev_dbg(&intf->dev, "set interface result %d\n", ret);
692:
693: interface = intf->cur_altsetting;
694:
695: if (interface->desc.bNumEndpoints < 2)
696: goto bail_out_early;
697:
698: /*
699: * Allocate parport interface
700: */
701: ret = -ENOMEM;
702: priv = kzalloc_obj(struct parport_uss720_private);
703: if (!priv)
704: goto bail_out_early;
705:
706: priv->pp = NULL;
707: priv->usbdev = usbdev;
708: kref_init(&priv->ref_count);
709: spin_lock_init(&priv->asynclock);
710: INIT_LIST_HEAD(&priv->asynclist);
711: pp = parport_register_port(0, PARPORT_IRQ_NONE, PARPORT_DMA_NONE, &parport_uss720_ops);
712: if (!pp) {
713: printk(KERN_WARNING "uss720: could not register parport\n");
714: goto probe_abort;
715: }
716:
717: priv->pp = pp;
718: pp->private_data = priv;
719: pp->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_TRISTATE | PARPORT_MODE_EPP | PARPORT_MODE_COMPAT;
720: if (interface->desc.bNumEndpoints >= 3)
721: pp->modes |= PARPORT_MODE_ECP;
722: pp->dev = &usbdev->dev;
723:
724: /* set the USS720 control register to manual mode, no ECP compression, enable all ints */
725: set_1284_register(pp, 7, 0x00, GFP_KERNEL);
726: set_1284_register(pp, 6, 0x30, GFP_KERNEL); /* PS/2 mode */
727: set_1284_register(pp, 2, 0x0c, GFP_KERNEL);
728:
729: /* The Belkin F5U002 Rev 2 P80453-B USB parallel port adapter shares the
730: * device ID 050d:0002 with some other device that works with this
731: * driver, but it itself does not. Detect and handle the bad cable
732: * here. */
733: ret = get_1284_register(pp, 0, ®, GFP_KERNEL);
734: dev_dbg(&intf->dev, "reg: %7ph\n", priv->reg);
735: if (ret < 0) {
736: priv->pp = NULL;
737: parport_del_port(pp);
738: goto probe_abort;
739: }
740:
741: ret = usb_find_last_int_in_endpoint(interface, &epd);
742: if (!ret) {
743: dev_dbg(&intf->dev, "epaddr %d interval %d\n",
744: epd->bEndpointAddress, epd->bInterval);
745: }
746: parport_announce_port(pp);
747:
748: usb_set_intfdata(intf, pp);
749: return 0;
750:
751: probe_abort:
752: kill_all_async_requests_priv(priv);
753: kref_put(&priv->ref_count, destroy_priv);
754: return -ENODEV;
755:
756: bail_out_early:
757: usb_put_dev(usbdev);
758: return ret;
759: }
SourceFile:drivers/usb/misc/uss720.c]
|
| 8/2 |
2026/07/15 21:37 |
llm |
expert |
0m
Model:
Tokens:
input: 25841
output: 39
thoughts: 96
Thoughts: **Analyzing the Failure Path in the 1284 Driver**
Okay, so I'm tracing through this driver code, and I'm focusing on how it handles potential allocation failures. I'm seeing that the `priv` structure, which is critical to the operation, is allocated at line 702. The crucial bit is that if `get_1284_register(pp, 0, ®, GFP_KERNEL)` fails, we immediately branch to `probe_abort`. That's the critical point.
Now, inside `probe_abort`, we have two critical function calls: `kill_all_async_requests_priv(priv)` and `kref_put(&priv->ref_count, destroy_priv)`. Clearly, `kill_all_async_requests_priv` is about cleaning up any potentially orphaned asynchronous requests before we shut down. But itβs `kref_put(&priv->ref_count, destroy_priv)` that's really grabbing my attention right now. This is where the cleanup process for the `priv` struct begins. It suggests a reference-counted memory management strategy. Therefore, I need to understand what `destroy_priv` is doing. This will be critical to the overall robustness of the driver's memory management.
|
| 9/2 |
2026/07/15 21:37 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/usb/misc/uss720.c Name:destroy_priv]
Results: map[SourceCode: 68: static void destroy_priv(struct kref *kref)
69: {
70: struct parport_uss720_private *priv = container_of(kref, struct parport_uss720_private, ref_count);
71:
72: dev_dbg(&priv->usbdev->dev, "destroying priv datastructure\n");
73: usb_put_dev(priv->usbdev);
74: priv->usbdev = NULL;
75: kfree(priv);
76: }
SourceFile:drivers/usb/misc/uss720.c]
|
| 10/2 |
2026/07/15 21:37 |
llm |
expert |
0m
Model:
Tokens:
input: 26432
output: 41
thoughts: 44
Thoughts: Okay, here's my take on those thoughts, framed from my own expert perspective:
**Investigating a Potential Memory Leak**
Right, so `destroy_priv` is *supposed* to free the `priv` structure. That's the obvious one to check, and it's the usual suspect in these situations. But the leak report is pointing fingers at `submit_async_request` and `usb_alloc_urb` as well. That's interesting, and potentially more troublesome, as these are often deeper down in the stack. We can probably rule out `usb_alloc_urb` first. So, let's start by digging into `submit_async_request`. We'll see if there is something not freeing properly within this specific routine.
|
| 11/2 |
2026/07/15 21:37 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/usb/misc/uss720.c Name:submit_async_request]
Results: map[SourceCode: 123: static struct uss720_async_request *submit_async_request(struct parport_uss720_private *priv,
124: __u8 request, __u8 requesttype, __u16 value, __u16 index,
125: gfp_t mem_flags)
126: {
127: struct usb_device *usbdev;
128: struct uss720_async_request *rq;
129: unsigned long flags;
130: int ret;
131:
132: if (!priv)
133: return NULL;
134: usbdev = priv->usbdev;
135: if (!usbdev)
136: return NULL;
137: rq = kzalloc_obj(struct uss720_async_request, mem_flags);
138: if (!rq)
139: return NULL;
140: kref_init(&rq->ref_count);
141: INIT_LIST_HEAD(&rq->asynclist);
142: init_completion(&rq->compl);
143: kref_get(&priv->ref_count);
144: rq->priv = priv;
145: rq->urb = usb_alloc_urb(0, mem_flags);
146: if (!rq->urb) {
147: kref_put(&rq->ref_count, destroy_async);
148: return NULL;
149: }
150: rq->dr = kmalloc_obj(*rq->dr, mem_flags);
151: if (!rq->dr) {
152: kref_put(&rq->ref_count, destroy_async);
153: return NULL;
154: }
155: rq->dr->bRequestType = requesttype;
156: rq->dr->bRequest = request;
157: rq->dr->wValue = cpu_to_le16(value);
158: rq->dr->wIndex = cpu_to_le16(index);
159: rq->dr->wLength = cpu_to_le16((request == 3) ? sizeof(rq->reg) : 0);
160: usb_fill_control_urb(rq->urb, usbdev, (requesttype & 0x80) ? usb_rcvctrlpipe(usbdev, 0) : usb_sndctrlpipe(usbdev, 0),
161: (unsigned char *)rq->dr,
162: (request == 3) ? rq->reg : NULL, (request == 3) ? sizeof(rq->reg) : 0, async_complete, rq);
163: /* rq->urb->transfer_flags |= URB_ASYNC_UNLINK; */
164: spin_lock_irqsave(&priv->asynclock, flags);
165: list_add_tail(&rq->asynclist, &priv->asynclist);
166: spin_unlock_irqrestore(&priv->asynclock, flags);
167: kref_get(&rq->ref_count);
168: ret = usb_submit_urb(rq->urb, mem_flags);
169: if (!ret)
170: return rq;
171: destroy_async(&rq->ref_count);
172: dev_err(&usbdev->dev, "submit_async_request submit_urb failed with %d\n", ret);
173: return NULL;
174: }
SourceFile:drivers/usb/misc/uss720.c]
|
| 12/2 |
2026/07/15 21:37 |
llm |
expert |
0m
Model:
Tokens:
input: 27685
output: 39
thoughts: 153
Thoughts: **Analyzing USB URB Submission Failure**
Okay, so I'm looking at this `usb_submit_urb` function, and I see that if it fails, it calls `destroy_async(&rq->ref_count)`. That seems straightforward enough, but my brain immediately raises a flag. I'm used to seeing `destroy_async` passed to `kref_put` normally. That's the standard pattern. But here, it's being called directly. That's not wrong per se, but it's making me pause.
My next thought is that `rq->ref_count` was initialized with a value of 1, as you'd expect with `kref_init`. Then, there's a `kref_get(&rq->ref_count)`, incrementing it to 2. So, if the submission *fails*, and we call `destroy_async(&rq->ref_count)` directly, wouldn't that just *decrement* the ref count to 1? This can't be correct. `destroy_async` is a function though, not just a macro.
Right, I need to check the definition of `destroy_async`. Let's see what that function *actually* does. There's definitely something I'm missing here; the logic in the decrement isn't matching what I'm expecting in a KREF scenario.
|
| 13/2 |
2026/07/15 21:37 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/usb/misc/uss720.c Name:destroy_async]
Results: map[SourceCode: 78: static void destroy_async(struct kref *kref)
79: {
80: struct uss720_async_request *rq = container_of(kref, struct uss720_async_request, ref_count);
81: struct parport_uss720_private *priv = rq->priv;
82: unsigned long flags;
83:
84: if (likely(rq->urb))
85: usb_free_urb(rq->urb);
86: kfree(rq->dr);
87: spin_lock_irqsave(&priv->asynclock, flags);
88: list_del_init(&rq->asynclist);
89: spin_unlock_irqrestore(&priv->asynclock, flags);
90: kfree(rq);
91: kref_put(&priv->ref_count, destroy_priv);
92: }
SourceFile:drivers/usb/misc/uss720.c]
|
| 14/2 |
2026/07/15 21:37 |
llm |
expert |
0m
Model:
Tokens:
input: 28466
output: 39
thoughts: 206
Thoughts: **Analyzing the Asynchronous USB Request Handling**
Okay, hold on a second. This `destroy_async` function... it seems to be unconditionally freeing the object it's given, right? And it's taking a `struct kref *kref`, which I know is a reference-counted structure. But there's no refcount check *inside* `destroy_async` itself? That's... unusual. I'm used to `kref_put` being the one that calls the destruction function when the count hits zero.
Aha! `usb_submit_urb`! If that function *fails*, it calls `destroy_async` directly, using `&rq->ref_count` as the argument. Okay, that makes sense - if the submit fails, it needs to clean up. But... wait... `destroy_async` frees `rq`. But what about the extra reference count that would have happened as a result of the urb submission process?
Oh! Right. If `usb_submit_urb` *fails*, it calls `destroy_async` directly. So `rq` gets freed immediately. Okay, I'm with you so far. But, hang on, wasn't `rq` added to `priv->asynclist`? `destroy_async` removes it from `priv->asynclist`, thankfully.
Okay, let's back up. If `usb_submit_urb` succeeds, it *returns* `rq`. Then who takes care of decreasing the refcount? We clearly need to look into `async_complete` to understand the full picture.
|
| 15/2 |
2026/07/15 21:37 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/usb/misc/uss720.c Name:async_complete]
Results: map[SourceCode: 96: static void async_complete(struct urb *urb)
97: {
98: struct uss720_async_request *rq;
99: struct parport *pp;
100: struct parport_uss720_private *priv;
101: int status = urb->status;
102:
103: rq = urb->context;
104: priv = rq->priv;
105: pp = priv->pp;
106: if (status) {
107: dev_err(&urb->dev->dev, "async_complete: urb error %d\n",
108: status);
109: } else if (rq->dr->bRequest == 3) {
110: memcpy(priv->reg, rq->reg, sizeof(priv->reg));
111: #if 0
112: dev_dbg(&priv->usbdev->dev, "async_complete regs %7ph\n",
113: priv->reg);
114: #endif
115: /* if nAck interrupts are enabled and we have an interrupt, call the interrupt procedure */
116: if (rq->reg[2] & rq->reg[1] & 0x10 && pp)
117: parport_generic_irq(pp);
118: }
119: complete(&rq->compl);
120: kref_put(&rq->ref_count, destroy_async);
121: }
SourceFile:drivers/usb/misc/uss720.c]
|
| 16/2 |
2026/07/15 21:37 |
llm |
expert |
0m
Model:
Tokens:
input: 29501
output: 44
thoughts: 227
Thoughts: **Analyzing Asynchronous Request Handling**
Okay, so I'm looking at how asynchronous requests are managed, specifically the lifecycle of a request (`rq`) within this driver. I see that `async_complete` is responsible for calling `kref_put` on the reference count (`rq->ref_count`), decrementing it and potentially calling a `destroy_async` function if it hits zero. That much makes sense.
Now, let's step through `submit_async_request`. It initializes the reference count to 1 with `kref_init`. Then, it adds the request to an asynchronous list under a lock. Crucially, it then calls `kref_get`, incrementing the refcount to 2 *before* submitting the USB request with `usb_submit_urb`. This is standard, ensuring the request is alive during submission.
The critical point here is what happens *after* `usb_submit_urb`. If `usb_submit_urb` succeeds, which it should in most cases, it returns `rq`. It leaves the `rq` with a refcount of 2. That's fine for now.
But who, or what, is supposed to put the other refcount? Since we are looking at `submit_async_request` we can see the `destroy_async` function is called if the submit fails.
I need to see where that second reference is handled. That means checking where `kref_get` is done. Perhaps `get_1284_register` is the place to start. I need to follow the execution path to understand when that second reference is dropped. This is a potential memory leak if not handled correctly.
|
| 17/2 |
2026/07/15 21:37 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/usb/misc/uss720.c Name:get_1284_register]
Results: map[SourceCode: 193: static int get_1284_register(struct parport *pp, unsigned char reg, unsigned char *val, gfp_t mem_flags)
194: {
195: struct parport_uss720_private *priv;
196: struct uss720_async_request *rq;
197: static const unsigned char regindex[9] = {
198: 4, 0, 1, 5, 5, 0, 2, 3, 6
199: };
200: int ret;
201:
202: if (!pp)
203: return -EIO;
204: priv = pp->private_data;
205: rq = submit_async_request(priv, 3, 0xc0, ((unsigned int)reg) << 8, 0, mem_flags);
206: if (!rq) {
207: dev_err(&priv->usbdev->dev, "get_1284_register(%u) failed",
208: (unsigned int)reg);
209: return -EIO;
210: }
211: if (!val) {
212: kref_put(&rq->ref_count, destroy_async);
213: return 0;
214: }
215: if (wait_for_completion_timeout(&rq->compl, HZ)) {
216: ret = rq->urb->status;
217: *val = priv->reg[(reg >= 9) ? 0 : regindex[reg]];
218: if (ret)
219: printk(KERN_WARNING "get_1284_register: "
220: "usb error %d\n", ret);
221: kref_put(&rq->ref_count, destroy_async);
222: return ret;
223: }
224: printk(KERN_WARNING "get_1284_register timeout\n");
225: kill_all_async_requests_priv(priv);
226: return -EIO;
227: }
SourceFile:drivers/usb/misc/uss720.c]
|
| 18/2 |
2026/07/15 21:37 |
llm |
expert |
0m
Model:
Tokens:
input: 30760
output: 45
thoughts: 87
Thoughts: Okay, let me think this through.
**Analyzing Asynchronous Request Handling**
Right, so `get_1284_register` ultimately cleans itself up by calling `kref_put(&rq->ref_count, destroy_async)` when it's done. That makes sense, standard reference counting. But hold on... if `wait_for_completion_timeout` times out, it's not a clean exit! Instead, it invokes `kill_all_async_requests_priv(priv)` and bails out with `-EIO`. That's important to remember; a timeout is treated like an I/O error, and initiates a forceful shutdown. Okay, so `kill_all_async_requests_priv` is obviously the critical function to understand in this error case. I should probably dive into the details of *that* function next.
|
| 19/2 |
2026/07/15 21:37 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/usb/misc/uss720.c Name:kill_all_async_requests_priv]
Results: map[SourceCode: 176: static unsigned int kill_all_async_requests_priv(struct parport_uss720_private *priv)
177: {
178: struct uss720_async_request *rq;
179: unsigned long flags;
180: unsigned int ret = 0;
181:
182: spin_lock_irqsave(&priv->asynclock, flags);
183: list_for_each_entry(rq, &priv->asynclist, asynclist) {
184: usb_unlink_urb(rq->urb);
185: ret++;
186: }
187: spin_unlock_irqrestore(&priv->asynclock, flags);
188: return ret;
189: }
SourceFile:drivers/usb/misc/uss720.c]
|
| 20/2 |
2026/07/15 21:37 |
llm |
expert |
0m
Model:
Tokens:
input: 31331
output: 44
thoughts: 621
Thoughts: **The Refcount Leak in `get_1284_register` and `set_1284_register`**
Okay, let's break this down. It looks like the `kill_all_async_requests_priv` function, specifically when called within the context of `get_1284_register` (and likely `set_1284_register`), is the source of a refcount leak. The sequence goes like this: a URB gets unlinked, forcing it to complete with an error code (-ECONNRESET or -ENOENT), which then leads to `async_complete` being called. Within `async_complete`, `kref_put` is called to decrement the `rq->ref_count` using the `destroy_async` function.
However, if `get_1284_register` times out before the request completes normally, it calls `kill_all_async_requests_priv`. Critically, it *doesn't* call `kref_put` itself to handle its own reference to `rq`. I can see the refcount sequence, now:
1. `kref_init(&rq->ref_count)` - refcount = 1
2. `kref_get(&rq->ref_count)` - refcount = 2 (when the async request is submitted)
3. `usb_submit_urb`
4. `submit_async_request` returns `rq` to `get_1284_register`.
5. `get_1284_register` is waiting.
6. If Timeout occurs, `kill_all_async_requests_priv` is called which in turns calls `usb_unlink_urb`
7. `usb_unlink_urb` causes `async_complete` to be called.
8. `async_complete` calls `kref_put(&rq->ref_count, destroy_async)`. Refcount becomes 1.
9. `get_1284_register` returns `-EIO`.
10. The remaining refcount of 1 is never put! So `rq` is leaked.
This means that the refcount from the initial `submit_async_request` is effectively leaked if the function times out. The bug report is showing leaks of `struct parport_uss720_private`, `struct uss720_async_request`, `rq->urb`, and `rq->dr` - all are the exact components that are held by `rq`!
Crucially, because `rq` holds a reference to `priv`, which is a `parport_uss720_private` struct, and the `kref_get` on `priv->ref_count` occurs in `submit_async_request` and the corresponding `kref_put` happens in `destroy_priv` - if `rq` is leaked, `priv` is *also* leaked. The objects in the leak report completely align with that. So the timeout condition is the key. And, yes, `set_1284_register` likely has the same flaw.
|
| 21/2 |
2026/07/15 21:38 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/usb/misc/uss720.c Name:set_1284_register]
Results: map[SourceCode: 229: static int set_1284_register(struct parport *pp, unsigned char reg, unsigned char val, gfp_t mem_flags)
230: {
231: struct parport_uss720_private *priv;
232: struct uss720_async_request *rq;
233:
234: if (!pp)
235: return -EIO;
236: priv = pp->private_data;
237: rq = submit_async_request(priv, 4, 0x40, (((unsigned int)reg) << 8) | val, 0, mem_flags);
238: if (!rq) {
239: dev_err(&priv->usbdev->dev, "set_1284_register(%u,%u) failed",
240: (unsigned int)reg, (unsigned int)val);
241: return -EIO;
242: }
243: kref_put(&rq->ref_count, destroy_async);
244: return 0;
245: }
SourceFile:drivers/usb/misc/uss720.c]
|
| 22/2 |
2026/07/15 21:38 |
llm |
expert |
0m
Model:
Tokens:
input: 33020
output: 39
thoughts: 475
Thoughts: **Analyzing Asynchronous Request Lifecycle**
Okay, so I'm walking through this asynchronous request management. `set_1284_register` immediately releases its reference via `kref_put`. This is good; it kicks off the asynchronous process, decrements the refcount to 1, and relies on `async_complete` to bring it down to 0 and free the memory. Wait... I need to be sure. I have to think about the timing here, if `async_complete` finishes *before* that initial `kref_put` call. In that scenario `async_complete` would hit the refcount first, decrementing it to 1, and then `set_1284_register` does it's decrement to 0, and the memory is freed correctly. Yep, it works out.
Now, I'm shifting my focus to `get_1284_register`. If it times out... *that's* where things get messy. It *doesn't* call `kref_put` on a timeout, which means that refcount leaks. That's a definite problem. I have to see how that scenario plays out.
But what if the timeout triggers `kill_all_async_requests_priv`? Does that cleanup somehow? If the URB gets unlinked and `async_complete` *does* get called, then `async_complete` would indeed decrement. But... the refcount was *2* originally (one for the URB itself, one for the `get_1284_register` call), right? So `async_complete` would only decrement it to 1, and we'd still leak. We're leaking a reference because of a timeout. That's a serious bug.
I need to make sure I don't see any other places where a `kref_put` is missing. Let's look at `change_mode`.
|
| 23/2 |
2026/07/15 21:38 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/usb/misc/uss720.c Name:change_mode]
Results: map[SourceCode: 256: /* Safely change the mode bits in the ECR */
257: static int change_mode(struct parport *pp, int m)
258: {
259: struct parport_uss720_private *priv = pp->private_data;
260: int mode;
261: __u8 reg;
262:
263: if (get_1284_register(pp, 6, ®, GFP_KERNEL))
264: return -EIO;
265: /* Bits <7:5> contain the mode. */
266: mode = (priv->reg[2] >> 5) & 0x7;
267: if (mode == m)
268: return 0;
269: /* We have to go through mode 000 or 001 */
270: if (mode > ECR_PS2 && m > ECR_PS2)
271: if (change_mode(pp, ECR_PS2))
272: return -EIO;
273:
274: if (m <= ECR_PS2 && !(priv->reg[1] & 0x20)) {
275: /* This mode resets the FIFO, so we may
276: * have to wait for it to drain first. */
277: unsigned long expire = jiffies + pp->physport->cad->timeout;
278: switch (mode) {
279: case ECR_PPF: /* Parallel Port FIFO mode */
280: case ECR_ECP: /* ECP Parallel Port mode */
281: /* Poll slowly. */
282: for (;;) {
283: if (get_1284_register(pp, 6, ®, GFP_KERNEL))
284: return -EIO;
285: if (priv->reg[2] & 0x01)
286: break;
287: if (time_after_eq (jiffies, expire))
288: /* The FIFO is stuck. */
289: return -EBUSY;
290: msleep_interruptible(10);
291: if (signal_pending (current))
292: break;
293: }
294: }
295: }
296: /* Set the mode. */
297: if (set_1284_register(pp, 6, m << 5, GFP_KERNEL))
298: return -EIO;
299: if (get_1284_register(pp, 6, ®, GFP_KERNEL))
300: return -EIO;
301: return 0;
302: }
SourceFile:drivers/usb/misc/uss720.c]
|
| 24/2 |
2026/07/15 21:38 |
llm |
expert |
0m
Model:
Tokens:
input: 34759
output: 38
thoughts: 6767
Thoughts: **Analysis of the USB Driver Memory Leak**
Alright, let's break this down. It seems there's a memory leak in the `uss720` USB parallel port driver, specifically in the `get_1284_register` function. My initial thought is that `get_1284_register` is the only function waiting for completion, and it leaks the reference count on a timeout, which is the key here.
The bug stems from how `get_1284_register` is called within `uss720_probe`. If a USB device times out while waiting for a response in `get_1284_register`, it returns an error and goes to `probe_abort`. This calls `kill_all_async_requests_priv` and `kref_put(&priv->ref_count, destroy_priv)`. The problem is the request `rq` is leaked, and consequently, so is `priv`, because `rq` holds a reference to it. It does *not* call `kref_put(&rq->ref_count, destroy_async)`, which is crucial.
This isn't an exploitable bug for privilege escalation or memory corruption. It's a pure memory leak. But, a memory leak can lead to a Denial of Service. So I'm now asking if the root cause can be triggered by an unprivileged user.
Since this happens during a USB device probe, the simplest trigger is a physical device plug (Peripheral Trigger). Can an unprivileged user exploit this through other methods? The code is in `uss720_probe` which is called when a USB device is plugged in. This could be simulated via `syz_usb_connect`. It seems like using something like `raw-gadget` might be a possibility, but that would involve special permissions, which the question excludes.
Now, if a host in a virtual machine environment hotplugs a device into the guest VM, the leak could also happen.
The leak happens because the refcount of `rq` is never decremented. `kill_all_async_requests_priv` unlinks the URB, and `async_complete` will run. But if `get_1284_register` times out, `async_complete` won't decrement the refcount as planned, which keeps it at a value of 1.
The fix, logically, is to add `kref_put(&rq->ref_count, destroy_async);` inside the timeout condition.
It is safe, because `async_complete` itself holds a reference to `rq`'s refcount, so even if the timeout triggers the leak, the memory will not be corrupted or prematurely freed.
|
| 25/2 |
2026/07/15 21:39 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/usb/core/urb.c Name:usb_unlink_urb]
Results: map[SourceCode: 592: /**
593: * usb_unlink_urb - abort/cancel a transfer request for an endpoint
594: * @urb: pointer to urb describing a previously submitted request,
595: * may be NULL
596: *
597: * This routine cancels an in-progress request. URBs complete only once
598: * per submission, and may be canceled only once per submission.
599: * Successful cancellation means termination of @urb will be expedited
600: * and the completion handler will be called with a status code
601: * indicating that the request has been canceled (rather than any other
602: * code).
603: *
604: * Drivers should not call this routine or related routines, such as
605: * usb_kill_urb(), after their disconnect method has returned. The
606: * disconnect function should synchronize with a driver's I/O routines
607: * to insure that all URB-related activity has completed before it returns.
608: *
609: * This request is asynchronous, however the HCD might call the ->complete()
610: * callback during unlink. Therefore when drivers call usb_unlink_urb(), they
611: * must not hold any locks that may be taken by the completion function.
612: * Success is indicated by returning -EINPROGRESS, at which time the URB will
613: * probably not yet have been given back to the device driver. When it is
614: * eventually called, the completion function will see @urb->status ==
615: * -ECONNRESET.
616: * Failure is indicated by usb_unlink_urb() returning any other value.
617: * Unlinking will fail when @urb is not currently "linked" (i.e., it was
618: * never submitted, or it was unlinked before, or the hardware is already
619: * finished with it), even if the completion handler has not yet run.
620: *
621: * The URB must not be deallocated while this routine is running. In
622: * particular, when a driver calls this routine, it must insure that the
623: * completion handler cannot deallocate the URB.
624: *
625: * Return: -EINPROGRESS on success. See description for other values on
626: * failure.
627: *
628: * Unlinking and Endpoint Queues:
629: *
630: * [The behaviors and guarantees described below do not apply to virtual
631: * root hubs but only to endpoint queues for physical USB devices.]
632: *
633: * Host Controller Drivers (HCDs) place all the URBs for a particular
634: * endpoint in a queue. Normally the queue advances as the controller
635: * hardware processes each request. But when an URB terminates with an
636: * error its queue generally stops (see below), at least until that URB's
637: * completion routine returns. It is guaranteed that a stopped queue
638: * will not restart until all its unlinked URBs have been fully retired,
639: * with their completion routines run, even if that's not until some time
640: * after the original completion handler returns. The same behavior and
641: * guarantee apply when an URB terminates because it was unlinked.
642: *
643: * Bulk and interrupt endpoint queues are guaranteed to stop whenever an
644: * URB terminates with any sort of error, including -ECONNRESET, -ENOENT,
645: * and -EREMOTEIO. Control endpoint queues behave the same way except
646: * that they are not guaranteed to stop for -EREMOTEIO errors. Queues
647: * for isochronous endpoints are treated differently, because they must
648: * advance at fixed rates. Such queues do not stop when an URB
649: * encounters an error or is unlinked. An unlinked isochronous URB may
650: * leave a gap in the stream of packets; it is undefined whether such
651: * gaps can be filled in.
652: *
653: * Note that early termination of an URB because a short packet was
654: * received will generate a -EREMOTEIO error if and only if the
655: * URB_SHORT_NOT_OK flag is set. By setting this flag, USB device
656: * drivers can build deep queues for large or complex bulk transfers
657: * and clean them up reliably after any sort of aborted transfer by
658: * unlinking all pending URBs at the first fault.
659: *
660: * When a control URB terminates with an error other than -EREMOTEIO, it
661: * is quite likely that the status stage of the transfer will not take
662: * place.
663: */
664: int usb_unlink_urb(struct urb *urb)
665: {
666: if (!urb)
667: return -EINVAL;
668: if (!urb->dev)
669: return -ENODEV;
670: if (!urb->ep)
671: return -EIDRM;
672: return usb_hcd_unlink_urb(urb, -ECONNRESET);
673: }
SourceFile:drivers/usb/core/urb.c]
|
| 26/2 |
2026/07/15 21:39 |
llm |
expert |
0m
Model:
Tokens:
input: 43649
output: 42
thoughts: 494
Thoughts: **Analyzing Potential Resource Leaks**
Okay, so I've been looking at this USB driver code, and I need to make sure I'm not missing any memory management issues. First, the question of `usb_unlink_urb` being called multiple times β that seems safe. It'll just return an error if the URB is already unlinked or completed, so no immediate use-after-free or double-free vulnerability there. Good.
Now, let's dig a bit deeper. I'm starting to think about potential leaks, particularly regarding the `priv` structure and its associated `parport` resource. Looking at `uss720_probe`, if `get_1284_register` times out and returns `-EIO`, the `parport` is correctly cleaned up with `parport_del_port(pp)` before hitting `probe_abort`, which calls `kill_all_async_requests_priv(priv)` and ultimately cleans up `priv` correctly. In this specific scenario, only `priv` and `rq` are leaked.
Ah, but what about other scenarios? Specifically, what happens if `get_1284_register` fails within the `change_mode` function?
```c
if (get_1284_register(pp, 6, ®, GFP_KERNEL))
return -EIO;
```
It seems that the code correctly returns the error. But, the caller handles the error by returning. The problem here is that `rq` is leaked. Furthermore, since `rq` holds a reference to `priv`, `priv->ref_count` is incremented.
This means that if `get_1284_register` times out, `priv->ref_count` will increase by 1, and an `rq` will be leaked every time it fails! Over time, if `get_1284_register` keeps timing out, then we'll have more and more `rq` resources that can't be freed.
The key to fixing this will probably be ensuring the `rq` is freed in the error path of `change_mode`, perhaps by cleaning it up before the function returns. Hopefully, the driver's `uss720_disconnect` function cleans everything up when the device is removed, so we don't have a *permanent* leak. But we should still fix the issue to avoid a buildup of these orphaned resources.
|
| 27/2 |
2026/07/15 21:39 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/usb/misc/uss720.c Name:uss720_disconnect]
Results: map[SourceCode: 761: static void uss720_disconnect(struct usb_interface *intf)
762: {
763: struct parport *pp = usb_get_intfdata(intf);
764: struct parport_uss720_private *priv;
765:
766: dev_dbg(&intf->dev, "disconnect\n");
767: usb_set_intfdata(intf, NULL);
768: if (pp) {
769: priv = pp->private_data;
770: priv->pp = NULL;
771: dev_dbg(&intf->dev, "parport_remove_port\n");
772: parport_remove_port(pp);
773: parport_put_port(pp);
774: kill_all_async_requests_priv(priv);
775: kref_put(&priv->ref_count, destroy_priv);
776: }
777: dev_dbg(&intf->dev, "disconnect done\n");
778: }
SourceFile:drivers/usb/misc/uss720.c]
|
| 28/2 |
2026/07/15 21:39 |
llm |
expert |
0m
Model:
Tokens:
input: 45043
output: 45
thoughts: 4128
Thoughts: **Analysis of the uss720 Driver Memory Leak and Potential Deadlock**
Alright, let's break this down. My initial observation confirms a memory leak: `uss720_disconnect` doesn't properly free resources due to the refcount of the request (`rq`) never reaching zero because it's been incremented elsewhere. I need to determine how to exploit this.
The question becomes: how can I trigger `change_mode` from userspace, since this function is the entry point for the relevant driver operations? Access to `/dev/parportX` through ioctls or read/write operations provides a path. If an unprivileged user has access (e.g., they're in the `lp` group), they could, in theory, trigger `change_mode`. However, that access is highly restricted. More critically, for this scenario to be a problem, a malicious USB device is required that times out on a control request, which can cause the leak. The malicious USB device negates any unprivileged user aspect. So the trigger is, fundamentally, the malicious USB device itself (Peripheral Trigger).
Can I trigger this some other way? I tried looking into sysfs files, specifically `bind` and `unbind` in `/sys/bus/usb/drivers/uss720/`. However, these require root privileges.
Now, let's explore if `usb_submit_urb` failing within `submit_async_request` introduces any issues. It looks like `destroy_async` is called, and this function incorrectly ignores the refcount when cleaning up the `rq`. However, the refcount is actually 2, not 1! After that, the caller (`get_1284_register`) gets a `NULL` and doesn't use the `rq`. Therefore, no use-after-free issue occurs because no one is using the pointer. This is an ugly but not a memory safety issue.
What if `async_complete` is called after `usb_submit_urb` fails? `usb_submit_urb` doesn't call the completion handler if it errors, so no use-after-free here.
What if `usb_submit_urb` succeeds, but completes synchronously? Then the completion function is called *before* the function returns, reducing the refcount to 1 and is safe.
So, the only bug is the memory leak in the timeout path in `get_1284_register`. That's it. It's a pure memory leak.
So, here's the summary:
* **Exploitable:** False (Pure memory leak, no code injection or information leaks).
* **DenialOfService:** True (OOM possible)
* **Unprivileged:** False (Requires a malicious USB device or, at the very least, physical access)
* **UserNamespace:** False (Same as above)
* **VMGuestTrigger:** False (USB isn't a paravirtualized feature)
* **VMHostTrigger:** False (Same as above)
* **NetworkTrigger:** False
* **RemoteTrigger:** False
* **PeripheralTrigger:** True (Malicious USB device needed)
* **FilesystemTrigger:** False
Can an unprivileged user *really* trigger this, assuming physical device access? While they could plug in a USB device, this would fall under the `PeripheralTrigger`, which is not purely software-based. Using `dummy_hcd` or `raw-gadget` requires root. Therefore, it's not a pure unprivileged bug.
I re-examined all the parport operations that ultimately call `get_1284_register`, namely via ioctls or `/dev/parportX`. An unprivileged user generally can't touch `/dev/parportX`. Also, they still need the malicious USB device to cause the timeout. A standard USB device will complete the control request in a timely fashion. No way for them to make a timeout otherwise. So, `PeripheralTrigger` is the only way.
Is there any software-based way to delay the URB completion? No. It's handled by the USB host controller and device, and nothing in software is delaying the URB. It is strictly a `Peripheral Trigger`.
Okay, next: let's look for other bugs. Let's explore a race condition: `kill_all_async_requests_priv` called concurrently with `async_complete`. `kill_all_async_requests_priv` takes the `priv->asynclock` lock. However, `async_complete` does NOT take the lock when removing `rq` from the list. Wait, I must look more carefully! `destroy_async` calls `spin_lock_irqsave(&priv
|
| 29/2 |
2026/07/15 21:39 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/usb/gadget/udc/dummy_hcd.c Name:dummy_urb_dequeue]
Results: map[SourceCode:1323: static int dummy_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1324: {
1325: struct dummy_hcd *dum_hcd;
1326: unsigned long flags;
1327: int rc;
1328:
1329: /* giveback happens automatically in timer callback,
1330: * so make sure the callback happens */
1331: dum_hcd = hcd_to_dummy_hcd(hcd);
1332: spin_lock_irqsave(&dum_hcd->dum->lock, flags);
1333:
1334: rc = usb_hcd_check_unlink_urb(hcd, urb, status);
1335: if (rc == 0 && !dum_hcd->timer_pending) {
1336: dum_hcd->timer_pending = 1;
1337: hrtimer_start(&dum_hcd->timer, ns_to_ktime(0), HRTIMER_MODE_REL_SOFT);
1338: }
1339:
1340: spin_unlock_irqrestore(&dum_hcd->dum->lock, flags);
1341: return rc;
1342: }
SourceFile:drivers/usb/gadget/udc/dummy_hcd.c]
|
| 30/2 |
2026/07/15 21:39 |
llm |
expert |
0m
Model:
Tokens:
input: 50624
output: 66
thoughts: 530
Thoughts: **My Final Assessment of the Memory Leak**
Okay, let's recap my thought process here. The timer in `dummy_hcd` makes the operation asynchronous, and given that `raw-gadget` relies on the underlying UDC (which could very well be `dummy_hcd`), this also makes that asynchronous. The key question is whether this asynchronicity leads to any exploitable vulnerabilities.
A deadlock, if it occurred, would result in a Denial of Service, but since the memory leak itself is already a DoS, that doesn't change the classification. Let's dig deeper and rule out potential consequences: could this leak sensitive information? No, the memory is allocated internally and the pointer is lost; it's never copied to userspace. Could it be a use-after-free scenario? Nope, the refcounts are solid. So, it's a straightforward memory leak.
Now, to double-check the requested fields:
* Exploitable: False
* DenialOfService: True
* Unprivileged: False
* UserNamespace: False
* VMGuestTrigger: False
* VMHostTrigger: False
* NetworkTrigger: False
* RemoteTrigger: False
* PeripheralTrigger: True
* FilesystemTrigger: False
Wait... let's ensure Unprivileged is still accurate. Does `raw-gadget` have any potential vulnerabilities when used by an unprivileged user? Nope, it needs root. Same for `dummy_hcd` and `vhci-hcd` (USB/IP). There's no purely software-based way to trigger this without root. They need a physical USB device. Thus, Unprivileged remains False.
Okay, is there *any* other way to trigger `get_1284_register`? Ah, the `parport` user-space interface (`/dev/parportX`). If the system administrator were to loosen the permissions on `/dev/parportX`, then an unprivileged user *could* trigger `change_mode` and therefore `get_1284_register`. But that's not the default configuration, and even *if* they could trigger it, they'd still need a USB device to time out and that's based on hardware. The device would need to be very poorly behaving to ever time out like this. So the timeout is a hardware behavior, and a normal USB device will not time out. So the user cannot force it. They need a malicious USB device.
Therefore, the only true trigger is a PeripheralTrigger (malicious USB device).
I'm confident in this final analysis.
|
| 31/2 |
2026/07/15 21:39 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 32/2 |
2026/07/15 21:40 |
llm |
expert |
0m
Model:
Tokens:
input: 51846
output: 640
thoughts: 14
Thoughts: Okay, here's the summary, rendered as a first-person thought process assuming expertise in the relevant field:
**Finalizing the Response**
Alright, the data is in, the analysis is complete, and the core findings are clear. Now it's time to craft the final response. I've considered all the nuances, the potential counterarguments, and the implications of the results. This isn't just about regurgitating findings; it's about synthesizing them into a coherent and compelling narrative that truly reflects the current state of knowledge, that shows the expert nature I've had to develop. The language must be precise, the arguments logically sound, and the conclusions well-supported. I will consider any relevant insights that need to be made. I will consider any limitations in the data. The objective is to make all this information relevant to the user. I can now write the final response.
|
| 33/1 |
2026/07/15 21:40 |
action |
format-explanation |
0m
Results: map[Explanation:The bug is a memory leak in the `uss720` USB-to-parallel port driver,
specifically in the `get_1284_register` function.
### Root Cause Analysis
When the driver communicates with the USB device, it submits an asynchronous
control transfer URB via `submit_async_request()`. This function allocates a
request structure (`rq`) and initializes its reference count to 1, then
increments it to 2 before submitting the URB (one reference for the URB
completion handler, one for the caller).
In `get_1284_register()`, the driver waits for the URB to complete using
`wait_for_completion_timeout()`.
If the device responds in time, the function correctly drops its reference by
calling `kref_put(&rq->ref_count, destroy_async)`.
However, if the device fails to respond and the wait times out, the function
executes the timeout path:
```c
if (wait_for_completion_timeout(&rq->compl, HZ)) {
// ... normal completion ...
kref_put(&rq->ref_count, destroy_async);
return ret;
}
printk(KERN_WARNING "get_1284_register timeout\n");
kill_all_async_requests_priv(priv);
return -EIO;
```
In the timeout path, the driver calls `kill_all_async_requests_priv()` to unlink
the pending URBs but **forgets to drop its reference** to `rq`. When the
unlinked URB eventually completes, the completion handler (`async_complete`)
drops its own reference, leaving the `rq` reference count at 1 forever.
Because `rq` also holds a reference to the driver's private data structure
(`priv`), this single missing `kref_put` causes a cascade of memory leaks,
leaking the `rq` structure, the URB, the DMA buffer, and the `priv` structure
itself. This perfectly matches the 4 unreferenced objects shown in the
KASAN/kmemleak report.
### Impact and Exploitability
- **Exploitable**: **False**. This is a pure memory leak. The reference counting
logic ensures that the objects are never freed prematurely, so there is no
use-after-free or memory corruption.
- **Denial of Service**: **True**. A malicious USB device that intentionally
ignores control requests can cause the driver to repeatedly hit the timeout
path, leaking memory on every attempt. This can eventually exhaust system memory
(OOM).
- **Peripheral Trigger**: **True**. Triggering this bug requires a USB device
that times out on specific control requests. Thus, it requires physical access
to plug in a malicious USB device (or root privileges to emulate one via
software like `raw-gadget`).
- **Unprivileged / User Namespaces**: **False**. Unprivileged users cannot
emulate USB devices, nor can they force a legitimate hardware device to time
out.]
|