| 0/0 |
2026/04/29 09:44 |
flow |
patching |
45m
Results: map[KernelBranch:master KernelCommit:254f49634ee16a731174d2ae34bc50bd5f45e731 KernelRepo:git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git PatchDescription:carl9170: fix stack-out-of-bounds in carl9170_cmd_callback()
When the driver sends a command to the firmware, it provides an output
buffer and its length. If the device sends a response that is larger
than expected, carl9170_cmd_callback() detects the mismatch, prints a
warning, and schedules a device restart.
However, it misses a return statement after calling carl9170_restart().
This causes the execution to fall through to the memcpy() call, which
copies the oversized response into the smaller stack-allocated buffer,
leading to a KASAN stack-out-of-bounds write.
Fix this by adding the missing return statement. This aligns with the
original author's explicit comment ("Do not complete. The command times
out..."), preventing the out-of-bounds memory write and allowing the
command to correctly time out and safely clean up the buffer. PatchDiff:diff --git a/drivers/net/wireless/ath/carl9170/rx.c b/drivers/net/wireless/ath/carl9170/rx.c
index 683343013..ea3f435fb 100644
--- a/drivers/net/wireless/ath/carl9170/rx.c
+++ b/drivers/net/wireless/ath/carl9170/rx.c
@@ -145,6 +145,7 @@ static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)
* and we get a stack trace from there.
*/
carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
+ return;
}
spin_lock(&ar->cmd_lock);
Recipients:[map[Email:chunkeey@googlemail.com Name:Christian Lamparter To:true] map[Email:linux-kernel@vger.kernel.org Name: To:false] map[Email:linux-wireless@vger.kernel.org Name: To:true]]]
|
| 1/1 |
2026/04/29 09:44 |
action |
base-commit-picker |
0m
Results: map[KernelBranch:master KernelCommit:254f49634ee16a731174d2ae34bc50bd5f45e731 KernelRepo:git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git]
|
| 2/1 |
2026/04/29 09:45 |
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 ATH9K_FIRMWARE_DOWNLOAD 0x30
#define ATH9K_FIRMWARE_DOWNLOAD_COMP 0x31
static bool lookup_connect_response_out_ath9k(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:
return true;
default:
break;
}
break;
case USB_TYPE_VENDOR:
switch (ctrl->bRequest) {
case ATH9K_FIRMWARE_DOWNLOAD:
return true;
case ATH9K_FIRMWARE_DOWNLOAD_COMP:
*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_ep_write(int fd, struct usb_raw_ep_io* io)
{
return ioctl(fd, USB_RAW_IOCTL_EP_WRITE, io);
}
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);
}
static int lookup_endpoint(int fd, uint8_t bEndpointAddress)
{
struct usb_device_index* index = lookup_usb_index(fd);
if (!index)
return -1;
if (index->iface_cur < 0)
return -1;
for (int ep = 0; ep < index->ifaces[index->iface_cur].eps_num; ep++)
if (index->ifaces[index->iface_cur].eps[ep].desc.bEndpointAddress == bEndpointAddress)
return index->ifaces[index->iface_cur].eps[ep].handle;
return -1;
}
#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);
}
static volatile long syz_usb_connect_ath9k(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_ath9k);
}
static volatile long syz_usb_ep_write(volatile long a0, volatile long a1, volatile long a2, volatile long a3)
{
int fd = a0;
uint8_t ep = a1;
uint32_t len = a2;
char* data = (char*)a3;
int ep_handle = lookup_endpoint(fd, ep);
if (ep_handle < 0) {
return -1;
}
struct usb_raw_ep_io_data io_data;
io_data.inner.ep = ep_handle;
io_data.inner.flags = 0;
if (len > sizeof(io_data.data))
len = sizeof(io_data.data);
io_data.inner.length = len;
memcpy(&io_data.data[0], data, len);
int rv = usb_raw_ep_write(fd, (struct usb_raw_ep_io*)&io_data);
if (rv < 0) {
return rv;
}
sleep_ms(200);
return 0;
}
static volatile long syz_usb_disconnect(volatile long a0)
{
int fd = a0;
int rv = close(fd);
sleep_ms(200);
return rv;
}
uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
const char* reason;
(void)reason;
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// syz_usb_connect_ath9k arguments: [
// speed: const = 0x3 (8 bytes)
// dev_len: len = 0x5a (8 bytes)
// dev: ptr[in, usb_device_descriptor_ath9k] {
// usb_device_descriptor_ath9k {
// inner: usb_device_descriptor_verbose_t[const[0x200, int16], USB_CLASS_VENDOR_SPEC, USB_SUBCLASS_VENDOR_SPEC, 0xff, const[64, int8], 0xcf3, 0x9271, 0x108, array[usb_config_descriptor_ath9k, 1]] {
// bLength: const = 0x12 (1 bytes)
// bDescriptorType: const = 0x1 (1 bytes)
// bcdUSB: const = 0x200 (2 bytes)
// bDeviceClass: const = 0xff (1 bytes)
// bDeviceSubClass: const = 0xff (1 bytes)
// bDeviceProtocol: const = 0xff (1 bytes)
// bMaxPacketSize0: const = 0x40 (1 bytes)
// idVendor: const = 0xcf3 (2 bytes)
// idProduct: const = 0x9271 (2 bytes)
// bcdDevice: const = 0x108 (2 bytes)
// iManufacturer: const = 0x1 (1 bytes)
// iProduct: const = 0x2 (1 bytes)
// iSerialNumber: const = 0x3 (1 bytes)
// bNumConfigurations: len = 0x1 (1 bytes)
// configs: array[usb_config_descriptor_ath9k] {
// usb_config_descriptor_ath9k {
// inner: usb_config_descriptor_verbose_t[const[1, int8], const[1, int8], const[0, int8], const[USB_CONFIG_ATT_ONE, int8], const[250, int8], void, usb_interface_descriptor_ath9k] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x2 (1 bytes)
// wTotalLength: len = 0x48 (2 bytes)
// bNumInterfaces: const = 0x1 (1 bytes)
// bConfigurationValue: const = 0x1 (1 bytes)
// iConfiguration: const = 0x0 (1 bytes)
// bmAttributes: const = 0x80 (1 bytes)
// bMaxPower: const = 0xfa (1 bytes)
// extra: buffer: {} (length 0x0)
// interfaces: usb_interface_descriptor_ath9k {
// iface: usb_interface_descriptor_verbose_t[const[0, int8], const[0, int8], const[6, int8], const[USB_CLASS_VENDOR_SPEC, int8], const[0, int8], const[0, int8], const[0, int8], void, usb_endpoint_descriptors_ath9k] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x4 (1 bytes)
// bInterfaceNumber: const = 0x0 (1 bytes)
// bAlternateSetting: const = 0x0 (1 bytes)
// bNumEndpoints: const = 0x6 (1 bytes)
// bInterfaceClass: const = 0xff (1 bytes)
// bInterfaceSubClass: const = 0x0 (1 bytes)
// bInterfaceProtocol: const = 0x0 (1 bytes)
// iInterface: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// endpoints: usb_endpoint_descriptors_ath9k {
// bulk_out: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_BULK_OUT_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_BULK_ATTRIBUTES, int8], const[512, int16], const[0, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x1 (1 bytes)
// bmAttributes: const = 0x2 (1 bytes)
// wMaxPacketSize: const = 0x200 (2 bytes)
// bInterval: const = 0x0 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// bulk_in: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_BULK_IN_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_BULK_ATTRIBUTES, int8], const[512, int16], const[0, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x82 (1 bytes)
// bmAttributes: const = 0x2 (1 bytes)
// wMaxPacketSize: const = 0x200 (2 bytes)
// bInterval: const = 0x0 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// int_in: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_INT_IN_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_INT_ATTRIBUTES, int8], const[64, int16], const[1, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x83 (1 bytes)
// bmAttributes: const = 0x3 (1 bytes)
// wMaxPacketSize: const = 0x40 (2 bytes)
// bInterval: const = 0x1 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// int_out: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_INT_OUT_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_INT_ATTRIBUTES, int8], const[64, int16], const[1, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x4 (1 bytes)
// bmAttributes: const = 0x3 (1 bytes)
// wMaxPacketSize: const = 0x40 (2 bytes)
// bInterval: const = 0x1 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// bulk_extra1: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_BULK_EXTRA1_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_BULK_ATTRIBUTES, int8], const[512, int16], const[0, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x5 (1 bytes)
// bmAttributes: const = 0x2 (1 bytes)
// wMaxPacketSize: const = 0x200 (2 bytes)
// bInterval: const = 0x0 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// bulk_extra2: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_BULK_EXTRA2_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_BULK_ATTRIBUTES, int8], const[512, int16], const[0, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x6 (1 bytes)
// bmAttributes: const = 0x2 (1 bytes)
// wMaxPacketSize: const = 0x200 (2 bytes)
// bInterval: const = 0x0 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// }
// }
// }
// }
// }
// }
// }
// }
// }
// conn_descs: const = 0x0 (8 bytes)
// ]
// returns fd_usb_ath9k
*(uint8_t*)0x2000000001c0 = 0x12;
*(uint8_t*)0x2000000001c1 = 1;
*(uint16_t*)0x2000000001c2 = 0x200;
*(uint8_t*)0x2000000001c4 = -1;
*(uint8_t*)0x2000000001c5 = -1;
*(uint8_t*)0x2000000001c6 = -1;
*(uint8_t*)0x2000000001c7 = 0x40;
*(uint16_t*)0x2000000001c8 = 0xcf3;
*(uint16_t*)0x2000000001ca = 0x9271;
*(uint16_t*)0x2000000001cc = 0x108;
*(uint8_t*)0x2000000001ce = 1;
*(uint8_t*)0x2000000001cf = 2;
*(uint8_t*)0x2000000001d0 = 3;
*(uint8_t*)0x2000000001d1 = 1;
*(uint8_t*)0x2000000001d2 = 9;
*(uint8_t*)0x2000000001d3 = 2;
*(uint16_t*)0x2000000001d4 = 0x48;
*(uint8_t*)0x2000000001d6 = 1;
*(uint8_t*)0x2000000001d7 = 1;
*(uint8_t*)0x2000000001d8 = 0;
*(uint8_t*)0x2000000001d9 = 0x80;
*(uint8_t*)0x2000000001da = 0xfa;
*(uint8_t*)0x2000000001db = 9;
*(uint8_t*)0x2000000001dc = 4;
*(uint8_t*)0x2000000001dd = 0;
*(uint8_t*)0x2000000001de = 0;
*(uint8_t*)0x2000000001df = 6;
*(uint8_t*)0x2000000001e0 = -1;
*(uint8_t*)0x2000000001e1 = 0;
*(uint8_t*)0x2000000001e2 = 0;
*(uint8_t*)0x2000000001e3 = 0;
*(uint8_t*)0x2000000001e4 = 9;
*(uint8_t*)0x2000000001e5 = 5;
*(uint8_t*)0x2000000001e6 = 1;
*(uint8_t*)0x2000000001e7 = 2;
*(uint16_t*)0x2000000001e8 = 0x200;
*(uint8_t*)0x2000000001ea = 0;
*(uint8_t*)0x2000000001eb = 0;
*(uint8_t*)0x2000000001ec = 0;
*(uint8_t*)0x2000000001ed = 9;
*(uint8_t*)0x2000000001ee = 5;
*(uint8_t*)0x2000000001ef = 0x82;
*(uint8_t*)0x2000000001f0 = 2;
*(uint16_t*)0x2000000001f1 = 0x200;
*(uint8_t*)0x2000000001f3 = 0;
*(uint8_t*)0x2000000001f4 = 0;
*(uint8_t*)0x2000000001f5 = 0;
*(uint8_t*)0x2000000001f6 = 9;
*(uint8_t*)0x2000000001f7 = 5;
*(uint8_t*)0x2000000001f8 = 0x83;
*(uint8_t*)0x2000000001f9 = 3;
*(uint16_t*)0x2000000001fa = 0x40;
*(uint8_t*)0x2000000001fc = 1;
*(uint8_t*)0x2000000001fd = 0;
*(uint8_t*)0x2000000001fe = 0;
*(uint8_t*)0x2000000001ff = 9;
*(uint8_t*)0x200000000200 = 5;
*(uint8_t*)0x200000000201 = 4;
*(uint8_t*)0x200000000202 = 3;
*(uint16_t*)0x200000000203 = 0x40;
*(uint8_t*)0x200000000205 = 1;
*(uint8_t*)0x200000000206 = 0;
*(uint8_t*)0x200000000207 = 0;
*(uint8_t*)0x200000000208 = 9;
*(uint8_t*)0x200000000209 = 5;
*(uint8_t*)0x20000000020a = 5;
*(uint8_t*)0x20000000020b = 2;
*(uint16_t*)0x20000000020c = 0x200;
*(uint8_t*)0x20000000020e = 0;
*(uint8_t*)0x20000000020f = 0;
*(uint8_t*)0x200000000210 = 0;
*(uint8_t*)0x200000000211 = 9;
*(uint8_t*)0x200000000212 = 5;
*(uint8_t*)0x200000000213 = 6;
*(uint8_t*)0x200000000214 = 2;
*(uint16_t*)0x200000000215 = 0x200;
*(uint8_t*)0x200000000217 = 0;
*(uint8_t*)0x200000000218 = 0;
*(uint8_t*)0x200000000219 = 0;
res = -1;
res = syz_usb_connect_ath9k(/*speed=*/3, /*dev_len=*/0x5a, /*dev=*/0x2000000001c0, /*conn_descs=*/0);
if (res != -1)
r[0] = res;
// syz_usb_ep_write arguments: [
// fd: fd_usb (resource)
// ep: int8 = 0x1e (1 bytes)
// len: len = 0x2 (8 bytes)
// data: ptr[in, buffer] {
// buffer: {3c cf} (length 0x2)
// }
// ]
memcpy((void*)0x2000000000c0, "\x3c\xcf", 2);
syz_usb_ep_write(/*fd=*/r[0], /*ep=*/0x1e, /*len=*/2, /*data=*/0x2000000000c0);
// syz_usb_disconnect arguments: [
// fd: fd_usb (resource)
// ]
syz_usb_disconnect(/*fd=*/r[0]);
// syz_usb_connect arguments: [
// speed: usb_device_speed = 0x0 (8 bytes)
// dev_len: len = 0x36 (8 bytes)
// dev: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// union ANYUNION {
// ANYBLOB: buffer: {12 01 00 00 ad 18 38 40 f3 0c 02 10} (length 0xc)
// }
// }
// }
// conn_descs: nil
// ]
// returns fd_usb
memcpy((void*)0x2000000001c0, "\x12\x01\x00\x00\xad\x18\x38\x40\xf3\x0c\x02\x10", 12);
res = -1;
res = syz_usb_connect(/*speed=*/0, /*dev_len=*/0x36, /*dev=*/0x2000000001c0, /*conn_descs=*/0);
if (res != -1)
r[1] = res;
// syz_usb_disconnect arguments: [
// fd: fd_usb (resource)
// ]
syz_usb_disconnect(/*fd=*/r[1]);
// syz_usb_connect_ath9k arguments: [
// speed: const = 0x3 (8 bytes)
// dev_len: len = 0xfdf9 (8 bytes)
// dev: ptr[in, usb_device_descriptor_ath9k] {
// usb_device_descriptor_ath9k {
// inner: usb_device_descriptor_verbose_t[const[0x200, int16], USB_CLASS_VENDOR_SPEC, USB_SUBCLASS_VENDOR_SPEC, 0xff, const[64, int8], 0xcf3, 0x9271, 0x108, array[usb_config_descriptor_ath9k, 1]] {
// bLength: const = 0x12 (1 bytes)
// bDescriptorType: const = 0x1 (1 bytes)
// bcdUSB: const = 0x200 (2 bytes)
// bDeviceClass: const = 0xff (1 bytes)
// bDeviceSubClass: const = 0xff (1 bytes)
// bDeviceProtocol: const = 0xff (1 bytes)
// bMaxPacketSize0: const = 0x40 (1 bytes)
// idVendor: const = 0xcf3 (2 bytes)
// idProduct: const = 0x9271 (2 bytes)
// bcdDevice: const = 0x108 (2 bytes)
// iManufacturer: const = 0x1 (1 bytes)
// iProduct: const = 0x2 (1 bytes)
// iSerialNumber: const = 0x3 (1 bytes)
// bNumConfigurations: len = 0x31 (1 bytes)
// configs: array[usb_config_descriptor_ath9k] {
// usb_config_descriptor_ath9k {
// inner: usb_config_descriptor_verbose_t[const[1, int8], const[1, int8], const[0, int8], const[USB_CONFIG_ATT_ONE, int8], const[250, int8], void, usb_interface_descriptor_ath9k] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x2 (1 bytes)
// wTotalLength: len = 0xfffffffffffffe9f (2 bytes)
// bNumInterfaces: const = 0x1 (1 bytes)
// bConfigurationValue: const = 0x1 (1 bytes)
// iConfiguration: const = 0x0 (1 bytes)
// bmAttributes: const = 0x80 (1 bytes)
// bMaxPower: const = 0xfa (1 bytes)
// extra: buffer: {} (length 0x0)
// interfaces: usb_interface_descriptor_ath9k {
// iface: usb_interface_descriptor_verbose_t[const[0, int8], const[0, int8], const[6, int8], const[USB_CLASS_VENDOR_SPEC, int8], const[0, int8], const[0, int8], const[0, int8], void, usb_endpoint_descriptors_ath9k] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x4 (1 bytes)
// bInterfaceNumber: const = 0x0 (1 bytes)
// bAlternateSetting: const = 0x0 (1 bytes)
// bNumEndpoints: const = 0x6 (1 bytes)
// bInterfaceClass: const = 0xff (1 bytes)
// bInterfaceSubClass: const = 0x0 (1 bytes)
// bInterfaceProtocol: const = 0x0 (1 bytes)
// iInterface: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// endpoints: usb_endpoint_descriptors_ath9k {
// bulk_out: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_BULK_OUT_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_BULK_ATTRIBUTES, int8], const[512, int16], const[0, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x1 (1 bytes)
// bmAttributes: const = 0x2 (1 bytes)
// wMaxPacketSize: const = 0x200 (2 bytes)
// bInterval: const = 0x0 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// bulk_in: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_BULK_IN_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_BULK_ATTRIBUTES, int8], const[512, int16], const[0, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x82 (1 bytes)
// bmAttributes: const = 0x2 (1 bytes)
// wMaxPacketSize: const = 0x200 (2 bytes)
// bInterval: const = 0x0 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// int_in: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_INT_IN_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_INT_ATTRIBUTES, int8], const[64, int16], const[1, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x83 (1 bytes)
// bmAttributes: const = 0x3 (1 bytes)
// wMaxPacketSize: const = 0x40 (2 bytes)
// bInterval: const = 0x1 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// int_out: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_INT_OUT_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_INT_ATTRIBUTES, int8], const[64, int16], const[1, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x4 (1 bytes)
// bmAttributes: const = 0x3 (1 bytes)
// wMaxPacketSize: const = 0x40 (2 bytes)
// bInterval: const = 0x1 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// bulk_extra1: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_BULK_EXTRA1_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_BULK_ATTRIBUTES, int8], const[512, int16], const[0, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x5 (1 bytes)
// bmAttributes: const = 0x2 (1 bytes)
// wMaxPacketSize: const = 0x200 (2 bytes)
// bInterval: const = 0x0 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// bulk_extra2: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_BULK_EXTRA2_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_BULK_ATTRIBUTES, int8], const[512, int16], const[0, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x6 (1 bytes)
// bmAttributes: const = 0x2 (1 bytes)
// wMaxPacketSize: const = 0x200 (2 bytes)
// bInterval: const = 0x0 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// }
// }
// }
// }
// }
// }
// }
// }
// }
// conn_descs: const = 0x0 (8 bytes)
// ]
// returns fd_usb_ath9k
*(uint8_t*)0x200000000000 = 0x12;
*(uint8_t*)0x200000000001 = 1;
*(uint16_t*)0x200000000002 = 0x200;
*(uint8_t*)0x200000000004 = -1;
*(uint8_t*)0x200000000005 = -1;
*(uint8_t*)0x200000000006 = -1;
*(uint8_t*)0x200000000007 = 0x40;
*(uint16_t*)0x200000000008 = 0xcf3;
*(uint16_t*)0x20000000000a = 0x9271;
*(uint16_t*)0x20000000000c = 0x108;
*(uint8_t*)0x20000000000e = 1;
*(uint8_t*)0x20000000000f = 2;
*(uint8_t*)0x200000000010 = 3;
*(uint8_t*)0x200000000011 = 0x31;
*(uint8_t*)0x200000000012 = 9;
*(uint8_t*)0x200000000013 = 2;
*(uint16_t*)0x200000000014 = 0xfe9f;
*(uint8_t*)0x200000000016 = 1;
*(uint8_t*)0x200000000017 = 1;
*(uint8_t*)0x200000000018 = 0;
*(uint8_t*)0x200000000019 = 0x80;
*(uint8_t*)0x20000000001a = 0xfa;
*(uint8_t*)0x20000000001b = 9;
*(uint8_t*)0x20000000001c = 4;
*(uint8_t*)0x20000000001d = 0;
*(uint8_t*)0x20000000001e = 0;
*(uint8_t*)0x20000000001f = 6;
*(uint8_t*)0x200000000020 = -1;
*(uint8_t*)0x200000000021 = 0;
*(uint8_t*)0x200000000022 = 0;
*(uint8_t*)0x200000000023 = 0;
*(uint8_t*)0x200000000024 = 9;
*(uint8_t*)0x200000000025 = 5;
*(uint8_t*)0x200000000026 = 1;
*(uint8_t*)0x200000000027 = 2;
*(uint16_t*)0x200000000028 = 0x200;
*(uint8_t*)0x20000000002a = 0;
*(uint8_t*)0x20000000002b = 0;
*(uint8_t*)0x20000000002c = 0;
*(uint8_t*)0x20000000002d = 9;
*(uint8_t*)0x20000000002e = 5;
*(uint8_t*)0x20000000002f = 0x82;
*(uint8_t*)0x200000000030 = 2;
*(uint16_t*)0x200000000031 = 0x200;
*(uint8_t*)0x200000000033 = 0;
*(uint8_t*)0x200000000034 = 0;
*(uint8_t*)0x200000000035 = 0;
*(uint8_t*)0x200000000036 = 9;
*(uint8_t*)0x200000000037 = 5;
*(uint8_t*)0x200000000038 = 0x83;
*(uint8_t*)0x200000000039 = 3;
*(uint16_t*)0x20000000003a = 0x40;
*(uint8_t*)0x20000000003c = 1;
*(uint8_t*)0x20000000003d = 0;
*(uint8_t*)0x20000000003e = 0;
*(uint8_t*)0x20000000003f = 9;
*(uint8_t*)0x200000000040 = 5;
*(uint8_t*)0x200000000041 = 4;
*(uint8_t*)0x200000000042 = 3;
*(uint16_t*)0x200000000043 = 0x40;
*(uint8_t*)0x200000000045 = 1;
*(uint8_t*)0x200000000046 = 0;
*(uint8_t*)0x200000000047 = 0;
*(uint8_t*)0x200000000048 = 9;
*(uint8_t*)0x200000000049 = 5;
*(uint8_t*)0x20000000004a = 5;
*(uint8_t*)0x20000000004b = 2;
*(uint16_t*)0x20000000004c = 0x200;
*(uint8_t*)0x20000000004e = 0;
*(uint8_t*)0x20000000004f = 0;
*(uint8_t*)0x200000000050 = 0;
*(uint8_t*)0x200000000051 = 9;
*(uint8_t*)0x200000000052 = 5;
*(uint8_t*)0x200000000053 = 6;
*(uint8_t*)0x200000000054 = 2;
*(uint16_t*)0x200000000055 = 0x200;
*(uint8_t*)0x200000000057 = 0;
*(uint8_t*)0x200000000058 = 0;
*(uint8_t*)0x200000000059 = 0;
syz_usb_connect_ath9k(/*speed=*/3, /*dev_len=*/0xfdf9, /*dev=*/0x200000000000, /*conn_descs=*/0);
// syz_usb_ep_write$ath9k_ep2 arguments: [
// fd: fd_usb_ath9k (resource)
// ep: const = 0x83 (1 bytes)
// len: bytesize = 0x82 (8 bytes)
// data: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// }
// }
// ]
syz_usb_ep_write(/*fd=*/r[1], /*ep=*/0x83, /*len=*/0x82, /*data=*/0x200000000080);
// syz_usb_ep_write$ath9k_ep2 arguments: [
// fd: fd_usb_ath9k (resource)
// ep: const = 0x83 (1 bytes)
// len: bytesize = 0xaf (8 bytes)
// data: ptr[in, htc_frame] {
// union htc_frame {
// generic: htc_generic_frame {
// endpoint_id: int8 = 0x7 (1 bytes)
// flags: htc_frame_flags = 0x2 (1 bytes)
// payload_len: len = 0xa7 (2 bytes)
// control: buffer: {c5 9d 3c 34} (length 0x4)
// payload: buffer: {ef a7 2b f9 5c d6 76 a1 af 96 9e d8 3b 71 57 8a 26 f7 d1 18 8b 83 2e c1 3d 91 68 bb 4b 80 3d 78 00 5a da 1b 01 7a 78 69 51 19 70 b2 96 e0 44 62 b2 a5 4e 20 c9 32 7d 81 b4 42 c3 93 6c 96 72 b2 d0 20 e6 8f 5a 34 f1 5e a5 5d 60 ce 82 da f4 5c c1 d0 37 3d 40 68 6a 80 9d cf 4a 8c da 69 6a 2f 0e 8e f3 77 7a d8 b8 8b 0c 7b f1 23 e1 31 df 56 3b 97 f6 f2 b2 7c be bd 22 0d fd 44 68 ba 5d f3 b3 3a 70 ff bc b6 29 5c 5f 5d 33 ba a6 b9 44 15 da 03 54 10 af b3 44 8c 86 90 c6 cb d5 2f 59 21 a7 9d 9e 00 43 d5 34} (length 0xa7)
// }
// }
// }
// ]
*(uint8_t*)0x200000000100 = 7;
*(uint8_t*)0x200000000101 = 2;
*(uint16_t*)0x200000000102 = htobe16(0xa7);
memcpy((void*)0x200000000104, "\xc5\x9d\x3c\x34", 4);
memcpy((void*)0x200000000108, "\xef\xa7\x2b\xf9\x5c\xd6\x76\xa1\xaf\x96\x9e\xd8\x3b\x71\x57\x8a\x26\xf7\xd1\x18\x8b\x83\x2e\xc1\x3d\x91\x68\xbb\x4b\x80\x3d\x78\x00\x5a\xda\x1b\x01\x7a\x78\x69\x51\x19\x70\xb2\x96\xe0\x44\x62\xb2\xa5\x4e\x20\xc9\x32\x7d\x81\xb4\x42\xc3\x93\x6c\x96\x72\xb2\xd0\x20\xe6\x8f\x5a\x34\xf1\x5e\xa5\x5d\x60\xce\x82\xda\xf4\x5c\xc1\xd0\x37\x3d\x40\x68\x6a\x80\x9d\xcf\x4a\x8c\xda\x69\x6a\x2f\x0e\x8e\xf3\x77\x7a\xd8\xb8\x8b\x0c\x7b\xf1\x23\xe1\x31\xdf\x56\x3b\x97\xf6\xf2\xb2\x7c\xbe\xbd\x22\x0d\xfd\x44\x68\xba\x5d\xf3\xb3\x3a\x70\xff\xbc\xb6\x29\x5c\x5f\x5d\x33\xba\xa6\xb9\x44\x15\xda\x03\x54\x10\xaf\xb3\x44\x8c\x86\x90\xc6\xcb\xd5\x2f\x59\x21\xa7\x9d\x9e\x00\x43\xd5\x34", 167);
syz_usb_ep_write(/*fd=*/r[0], /*ep=*/0x83, /*len=*/0xaf, /*data=*/0x200000000100);
return 0;
}
]
|
| 3/1 |
2026/04/29 09:45 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/a7966833164a791a1f7c3009b83c0bfc0425cdbf]
|
| 4/1 |
2026/04/29 09:46 |
action |
kernel-builder |
8m
Results: map[KernelObj:/app/workdir/cache/build/3ab1f79f2372c89e334962da22ff3f58432c6215]
|
| 5/1 |
2026/04/29 09:54 |
action |
crash-reproducer |
1m
Results: map[ReproducedBugTitle:KASAN: stack-out-of-bounds Write in carl9170_handle_command_response ReproducedCrashReport:usb 4-1: received invalid command response:got -2, instead of 0
usb 4-1: received invalid command response:got 60, instead of 4
==================================================================
BUG: KASAN: stack-out-of-bounds in carl9170_cmd_callback drivers/net/wireless/ath/carl9170/rx.c:153 [inline]
BUG: KASAN: stack-out-of-bounds in carl9170_handle_command_response+0x21c/0x11b0 drivers/net/wireless/ath/carl9170/rx.c:168
Write of size 60 at addr ffffc900002c7930 by task swapper/1/0
CPU: 1 UID: 0 PID: 0 Comm: swapper/1 Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<IRQ>
dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
print_address_description+0x55/0x1e0 mm/kasan/report.c:378
print_report+0x58/0x70 mm/kasan/report.c:482
kasan_report+0x117/0x150 mm/kasan/report.c:595
check_region_inline mm/kasan/generic.c:-1 [inline]
kasan_check_range+0x264/0x2c0 mm/kasan/generic.c:200
__asan_memcpy+0x40/0x70 mm/kasan/shadow.c:106
carl9170_cmd_callback drivers/net/wireless/ath/carl9170/rx.c:153 [inline]
carl9170_handle_command_response+0x21c/0x11b0 drivers/net/wireless/ath/carl9170/rx.c:168
carl9170_usb_rx_irq_complete+0xce/0x1a0 drivers/net/wireless/ath/carl9170/usb.c:307
__usb_hcd_giveback_urb+0x376/0x540 drivers/usb/core/hcd.c:1657
dummy_timer+0xbc0/0x4650 drivers/usb/gadget/udc/dummy_hcd.c:2005
__run_hrtimer kernel/time/hrtimer.c:1930 [inline]
__hrtimer_run_queues+0x3c0/0xa20 kernel/time/hrtimer.c:1994
hrtimer_run_softirq+0x17a/0x240 kernel/time/hrtimer.c:2011
handle_softirqs+0x21b/0x830 kernel/softirq.c:622
__do_softirq kernel/softirq.c:656 [inline]
invoke_softirq kernel/softirq.c:496 [inline]
__irq_exit_rcu+0xc0/0x210 kernel/softirq.c:735
irq_exit_rcu+0x9/0x30 kernel/softirq.c:752
instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1061 [inline]
sysvec_apic_timer_interrupt+0x92/0xb0 arch/x86/kernel/apic/apic.c:1061
</IRQ>
<TASK>
asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:697
RIP: 0010:pv_native_safe_halt+0xf/0x20 arch/x86/kernel/paravirt.c:63
Code: 24 b3 01 e9 13 a2 02 00 cc cc cc 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 f3 0f 1e fa eb 07 0f 00 2d 93 77 15 00 fb f4 <c3> cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc 90 90 90 90 90
RSP: 0018:ffffc9000013fe20 EFLAGS: 00000202
RAX: 00000000000b70a1 RBX: ffffffff815b4fea RCX: 0000000080000001
RDX: 0000000000000001 RSI: ffffffff8927d953 RDI: ffffffff87c938c0
RBP: ffffc9000013ff20 R08: ffff88806b9336d3 R09: 1ffff1100d7266da
R10: dffffc0000000000 R11: ffffed100d7266db R12: 0000000000000001
R13: 1ffff11002bd5390 R14: 0000000000000001 R15: 1ffff11002bd5390
arch_safe_halt arch/x86/kernel/process.c:766 [inline]
default_idle+0x9/0x20 arch/x86/kernel/process.c:767
default_idle_call+0x72/0xb0 kernel/sched/idle.c:122
cpuidle_idle_call kernel/sched/idle.c:199 [inline]
do_idle+0x36a/0x5f0 kernel/sched/idle.c:352
cpu_startup_entry+0x43/0x60 kernel/sched/idle.c:451
start_secondary+0x101/0x110 arch/x86/kernel/smpboot.c:312
common_startup_64+0x13e/0x147
</TASK>
The buggy address belongs to a 8-page vmalloc region starting at 0xffffc900002c0000 allocated at copy_process+0x89b/0x4380 kernel/fork.c:2088
The buggy address belongs to the physical page:
page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1a16f
flags: 0x100000000000000(node=0|zone=1)
raw: 0100000000000000 ffffea0000685bc8 ffffea0000685bc8 0000000000000000
raw: 0000000000000000 0000000000000000 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x29c2(GFP_NOWAIT|__GFP_HIGHMEM|__GFP_IO|__GFP_FS|__GFP_ZERO), pid 2, tgid 2 (kthreadd), ts 2604993278, free_ts 0
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x231/0x280 mm/page_alloc.c:1858
prep_new_page mm/page_alloc.c:1866 [inline]
get_page_from_freelist+0x2274/0x2370 mm/page_alloc.c:3946
__alloc_frozen_pages_noprof+0x18d/0x380 mm/page_alloc.c:5226
__alloc_pages_noprof+0x10/0x100 mm/page_alloc.c:5260
__alloc_pages_node_noprof include/linux/gfp.h:289 [inline]
alloc_pages_node_noprof include/linux/gfp.h:316 [inline]
vm_area_alloc_pages mm/vmalloc.c:3655 [inline]
__vmalloc_area_node mm/vmalloc.c:3878 [inline]
__vmalloc_node_range_noprof+0x7ca/0x1750 mm/vmalloc.c:4064
__vmalloc_node_noprof+0xc2/0x100 mm/vmalloc.c:4124
alloc_thread_stack_node kernel/fork.c:357 [inline]
dup_task_struct+0x298/0x830 kernel/fork.c:926
copy_process+0x89b/0x4380 kernel/fork.c:2088
kernel_clone+0x284/0x8f0 kernel/fork.c:2723
kernel_thread+0x13f/0x1b0 kernel/fork.c:2784
create_kthread kernel/kthread.c:459 [inline]
kthreadd+0x4ec/0x6e0 kernel/kthread.c:817
ret_from_fork+0x491/0xad0 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
page_owner free stack trace missing
Memory state around the buggy address:
ffffc900002c7800: f3 f3 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00
ffffc900002c7880: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffffc900002c7900: f1 f1 f1 f1 04 f2 04 f3 00 00 00 00 00 00 00 00
^
ffffc900002c7980: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ffffc900002c7a00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
==================================================================
----------------
Code disassembly (best guess):
0: 24 b3 and $0xb3,%al
2: 01 e9 add %ebp,%ecx
4: 13 a2 02 00 cc cc adc -0x3333fffe(%rdx),%esp
a: cc int3
b: 90 nop
c: 90 nop
d: 90 nop
e: 90 nop
f: 90 nop
10: 90 nop
11: 90 nop
12: 90 nop
13: 90 nop
14: 90 nop
15: 90 nop
16: 90 nop
17: 90 nop
18: 90 nop
19: 90 nop
1a: 90 nop
1b: f3 0f 1e fa endbr64
1f: eb 07 jmp 0x28
21: 0f 00 2d 93 77 15 00 verw 0x157793(%rip) # 0x1577bb
28: fb sti
29: f4 hlt
* 2a: c3 ret <-- trapping instruction
2b: cc int3
2c: cc int3
2d: cc int3
2e: cc int3
2f: cc int3
30: cc int3
31: cc int3
32: cc int3
33: cc int3
34: cc int3
35: cc int3
36: cc int3
37: cc int3
38: cc int3
39: cc int3
3a: cc int3
3b: 90 nop
3c: 90 nop
3d: 90 nop
3e: 90 nop
3f: 90 nop
]
|
| 6/1 |
2026/04/29 09:56 |
action |
codesearch-prepare |
6m
Results: map[Index:codesearch-index]
|
| 7/1 |
2026/04/29 10:02 |
agent |
debugger |
6m
Model:
Instruction:
You are an experienced Linux kernel developer tasked with debugging a kernel crash root cause.
You need to provide a detailed explanation of the root cause for another developer to be
able to write a fix for the bug based on your explanation. Include all relevant details
into the response: function/struct/field/etc names, code snippets, line numbers,
macro/enum values, etc.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash is:
usb 4-1: received invalid command response:got -2, instead of 0
usb 4-1: received invalid command response:got 60, instead of 4
==================================================================
BUG: KASAN: stack-out-of-bounds in carl9170_cmd_callback drivers/net/wireless/ath/carl9170/rx.c:153 [inline]
BUG: KASAN: stack-out-of-bounds in carl9170_handle_command_response+0x21c/0x11b0 drivers/net/wireless/ath/carl9170/rx.c:168
Write of size 60 at addr ffffc900002c7930 by task swapper/1/0
CPU: 1 UID: 0 PID: 0 Comm: swapper/1 Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<IRQ>
dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
print_address_description+0x55/0x1e0 mm/kasan/report.c:378
print_report+0x58/0x70 mm/kasan/report.c:482
kasan_report+0x117/0x150 mm/kasan/report.c:595
check_region_inline mm/kasan/generic.c:-1 [inline]
kasan_check_range+0x264/0x2c0 mm/kasan/generic.c:200
__asan_memcpy+0x40/0x70 mm/kasan/shadow.c:106
carl9170_cmd_callback drivers/net/wireless/ath/carl9170/rx.c:153 [inline]
carl9170_handle_command_response+0x21c/0x11b0 drivers/net/wireless/ath/carl9170/rx.c:168
carl9170_usb_rx_irq_complete+0xce/0x1a0 drivers/net/wireless/ath/carl9170/usb.c:307
__usb_hcd_giveback_urb+0x376/0x540 drivers/usb/core/hcd.c:1657
dummy_timer+0xbc0/0x4650 drivers/usb/gadget/udc/dummy_hcd.c:2005
__run_hrtimer kernel/time/hrtimer.c:1930 [inline]
__hrtimer_run_queues+0x3c0/0xa20 kernel/time/hrtimer.c:1994
hrtimer_run_softirq+0x17a/0x240 kernel/time/hrtimer.c:2011
handle_softirqs+0x21b/0x830 kernel/softirq.c:622
__do_softirq kernel/softirq.c:656 [inline]
invoke_softirq kernel/softirq.c:496 [inline]
__irq_exit_rcu+0xc0/0x210 kernel/softirq.c:735
irq_exit_rcu+0x9/0x30 kernel/softirq.c:752
instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1061 [inline]
sysvec_apic_timer_interrupt+0x92/0xb0 arch/x86/kernel/apic/apic.c:1061
</IRQ>
<TASK>
asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:697
RIP: 0010:pv_native_safe_halt+0xf/0x20 arch/x86/kernel/paravirt.c:63
Code: 24 b3 01 e9 13 a2 02 00 cc cc cc 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 f3 0f 1e fa eb 07 0f 00 2d 93 77 15 00 fb f4 <c3> cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc 90 90 90 90 90
RSP: 0018:ffffc9000013fe20 EFLAGS: 00000202
RAX: 00000000000b70a1 RBX: ffffffff815b4fea RCX: 0000000080000001
RDX: 0000000000000001 RSI: ffffffff8927d953 RDI: ffffffff87c938c0
RBP: ffffc9000013ff20 R08: ffff88806b9336d3 R09: 1ffff1100d7266da
R10: dffffc0000000000 R11: ffffed100d7266db R12: 0000000000000001
R13: 1ffff11002bd5390 R14: 0000000000000001 R15: 1ffff11002bd5390
arch_safe_halt arch/x86/kernel/process.c:766 [inline]
default_idle+0x9/0x20 arch/x86/kernel/process.c:767
default_idle_call+0x72/0xb0 kernel/sched/idle.c:122
cpuidle_idle_call kernel/sched/idle.c:199 [inline]
do_idle+0x36a/0x5f0 kernel/sched/idle.c:352
cpu_startup_entry+0x43/0x60 kernel/sched/idle.c:451
start_secondary+0x101/0x110 arch/x86/kernel/smpboot.c:312
common_startup_64+0x13e/0x147
</TASK>
The buggy address belongs to a 8-page vmalloc region starting at 0xffffc900002c0000 allocated at copy_process+0x89b/0x4380 kernel/fork.c:2088
The buggy address belongs to the physical page:
page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1a16f
flags: 0x100000000000000(node=0|zone=1)
raw: 0100000000000000 ffffea0000685bc8 ffffea0000685bc8 0000000000000000
raw: 0000000000000000 0000000000000000 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x29c2(GFP_NOWAIT|__GFP_HIGHMEM|__GFP_IO|__GFP_FS|__GFP_ZERO), pid 2, tgid 2 (kthreadd), ts 2604993278, free_ts 0
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x231/0x280 mm/page_alloc.c:1858
prep_new_page mm/page_alloc.c:1866 [inline]
get_page_from_freelist+0x2274/0x2370 mm/page_alloc.c:3946
__alloc_frozen_pages_noprof+0x18d/0x380 mm/page_alloc.c:5226
__alloc_pages_noprof+0x10/0x100 mm/page_alloc.c:5260
__alloc_pages_node_noprof include/linux/gfp.h:289 [inline]
alloc_pages_node_noprof include/linux/gfp.h:316 [inline]
vm_area_alloc_pages mm/vmalloc.c:3655 [inline]
__vmalloc_area_node mm/vmalloc.c:3878 [inline]
__vmalloc_node_range_noprof+0x7ca/0x1750 mm/vmalloc.c:4064
__vmalloc_node_noprof+0xc2/0x100 mm/vmalloc.c:4124
alloc_thread_stack_node kernel/fork.c:357 [inline]
dup_task_struct+0x298/0x830 kernel/fork.c:926
copy_process+0x89b/0x4380 kernel/fork.c:2088
kernel_clone+0x284/0x8f0 kernel/fork.c:2723
kernel_thread+0x13f/0x1b0 kernel/fork.c:2784
create_kthread kernel/kthread.c:459 [inline]
kthreadd+0x4ec/0x6e0 kernel/kthread.c:817
ret_from_fork+0x491/0xad0 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
page_owner free stack trace missing
Memory state around the buggy address:
ffffc900002c7800: f3 f3 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00
ffffc900002c7880: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffffc900002c7900: f1 f1 f1 f1 04 f2 04 f3 00 00 00 00 00 00 00 00
^
ffffc900002c7980: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ffffc900002c7a00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
==================================================================
----------------
Code disassembly (best guess):
0: 24 b3 and $0xb3,%al
2: 01 e9 add %ebp,%ecx
4: 13 a2 02 00 cc cc adc -0x3333fffe(%rdx),%esp
a: cc int3
b: 90 nop
c: 90 nop
d: 90 nop
e: 90 nop
f: 90 nop
10: 90 nop
11: 90 nop
12: 90 nop
13: 90 nop
14: 90 nop
15: 90 nop
16: 90 nop
17: 90 nop
18: 90 nop
19: 90 nop
1a: 90 nop
1b: f3 0f 1e fa endbr64
1f: eb 07 jmp 0x28
21: 0f 00 2d 93 77 15 00 verw 0x157793(%rip) # 0x1577bb
28: fb sti
29: f4 hlt
* 2a: c3 ret <-- trapping instruction
2b: cc int3
2c: cc int3
2d: cc int3
2e: cc int3
2f: cc int3
30: cc int3
31: cc int3
32: cc int3
33: cc int3
34: cc int3
35: cc int3
36: cc int3
37: cc int3
38: cc int3
39: cc int3
3a: cc int3
3b: 90 nop
3c: 90 nop
3d: 90 nop
3e: 90 nop
3f: 90 nop
The following C code is a draft of the vulnerable syscall sequence. Keep in mind that
it may lack the precise threading, sandboxing, and some arguments of a working reproducer:
// 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 ATH9K_FIRMWARE_DOWNLOAD 0x30
#define ATH9K_FIRMWARE_DOWNLOAD_COMP 0x31
static bool lookup_connect_response_out_ath9k(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:
return true;
default:
break;
}
break;
case USB_TYPE_VENDOR:
switch (ctrl->bRequest) {
case ATH9K_FIRMWARE_DOWNLOAD:
return true;
case ATH9K_FIRMWARE_DOWNLOAD_COMP:
*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_ep_write(int fd, struct usb_raw_ep_io* io)
{
return ioctl(fd, USB_RAW_IOCTL_EP_WRITE, io);
}
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);
}
static int lookup_endpoint(int fd, uint8_t bEndpointAddress)
{
struct usb_device_index* index = lookup_usb_index(fd);
if (!index)
return -1;
if (index->iface_cur < 0)
return -1;
for (int ep = 0; ep < index->ifaces[index->iface_cur].eps_num; ep++)
if (index->ifaces[index->iface_cur].eps[ep].desc.bEndpointAddress == bEndpointAddress)
return index->ifaces[index->iface_cur].eps[ep].handle;
return -1;
}
#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);
}
static volatile long syz_usb_connect_ath9k(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_ath9k);
}
static volatile long syz_usb_ep_write(volatile long a0, volatile long a1, volatile long a2, volatile long a3)
{
int fd = a0;
uint8_t ep = a1;
uint32_t len = a2;
char* data = (char*)a3;
int ep_handle = lookup_endpoint(fd, ep);
if (ep_handle < 0) {
return -1;
}
struct usb_raw_ep_io_data io_data;
io_data.inner.ep = ep_handle;
io_data.inner.flags = 0;
if (len > sizeof(io_data.data))
len = sizeof(io_data.data);
io_data.inner.length = len;
memcpy(&io_data.data[0], data, len);
int rv = usb_raw_ep_write(fd, (struct usb_raw_ep_io*)&io_data);
if (rv < 0) {
return rv;
}
sleep_ms(200);
return 0;
}
static volatile long syz_usb_disconnect(volatile long a0)
{
int fd = a0;
int rv = close(fd);
sleep_ms(200);
return rv;
}
uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
const char* reason;
(void)reason;
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// syz_usb_connect_ath9k arguments: [
// speed: const = 0x3 (8 bytes)
// dev_len: len = 0x5a (8 bytes)
// dev: ptr[in, usb_device_descriptor_ath9k] {
// usb_device_descriptor_ath9k {
// inner: usb_device_descriptor_verbose_t[const[0x200, int16], USB_CLASS_VENDOR_SPEC, USB_SUBCLASS_VENDOR_SPEC, 0xff, const[64, int8], 0xcf3, 0x9271, 0x108, array[usb_config_descriptor_ath9k, 1]] {
// bLength: const = 0x12 (1 bytes)
// bDescriptorType: const = 0x1 (1 bytes)
// bcdUSB: const = 0x200 (2 bytes)
// bDeviceClass: const = 0xff (1 bytes)
// bDeviceSubClass: const = 0xff (1 bytes)
// bDeviceProtocol: const = 0xff (1 bytes)
// bMaxPacketSize0: const = 0x40 (1 bytes)
// idVendor: const = 0xcf3 (2 bytes)
// idProduct: const = 0x9271 (2 bytes)
// bcdDevice: const = 0x108 (2 bytes)
// iManufacturer: const = 0x1 (1 bytes)
// iProduct: const = 0x2 (1 bytes)
// iSerialNumber: const = 0x3 (1 bytes)
// bNumConfigurations: len = 0x1 (1 bytes)
// configs: array[usb_config_descriptor_ath9k] {
// usb_config_descriptor_ath9k {
// inner: usb_config_descriptor_verbose_t[const[1, int8], const[1, int8], const[0, int8], const[USB_CONFIG_ATT_ONE, int8], const[250, int8], void, usb_interface_descriptor_ath9k] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x2 (1 bytes)
// wTotalLength: len = 0x48 (2 bytes)
// bNumInterfaces: const = 0x1 (1 bytes)
// bConfigurationValue: const = 0x1 (1 bytes)
// iConfiguration: const = 0x0 (1 bytes)
// bmAttributes: const = 0x80 (1 bytes)
// bMaxPower: const = 0xfa (1 bytes)
// extra: buffer: {} (length 0x0)
// interfaces: usb_interface_descriptor_ath9k {
// iface: usb_interface_descriptor_verbose_t[const[0, int8], const[0, int8], const[6, int8], const[USB_CLASS_VENDOR_SPEC, int8], const[0, int8], const[0, int8], const[0, int8], void, usb_endpoint_descriptors_ath9k] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x4 (1 bytes)
// bInterfaceNumber: const = 0x0 (1 bytes)
// bAlternateSetting: const = 0x0 (1 bytes)
// bNumEndpoints: const = 0x6 (1 bytes)
// bInterfaceClass: const = 0xff (1 bytes)
// bInterfaceSubClass: const = 0x0 (1 bytes)
// bInterfaceProtocol: const = 0x0 (1 bytes)
// iInterface: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// endpoints: usb_endpoint_descriptors_ath9k {
// bulk_out: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_BULK_OUT_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_BULK_ATTRIBUTES, int8], const[512, int16], const[0, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x1 (1 bytes)
// bmAttributes: const = 0x2 (1 bytes)
// wMaxPacketSize: const = 0x200 (2 bytes)
// bInterval: const = 0x0 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// bulk_in: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_BULK_IN_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_BULK_ATTRIBUTES, int8], const[512, int16], const[0, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x82 (1 bytes)
// bmAttributes: const = 0x2 (1 bytes)
// wMaxPacketSize: const = 0x200 (2 bytes)
// bInterval: const = 0x0 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// int_in: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_INT_IN_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_INT_ATTRIBUTES, int8], const[64, int16], const[1, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x83 (1 bytes)
// bmAttributes: const = 0x3 (1 bytes)
// wMaxPacketSize: const = 0x40 (2 bytes)
// bInterval: const = 0x1 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// int_out: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_INT_OUT_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_INT_ATTRIBUTES, int8], const[64, int16], const[1, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x4 (1 bytes)
// bmAttributes: const = 0x3 (1 bytes)
// wMaxPacketSize: const = 0x40 (2 bytes)
// bInterval: const = 0x1 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// bulk_extra1: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_BULK_EXTRA1_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_BULK_ATTRIBUTES, int8], const[512, int16], const[0, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x5 (1 bytes)
// bmAttributes: const = 0x2 (1 bytes)
// wMaxPacketSize: const = 0x200 (2 bytes)
// bInterval: const = 0x0 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// bulk_extra2: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_BULK_EXTRA2_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_BULK_ATTRIBUTES, int8], const[512, int16], const[0, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x6 (1 bytes)
// bmAttributes: const = 0x2 (1 bytes)
// wMaxPacketSize: const = 0x200 (2 bytes)
// bInterval: const = 0x0 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// }
// }
// }
// }
// }
// }
// }
// }
// }
// conn_descs: const = 0x0 (8 bytes)
// ]
// returns fd_usb_ath9k
*(uint8_t*)0x2000000001c0 = 0x12;
*(uint8_t*)0x2000000001c1 = 1;
*(uint16_t*)0x2000000001c2 = 0x200;
*(uint8_t*)0x2000000001c4 = -1;
*(uint8_t*)0x2000000001c5 = -1;
*(uint8_t*)0x2000000001c6 = -1;
*(uint8_t*)0x2000000001c7 = 0x40;
*(uint16_t*)0x2000000001c8 = 0xcf3;
*(uint16_t*)0x2000000001ca = 0x9271;
*(uint16_t*)0x2000000001cc = 0x108;
*(uint8_t*)0x2000000001ce = 1;
*(uint8_t*)0x2000000001cf = 2;
*(uint8_t*)0x2000000001d0 = 3;
*(uint8_t*)0x2000000001d1 = 1;
*(uint8_t*)0x2000000001d2 = 9;
*(uint8_t*)0x2000000001d3 = 2;
*(uint16_t*)0x2000000001d4 = 0x48;
*(uint8_t*)0x2000000001d6 = 1;
*(uint8_t*)0x2000000001d7 = 1;
*(uint8_t*)0x2000000001d8 = 0;
*(uint8_t*)0x2000000001d9 = 0x80;
*(uint8_t*)0x2000000001da = 0xfa;
*(uint8_t*)0x2000000001db = 9;
*(uint8_t*)0x2000000001dc = 4;
*(uint8_t*)0x2000000001dd = 0;
*(uint8_t*)0x2000000001de = 0;
*(uint8_t*)0x2000000001df = 6;
*(uint8_t*)0x2000000001e0 = -1;
*(uint8_t*)0x2000000001e1 = 0;
*(uint8_t*)0x2000000001e2 = 0;
*(uint8_t*)0x2000000001e3 = 0;
*(uint8_t*)0x2000000001e4 = 9;
*(uint8_t*)0x2000000001e5 = 5;
*(uint8_t*)0x2000000001e6 = 1;
*(uint8_t*)0x2000000001e7 = 2;
*(uint16_t*)0x2000000001e8 = 0x200;
*(uint8_t*)0x2000000001ea = 0;
*(uint8_t*)0x2000000001eb = 0;
*(uint8_t*)0x2000000001ec = 0;
*(uint8_t*)0x2000000001ed = 9;
*(uint8_t*)0x2000000001ee = 5;
*(uint8_t*)0x2000000001ef = 0x82;
*(uint8_t*)0x2000000001f0 = 2;
*(uint16_t*)0x2000000001f1 = 0x200;
*(uint8_t*)0x2000000001f3 = 0;
*(uint8_t*)0x2000000001f4 = 0;
*(uint8_t*)0x2000000001f5 = 0;
*(uint8_t*)0x2000000001f6 = 9;
*(uint8_t*)0x2000000001f7 = 5;
*(uint8_t*)0x2000000001f8 = 0x83;
*(uint8_t*)0x2000000001f9 = 3;
*(uint16_t*)0x2000000001fa = 0x40;
*(uint8_t*)0x2000000001fc = 1;
*(uint8_t*)0x2000000001fd = 0;
*(uint8_t*)0x2000000001fe = 0;
*(uint8_t*)0x2000000001ff = 9;
*(uint8_t*)0x200000000200 = 5;
*(uint8_t*)0x200000000201 = 4;
*(uint8_t*)0x200000000202 = 3;
*(uint16_t*)0x200000000203 = 0x40;
*(uint8_t*)0x200000000205 = 1;
*(uint8_t*)0x200000000206 = 0;
*(uint8_t*)0x200000000207 = 0;
*(uint8_t*)0x200000000208 = 9;
*(uint8_t*)0x200000000209 = 5;
*(uint8_t*)0x20000000020a = 5;
*(uint8_t*)0x20000000020b = 2;
*(uint16_t*)0x20000000020c = 0x200;
*(uint8_t*)0x20000000020e = 0;
*(uint8_t*)0x20000000020f = 0;
*(uint8_t*)0x200000000210 = 0;
*(uint8_t*)0x200000000211 = 9;
*(uint8_t*)0x200000000212 = 5;
*(uint8_t*)0x200000000213 = 6;
*(uint8_t*)0x200000000214 = 2;
*(uint16_t*)0x200000000215 = 0x200;
*(uint8_t*)0x200000000217 = 0;
*(uint8_t*)0x200000000218 = 0;
*(uint8_t*)0x200000000219 = 0;
res = -1;
res = syz_usb_connect_ath9k(/*speed=*/3, /*dev_len=*/0x5a, /*dev=*/0x2000000001c0, /*conn_descs=*/0);
if (res != -1)
r[0] = res;
// syz_usb_ep_write arguments: [
// fd: fd_usb (resource)
// ep: int8 = 0x1e (1 bytes)
// len: len = 0x2 (8 bytes)
// data: ptr[in, buffer] {
// buffer: {3c cf} (length 0x2)
// }
// ]
memcpy((void*)0x2000000000c0, "\x3c\xcf", 2);
syz_usb_ep_write(/*fd=*/r[0], /*ep=*/0x1e, /*len=*/2, /*data=*/0x2000000000c0);
// syz_usb_disconnect arguments: [
// fd: fd_usb (resource)
// ]
syz_usb_disconnect(/*fd=*/r[0]);
// syz_usb_connect arguments: [
// speed: usb_device_speed = 0x0 (8 bytes)
// dev_len: len = 0x36 (8 bytes)
// dev: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// union ANYUNION {
// ANYBLOB: buffer: {12 01 00 00 ad 18 38 40 f3 0c 02 10} (length 0xc)
// }
// }
// }
// conn_descs: nil
// ]
// returns fd_usb
memcpy((void*)0x2000000001c0, "\x12\x01\x00\x00\xad\x18\x38\x40\xf3\x0c\x02\x10", 12);
res = -1;
res = syz_usb_connect(/*speed=*/0, /*dev_len=*/0x36, /*dev=*/0x2000000001c0, /*conn_descs=*/0);
if (res != -1)
r[1] = res;
// syz_usb_disconnect arguments: [
// fd: fd_usb (resource)
// ]
syz_usb_disconnect(/*fd=*/r[1]);
// syz_usb_connect_ath9k arguments: [
// speed: const = 0x3 (8 bytes)
// dev_len: len = 0xfdf9 (8 bytes)
// dev: ptr[in, usb_device_descriptor_ath9k] {
// usb_device_descriptor_ath9k {
// inner: usb_device_descriptor_verbose_t[const[0x200, int16], USB_CLASS_VENDOR_SPEC, USB_SUBCLASS_VENDOR_SPEC, 0xff, const[64, int8], 0xcf3, 0x9271, 0x108, array[usb_config_descriptor_ath9k, 1]] {
// bLength: const = 0x12 (1 bytes)
// bDescriptorType: const = 0x1 (1 bytes)
// bcdUSB: const = 0x200 (2 bytes)
// bDeviceClass: const = 0xff (1 bytes)
// bDeviceSubClass: const = 0xff (1 bytes)
// bDeviceProtocol: const = 0xff (1 bytes)
// bMaxPacketSize0: const = 0x40 (1 bytes)
// idVendor: const = 0xcf3 (2 bytes)
// idProduct: const = 0x9271 (2 bytes)
// bcdDevice: const = 0x108 (2 bytes)
// iManufacturer: const = 0x1 (1 bytes)
// iProduct: const = 0x2 (1 bytes)
// iSerialNumber: const = 0x3 (1 bytes)
// bNumConfigurations: len = 0x31 (1 bytes)
// configs: array[usb_config_descriptor_ath9k] {
// usb_config_descriptor_ath9k {
// inner: usb_config_descriptor_verbose_t[const[1, int8], const[1, int8], const[0, int8], const[USB_CONFIG_ATT_ONE, int8], const[250, int8], void, usb_interface_descriptor_ath9k] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x2 (1 bytes)
// wTotalLength: len = 0xfffffffffffffe9f (2 bytes)
// bNumInterfaces: const = 0x1 (1 bytes)
// bConfigurationValue: const = 0x1 (1 bytes)
// iConfiguration: const = 0x0 (1 bytes)
// bmAttributes: const = 0x80 (1 bytes)
// bMaxPower: const = 0xfa (1 bytes)
// extra: buffer: {} (length 0x0)
// interfaces: usb_interface_descriptor_ath9k {
// iface: usb_interface_descriptor_verbose_t[const[0, int8], const[0, int8], const[6, int8], const[USB_CLASS_VENDOR_SPEC, int8], const[0, int8], const[0, int8], const[0, int8], void, usb_endpoint_descriptors_ath9k] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x4 (1 bytes)
// bInterfaceNumber: const = 0x0 (1 bytes)
// bAlternateSetting: const = 0x0 (1 bytes)
// bNumEndpoints: const = 0x6 (1 bytes)
// bInterfaceClass: const = 0xff (1 bytes)
// bInterfaceSubClass: const = 0x0 (1 bytes)
// bInterfaceProtocol: const = 0x0 (1 bytes)
// iInterface: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// endpoints: usb_endpoint_descriptors_ath9k {
// bulk_out: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_BULK_OUT_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_BULK_ATTRIBUTES, int8], const[512, int16], const[0, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x1 (1 bytes)
// bmAttributes: const = 0x2 (1 bytes)
// wMaxPacketSize: const = 0x200 (2 bytes)
// bInterval: const = 0x0 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// bulk_in: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_BULK_IN_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_BULK_ATTRIBUTES, int8], const[512, int16], const[0, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x82 (1 bytes)
// bmAttributes: const = 0x2 (1 bytes)
// wMaxPacketSize: const = 0x200 (2 bytes)
// bInterval: const = 0x0 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// int_in: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_INT_IN_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_INT_ATTRIBUTES, int8], const[64, int16], const[1, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x83 (1 bytes)
// bmAttributes: const = 0x3 (1 bytes)
// wMaxPacketSize: const = 0x40 (2 bytes)
// bInterval: const = 0x1 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// int_out: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_INT_OUT_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_INT_ATTRIBUTES, int8], const[64, int16], const[1, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x4 (1 bytes)
// bmAttributes: const = 0x3 (1 bytes)
// wMaxPacketSize: const = 0x40 (2 bytes)
// bInterval: const = 0x1 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// bulk_extra1: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_BULK_EXTRA1_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_BULK_ATTRIBUTES, int8], const[512, int16], const[0, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x5 (1 bytes)
// bmAttributes: const = 0x2 (1 bytes)
// wMaxPacketSize: const = 0x200 (2 bytes)
// bInterval: const = 0x0 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// bulk_extra2: usb_endpoint_descriptor_verbose_t[const[USB_ENDPOINT_ATH9K_BULK_EXTRA2_ADDRESS, int8], const[USB_ENDPOINT_ATH9K_BULK_ATTRIBUTES, int8], const[512, int16], const[0, int8], const[0, int8], const[0, int8], void] {
// bLength: const = 0x9 (1 bytes)
// bDescriptorType: const = 0x5 (1 bytes)
// bEndpointAddress: const = 0x6 (1 bytes)
// bmAttributes: const = 0x2 (1 bytes)
// wMaxPacketSize: const = 0x200 (2 bytes)
// bInterval: const = 0x0 (1 bytes)
// bRefresh: const = 0x0 (1 bytes)
// bSynchAddress: const = 0x0 (1 bytes)
// extra: buffer: {} (length 0x0)
// }
// }
// }
// }
// }
// }
// }
// }
// }
// }
// conn_descs: const = 0x0 (8 bytes)
// ]
// returns fd_usb_ath9k
*(uint8_t*)0x200000000000 = 0x12;
*(uint8_t*)0x200000000001 = 1;
*(uint16_t*)0x200000000002 = 0x200;
*(uint8_t*)0x200000000004 = -1;
*(uint8_t*)0x200000000005 = -1;
*(uint8_t*)0x200000000006 = -1;
*(uint8_t*)0x200000000007 = 0x40;
*(uint16_t*)0x200000000008 = 0xcf3;
*(uint16_t*)0x20000000000a = 0x9271;
*(uint16_t*)0x20000000000c = 0x108;
*(uint8_t*)0x20000000000e = 1;
*(uint8_t*)0x20000000000f = 2;
*(uint8_t*)0x200000000010 = 3;
*(uint8_t*)0x200000000011 = 0x31;
*(uint8_t*)0x200000000012 = 9;
*(uint8_t*)0x200000000013 = 2;
*(uint16_t*)0x200000000014 = 0xfe9f;
*(uint8_t*)0x200000000016 = 1;
*(uint8_t*)0x200000000017 = 1;
*(uint8_t*)0x200000000018 = 0;
*(uint8_t*)0x200000000019 = 0x80;
*(uint8_t*)0x20000000001a = 0xfa;
*(uint8_t*)0x20000000001b = 9;
*(uint8_t*)0x20000000001c = 4;
*(uint8_t*)0x20000000001d = 0;
*(uint8_t*)0x20000000001e = 0;
*(uint8_t*)0x20000000001f = 6;
*(uint8_t*)0x200000000020 = -1;
*(uint8_t*)0x200000000021 = 0;
*(uint8_t*)0x200000000022 = 0;
*(uint8_t*)0x200000000023 = 0;
*(uint8_t*)0x200000000024 = 9;
*(uint8_t*)0x200000000025 = 5;
*(uint8_t*)0x200000000026 = 1;
*(uint8_t*)0x200000000027 = 2;
*(uint16_t*)0x200000000028 = 0x200;
*(uint8_t*)0x20000000002a = 0;
*(uint8_t*)0x20000000002b = 0;
*(uint8_t*)0x20000000002c = 0;
*(uint8_t*)0x20000000002d = 9;
*(uint8_t*)0x20000000002e = 5;
*(uint8_t*)0x20000000002f = 0x82;
*(uint8_t*)0x200000000030 = 2;
*(uint16_t*)0x200000000031 = 0x200;
*(uint8_t*)0x200000000033 = 0;
*(uint8_t*)0x200000000034 = 0;
*(uint8_t*)0x200000000035 = 0;
*(uint8_t*)0x200000000036 = 9;
*(uint8_t*)0x200000000037 = 5;
*(uint8_t*)0x200000000038 = 0x83;
*(uint8_t*)0x200000000039 = 3;
*(uint16_t*)0x20000000003a = 0x40;
*(uint8_t*)0x20000000003c = 1;
*(uint8_t*)0x20000000003d = 0;
*(uint8_t*)0x20000000003e = 0;
*(uint8_t*)0x20000000003f = 9;
*(uint8_t*)0x200000000040 = 5;
*(uint8_t*)0x200000000041 = 4;
*(uint8_t*)0x200000000042 = 3;
*(uint16_t*)0x200000000043 = 0x40;
*(uint8_t*)0x200000000045 = 1;
*(uint8_t*)0x200000000046 = 0;
*(uint8_t*)0x200000000047 = 0;
*(uint8_t*)0x200000000048 = 9;
*(uint8_t*)0x200000000049 = 5;
*(uint8_t*)0x20000000004a = 5;
*(uint8_t*)0x20000000004b = 2;
*(uint16_t*)0x20000000004c = 0x200;
*(uint8_t*)0x20000000004e = 0;
*(uint8_t*)0x20000000004f = 0;
*(uint8_t*)0x200000000050 = 0;
*(uint8_t*)0x200000000051 = 9;
*(uint8_t*)0x200000000052 = 5;
*(uint8_t*)0x200000000053 = 6;
*(uint8_t*)0x200000000054 = 2;
*(uint16_t*)0x200000000055 = 0x200;
*(uint8_t*)0x200000000057 = 0;
*(uint8_t*)0x200000000058 = 0;
*(uint8_t*)0x200000000059 = 0;
syz_usb_connect_ath9k(/*speed=*/3, /*dev_len=*/0xfdf9, /*dev=*/0x200000000000, /*conn_descs=*/0);
// syz_usb_ep_write$ath9k_ep2 arguments: [
// fd: fd_usb_ath9k (resource)
// ep: const = 0x83 (1 bytes)
// len: bytesize = 0x82 (8 bytes)
// data: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// }
// }
// ]
syz_usb_ep_write(/*fd=*/r[1], /*ep=*/0x83, /*len=*/0x82, /*data=*/0x200000000080);
// syz_usb_ep_write$ath9k_ep2 arguments: [
// fd: fd_usb_ath9k (resource)
// ep: const = 0x83 (1 bytes)
// len: bytesize = 0xaf (8 bytes)
// data: ptr[in, htc_frame] {
// union htc_frame {
// generic: htc_generic_frame {
// endpoint_id: int8 = 0x7 (1 bytes)
// flags: htc_frame_flags = 0x2 (1 bytes)
// payload_len: len = 0xa7 (2 bytes)
// control: buffer: {c5 9d 3c 34} (length 0x4)
// payload: buffer: {ef a7 2b f9 5c d6 76 a1 af 96 9e d8 3b 71 57 8a 26 f7 d1 18 8b 83 2e c1 3d 91 68 bb 4b 80 3d 78 00 5a da 1b 01 7a 78 69 51 19 70 b2 96 e0 44 62 b2 a5 4e 20 c9 32 7d 81 b4 42 c3 93 6c 96 72 b2 d0 20 e6 8f 5a 34 f1 5e a5 5d 60 ce 82 da f4 5c c1 d0 37 3d 40 68 6a 80 9d cf 4a 8c da 69 6a 2f 0e 8e f3 77 7a d8 b8 8b 0c 7b f1 23 e1 31 df 56 3b 97 f6 f2 b2 7c be bd 22 0d fd 44 68 ba 5d f3 b3 3a 70 ff bc b6 29 5c 5f 5d 33 ba a6 b9 44 15 da 03 54 10 af b3 44 8c 86 90 c6 cb d5 2f 59 21 a7 9d 9e 00 43 d5 34} (length 0xa7)
// }
// }
// }
// ]
*(uint8_t*)0x200000000100 = 7;
*(uint8_t*)0x200000000101 = 2;
*(uint16_t*)0x200000000102 = htobe16(0xa7);
memcpy((void*)0x200000000104, "\xc5\x9d\x3c\x34", 4);
memcpy((void*)0x200000000108, "\xef\xa7\x2b\xf9\x5c\xd6\x76\xa1\xaf\x96\x9e\xd8\x3b\x71\x57\x8a\x26\xf7\xd1\x18\x8b\x83\x2e\xc1\x3d\x91\x68\xbb\x4b\x80\x3d\x78\x00\x5a\xda\x1b\x01\x7a\x78\x69\x51\x19\x70\xb2\x96\xe0\x44\x62\xb2\xa5\x4e\x20\xc9\x32\x7d\x81\xb4\x42\xc3\x93\x6c\x96\x72\xb2\xd0\x20\xe6\x8f\x5a\x34\xf1\x5e\xa5\x5d\x60\xce\x82\xda\xf4\x5c\xc1\xd0\x37\x3d\x40\x68\x6a\x80\x9d\xcf\x4a\x8c\xda\x69\x6a\x2f\x0e\x8e\xf3\x77\x7a\xd8\xb8\x8b\x0c\x7b\xf1\x23\xe1\x31\xdf\x56\x3b\x97\xf6\xf2\xb2\x7c\xbe\xbd\x22\x0d\xfd\x44\x68\xba\x5d\xf3\xb3\x3a\x70\xff\xbc\xb6\x29\x5c\x5f\x5d\x33\xba\xa6\xb9\x44\x15\xda\x03\x54\x10\xaf\xb3\x44\x8c\x86\x90\xc6\xcb\xd5\x2f\x59\x21\xa7\x9d\x9e\x00\x43\xd5\x34", 167);
syz_usb_ep_write(/*fd=*/r[0], /*ep=*/0x83, /*len=*/0xaf, /*data=*/0x200000000100);
return 0;
}
Reply: The root cause of this crash is a missing `return` statement in the command response handler, which leads to a stack-out-of-bounds write when the device sends a response that is larger than expected.
### Root Cause Analysis
When the driver sends a command to the firmware using `carl9170_exec_cmd()`, it provides an output buffer `out` (which is often a local stack variable) and its length `outlen`. The function sets up `ar->readbuf` and `ar->readlen` to point to this buffer and waits for the completion:
```c
// drivers/net/wireless/ath/carl9170/usb.c:677
spin_lock_bh(&ar->cmd_lock);
ar->readbuf = out;
ar->readlen = outlen;
spin_unlock_bh(&ar->cmd_lock);
reinit_completion(&ar->cmd_wait);
err = __carl9170_exec_cmd(ar, &ar->cmd, false);
if (!(cmd & CARL9170_CMD_ASYNC_FLAG)) {
time_left = wait_for_completion_timeout(&ar->cmd_wait, HZ);
// ...
```
When the device sends the command response back, it is handled by `carl9170_cmd_callback()`. This function checks if the received response length matches the expected length (`ar->readlen`). If it doesn't, it prints a warning and schedules a device restart:
```c
// drivers/net/wireless/ath/carl9170/rx.c:136
if (unlikely(ar->readlen != (len - 4))) {
dev_warn(&ar->udev->dev, "received invalid command response:"
"got %d, instead of %d\n", len - 4, ar->readlen);
print_hex_dump_bytes("carl9170 cmd:", DUMP_PREFIX_OFFSET,
ar->cmd_buf, (ar->cmd.hdr.len + 4) & 0x3f);
print_hex_dump_bytes("carl9170 rsp:", DUMP_PREFIX_OFFSET,
buffer, len);
/*
* Do not complete. The command times out,
* and we get a stack trace from there.
*/
carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
// BUG: Missing return statement here!
}
spin_lock(&ar->cmd_lock);
if (ar->readbuf) {
if (len >= 4)
memcpy(ar->readbuf, buffer + 4, len - 4);
ar->readbuf = NULL;
}
complete(&ar->cmd_wait);
spin_unlock(&ar->cmd_lock);
```
Because there is no `return;` statement after `carl9170_restart()`, the execution falls through to the `memcpy()`. If the received response is larger than expected (`len - 4 > ar->readlen`), the `memcpy()` will write `len - 4` bytes into `ar->readbuf`, overflowing the buffer (which is sized `ar->readlen`).
In your crash log, we can see exactly this happening:
```text
usb 4-1: received invalid command response:got 60, instead of 4
```
The driver expected a 4-byte response but received a 60-byte one. It warned about it, but then proceeded to `memcpy` 60 bytes into the 4-byte stack variable, causing the KASAN stack-out-of-bounds crash.
### The Fix
To fix this bug, you simply need to add a `return;` statement inside the `if` block. This perfectly aligns with the author's original comment right above it (`Do not complete. The command times out...`).
By returning early, `carl9170_exec_cmd()` will eventually time out, print a timeout error, and safely clean up `ar->readbuf` and `ar->readlen` under the `cmd_lock` in its `err_unbuf` error path.
```diff
--- a/drivers/net/wireless/ath/carl9170/rx.c
+++ b/drivers/net/wireless/ath/carl9170/rx.c
@@ -145,6 +145,7 @@ static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)
* and we get a stack trace from there.
*/
carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
+ return;
}
spin_lock(&ar->cmd_lock);
```
|
| 8/2 |
2026/04/29 10:02 |
llm |
debugger |
0m
Model:
Tokens:
input: 24516
output: 116
thoughts: 159
Thoughts: **Investigating a KASAN Crash in the carl9170 Driver**
Okay, so I've got a KASAN stack-out-of-bounds crash in the `carl9170_cmd_callback` function, and it's happening at `drivers/net/wireless/ath/carl9170/rx.c:153`. It looks like there's a write of size 60 at address `ffffc900002c7930` that's causing the problem. My immediate thought is to understand the context. What's going on within these functions to cause this, and how can I determine the root cause?
My next step is to examine the code. I'll start by retrieving the source code for `carl9170_cmd_callback` and `carl9170_handle_command_response`. I'll use `codesearch-definition-source` to get a precise view of these functions. With those code snippets in front of me, I can start to follow the data flow and understand how the write happens. I need to understand what arguments are being passed to these functions, how they're used, and if there are any potential buffer overflows or incorrect calculations involved in the memory write.
|
| 9/2 |
2026/04/29 10:02 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/rx.c IncludeLines:true Name:carl9170_cmd_callback]
Results: map[SourceCode: 129: static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)
130: {
131: /*
132: * Some commands may have a variable response length
133: * and we cannot predict the correct length in advance.
134: * So we only check if we provided enough space for the data.
135: */
136: if (unlikely(ar->readlen != (len - 4))) {
137: dev_warn(&ar->udev->dev, "received invalid command response:"
138: "got %d, instead of %d\n", len - 4, ar->readlen);
139: print_hex_dump_bytes("carl9170 cmd:", DUMP_PREFIX_OFFSET,
140: ar->cmd_buf, (ar->cmd.hdr.len + 4) & 0x3f);
141: print_hex_dump_bytes("carl9170 rsp:", DUMP_PREFIX_OFFSET,
142: buffer, len);
143: /*
144: * Do not complete. The command times out,
145: * and we get a stack trace from there.
146: */
147: carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
148: }
149:
150: spin_lock(&ar->cmd_lock);
151: if (ar->readbuf) {
152: if (len >= 4)
153: memcpy(ar->readbuf, buffer + 4, len - 4);
154:
155: ar->readbuf = NULL;
156: }
157: complete(&ar->cmd_wait);
158: spin_unlock(&ar->cmd_lock);
159: }
SourceFile:drivers/net/wireless/ath/carl9170/rx.c]
|
| 10/2 |
2026/04/29 10:02 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/rx.c IncludeLines:true Name:carl9170_handle_command_response]
Results: map[SourceCode: 161: void carl9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len)
162: {
163: struct carl9170_rsp *cmd = buf;
164: struct ieee80211_vif *vif;
165:
166: if ((cmd->hdr.cmd & CARL9170_RSP_FLAG) != CARL9170_RSP_FLAG) {
167: if (!(cmd->hdr.cmd & CARL9170_CMD_ASYNC_FLAG))
168: carl9170_cmd_callback(ar, len, buf);
169:
170: return;
171: }
172:
173: if (unlikely(cmd->hdr.len != (len - 4))) {
174: if (net_ratelimit()) {
175: wiphy_err(ar->hw->wiphy, "FW: received over-/under"
176: "sized event %x (%d, but should be %d).\n",
177: cmd->hdr.cmd, cmd->hdr.len, len - 4);
178:
179: print_hex_dump_bytes("dump:", DUMP_PREFIX_NONE,
180: buf, len);
181: }
182:
183: return;
184: }
185:
186: /* hardware event handlers */
187: switch (cmd->hdr.cmd) {
188: case CARL9170_RSP_PRETBTT:
189: /* pre-TBTT event */
190: rcu_read_lock();
191: vif = carl9170_get_main_vif(ar);
192:
193: if (!vif) {
194: rcu_read_unlock();
195: break;
196: }
197:
198: switch (vif->type) {
199: case NL80211_IFTYPE_STATION:
200: carl9170_handle_ps(ar, cmd);
201: break;
202:
203: case NL80211_IFTYPE_AP:
204: case NL80211_IFTYPE_ADHOC:
205: case NL80211_IFTYPE_MESH_POINT:
206: carl9170_update_beacon(ar, true);
207: break;
208:
209: default:
210: break;
211: }
212: rcu_read_unlock();
213:
214: break;
215:
216:
217: case CARL9170_RSP_TXCOMP:
218: /* TX status notification */
219: carl9170_tx_process_status(ar, cmd);
220: break;
221:
222: case CARL9170_RSP_BEACON_CONFIG:
223: /*
224: * (IBSS) beacon send notification
225: * bytes: 04 c2 XX YY B4 B3 B2 B1
226: *
227: * XX always 80
228: * YY always 00
229: * B1-B4 "should" be the number of send out beacons.
230: */
231: break;
232:
233: case CARL9170_RSP_ATIM:
234: /* End of Atim Window */
235: break;
236:
237: case CARL9170_RSP_WATCHDOG:
238: /* Watchdog Interrupt */
239: carl9170_restart(ar, CARL9170_RR_WATCHDOG);
240: break;
241:
242: case CARL9170_RSP_TEXT:
243: /* firmware debug */
244: carl9170_dbg_message(ar, (char *)buf + 4, len - 4);
245: break;
246:
247: case CARL9170_RSP_HEXDUMP:
248: wiphy_dbg(ar->hw->wiphy, "FW: HD %d\n", len - 4);
249: print_hex_dump_bytes("FW:", DUMP_PREFIX_NONE,
250: (char *)buf + 4, len - 4);
251: break;
252:
253: case CARL9170_RSP_RADAR:
254: if (!net_ratelimit())
255: break;
256:
257: wiphy_info(ar->hw->wiphy, "FW: RADAR! Please report this "
258: "incident to linux-wireless@vger.kernel.org !\n");
259: break;
260:
261: case CARL9170_RSP_GPIO:
262: #ifdef CONFIG_CARL9170_WPC
263: if (ar->wps.pbc) {
264: bool state = !!(cmd->gpio.gpio & cpu_to_le32(
265: AR9170_GPIO_PORT_WPS_BUTTON_PRESSED));
266:
267: if (state != ar->wps.pbc_state) {
268: ar->wps.pbc_state = state;
269: input_report_key(ar->wps.pbc, KEY_WPS_BUTTON,
270: state);
271: input_sync(ar->wps.pbc);
272: }
273: }
274: #endif /* CONFIG_CARL9170_WPC */
275: break;
276:
277: case CARL9170_RSP_BOOT:
278: complete(&ar->fw_boot_wait);
279: break;
280:
281: default:
282: wiphy_err(ar->hw->wiphy, "FW: received unhandled event %x\n",
283: cmd->hdr.cmd);
284: print_hex_dump_bytes("dump:", DUMP_PREFIX_NONE, buf, len);
285: break;
286: }
287: }
SourceFile:drivers/net/wireless/ath/carl9170/rx.c]
|
| 11/2 |
2026/04/29 10:02 |
llm |
debugger |
0m
Model:
Tokens:
input: 27595
output: 26
thoughts: 325
Thoughts: **Analyzing a KASAN Stack-Out-of-Bounds Crash in carl9170_cmd_callback**
Okay, so I'm looking at this KASAN stack-out-of-bounds crash in the `carl9170` driver. The report pinpoints the issue within `carl9170_cmd_callback`, specifically on line 153 in `drivers/net/wireless/ath/carl9170/rx.c`. The trace shows a write of size 60 to the address `ffffc900002c7930`, and it's flagged as stack-out-of-bounds.
My immediate thought is to zero in on that `memcpy` call: `memcpy(ar->readbuf, buffer + 4, len - 4);`. The crash description tells me that the write happens *to* `ar->readbuf`. I know that KASAN gives a pretty good clue where the corruption happened, and in this case, it's stack memory.
Right, so the size of the write is 60 bytes, and the code shows that the amount to be copied is `len - 4`. We know the write size is 60 and this is consistent. Okay.
Now, the crucial question: where is `ar->readbuf` pointing? The "stack-out-of-bounds" part is the real alarm bell here. I need to trace back and understand how `ar->readbuf` is being set and what the allocated size is. It looks like `ar->readbuf` is the destination of the write, which is an indication of the source of the out-of-bounds issue. The next step is to find where `ar->readbuf` is initialized and how big the buffer allocated for it really is, to correlate that with the intended write size.
|
| 12/2 |
2026/04/29 10:03 |
tool |
codesearch-find-references |
0m
Args: map[Name:ar9170::readbuf]
Results: map[References:[map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:carl9170_cmd_callback SourceFile:drivers/net/wireless/ath/carl9170/rx.c SourceLine:151] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:carl9170_cmd_callback SourceFile:drivers/net/wireless/ath/carl9170/rx.c SourceLine:153] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:carl9170_cmd_callback SourceFile:drivers/net/wireless/ath/carl9170/rx.c SourceLine:153] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:carl9170_cmd_callback SourceFile:drivers/net/wireless/ath/carl9170/rx.c SourceLine:153] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:carl9170_cmd_callback SourceFile:drivers/net/wireless/ath/carl9170/rx.c SourceLine:155] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:carl9170_exec_cmd SourceFile:drivers/net/wireless/ath/carl9170/usb.c SourceLine:678] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:carl9170_exec_cmd SourceFile:drivers/net/wireless/ath/carl9170/usb.c SourceLine:715]] TruncatedOutput:false]
|
| 13/2 |
2026/04/29 10:03 |
llm |
debugger |
0m
Model:
Tokens:
input: 28824
output: 57
thoughts: 16
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm an expert in this field, and speaking from the first person perspective:
**Diving into `carl9170_exec_cmd`**
Alright, my first instinct is to zero in on `carl9170_exec_cmd`. No time for generalities; that's where we need to start. I need to understand its role and what specific functionality it encompasses. Is it a central command execution function? Does it handle inter-process communication? Is it related to the kernel, or more user-space? This call is clearly a critical juncture, and I need to assess its behavior immediately. Knowing the context of this function is going to be key to any further investigation.
|
| 14/2 |
2026/04/29 10:03 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/usb.c IncludeLines:true Name:carl9170_exec_cmd]
Results: map[SourceCode: 659: int carl9170_exec_cmd(struct ar9170 *ar, const enum carl9170_cmd_oids cmd,
660: unsigned int plen, void *payload, unsigned int outlen, void *out)
661: {
662: int err = -ENOMEM;
663: unsigned long time_left;
664:
665: if (!IS_ACCEPTING_CMD(ar))
666: return -EIO;
667:
668: if (!(cmd & CARL9170_CMD_ASYNC_FLAG))
669: might_sleep();
670:
671: ar->cmd.hdr.len = plen;
672: ar->cmd.hdr.cmd = cmd;
673: /* writing multiple regs fills this buffer already */
674: if (plen && payload != (u8 *)(ar->cmd.data))
675: memcpy(ar->cmd.data, payload, plen);
676:
677: spin_lock_bh(&ar->cmd_lock);
678: ar->readbuf = out;
679: ar->readlen = outlen;
680: spin_unlock_bh(&ar->cmd_lock);
681:
682: reinit_completion(&ar->cmd_wait);
683: err = __carl9170_exec_cmd(ar, &ar->cmd, false);
684:
685: if (!(cmd & CARL9170_CMD_ASYNC_FLAG)) {
686: time_left = wait_for_completion_timeout(&ar->cmd_wait, HZ);
687: if (time_left == 0) {
688: err = -ETIMEDOUT;
689: goto err_unbuf;
690: }
691:
692: if (ar->readlen != outlen) {
693: err = -EMSGSIZE;
694: goto err_unbuf;
695: }
696: }
697:
698: return 0;
699:
700: err_unbuf:
701: /* Maybe the device was removed in the moment we were waiting? */
702: if (IS_STARTED(ar)) {
703: dev_err(&ar->udev->dev, "no command feedback "
704: "received (%d).\n", err);
705:
706: /* provide some maybe useful debug information */
707: print_hex_dump_bytes("carl9170 cmd: ", DUMP_PREFIX_NONE,
708: &ar->cmd, plen + 4);
709:
710: carl9170_restart(ar, CARL9170_RR_COMMAND_TIMEOUT);
711: }
712:
713: /* invalidate to avoid completing the next command prematurely */
714: spin_lock_bh(&ar->cmd_lock);
715: ar->readbuf = NULL;
716: ar->readlen = 0;
717: spin_unlock_bh(&ar->cmd_lock);
718:
719: return err;
720: }
SourceFile:drivers/net/wireless/ath/carl9170/usb.c]
|
| 15/2 |
2026/04/29 10:03 |
llm |
debugger |
0m
Model:
Tokens:
input: 30035
output: 55
thoughts: 817
Thoughts: **Vulnerability Assessment: carl9170_cmd_callback**
Okay, let's see. My initial thought is that `carl9170_cmd_callback` has a potential buffer overflow issue. I notice that the code checks `if (unlikely(ar->readlen != (len - 4)))`, and prints a warning. But it *doesn't* return! That's the first red flag. The code continues execution regardless.
Now, consider this: If `len - 4` (the received response size) is *greater* than `ar->readlen` (the expected response size, which also defines the size of the buffer `ar->readbuf`), then the `memcpy` on line 153 will write out-of-bounds. It looks like `ar->readbuf` is set to `out`, a stack variable in the calling function, `carl9170_exec_cmd`. The size of `out` is defined by `outlen`, which is equivalent to `ar->readlen`.
So, it's pretty clear: if the received response is larger than expected, the `memcpy` will overflow the stack buffer.
I was a bit confused by the comment that says "Do not complete," implying that the command will timeout, and a stack trace is triggered. But it *does* complete! After the restart call, which just *schedules* a work item, the code proceeds to copy the potentially oversized response into `ar->readbuf` and then `complete` the command. That confirms the overflow. If `ar->readlen != (len - 4)` happens, it prints a warning, calls `carl9170_restart`, and *then* continues with the copy and completion. That's a textbook stack buffer overflow. Time to check `carl9170_restart` to confirm my understanding of that function.
|
| 16/2 |
2026/04/29 10:03 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/rx.c IncludeLines:true Name:carl9170_restart]
Results: map[SourceCode: 506: void carl9170_restart(struct ar9170 *ar, const enum carl9170_restart_reasons r)
507: {
508: carl9170_set_state_when(ar, CARL9170_STARTED, CARL9170_IDLE);
509:
510: /*
511: * Sometimes, an error can trigger several different reset events.
512: * By ignoring these *surplus* reset events, the device won't be
513: * killed again, right after it has recovered.
514: */
515: if (atomic_inc_return(&ar->pending_restarts) > 1) {
516: dev_dbg(&ar->udev->dev, "ignoring restart (%d)\n", r);
517: return;
518: }
519:
520: ieee80211_stop_queues(ar->hw);
521:
522: dev_err(&ar->udev->dev, "restart device (%d)\n", r);
523:
524: if (!WARN_ON(r == CARL9170_RR_NO_REASON) ||
525: !WARN_ON(r >= __CARL9170_RR_LAST))
526: ar->last_reason = r;
527:
528: if (!ar->registered)
529: return;
530:
531: if (!IS_ACCEPTING_CMD(ar) || ar->needs_full_reset)
532: ar->force_usb_reset = true;
533:
534: ieee80211_queue_work(ar->hw, &ar->restart_work);
535:
536: /*
537: * At this point, the device instance might have vanished/disabled.
538: * So, don't put any code which access the ar9170 struct
539: * without proper protection.
540: */
541: }
SourceFile:drivers/net/wireless/ath/carl9170/main.c]
|
| 17/2 |
2026/04/29 10:03 |
llm |
debugger |
0m
Model:
Tokens:
input: 31949
output: 24
thoughts: 1333
Thoughts: **Analyzing a Potential Buffer Overflow and Race Condition**
Okay, so `carl9170_restart` simply queues work; it doesn't halt the current execution flow of `carl9170_cmd_callback`. That means `carl9170_cmd_callback` continues right after the call to the restart function, and there's a memcpy potentially waiting to cause a problem.
Here's the problem: The code reads a response into `ar->readbuf`. It grabs `ar->cmd_lock`, and if the `len - 4` is larger than the allocated space `ar->readlen`, then `memcpy` will overflow `ar->readbuf`. That's a classic buffer overflow.
The comment here, however, states that the command should time out and provide a stack trace. This should prevent the completion of the command. But it *does* complete because there's no `return` or `goto` after the `carl9170_restart` call. That's a bug. The comment says we shouldn't complete, so we should either `goto out;` or `return;`. If we return, it would match the comment, because the `complete(&ar->cmd_wait)` would not be called.
So, where else is `carl9170_cmd_callback` called, and is there a missing `goto` here?
There's an `if (unlikely(ar->readlen != (len - 4)))` block here, and the comment is clear: "Do not complete. The command times out, and we get a stack trace from there." A missing `goto out;` or `return;` is causing the command to complete when it should not.
Adding `goto out;` or `return;` is a good fix. If we `return`, we don't set `ar->readbuf` to `NULL`, but it will be set to `NULL` when `carl9170_exec_cmd` times out:
In the timeout case, `carl9170_exec_cmd` sets `ar->readbuf` to `NULL` under a lock. This is where I think the race could happen.
If `carl9170_cmd_callback` returns without setting `ar->readbuf` to `NULL` under a lock, could there be a race? Suppose `carl9170_exec_cmd` times out first and takes the lock and sets `ar->readbuf` to `NULL`. What if `carl9170_cmd_callback` is called again before the timeout completes?
Now `carl9170_cmd_callback` is called, and sees `ar->readbuf` is still set and the length is valid, so it writes to the buffer and completes. So if we have an invalid response, it messes up the whole command.
Actually, it makes more sense to just `return;` after calling `carl9170_restart` in that `if` statement. That matches the comment perfectly, prevents the completion, and aligns with the expected behavior.
I'll check the history to see if there was a `return;` here before, to understand why it was removed.
|
| 18/2 |
2026/04/29 10:03 |
tool |
grepper |
0m
Args: map[Expression:carl9170_cmd_callback]
Results: map[Output:drivers/net/wireless/ath/carl9170/rx.c=96=static int carl9170_check_sequence(struct ar9170 *ar, unsigned int seq)
--
drivers/net/wireless/ath/carl9170/rx.c-128-
drivers/net/wireless/ath/carl9170/rx.c:129:static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)
drivers/net/wireless/ath/carl9170/rx.c-130-{
--
drivers/net/wireless/ath/carl9170/rx.c=161=void carl9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len)
--
drivers/net/wireless/ath/carl9170/rx.c-167- if (!(cmd->hdr.cmd & CARL9170_CMD_ASYNC_FLAG))
drivers/net/wireless/ath/carl9170/rx.c:168: carl9170_cmd_callback(ar, len, buf);
drivers/net/wireless/ath/carl9170/rx.c-169-
]
|
| 19/2 |
2026/04/29 10:03 |
llm |
debugger |
0m
Model:
Tokens:
input: 34355
output: 26
thoughts: 1519
Thoughts: **Analyzing a Potential Buffer Overflow in the carl9170 Driver**
Okay, so I'm looking at this `carl9170` driver code, and I've got a potential buffer overflow issue to address. My first instinct was to just `return;` if the response length is incorrect, but that seemed too simplistic. I needed to think through the implications. Returning early would mean `ar->readbuf` doesn't get set to `NULL` immediately. However, it looks like `carl9170_exec_cmd` times out and sets `ar->readbuf = NULL`, and `carl9170_restart` also gets queued. Is this safe?
I started by considering the `memcpy` operation. The code checks `len >= 4`, so if `len` is smaller than 4, `memcpy` is skipped which is probably correct. I then started looking at a crash report that indicated the kernel received an invalid response length. Specifically, "got -2, instead of 0". If `len - 4` is -2, then `len` would be 2. Since `len >= 4` is checked before `memcpy` is called, this should not be a problem. This did not explain the bug. However, the crash report also showed "got 60, instead of 4". If `len - 4` is 60, then `len` must be 64, and `ar->readlen` is 4. Here, `memcpy(ar->readbuf, buffer + 4, 60)` is called, but the buffer is only 4 bytes long! A stack-out-of-bounds write of size 60.
So the fix must involve skipping the `memcpy` and `complete` calls, as indicated by the crash report. Returning early or using a `goto` statement seems like the obvious solution. The driver is getting an invalid response length. Skipping `complete` could cause the command to timeout, so I'm wondering if that's a problem.
Now, let me go back to the code and see what else I'm missing. The `carl9170_cmd_callback` function, specifically. There's a comment that mentions variable response lengths. But, looking at the check, `if (unlikely(ar->readlen != (len - 4)))` is an exact match check. It's not checking if there's *enough* space, which the comment seems to imply. If the code was checking for enough space, it should be `<` instead of `!=`.
Let's think. If `ar->readlen < (len - 4)`, it's a buffer overflow. If `ar->readlen > (len - 4)`, it's technically an underflow, but `memcpy` won't overflow the buffer. The problem is the code checks `!=`. So, this `!=` check is wrong.
Also, I need to check the calling function `carl9170_exec_cmd`. Here the code checks `ar->readlen != outlen`. Wait, `ar->readlen` is initialized to `outlen`. `ar->readbuf` gets the buffer. And `ar->readlen` gets `outlen`. So `ar->readlen` is never modified by `carl9170_cmd_callback`! Therefore `ar->readlen != outlen` will NEVER be true, which is wrong. I need to figure out where `ar->readlen` is modified.
|
| 20/2 |
2026/04/29 10:04 |
tool |
codesearch-find-references |
0m
Args: map[Name:ar9170::readlen]
Results: map[References:[map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:carl9170_cmd_callback SourceFile:drivers/net/wireless/ath/carl9170/rx.c SourceLine:136] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:carl9170_cmd_callback SourceFile:drivers/net/wireless/ath/carl9170/rx.c SourceLine:137] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:carl9170_exec_cmd SourceFile:drivers/net/wireless/ath/carl9170/usb.c SourceLine:679] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:carl9170_exec_cmd SourceFile:drivers/net/wireless/ath/carl9170/usb.c SourceLine:692] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:carl9170_exec_cmd SourceFile:drivers/net/wireless/ath/carl9170/usb.c SourceLine:716] map[ReferenceKind:writes ReferencingEntityKind:function ReferencingEntityName:carl9170_usb_stop SourceFile:drivers/net/wireless/ath/carl9170/usb.c SourceLine:789]] TruncatedOutput:false]
|
| 21/2 |
2026/04/29 10:04 |
llm |
debugger |
0m
Model:
Tokens:
input: 37084
output: 22
thoughts: 356
Thoughts: **Analyzing the `carl9170_cmd_callback` and `carl9170_exec_cmd` Flow**
Okay, let me think this through. It appears that `ar->readlen` isn't being modified *at all* within `carl9170_cmd_callback`. Consequently, the check `ar->readlen != outlen` inside `carl9170_exec_cmd` will *always* evaluate to false, unless `ar->readlen` was specifically initialized to zero by an error handler, or reset by the stop function.
The implication here is that if `carl9170_cmd_callback` *should* be updating `ar->readlen` to `len - 4`, then `carl9170_exec_cmd` *could* have been used to verify against the expected `outlen`. But, the fact is that this isn't happening. The callback function isn't updating `ar->readlen`.
Ah, but the comment in `carl9170_cmd_callback` provides a clue:
```c
/*
* Some commands may have a variable response length
* and we cannot predict the correct length in advance.
* So we only check if we provided enough space for the data.
*/
if (unlikely(ar->readlen != (len - 4))) {
```
The comment explicitly states that the code only checks if *enough* space has been provided. If that's the intention, the comparison should logically be `ar->readlen < (len - 4)`. If the provided space (`ar->readlen`) is less than the required space (`len - 4`), then we haven't allocated enough memory. Conversely, if `ar->readlen >= (len - 4)`, we *have* provided enough space.
But the code uses `!=`. This suggests a potential bug, or at least, a misunderstanding of the intended logic. The comparison using `!=` is flawed: `ar->readlen != (len - 4)` means we're only checking for an *exact* match. This is incorrect. Therefore, I need to check the git history of this function immediately to understand the reasoning behind this check and see if it was changed at some point.
|
| 22/2 |
2026/04/29 10:04 |
tool |
grepper |
0m
Args: map[Expression:Some commands may have a variable response length]
Results: map[Output:drivers/net/wireless/ath/carl9170/rx.c=129=static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)
--
drivers/net/wireless/ath/carl9170/rx.c-131- /*
drivers/net/wireless/ath/carl9170/rx.c:132: * Some commands may have a variable response length
drivers/net/wireless/ath/carl9170/rx.c-133- * and we cannot predict the correct length in advance.
]
|
| 23/2 |
2026/04/29 10:04 |
llm |
debugger |
0m
Model:
Tokens:
input: 38131
output: 24
thoughts: 21
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**Analyzing the Origins of `carl9170_cmd_callback`**
Right, let's dig into the lineage of this `carl9170_cmd_callback`. It seems like we're trying to figure out where the responsibility lies, or perhaps trace the evolution of this particular callback function. Is there a specific bug report tied to it? Were there any significant refactorings in the driver code that might have impacted its behavior? I'm immediately thinking about the potential for race conditions or synchronization issues, given that it's a callback ā it's crucial to understand the context in which it's invoked. We'll need to go back through the commit history and see how it was introduced, modified, and potentially, if there were any discussions around its implementation. Any prior issues or "blame" associated with this function are probably key to diagnosing any current problem.
|
| 24/2 |
2026/04/29 10:04 |
tool |
grepper |
0m
Args: map[Expression:carl9170_cmd_callback]
Results: map[Output:drivers/net/wireless/ath/carl9170/rx.c=96=static int carl9170_check_sequence(struct ar9170 *ar, unsigned int seq)
--
drivers/net/wireless/ath/carl9170/rx.c-128-
drivers/net/wireless/ath/carl9170/rx.c:129:static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)
drivers/net/wireless/ath/carl9170/rx.c-130-{
--
drivers/net/wireless/ath/carl9170/rx.c=161=void carl9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len)
--
drivers/net/wireless/ath/carl9170/rx.c-167- if (!(cmd->hdr.cmd & CARL9170_CMD_ASYNC_FLAG))
drivers/net/wireless/ath/carl9170/rx.c:168: carl9170_cmd_callback(ar, len, buf);
drivers/net/wireless/ath/carl9170/rx.c-169-
]
|
| 25/2 |
2026/04/29 10:04 |
llm |
debugger |
0m
Model:
Tokens:
input: 38728
output: 28
thoughts: 858
Thoughts: **Analyzing a Potential Buffer Overflow in carl9170_cmd_callback**
Okay, let's break this down. My initial thought is triggered by this `if` statement: `ar->readlen != (len - 4)`. If that's true, it warns and restarts, but crucially, it *doesn't* return. It proceeds to copy with `memcpy(ar->readbuf, buffer + 4, len - 4)`. The comment implies the check is about space, meaning the check should have been `ar->readlen < (len - 4)`.
If `len - 4` exceeds `ar->readlen`, then, as I suspected, this `memcpy` would overflow the buffer. However, the existing check isn't doing that. But even if it doesn't overflow, it still copies `len - 4` bytes.
My mind then jumps ahead. Let's say I *do* change the check to `ar->readlen < (len - 4)`. Now, if `len - 4` is *less* than `ar->readlen`, there's no warning, no restart. It just proceeds with `memcpy`, which is fine, because it won't overflow. It completes the wait, `carl9170_exec_cmd` wakes up and checks `if (ar->readlen != outlen)`. But crucially, `ar->readlen` is *still* equal to `outlen`! The crucial point is that it's *not* being updated by the callback. So, `ar->readlen != outlen` is false. This means `carl9170_exec_cmd` returns success (0).
Here's the problem. The caller *expects* `outlen` bytes, but only `len - 4` bytes were actually copied! The rest of the `out` buffer would be uninitialized garbage. I can see this is a potential bug! The command *thinks* it succeeded, but it hasn't filled the buffer correctly.
So, I need to understand why the callback doesn't update `ar->readlen`. It should be `ar->readlen = len - 4`. If it did, then `ar->readlen != outlen` would be true if `len - 4 != outlen`, and `carl9170_exec_cmd` would return `-EMSGSIZE`.
Wait. Then I thought about the possibility of *variable length responses*. I need to see if some commands actually *do* have variable response lengths. If they do, then returning `-EMSGSIZE` when `len - 4 != outlen` would break the driver. I need to investigate that before I make any changes.
|
| 26/2 |
2026/04/29 10:04 |
tool |
codesearch-find-references |
0m
Args: map[Name:carl9170_exec_cmd]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_collect_tally SourceFile:drivers/net/wireless/ath/carl9170/cmd.c SourceLine:176] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_disable_key SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:497] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_echo_test SourceFile:drivers/net/wireless/ath/carl9170/cmd.c SourceLine:104] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:176] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:178] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:180] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:182] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:186] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:189] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:191] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:192] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:193] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:196] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:199] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:203] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:205] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:208] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:209] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:211] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:214] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:219] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:220] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:221] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:224] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:226] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:229] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:232] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:235] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:237] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:241] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:245] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:246] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:249] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:250] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_mac SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:252] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:565] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:568] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy_from_eeprom SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:446] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy_from_eeprom SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:450] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy_from_eeprom SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:454] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy_from_eeprom SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:462] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy_from_eeprom SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:469] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy_from_eeprom SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:477] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy_from_eeprom SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:482] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy_from_eeprom SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:487] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy_from_eeprom SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:492] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy_from_eeprom SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:498] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy_from_eeprom SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:506] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy_from_eeprom SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:512] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy_from_eeprom SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:519] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy_from_eeprom SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:526] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy_from_eeprom SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:534] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy_from_eeprom SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:536] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy_from_eeprom SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:537] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_phy_from_eeprom SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:539] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_power_cal SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:48] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_power_cal SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:49] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_power_cal SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:50] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_power_cal SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:51] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_power_cal SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:52] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_power_cal SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:53] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_power_cal SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:54] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_power_cal SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:55] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_power_cal SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:56] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_power_cal SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:57] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_power_cal SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:59] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_rf_bank4_pwr SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:1023] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_rf_bank4_pwr SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:1024] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_rf_bank4_pwr SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:1026] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_rf_banks_0_7 SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:679] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_init_rf_banks_0_7 SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:683] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_mac_reset SourceFile:drivers/net/wireless/ath/carl9170/cmd.c SourceLine:147] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_op_get_tsf SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1149] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_read_eeprom SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1870] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_read_mreg SourceFile:drivers/net/wireless/ath/carl9170/cmd.c SourceLine:76] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_rng_get SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1545] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_rx_filter SourceFile:drivers/net/wireless/ath/carl9170/cmd.h SourceLine:68] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_beacon_timers SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:464] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_beacon_timers SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:465] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_beacon_timers SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:466] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_channel SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:1614] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_channel SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:1680] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_freq_cal_data SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:1202] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_freq_cal_data SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:1209] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_freq_cal_data SourceFile:drivers/net/wireless/ath/carl9170/phy.c SourceLine:1213] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_mac_rates SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:129] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_mac_rates SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:130] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_mac_rates SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:131] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_mac_reg SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:267] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_mac_reg SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:268] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_mac_reg SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:270] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_mac_tpc SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:524] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_mac_tpc SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:526] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_mac_tpc SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:529] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_mac_tpc SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:532] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_operating_mode SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:383] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_operating_mode SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:384] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_operating_mode SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:385] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_operating_mode SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:386] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_operating_mode SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:387] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_qos SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:140] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_qos SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:142] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_qos SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:144] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_qos SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:146] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_qos SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:148] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_qos SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:151] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_qos SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:155] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_qos SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:160] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_qos SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:162] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_set_qos SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:166] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_update_multicast SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:290] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_update_multicast SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:291] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_update_multicast SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:292] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_upload_key SourceFile:drivers/net/wireless/ath/carl9170/mac.c SourceLine:487] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:carl9170_write_reg SourceFile:drivers/net/wireless/ath/carl9170/cmd.c SourceLine:51]] TruncatedOutput:false]
|
| 27/2 |
2026/04/29 10:04 |
llm |
debugger |
0m
Model:
Tokens:
input: 47898
output: 58
thoughts: 17
Thoughts: Okay, here's my attempt at summarizing the thought process, as requested, aimed at an expert audience and in the first person:
**Diving into `carl9170_read_mreg`**
Alright, time to dig into `carl9170_read_mreg`. My initial thought is to quickly ascertain its purpose. Is this a critical path function? Is it likely to be a performance bottleneck? Or perhaps it's related to initialization or error handling? I'm already mentally running through the typical places I'd expect to see this kind of register read happening: interrupt handling, DMA configuration, maybe some low-level power management, or possibly a status check within a larger state machine. I need to understand its context. I'll probably start by looking at its callers. A cross-reference will tell me who is *using* this function. From the caller context I can hopefully deduce *why* this function exists. Then I'll check its implementation. Are there any potential concurrency issues? Is there any masking or byte swapping involved that could be a source of problems? If it's reading a hardware register, I'm going to be looking for potential side effects, especially if it's reading a memory-mapped register that could trigger some hardware activity. I'll need to see if error handling is robust enough, or whether it might be leading to race conditions. I'm hoping I can trace this quickly to ensure it is secure. Finally, I'll consider how this register read fits into the wider system architecture and if there are any obvious opportunities for optimization or potential issues that could manifest at scale. Let's see what we've got!
|
| 28/2 |
2026/04/29 10:05 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/cmd.c IncludeLines:true Name:carl9170_read_mreg]
Results: map[SourceCode: 62: int carl9170_read_mreg(struct ar9170 *ar, const int nregs,
63: const u32 *regs, u32 *out)
64: {
65: int i, err;
66: __le32 *offs, *res;
67:
68: /* abuse "out" for the register offsets, must be same length */
69: offs = (__le32 *)out;
70: for (i = 0; i < nregs; i++)
71: offs[i] = cpu_to_le32(regs[i]);
72:
73: /* also use the same buffer for the input */
74: res = (__le32 *)out;
75:
76: err = carl9170_exec_cmd(ar, CARL9170_CMD_RREG,
77: 4 * nregs, (u8 *)offs,
78: 4 * nregs, (u8 *)res);
79: if (err) {
80: if (net_ratelimit()) {
81: wiphy_err(ar->hw->wiphy, "reading regs failed (%d)\n",
82: err);
83: }
84: return err;
85: }
86:
87: /* convert result to cpu endian */
88: for (i = 0; i < nregs; i++)
89: out[i] = le32_to_cpu(res[i]);
90:
91: return 0;
92: }
SourceFile:drivers/net/wireless/ath/carl9170/cmd.c]
|
| 29/2 |
2026/04/29 10:05 |
llm |
debugger |
0m
Model:
Tokens:
input: 48818
output: 57
thoughts: 16
Thoughts: Okay, let's dive into this. Here's my thought process on what we're looking at, summarized in the first person, assuming I'm already pretty familiar with the subject matter:
**Checking `carl9170_echo_test`**
Alright, so `carl9170_echo_test`... that name immediately rings a bell. It's likely a test script, likely one I've written or collaborated on before, given the potential naming convention. My first thought is to recall its purpose. Is this for a simple echo test within a specific module or subsystem? Is it part of a larger integration suite? The "echo" part implies it's probably pretty basic, meant to verify that some input is successfully received and returned, perhaps for testing a network connection, a driver, or a communication protocol. I need to quickly determine the context ā what exactly is being "echoed"? Is it a string, a data packet, a specific control code?
I need to see how robust it is. Does it handle different input lengths, edge cases like null input, and potential error conditions gracefully? Does it have any logging or reporting mechanisms to help with debugging if it fails? I also want to check for any dependencies. Are there any libraries, external configurations, or specific hardware setups required to run this test successfully? I'm hoping it's well-documented ā ideally, there's a comment block at the beginning explaining the test's objective, expected inputs, and anticipated outputs. Ultimately, I need to understand if this test is fit for its purpose and if it aligns with the overall testing strategy.
|
| 30/2 |
2026/04/29 10:05 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/cmd.c IncludeLines:true Name:carl9170_echo_test]
Results: map[SourceCode: 99: int carl9170_echo_test(struct ar9170 *ar, const u32 v)
100: {
101: u32 echores;
102: int err;
103:
104: err = carl9170_exec_cmd(ar, CARL9170_CMD_ECHO,
105: 4, (u8 *)&v,
106: 4, (u8 *)&echores);
107: if (err)
108: return err;
109:
110: if (v != echores) {
111: wiphy_info(ar->hw->wiphy, "wrong echo %x != %x", v, echores);
112: return -EINVAL;
113: }
114:
115: return 0;
116: }
SourceFile:drivers/net/wireless/ath/carl9170/cmd.c]
|
| 31/2 |
2026/04/29 10:05 |
llm |
debugger |
0m
Model:
Tokens:
input: 49531
output: 58
thoughts: 38
Thoughts: Okay, here's my interpretation of those thoughts, crafted with the perspective you requested:
**Assessing Command Execution in Relation to Data Collection**
Alright, let's see... so I'm looking at this `carl9170_exec_cmd` function, and it seems to be working with commands of a pre-defined, fixed length. That's a common strategy for some embedded systems. Okay, that's not unusual. But then the question hits me: what about `carl9170_collect_tally`? Is it working in the same fixed length fashion? Is the data acquisition aspect of the software design, and the management of that data stream related to execution? How does that work in practice? We need to keep consistency in mind and I have to fully understand the interaction between execution and data aggregation.
|
| 32/2 |
2026/04/29 10:05 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/cmd.c IncludeLines:true Name:carl9170_collect_tally]
Results: map[SourceCode: 169: int carl9170_collect_tally(struct ar9170 *ar)
170: {
171: struct carl9170_tally_rsp tally;
172: struct survey_info *info;
173: unsigned int tick;
174: int err;
175:
176: err = carl9170_exec_cmd(ar, CARL9170_CMD_TALLY, 0, NULL,
177: sizeof(tally), (u8 *)&tally);
178: if (err)
179: return err;
180:
181: tick = le32_to_cpu(tally.tick);
182: if (tick) {
183: ar->tally.active += le32_to_cpu(tally.active) / tick;
184: ar->tally.cca += le32_to_cpu(tally.cca) / tick;
185: ar->tally.tx_time += le32_to_cpu(tally.tx_time) / tick;
186: ar->tally.rx_total += le32_to_cpu(tally.rx_total);
187: ar->tally.rx_overrun += le32_to_cpu(tally.rx_overrun);
188:
189: if (ar->channel) {
190: info = &ar->survey[ar->channel->hw_value];
191: info->time = ar->tally.active;
192: info->time_busy = ar->tally.cca;
193: info->time_tx = ar->tally.tx_time;
194: do_div(info->time, 1000);
195: do_div(info->time_busy, 1000);
196: do_div(info->time_tx, 1000);
197: }
198: }
199: return 0;
200: }
SourceFile:drivers/net/wireless/ath/carl9170/cmd.c]
|
| 33/2 |
2026/04/29 10:05 |
llm |
debugger |
0m
Model:
Tokens:
input: 50428
output: 22
thoughts: 150
Thoughts: **Concerning `carl9170_collect_tally` and Potential Buffer Overflow**
Okay, hold on a second. I'm looking at this `carl9170_collect_tally` function and I've just realized something concerning. It's using `sizeof(tally)` to determine the size of the buffer. But what if the *firmware* is returning a length that's different from the size I've defined locally?
If the firmware gives back a mismatched length, `carl9170_cmd_callback` does print a warning and attempts to restart the device. However, thatās not the whole story. If `len - 4` is *greater* than `sizeof(tally)`, the code is going to overflow the buffer *before* the restart, creating a nasty security vulnerability.
And... wait a minute! This is throwing me off. If `carl9170_cmd_callback` was actually *designed* to handle variable-length responses, why is it checking `ar->readlen != (len - 4)`? That check implies an expectation of a *fixed* size, which contradicts the idea of variable length, potentially leading to a flawed design.
I need to dig deeper into the history of `carl9170_cmd_callback`. It is time to review the version control log. I need to understand why this code was written this way and whether there have been previous attempts to address variable-length responses. It seems like a core issue that needs investigation.
|
| 34/2 |
2026/04/29 10:05 |
tool |
grepper |
0m
Args: map[Expression:Some commands may have a variable response length]
Results: map[Output:drivers/net/wireless/ath/carl9170/rx.c=129=static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)
--
drivers/net/wireless/ath/carl9170/rx.c-131- /*
drivers/net/wireless/ath/carl9170/rx.c:132: * Some commands may have a variable response length
drivers/net/wireless/ath/carl9170/rx.c-133- * and we cannot predict the correct length in advance.
]
|
| 35/2 |
2026/04/29 10:05 |
llm |
debugger |
1m
Model:
Tokens:
input: 51096
output: 57
thoughts: 4621
Thoughts: **Analysis of Potential Vulnerability in carl9170 Driver**
Okay, I've got a handle on this. The driver's logic for handling command responses in `carl9170_cmd_callback` seems flawed when the received response length doesn't match the expected length. It seems like the core issue lies in how the driver handles variable-length responses, and, even more concerning, how it *doesn't* handle cases where the received length is incorrect.
My initial thought was to see if there were any commands with variable-length responses, and the comment does suggest this. However, after reviewing the code, it seems the check `ar->readlen != (len - 4)` isn't really intended for that purpose. It's meant to detect discrepancies between the *expected* length and the *actual* length of a response. This check should have a `return` or `goto` after the warning to actually *prevent* the command from completing with potentially corrupted data.
The check `if (unlikely(ar->readlen != (len - 4)))` is the linchpin. If the check flags an invalid response length, the driver prints a warning, restarts the hardware, and then blindly proceeds to copy the data from the response buffer into the `ar->readbuf`. In the event of a length mismatch, this `memcpy` becomes dangerous. If the received response is longer than expected, it leads to a stack buffer overflow. If shorter, the caller could believe it has received the intended data even though the response has not completed.
Let's drill down. If the driver gets an incorrect response length, and the response is shorter than the expected length, `ar->readlen` is *not* updated, but the driver still signals the command as completed. This leads to the calling function in `carl9170_exec_cmd` incorrectly assuming that all bytes were copied correctly.
If the response is longer than expected, the `memcpy` overflows `ar->readbuf`. The driver's current implementation allows this, causing a buffer overflow, as reported in the KASAN crash dump. Adding a simple `return;` after the warning within the `if` block immediately fixes the issue and prevents this memory corruption.
I've also confirmed that the existing callers of `carl9170_exec_cmd` don't expect variable response lengths. The code currently does NOT handle the situation where spurious responses arrive. In the event of an erroneous or out-of-sequence response, the current implementation in `carl9170_handle_command_response` does not validate whether the response is for the specific command that is currently being executed, which could allow a malicious actor to inject incorrect data into the system, or cause it to return with a success code from a previous command.
|
| 36/2 |
2026/04/29 10:07 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/usb.c IncludeLines:true Name:carl9170_exec_cmd]
Results: map[SourceCode: 659: int carl9170_exec_cmd(struct ar9170 *ar, const enum carl9170_cmd_oids cmd,
660: unsigned int plen, void *payload, unsigned int outlen, void *out)
661: {
662: int err = -ENOMEM;
663: unsigned long time_left;
664:
665: if (!IS_ACCEPTING_CMD(ar))
666: return -EIO;
667:
668: if (!(cmd & CARL9170_CMD_ASYNC_FLAG))
669: might_sleep();
670:
671: ar->cmd.hdr.len = plen;
672: ar->cmd.hdr.cmd = cmd;
673: /* writing multiple regs fills this buffer already */
674: if (plen && payload != (u8 *)(ar->cmd.data))
675: memcpy(ar->cmd.data, payload, plen);
676:
677: spin_lock_bh(&ar->cmd_lock);
678: ar->readbuf = out;
679: ar->readlen = outlen;
680: spin_unlock_bh(&ar->cmd_lock);
681:
682: reinit_completion(&ar->cmd_wait);
683: err = __carl9170_exec_cmd(ar, &ar->cmd, false);
684:
685: if (!(cmd & CARL9170_CMD_ASYNC_FLAG)) {
686: time_left = wait_for_completion_timeout(&ar->cmd_wait, HZ);
687: if (time_left == 0) {
688: err = -ETIMEDOUT;
689: goto err_unbuf;
690: }
691:
692: if (ar->readlen != outlen) {
693: err = -EMSGSIZE;
694: goto err_unbuf;
695: }
696: }
697:
698: return 0;
699:
700: err_unbuf:
701: /* Maybe the device was removed in the moment we were waiting? */
702: if (IS_STARTED(ar)) {
703: dev_err(&ar->udev->dev, "no command feedback "
704: "received (%d).\n", err);
705:
706: /* provide some maybe useful debug information */
707: print_hex_dump_bytes("carl9170 cmd: ", DUMP_PREFIX_NONE,
708: &ar->cmd, plen + 4);
709:
710: carl9170_restart(ar, CARL9170_RR_COMMAND_TIMEOUT);
711: }
712:
713: /* invalidate to avoid completing the next command prematurely */
714: spin_lock_bh(&ar->cmd_lock);
715: ar->readbuf = NULL;
716: ar->readlen = 0;
717: spin_unlock_bh(&ar->cmd_lock);
718:
719: return err;
720: }
SourceFile:drivers/net/wireless/ath/carl9170/usb.c]
|
| 37/2 |
2026/04/29 10:07 |
llm |
debugger |
0m
Model:
Tokens:
input: 57349
output: 25
thoughts: 73
Thoughts: **Concurrency Concerns in `carl9170_exec_cmd`**
Okay, hold on a second. It just hit me: `ar->cmd` is *one single struct* within the `ar` structure. That's a problem. If multiple threads are calling `carl9170_exec_cmd` at the same time, they're going to stomp all over each other's data in that `ar->cmd` field! We've got a classic race condition scenario brewing here. This means there *absolutely has* to be a mutex, some form of synchronization, to protect that function and, specifically, that shared `ar->cmd` struct. I need to verify that this is the case. Let's go check for `ar->mutex` right now. It's the only way to ensure data integrity and thread safety in this situation.
|
| 38/2 |
2026/04/29 10:07 |
tool |
codesearch-find-references |
0m
Args:
Results: map[References:[map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_alloc SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1779] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_ampdu_work SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1390] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_ampdu_work SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1392] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_free SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:2055] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_led_update SourceFile:drivers/net/wireless/ath/carl9170/led.c SourceLine:76] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_led_update SourceFile:drivers/net/wireless/ath/carl9170/led.c SourceLine:96] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_add_interface SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:605] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_add_interface SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:737] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_add_interface SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:743] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_bss_info_changed SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1043] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_bss_info_changed SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1138] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_conf_tx SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1375] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_conf_tx SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1378] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_config SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:898] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_config SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:953] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_configure_filter SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:985] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_configure_filter SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1028] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_flush SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1667] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_flush SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1672] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_get_survey SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1620] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_get_survey SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1622] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_get_tsf SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1148] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_get_tsf SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1151] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_remove_interface SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:757] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_remove_interface SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:806] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_set_key SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1178] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_set_key SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1210] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_set_key SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1288] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_set_key SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1296] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_start SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:341] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_start SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:426] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_stop SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:450] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_op_stop SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:462] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_ping_work SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:551] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_ping_work SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:555] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_ps_work SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:849] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_ps_work SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:852] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_restart_work SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:477] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_restart_work SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:488] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_rng_read SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1571] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_rng_read SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1575] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_rng_read SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:1581] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_stat_work SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:882] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_stat_work SourceFile:drivers/net/wireless/ath/carl9170/main.c SourceLine:884] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_usb_init_device SourceFile:drivers/net/wireless/ath/carl9170/usb.c SourceLine:958] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:carl9170_usb_init_device SourceFile:drivers/net/wireless/ath/carl9170/usb.c SourceLine:960]] TruncatedOutput:false]
|
| 39/2 |
2026/04/29 10:07 |
llm |
debugger |
1m
Model:
Tokens:
input: 60893
output: 1135
thoughts: 1814
Thoughts: **Analysis of the carl9170 Command Response Stack Overflow**
Okay, here's the breakdown of what I've found. It looks like we have a pretty clear stack overflow issue in the carl9170 driver.
**Root Cause Analysis:** The problem stems from how `carl9170_exec_cmd` handles command responses. Basically, it sets up a local stack variable (`out`) to act as a buffer (`ar->readbuf`) for the response data. It then sets `ar->readlen` to the expected length of the response (`outlen`). Then, it waits for the device to send back a command response.
**The Bug:** The core vulnerability lies within `carl9170_cmd_callback`. This function gets called when the device actually sends a response. It checks if the response's length matches what was expected. If the length is *incorrect* (i.e., `ar->readlen != (len - 4)`), the code prints a warning and schedules a device restart via `carl9170_restart()`. However, *crucially*, it doesn't immediately abort the execution. Instead, it proceeds to attempt a `memcpy` of the response data into `ar->readbuf`. Here's the relevant code:
```c
if (ar->readbuf) {
if (len >= 4)
memcpy(ar->readbuf, buffer + 4, len - 4);
ar->readbuf = NULL;
}
```
The problem is that if the response's `len` is *larger* than the expected length (`ar->readlen`), the `memcpy` will write beyond the bounds of that `ar->readbuf` which is the local stack variable `out` in `carl9170_exec_cmd`. This leads to the stack-out-of-bounds write and the crash.
**The Fix:** The solution is straightforward. We need to prevent the `memcpy` if the response is invalid. That can be done by simply adding a `return;` *after* the `carl9170_restart(ar, CARL9170_RR_INVALID_RSP);` call in `carl9170_cmd_callback`. The fixed code looks like this:
```c
/*
* Do not complete. The command times out,
* and we get a stack trace from there.
*/
carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
return;
}
```
This ensures that the function returns immediately if the response is invalid. By design, this lets the timeout handler in `carl9170_exec_cmd` clean up `ar->readbuf`. This design matches the comment "Do not complete. The command times out" which explicitly confirms that this is the correct behavior.
|
| 40/1 |
2026/04/29 10:08 |
action |
kernel-scratch-checkouter |
0m
Results: map[KernelScratchSrc:/app/workdir/cache/tmp/tmp723381683]
|
| 41/1 |
2026/04/29 10:09 |
loop |
|
20m
|
| 42/2 |
2026/04/29 10:09 |
iteration |
0 |
20m
|
| 43/3 |
2026/04/29 10:09 |
agent |
patch-generator |
3m
Model:
Instruction:
You are an experienced Linux kernel developer tasked with creating a fix for a kernel bug.
You will be given a crash report, and an initial explanation of the root cause done by another
kernel expert.
Use the codeedit tool to do code edits.
Note: you will not see your changes when looking at the code using codesearch tools.
Your final reply should contain explanation of what you did in the patch and why
(details not present in the initial explanation of the bug).
Your fix must not just prevent the given crash, but also be the best fix for the underlying
root cause from the software engineering point of view. There can be several ways to fix the
same bug. Consider alternatives, and pick the best one. For example, additional checks may be
added at different locations/functions, it's usually better to place them earlier in the
execution to avoid multiple checks at various locations later.
Frequently the same coding mistake is done in several locations in the source code.
Check if your fix should be extended/applied to similar cases around to fix other similar bugs.
But don't go too wide, don't try to fix problems kernel-wide, fix similar issues
in the same file only.
If you are changing post-conditions of a function, consider all callers of the functions,
and if they need to be updated to handle new post-conditions. For example, if you make
a function that previously never returned a NULL, return NULL, consider if callers
need to be updated to handle NULL return value.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash that corresponds to the bug is:
usb 4-1: received invalid command response:got -2, instead of 0
usb 4-1: received invalid command response:got 60, instead of 4
==================================================================
BUG: KASAN: stack-out-of-bounds in carl9170_cmd_callback drivers/net/wireless/ath/carl9170/rx.c:153 [inline]
BUG: KASAN: stack-out-of-bounds in carl9170_handle_command_response+0x21c/0x11b0 drivers/net/wireless/ath/carl9170/rx.c:168
Write of size 60 at addr ffffc900002c7930 by task swapper/1/0
CPU: 1 UID: 0 PID: 0 Comm: swapper/1 Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<IRQ>
dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
print_address_description+0x55/0x1e0 mm/kasan/report.c:378
print_report+0x58/0x70 mm/kasan/report.c:482
kasan_report+0x117/0x150 mm/kasan/report.c:595
check_region_inline mm/kasan/generic.c:-1 [inline]
kasan_check_range+0x264/0x2c0 mm/kasan/generic.c:200
__asan_memcpy+0x40/0x70 mm/kasan/shadow.c:106
carl9170_cmd_callback drivers/net/wireless/ath/carl9170/rx.c:153 [inline]
carl9170_handle_command_response+0x21c/0x11b0 drivers/net/wireless/ath/carl9170/rx.c:168
carl9170_usb_rx_irq_complete+0xce/0x1a0 drivers/net/wireless/ath/carl9170/usb.c:307
__usb_hcd_giveback_urb+0x376/0x540 drivers/usb/core/hcd.c:1657
dummy_timer+0xbc0/0x4650 drivers/usb/gadget/udc/dummy_hcd.c:2005
__run_hrtimer kernel/time/hrtimer.c:1930 [inline]
__hrtimer_run_queues+0x3c0/0xa20 kernel/time/hrtimer.c:1994
hrtimer_run_softirq+0x17a/0x240 kernel/time/hrtimer.c:2011
handle_softirqs+0x21b/0x830 kernel/softirq.c:622
__do_softirq kernel/softirq.c:656 [inline]
invoke_softirq kernel/softirq.c:496 [inline]
__irq_exit_rcu+0xc0/0x210 kernel/softirq.c:735
irq_exit_rcu+0x9/0x30 kernel/softirq.c:752
instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1061 [inline]
sysvec_apic_timer_interrupt+0x92/0xb0 arch/x86/kernel/apic/apic.c:1061
</IRQ>
<TASK>
asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:697
RIP: 0010:pv_native_safe_halt+0xf/0x20 arch/x86/kernel/paravirt.c:63
Code: 24 b3 01 e9 13 a2 02 00 cc cc cc 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 f3 0f 1e fa eb 07 0f 00 2d 93 77 15 00 fb f4 <c3> cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc 90 90 90 90 90
RSP: 0018:ffffc9000013fe20 EFLAGS: 00000202
RAX: 00000000000b70a1 RBX: ffffffff815b4fea RCX: 0000000080000001
RDX: 0000000000000001 RSI: ffffffff8927d953 RDI: ffffffff87c938c0
RBP: ffffc9000013ff20 R08: ffff88806b9336d3 R09: 1ffff1100d7266da
R10: dffffc0000000000 R11: ffffed100d7266db R12: 0000000000000001
R13: 1ffff11002bd5390 R14: 0000000000000001 R15: 1ffff11002bd5390
arch_safe_halt arch/x86/kernel/process.c:766 [inline]
default_idle+0x9/0x20 arch/x86/kernel/process.c:767
default_idle_call+0x72/0xb0 kernel/sched/idle.c:122
cpuidle_idle_call kernel/sched/idle.c:199 [inline]
do_idle+0x36a/0x5f0 kernel/sched/idle.c:352
cpu_startup_entry+0x43/0x60 kernel/sched/idle.c:451
start_secondary+0x101/0x110 arch/x86/kernel/smpboot.c:312
common_startup_64+0x13e/0x147
</TASK>
The buggy address belongs to a 8-page vmalloc region starting at 0xffffc900002c0000 allocated at copy_process+0x89b/0x4380 kernel/fork.c:2088
The buggy address belongs to the physical page:
page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1a16f
flags: 0x100000000000000(node=0|zone=1)
raw: 0100000000000000 ffffea0000685bc8 ffffea0000685bc8 0000000000000000
raw: 0000000000000000 0000000000000000 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x29c2(GFP_NOWAIT|__GFP_HIGHMEM|__GFP_IO|__GFP_FS|__GFP_ZERO), pid 2, tgid 2 (kthreadd), ts 2604993278, free_ts 0
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x231/0x280 mm/page_alloc.c:1858
prep_new_page mm/page_alloc.c:1866 [inline]
get_page_from_freelist+0x2274/0x2370 mm/page_alloc.c:3946
__alloc_frozen_pages_noprof+0x18d/0x380 mm/page_alloc.c:5226
__alloc_pages_noprof+0x10/0x100 mm/page_alloc.c:5260
__alloc_pages_node_noprof include/linux/gfp.h:289 [inline]
alloc_pages_node_noprof include/linux/gfp.h:316 [inline]
vm_area_alloc_pages mm/vmalloc.c:3655 [inline]
__vmalloc_area_node mm/vmalloc.c:3878 [inline]
__vmalloc_node_range_noprof+0x7ca/0x1750 mm/vmalloc.c:4064
__vmalloc_node_noprof+0xc2/0x100 mm/vmalloc.c:4124
alloc_thread_stack_node kernel/fork.c:357 [inline]
dup_task_struct+0x298/0x830 kernel/fork.c:926
copy_process+0x89b/0x4380 kernel/fork.c:2088
kernel_clone+0x284/0x8f0 kernel/fork.c:2723
kernel_thread+0x13f/0x1b0 kernel/fork.c:2784
create_kthread kernel/kthread.c:459 [inline]
kthreadd+0x4ec/0x6e0 kernel/kthread.c:817
ret_from_fork+0x491/0xad0 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
page_owner free stack trace missing
Memory state around the buggy address:
ffffc900002c7800: f3 f3 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00
ffffc900002c7880: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffffc900002c7900: f1 f1 f1 f1 04 f2 04 f3 00 00 00 00 00 00 00 00
^
ffffc900002c7980: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ffffc900002c7a00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
==================================================================
----------------
Code disassembly (best guess):
0: 24 b3 and $0xb3,%al
2: 01 e9 add %ebp,%ecx
4: 13 a2 02 00 cc cc adc -0x3333fffe(%rdx),%esp
a: cc int3
b: 90 nop
c: 90 nop
d: 90 nop
e: 90 nop
f: 90 nop
10: 90 nop
11: 90 nop
12: 90 nop
13: 90 nop
14: 90 nop
15: 90 nop
16: 90 nop
17: 90 nop
18: 90 nop
19: 90 nop
1a: 90 nop
1b: f3 0f 1e fa endbr64
1f: eb 07 jmp 0x28
21: 0f 00 2d 93 77 15 00 verw 0x157793(%rip) # 0x1577bb
28: fb sti
29: f4 hlt
* 2a: c3 ret <-- trapping instruction
2b: cc int3
2c: cc int3
2d: cc int3
2e: cc int3
2f: cc int3
30: cc int3
31: cc int3
32: cc int3
33: cc int3
34: cc int3
35: cc int3
36: cc int3
37: cc int3
38: cc int3
39: cc int3
3a: cc int3
3b: 90 nop
3c: 90 nop
3d: 90 nop
3e: 90 nop
3f: 90 nop
The explanation of the root cause of the bug is:
The root cause of this crash is a missing `return` statement in the command response handler, which leads to a stack-out-of-bounds write when the device sends a response that is larger than expected.
### Root Cause Analysis
When the driver sends a command to the firmware using `carl9170_exec_cmd()`, it provides an output buffer `out` (which is often a local stack variable) and its length `outlen`. The function sets up `ar->readbuf` and `ar->readlen` to point to this buffer and waits for the completion:
```c
// drivers/net/wireless/ath/carl9170/usb.c:677
spin_lock_bh(&ar->cmd_lock);
ar->readbuf = out;
ar->readlen = outlen;
spin_unlock_bh(&ar->cmd_lock);
reinit_completion(&ar->cmd_wait);
err = __carl9170_exec_cmd(ar, &ar->cmd, false);
if (!(cmd & CARL9170_CMD_ASYNC_FLAG)) {
time_left = wait_for_completion_timeout(&ar->cmd_wait, HZ);
// ...
```
When the device sends the command response back, it is handled by `carl9170_cmd_callback()`. This function checks if the received response length matches the expected length (`ar->readlen`). If it doesn't, it prints a warning and schedules a device restart:
```c
// drivers/net/wireless/ath/carl9170/rx.c:136
if (unlikely(ar->readlen != (len - 4))) {
dev_warn(&ar->udev->dev, "received invalid command response:"
"got %d, instead of %d\n", len - 4, ar->readlen);
print_hex_dump_bytes("carl9170 cmd:", DUMP_PREFIX_OFFSET,
ar->cmd_buf, (ar->cmd.hdr.len + 4) & 0x3f);
print_hex_dump_bytes("carl9170 rsp:", DUMP_PREFIX_OFFSET,
buffer, len);
/*
* Do not complete. The command times out,
* and we get a stack trace from there.
*/
carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
// BUG: Missing return statement here!
}
spin_lock(&ar->cmd_lock);
if (ar->readbuf) {
if (len >= 4)
memcpy(ar->readbuf, buffer + 4, len - 4);
ar->readbuf = NULL;
}
complete(&ar->cmd_wait);
spin_unlock(&ar->cmd_lock);
```
Because there is no `return;` statement after `carl9170_restart()`, the execution falls through to the `memcpy()`. If the received response is larger than expected (`len - 4 > ar->readlen`), the `memcpy()` will write `len - 4` bytes into `ar->readbuf`, overflowing the buffer (which is sized `ar->readlen`).
In your crash log, we can see exactly this happening:
```text
usb 4-1: received invalid command response:got 60, instead of 4
```
The driver expected a 4-byte response but received a 60-byte one. It warned about it, but then proceeded to `memcpy` 60 bytes into the 4-byte stack variable, causing the KASAN stack-out-of-bounds crash.
### The Fix
To fix this bug, you simply need to add a `return;` statement inside the `if` block. This perfectly aligns with the author's original comment right above it (`Do not complete. The command times out...`).
By returning early, `carl9170_exec_cmd()` will eventually time out, print a timeout error, and safely clean up `ar->readbuf` and `ar->readlen` under the `cmd_lock` in its `err_unbuf` error path.
```diff
--- a/drivers/net/wireless/ath/carl9170/rx.c
+++ b/drivers/net/wireless/ath/carl9170/rx.c
@@ -145,6 +145,7 @@ static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)
* and we get a stack trace from there.
*/
carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
+ return;
}
spin_lock(&ar->cmd_lock);
```
Reply: I have analyzed the crash report and the root cause explanation. The issue is indeed a missing `return;` statement in `carl9170_cmd_callback()` after calling `carl9170_restart()`.
When the device sends a response that is larger than expected, the driver correctly detects the mismatch, prints a warning, and schedules a device restart. However, because it doesn't return early, the execution falls through to the `memcpy()` call. This causes the driver to copy the oversized response into the smaller stack-allocated buffer `ar->readbuf`, leading to a KASAN stack-out-of-bounds write.
I have applied the fix by adding the missing `return;` statement.
### Code changes made:
```c
--- a/drivers/net/wireless/ath/carl9170/rx.c
+++ b/drivers/net/wireless/ath/carl9170/rx.c
@@ -145,6 +145,7 @@ static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)
* and we get a stack trace from there.
*/
carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
+ return;
}
spin_lock(&ar->cmd_lock);
```
### Why this is the best fix:
1. **Prevents Buffer Overflow:** By returning early, we completely bypass the `memcpy()` and `complete()` calls, preventing the out-of-bounds memory write.
2. **Aligns with Design Intent:** The original author explicitly commented `Do not complete. The command times out...`. Adding the `return` statement fulfills this intent. The command will now correctly time out in `carl9170_exec_cmd()`, which will safely clean up `ar->readbuf` and `ar->readlen` under the `cmd_lock` in its `err_unbuf` error path.
3. **Safe Multiple Restarts:** `carl9170_exec_cmd()` will eventually trigger another `carl9170_restart(ar, CARL9170_RR_COMMAND_TIMEOUT)` upon timeout. This is perfectly safe because `carl9170_restart()` uses an atomic counter (`atomic_inc_return(&ar->pending_restarts)`) to ignore subsequent surplus restart requests while a restart is already pending.
4. **Handles Undersized Responses:** If `len < 4`, `len - 4` will wrap around to a huge `u32` value. Since `ar->readlen` is typically small (e.g., size of a struct), the condition `ar->readlen != (len - 4)` will evaluate to true, and the function will safely return early, preventing a `memcpy()` with a huge length.
I also audited the rest of the `carl9170` driver for similar missing `return` statements after `carl9170_restart()` calls (e.g., in `carl9170_check_sequence()`, `carl9170_handle_command_response()`, `carl9170_check_queue_stop_timeout()`, etc.). All other invocations either correctly return immediately or are placed at the very end of their respective functions, meaning this specific bug was isolated to `carl9170_cmd_callback()`.
|
| 44/4 |
2026/04/29 10:09 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 7948
output: 57
thoughts: 188
Thoughts: **Analyzing a Stack-Out-of-Bounds Write**
Okay, so we've got a bug report, and it's flagged a stack-out-of-bounds write. Specifically, it's hitting in `carl9170_cmd_callback`, down in `drivers/net/wireless/ath/carl9170/rx.c`. I'm already mentally parsing that ā sounds like a command response handler in the carl9170 wireless driver's receive path. The report singles out a missing `return;` as the culprit after that `carl9170_restart` call, nested inside an `if (unlikely)` block that checks `ar->readlen != (len - 4)`.
The crucial bit, if I'm understanding this correctly, is that without the `return;` the code *continues* on to that `memcpy` where it copies the received buffer into `ar->readbuf`. And since `ar->readbuf` is smaller than `len - 4` in this conditional branch, we're talking about writing past the end of the allocated buffer. That's a classic stack overflow, right there.
Time to dive into the code. Let's fire up that `rx.c` file and pinpoint the exact line where this `memcpy` happens. We need to confirm this missing `return` is the only thing preventing the overflow. We also need to see the context surrounding those variables to understand the underlying logic. Is there a race condition? Is `ar->readlen` getting set correctly upstream? Gotta trace that through. Looks like we have some work to do.
|
| 45/4 |
2026/04/29 10:09 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/rx.c IncludeLines:true Name:carl9170_cmd_callback]
Results: map[SourceCode: 129: static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)
130: {
131: /*
132: * Some commands may have a variable response length
133: * and we cannot predict the correct length in advance.
134: * So we only check if we provided enough space for the data.
135: */
136: if (unlikely(ar->readlen != (len - 4))) {
137: dev_warn(&ar->udev->dev, "received invalid command response:"
138: "got %d, instead of %d\n", len - 4, ar->readlen);
139: print_hex_dump_bytes("carl9170 cmd:", DUMP_PREFIX_OFFSET,
140: ar->cmd_buf, (ar->cmd.hdr.len + 4) & 0x3f);
141: print_hex_dump_bytes("carl9170 rsp:", DUMP_PREFIX_OFFSET,
142: buffer, len);
143: /*
144: * Do not complete. The command times out,
145: * and we get a stack trace from there.
146: */
147: carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
148: }
149:
150: spin_lock(&ar->cmd_lock);
151: if (ar->readbuf) {
152: if (len >= 4)
153: memcpy(ar->readbuf, buffer + 4, len - 4);
154:
155: ar->readbuf = NULL;
156: }
157: complete(&ar->cmd_wait);
158: spin_unlock(&ar->cmd_lock);
159: }
SourceFile:drivers/net/wireless/ath/carl9170/rx.c]
|
| 46/4 |
2026/04/29 10:09 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 9116
output: 57
thoughts: 181
Thoughts: **Analyzing the Bug Fix: A Thought Process**
Okay, so the proposed solution is to slap a `return;` into the `if` block. The explanation claims this magically aligns with the original comment about the command timing out. My immediate thought is, "Wait a second, what about `ar->readbuf`? Does this early return even *address* that?" I need to see what happens to that buffer.
Ah, the explanation anticipates my concern. It explicitly states that by returning early, `carl9170_exec_cmd()` will eventually time out, log an error, and *then* take care of cleaning up `ar->readbuf` and `ar->readlen` within its `err_unbuf` error path, presumably under the `cmd_lock`. Sounds reasonable, assuming the error handling is robust.
Let's verify this. I need to dive into the code for `carl9170_exec_cmd()` itself. I'll need to check the `drivers/net/wireless/ath/carl9170/usb.c` file to understand the flow and confirm that the timeout mechanism and subsequent cleanup within `err_unbuf` actually functions as described. I want to see if this `return;` introduces any new race conditions or other unforeseen issues. This feels like a decent approach, but the devil is in the details, as always. Gotta check that error path carefully.
|
| 47/4 |
2026/04/29 10:09 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/usb.c IncludeLines:true Name:carl9170_exec_cmd]
Results: map[SourceCode: 659: int carl9170_exec_cmd(struct ar9170 *ar, const enum carl9170_cmd_oids cmd,
660: unsigned int plen, void *payload, unsigned int outlen, void *out)
661: {
662: int err = -ENOMEM;
663: unsigned long time_left;
664:
665: if (!IS_ACCEPTING_CMD(ar))
666: return -EIO;
667:
668: if (!(cmd & CARL9170_CMD_ASYNC_FLAG))
669: might_sleep();
670:
671: ar->cmd.hdr.len = plen;
672: ar->cmd.hdr.cmd = cmd;
673: /* writing multiple regs fills this buffer already */
674: if (plen && payload != (u8 *)(ar->cmd.data))
675: memcpy(ar->cmd.data, payload, plen);
676:
677: spin_lock_bh(&ar->cmd_lock);
678: ar->readbuf = out;
679: ar->readlen = outlen;
680: spin_unlock_bh(&ar->cmd_lock);
681:
682: reinit_completion(&ar->cmd_wait);
683: err = __carl9170_exec_cmd(ar, &ar->cmd, false);
684:
685: if (!(cmd & CARL9170_CMD_ASYNC_FLAG)) {
686: time_left = wait_for_completion_timeout(&ar->cmd_wait, HZ);
687: if (time_left == 0) {
688: err = -ETIMEDOUT;
689: goto err_unbuf;
690: }
691:
692: if (ar->readlen != outlen) {
693: err = -EMSGSIZE;
694: goto err_unbuf;
695: }
696: }
697:
698: return 0;
699:
700: err_unbuf:
701: /* Maybe the device was removed in the moment we were waiting? */
702: if (IS_STARTED(ar)) {
703: dev_err(&ar->udev->dev, "no command feedback "
704: "received (%d).\n", err);
705:
706: /* provide some maybe useful debug information */
707: print_hex_dump_bytes("carl9170 cmd: ", DUMP_PREFIX_NONE,
708: &ar->cmd, plen + 4);
709:
710: carl9170_restart(ar, CARL9170_RR_COMMAND_TIMEOUT);
711: }
712:
713: /* invalidate to avoid completing the next command prematurely */
714: spin_lock_bh(&ar->cmd_lock);
715: ar->readbuf = NULL;
716: ar->readlen = 0;
717: spin_unlock_bh(&ar->cmd_lock);
718:
719: return err;
720: }
SourceFile:drivers/net/wireless/ath/carl9170/usb.c]
|
| 48/4 |
2026/04/29 10:09 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 10634
output: 55
thoughts: 288
Thoughts: **Analyzing the Command Completion Logic**
Okay, so I'm looking at this `carl9170_exec_cmd` function, and my initial instinct is to avoid that 1-second timeout. Waiting for `HZ` is just inefficient. The question then becomes, how can I short-circuit this? Could I just complete the command immediately? Maybe I could manipulate `ar->readlen` or `ar->readbuf` to trick it?
But then I see that comment, and that's the kicker! The original developer *wanted* the timeout! They specifically designed it to time out to get a stack trace within `carl9170_exec_cmd`. This is clever, using the timeout as a debug mechanism.
Alright, so the timeout triggers "no command feedback received" and calls `carl9170_restart` with `CARL9170_RR_COMMAND_TIMEOUT`. But wait... wasn't `carl9170_cmd_callback` already calling `carl9170_restart` with `CARL9170_RR_INVALID_RSP`? Now, my biggest question is, can we call `carl9170_restart` twice without causing a problem? I'll need to check the implementation of `carl9170_restart` to see if it handles multiple calls gracefully.
|
| 49/4 |
2026/04/29 10:09 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/rx.c IncludeLines:true Name:carl9170_restart]
Results: map[SourceCode: 506: void carl9170_restart(struct ar9170 *ar, const enum carl9170_restart_reasons r)
507: {
508: carl9170_set_state_when(ar, CARL9170_STARTED, CARL9170_IDLE);
509:
510: /*
511: * Sometimes, an error can trigger several different reset events.
512: * By ignoring these *surplus* reset events, the device won't be
513: * killed again, right after it has recovered.
514: */
515: if (atomic_inc_return(&ar->pending_restarts) > 1) {
516: dev_dbg(&ar->udev->dev, "ignoring restart (%d)\n", r);
517: return;
518: }
519:
520: ieee80211_stop_queues(ar->hw);
521:
522: dev_err(&ar->udev->dev, "restart device (%d)\n", r);
523:
524: if (!WARN_ON(r == CARL9170_RR_NO_REASON) ||
525: !WARN_ON(r >= __CARL9170_RR_LAST))
526: ar->last_reason = r;
527:
528: if (!ar->registered)
529: return;
530:
531: if (!IS_ACCEPTING_CMD(ar) || ar->needs_full_reset)
532: ar->force_usb_reset = true;
533:
534: ieee80211_queue_work(ar->hw, &ar->restart_work);
535:
536: /*
537: * At this point, the device instance might have vanished/disabled.
538: * So, don't put any code which access the ar9170 struct
539: * without proper protection.
540: */
541: }
SourceFile:drivers/net/wireless/ath/carl9170/main.c]
|
| 50/4 |
2026/04/29 10:09 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 11909
output: 57
thoughts: 93
Thoughts: Okay, let me think this through.
**Analyzing the `carl9170` Driver Fix**
Right, `carl9170_restart` is designed to handle multiple calls concurrently, thanks to that clever `atomic_inc_return(&ar->pending_restarts)` construct. So, my gut feeling is that adding `return;` within that `if` block in `carl9170_cmd_callback` *is* the correct solution. It should prevent redundant actions if `carl9170_restart` is already in flight. Makes perfect sense.
Now, I need to be thorough. I want to be certain we've addressed all potential vulnerabilities in the codebase. Let me scan `carl9170_cmd_callback` again, very carefully. Are there other similar conditional statements that could lead to multiple executions or race conditions? And it's not enough to stop there, I should expand the search. I should check other related callback functions as well. I'll need to look for patterns similar to this and confirm the fix applies more broadly. Let's make sure this is a comprehensive solution, not just a band-aid.
|
| 51/4 |
2026/04/29 10:09 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/rx.c IncludeLines:true Name:carl9170_cmd_callback]
Results: map[SourceCode: 129: static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)
130: {
131: /*
132: * Some commands may have a variable response length
133: * and we cannot predict the correct length in advance.
134: * So we only check if we provided enough space for the data.
135: */
136: if (unlikely(ar->readlen != (len - 4))) {
137: dev_warn(&ar->udev->dev, "received invalid command response:"
138: "got %d, instead of %d\n", len - 4, ar->readlen);
139: print_hex_dump_bytes("carl9170 cmd:", DUMP_PREFIX_OFFSET,
140: ar->cmd_buf, (ar->cmd.hdr.len + 4) & 0x3f);
141: print_hex_dump_bytes("carl9170 rsp:", DUMP_PREFIX_OFFSET,
142: buffer, len);
143: /*
144: * Do not complete. The command times out,
145: * and we get a stack trace from there.
146: */
147: carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
148: }
149:
150: spin_lock(&ar->cmd_lock);
151: if (ar->readbuf) {
152: if (len >= 4)
153: memcpy(ar->readbuf, buffer + 4, len - 4);
154:
155: ar->readbuf = NULL;
156: }
157: complete(&ar->cmd_wait);
158: spin_unlock(&ar->cmd_lock);
159: }
SourceFile:drivers/net/wireless/ath/carl9170/rx.c]
|
| 52/4 |
2026/04/29 10:09 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 12883
output: 22
thoughts: 72
Thoughts: Okay, let me think this through.
**Analyzing Potential Logic Flaws in the Code**
Hmm, so if we're putting a `return;` statement *inside* that `if` block, that means we're intentionally skipping the `complete(&ar->cmd_wait);` call. The comment explicitly states, "Do not complete. The command times out." That makes sense, in this particular scenario. But this has me wondering: are there other instances where `carl9170_restart` is called, but we *forgot* that critical `return;`? A missing `return;` could lead to unintended consequences, potentially completing something we shouldn't have, or vice versa, causing an unexpected side effect or even a crash if we continue execution in a state we shouldn't. I need to scan the codebase for all calls to that function and verify that the `return;` statement is consistently present where intended, and absent where needed. This is about ensuring the control flow accurately reflects the timeout logic. Let's see what else the code reveals.
|
| 53/4 |
2026/04/29 10:09 |
tool |
grepper |
0m
Args: map[Expression:carl9170_restart]
Results: map[Output:drivers/net/wireless/ath/carl9170/carl9170.h=200=struct carl9170_led {
--
drivers/net/wireless/ath/carl9170/carl9170.h-209-
drivers/net/wireless/ath/carl9170/carl9170.h:210:enum carl9170_restart_reasons {
drivers/net/wireless/ath/carl9170/carl9170.h-211- CARL9170_RR_NO_REASON = 0,
--
drivers/net/wireless/ath/carl9170/carl9170.h=236=struct ar9170 {
--
drivers/net/wireless/ath/carl9170/carl9170.h-241- spinlock_t state_lock;
drivers/net/wireless/ath/carl9170/carl9170.h:242: enum carl9170_restart_reasons last_reason;
drivers/net/wireless/ath/carl9170/carl9170.h-243- bool registered;
--
drivers/net/wireless/ath/carl9170/carl9170.h=539=void carl9170_free(struct ar9170 *ar);
drivers/net/wireless/ath/carl9170/carl9170.h:540:void carl9170_restart(struct ar9170 *ar, const enum carl9170_restart_reasons r);
drivers/net/wireless/ath/carl9170/carl9170.h-541-void carl9170_ps_check(struct ar9170 *ar);
--
drivers/net/wireless/ath/carl9170/debug.c=612=static ssize_t carl9170_debugfs_bug_write(struct ar9170 *ar, const char *buf,
--
drivers/net/wireless/ath/carl9170/debug.c-652-
drivers/net/wireless/ath/carl9170/debug.c:653: carl9170_restart(ar, CARL9170_RR_USER_REQUEST);
drivers/net/wireless/ath/carl9170/debug.c-654-
--
drivers/net/wireless/ath/carl9170/main.c=442=static void carl9170_op_stop(struct ieee80211_hw *hw, bool suspend)
--
drivers/net/wireless/ath/carl9170/main.c-466-
drivers/net/wireless/ath/carl9170/main.c:467:static void carl9170_restart_work(struct work_struct *work)
drivers/net/wireless/ath/carl9170/main.c-468-{
--
drivers/net/wireless/ath/carl9170/main.c-505-
drivers/net/wireless/ath/carl9170/main.c:506:void carl9170_restart(struct ar9170 *ar, const enum carl9170_restart_reasons r)
drivers/net/wireless/ath/carl9170/main.c-507-{
--
drivers/net/wireless/ath/carl9170/main.c=543=static void carl9170_ping_work(struct work_struct *work)
--
drivers/net/wireless/ath/carl9170/main.c-553- if (err)
drivers/net/wireless/ath/carl9170/main.c:554: carl9170_restart(ar, CARL9170_RR_UNRESPONSIVE_DEVICE);
drivers/net/wireless/ath/carl9170/main.c-555- mutex_unlock(&ar->mutex);
--
drivers/net/wireless/ath/carl9170/main.c=1741=void *carl9170_alloc(size_t priv_size)
--
drivers/net/wireless/ath/carl9170/main.c-1796- INIT_WORK(&ar->ping_work, carl9170_ping_work);
drivers/net/wireless/ath/carl9170/main.c:1797: INIT_WORK(&ar->restart_work, carl9170_restart_work);
drivers/net/wireless/ath/carl9170/main.c-1798- INIT_WORK(&ar->ampdu_work, carl9170_ampdu_work);
--
drivers/net/wireless/ath/carl9170/phy.c=1570=int carl9170_set_channel(struct ar9170 *ar, struct ieee80211_channel *channel,
--
drivers/net/wireless/ath/carl9170/phy.c-1701- */
drivers/net/wireless/ath/carl9170/phy.c:1702: carl9170_restart(ar, CARL9170_RR_TOO_MANY_PHY_ERRORS);
drivers/net/wireless/ath/carl9170/phy.c-1703- return 0;
--
drivers/net/wireless/ath/carl9170/rx.c=49=static void carl9170_dbg_message(struct ar9170 *ar, const char *buf, u32 len)
--
drivers/net/wireless/ath/carl9170/rx.c-51- bool restart = false;
drivers/net/wireless/ath/carl9170/rx.c:52: enum carl9170_restart_reasons reason = CARL9170_RR_NO_REASON;
drivers/net/wireless/ath/carl9170/rx.c-53-
--
drivers/net/wireless/ath/carl9170/rx.c-72- if (restart)
drivers/net/wireless/ath/carl9170/rx.c:73: carl9170_restart(ar, reason);
drivers/net/wireless/ath/carl9170/rx.c-74-}
--
drivers/net/wireless/ath/carl9170/rx.c=96=static int carl9170_check_sequence(struct ar9170 *ar, unsigned int seq)
--
drivers/net/wireless/ath/carl9170/rx.c-120-
drivers/net/wireless/ath/carl9170/rx.c:121: carl9170_restart(ar, CARL9170_RR_LOST_RSP);
drivers/net/wireless/ath/carl9170/rx.c-122- return -EIO;
--
drivers/net/wireless/ath/carl9170/rx.c=129=static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)
--
drivers/net/wireless/ath/carl9170/rx.c-146- */
drivers/net/wireless/ath/carl9170/rx.c:147: carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
drivers/net/wireless/ath/carl9170/rx.c-148- }
--
drivers/net/wireless/ath/carl9170/rx.c=161=void carl9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len)
--
drivers/net/wireless/ath/carl9170/rx.c-238- /* Watchdog Interrupt */
drivers/net/wireless/ath/carl9170/rx.c:239: carl9170_restart(ar, CARL9170_RR_WATCHDOG);
drivers/net/wireless/ath/carl9170/rx.c-240- break;
--
drivers/net/wireless/ath/carl9170/tx.c=558=static void carl9170_check_queue_stop_timeout(struct ar9170 *ar)
--
drivers/net/wireless/ath/carl9170/tx.c-598- */
drivers/net/wireless/ath/carl9170/tx.c:599: carl9170_restart(ar, CARL9170_RR_STUCK_TX);
drivers/net/wireless/ath/carl9170/tx.c-600- }
--
drivers/net/wireless/ath/carl9170/usb.c=659=int carl9170_exec_cmd(struct ar9170 *ar, const enum carl9170_cmd_oids cmd,
--
drivers/net/wireless/ath/carl9170/usb.c-709-
drivers/net/wireless/ath/carl9170/usb.c:710: carl9170_restart(ar, CARL9170_RR_COMMAND_TIMEOUT);
drivers/net/wireless/ath/carl9170/usb.c-711- }
]
|
| 54/4 |
2026/04/29 10:09 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 15679
output: 189
thoughts: 436
Thoughts: **Analyzing the `carl9170_restart` Call**
Okay, I need to take a look at how `carl9170_restart` is being used in this driver. It looks like it's called in a few places, and my initial concern is whether it's always handled correctly. Specifically, I'm thinking about `carl9170_cmd_callback`. It seems that the function `carl9170_restart` is called without any `return` statements, which means execution continues after the restart call.
I quickly scanned other functions where `carl9170_restart` is used. In `carl9170_check_sequence`, `carl9170_dbg_message`, `carl9170_handle_command_response`, `carl9170_check_queue_stop_timeout` and `carl9170_exec_cmd`, there's a subsequent `return` or a `break` or code that clearly indicates a termination or a branch. This makes sense; a restart usually implies some error condition that needs to be handled and the current execution context needs to be aborted.
So, in the other instances of the `carl9170_restart` function call, the control flow is clearly defined after the call. The only exception I see is inside `carl9170_cmd_callback`. It looks like execution continues after calling `carl9170_restart`, potentially leading to undefined behavior or data corruption after a restart event, which is unacceptable. Let's add a `return;` statement to prevent potential issues.
|
| 55/4 |
2026/04/29 10:09 |
tool |
codeeditor |
0m
Args: map[CurrentCode: /*
* Do not complete. The command times out,
* and we get a stack trace from there.
*/
carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
}
spin_lock(&ar->cmd_lock); NewCode: /*
* Do not complete. The command times out,
* and we get a stack trace from there.
*/
carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
return;
}
spin_lock(&ar->cmd_lock); SourceFile:drivers/net/wireless/ath/carl9170/rx.c]
Results:
|
| 56/4 |
2026/04/29 10:09 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 16670
output: 59
thoughts: 55
Thoughts: Okay, here's my summary, presented as a stream of thought:
**Code Verification and Optimization Check**
Alright, that code edit landed cleanly ā good to see that validation pass. Now, before I move on, let's just make absolutely sure we've covered our bases. I need to quickly scan the codebase for any other instances where `carl9170_restart` is invoked. The primary goal is to ensure we identify any potential locations where we could optimize the flow by returning early, perhaps based on the same conditions, or any related conditions, that we're addressing in this particular function. No point in repeating work or unnecessarily complicating things. Let's start with `carl9170_handle_command_response`.
|
| 57/4 |
2026/04/29 10:09 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/rx.c IncludeLines:true Name:carl9170_handle_command_response]
Results: map[SourceCode: 161: void carl9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len)
162: {
163: struct carl9170_rsp *cmd = buf;
164: struct ieee80211_vif *vif;
165:
166: if ((cmd->hdr.cmd & CARL9170_RSP_FLAG) != CARL9170_RSP_FLAG) {
167: if (!(cmd->hdr.cmd & CARL9170_CMD_ASYNC_FLAG))
168: carl9170_cmd_callback(ar, len, buf);
169:
170: return;
171: }
172:
173: if (unlikely(cmd->hdr.len != (len - 4))) {
174: if (net_ratelimit()) {
175: wiphy_err(ar->hw->wiphy, "FW: received over-/under"
176: "sized event %x (%d, but should be %d).\n",
177: cmd->hdr.cmd, cmd->hdr.len, len - 4);
178:
179: print_hex_dump_bytes("dump:", DUMP_PREFIX_NONE,
180: buf, len);
181: }
182:
183: return;
184: }
185:
186: /* hardware event handlers */
187: switch (cmd->hdr.cmd) {
188: case CARL9170_RSP_PRETBTT:
189: /* pre-TBTT event */
190: rcu_read_lock();
191: vif = carl9170_get_main_vif(ar);
192:
193: if (!vif) {
194: rcu_read_unlock();
195: break;
196: }
197:
198: switch (vif->type) {
199: case NL80211_IFTYPE_STATION:
200: carl9170_handle_ps(ar, cmd);
201: break;
202:
203: case NL80211_IFTYPE_AP:
204: case NL80211_IFTYPE_ADHOC:
205: case NL80211_IFTYPE_MESH_POINT:
206: carl9170_update_beacon(ar, true);
207: break;
208:
209: default:
210: break;
211: }
212: rcu_read_unlock();
213:
214: break;
215:
216:
217: case CARL9170_RSP_TXCOMP:
218: /* TX status notification */
219: carl9170_tx_process_status(ar, cmd);
220: break;
221:
222: case CARL9170_RSP_BEACON_CONFIG:
223: /*
224: * (IBSS) beacon send notification
225: * bytes: 04 c2 XX YY B4 B3 B2 B1
226: *
227: * XX always 80
228: * YY always 00
229: * B1-B4 "should" be the number of send out beacons.
230: */
231: break;
232:
233: case CARL9170_RSP_ATIM:
234: /* End of Atim Window */
235: break;
236:
237: case CARL9170_RSP_WATCHDOG:
238: /* Watchdog Interrupt */
239: carl9170_restart(ar, CARL9170_RR_WATCHDOG);
240: break;
241:
242: case CARL9170_RSP_TEXT:
243: /* firmware debug */
244: carl9170_dbg_message(ar, (char *)buf + 4, len - 4);
245: break;
246:
247: case CARL9170_RSP_HEXDUMP:
248: wiphy_dbg(ar->hw->wiphy, "FW: HD %d\n", len - 4);
249: print_hex_dump_bytes("FW:", DUMP_PREFIX_NONE,
250: (char *)buf + 4, len - 4);
251: break;
252:
253: case CARL9170_RSP_RADAR:
254: if (!net_ratelimit())
255: break;
256:
257: wiphy_info(ar->hw->wiphy, "FW: RADAR! Please report this "
258: "incident to linux-wireless@vger.kernel.org !\n");
259: break;
260:
261: case CARL9170_RSP_GPIO:
262: #ifdef CONFIG_CARL9170_WPC
263: if (ar->wps.pbc) {
264: bool state = !!(cmd->gpio.gpio & cpu_to_le32(
265: AR9170_GPIO_PORT_WPS_BUTTON_PRESSED));
266:
267: if (state != ar->wps.pbc_state) {
268: ar->wps.pbc_state = state;
269: input_report_key(ar->wps.pbc, KEY_WPS_BUTTON,
270: state);
271: input_sync(ar->wps.pbc);
272: }
273: }
274: #endif /* CONFIG_CARL9170_WPC */
275: break;
276:
277: case CARL9170_RSP_BOOT:
278: complete(&ar->fw_boot_wait);
279: break;
280:
281: default:
282: wiphy_err(ar->hw->wiphy, "FW: received unhandled event %x\n",
283: cmd->hdr.cmd);
284: print_hex_dump_bytes("dump:", DUMP_PREFIX_NONE, buf, len);
285: break;
286: }
287: }
SourceFile:drivers/net/wireless/ath/carl9170/rx.c]
|
| 58/4 |
2026/04/29 10:09 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 18896
output: 55
thoughts: 1996
Thoughts: **Analyzing Potential Buffer Overflows in the carl9170 Driver**
Okay, let's break this down. My initial focus was on understanding how `carl9170_restart` is called and where execution continues after that call. The initial code review highlighted that `carl9170_restart` is called in a few places: `carl9170_handle_command_response`, `carl9170_check_queue_stop_timeout`, `carl9170_exec_cmd` and `carl9170_dbg_message`. However, in the context of the potential bug, the most interesting call was inside `carl9170_cmd_callback`.
Specifically, I zoned in on the potential issue inside `carl9170_cmd_callback` where `carl9170_restart` is called due to an invalid response, but no `return` statement followed. This, as I understand it, opens the door to a dangerous scenario; the function does not exit, and, potentially a `memcpy` operation might occur after the `carl9170_restart` call, which would be the root cause of the overflow.
Digging further, I re-examined the code in `carl9170_cmd_callback`. If an invalid response length is received, the code now calls `carl9170_restart` with `CARL9170_RR_INVALID_RSP`. The key here is the comment that states "Do not complete. The command times out, and we get a stack trace from there." I was puzzled because I didn't see where the stack trace was actually printed and I started to think that perhaps the intended stack trace was not being printed, although it was the intended behavior.
The initial thought was the stack trace might come from `carl9170_exec_cmd` during the timeout, but no trace was printed there. This prompted me to re-examine the `carl9170_restart` function. Aha! I finally found that `WARN_ON` prints a stack trace, but only under specific conditions (if `r` is `CARL9170_RR_NO_REASON` or greater than or equal to `__CARL9170_RR_LAST`). `CARL9170_RR_INVALID_RSP` which is called here doesn't meet these conditions! Therefore, no stack trace would be printed. It seems that the original comment was a bit misleading, because there is no stack trace printed, only the timeout error.
So, while the author intended to get a stack trace, the current logic doesn't achieve that. The missing `return` is indeed a bug, and that it would allow a buffer overflow to happen.
To be thorough, I then scanned for other potential vulnerabilities, specifically other `memcpy` calls. I re-checked `carl9170_handle_command_response` but found the length check there to be safe. Finally I need to check `carl9170_rx` and similar functions for potential vulnerabilities.
|
| 59/4 |
2026/04/29 10:10 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/rx.c IncludeLines:true Name:carl9170_rx]
Results: map[SourceCode:1007: void carl9170_rx(struct ar9170 *ar, void *buf, unsigned int len)
1008: {
1009: if (ar->fw.rx_stream)
1010: carl9170_rx_stream(ar, buf, len);
1011: else
1012: __carl9170_rx(ar, buf, len);
1013: }
SourceFile:drivers/net/wireless/ath/carl9170/rx.c]
|
| 60/4 |
2026/04/29 10:10 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 21792
output: 56
thoughts: 15
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and presented as if it were my own internal monologue:
**Checking a Receive Function**
Alright, time to dig in. The name, `__carl9170_rx`, immediately screams "likely a low-level driver function related to packet reception, probably specific to the Atheros AR9170 chipset." The double underscore prefix is a convention that tells me it's probably internal, not directly exposed as part of a public API. Itās likely within the driver's kernel code. I'm assuming that this is where the hardware-specific details of receiving a frame on the wireless card get translated to something the operating system can use. Now, what needs to be checked in that function? Well, the obvious suspects would include the usual suspects:
* **Error Handling:** Is it robust to a wide range of incoming packet corruption? Any checks for malformed frames, out-of-order packets, or CRC errors? Does it log these errors effectively? How does it handle buffer overruns or other potential buffer related problems?
* **Buffer Management:** I have to look into the buffer handling. Is the function using DMA correctly? Are there any potential race conditions between the DMA completion and the kernel's use of the buffer? Are memory leaks a concern? Is the buffer allocation efficient?
* **Interrupt Handling:** How is it interacting with the network card's interrupt handlers? Are interrupts being correctly acknowledged and masked? Are there any potential interrupt storms or missed interrupts? Is interrupt processing done in a timely manner?
* **Packet Processing:** The packet processing logic. Itās important to see how the received frame is parsed, its headers interpreted (MAC, IP, TCP/UDP, etc.), and the data payload extracted and passed up the stack. Any optimizations, such as zero-copy techniques, or are there any inefficiencies, such as excessive memory copies?
* **Synchronization:** Any synchronization mechanisms, like mutexes or spinlocks, used to protect shared data structures within the `__carl9170_rx` function? Are they used correctly to avoid deadlocks or race conditions?
* **Context:** What context is this function running in? Is it an interrupt context, a soft interrupt, a tasklet, or a kernel thread? This will determine the constraints on what operations are permissible. Are we using the correct locking primitives for the context we are in?
* **Performance:** Check for any performance bottlenecks. Are there any loops that could be optimized? Are there any unnecessary memory allocations or copies?
Okay, let's start by looking at those areas... and let's see what that function *actually* does.
|
| 61/4 |
2026/04/29 10:10 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/rx.c IncludeLines:true Name:__carl9170_rx]
Results: map[SourceCode: 854: static void __carl9170_rx(struct ar9170 *ar, u8 *buf, unsigned int len)
855: {
856: unsigned int i = 0;
857:
858: /* weird thing, but this is the same in the original driver */
859: while (len > 2 && i < 12 && buf[0] == 0xff && buf[1] == 0xff) {
860: i += 2;
861: len -= 2;
862: buf += 2;
863: }
864:
865: if (unlikely(len < 4))
866: return;
867:
868: /* found the 6 * 0xffff marker? */
869: if (i == 12)
870: carl9170_rx_untie_cmds(ar, buf, len);
871: else
872: carl9170_rx_untie_data(ar, buf, len);
873: }
SourceFile:drivers/net/wireless/ath/carl9170/rx.c]
|
| 62/4 |
2026/04/29 10:10 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 22792
output: 60
thoughts: 19
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, and delivered as if they were my own:
**Analyzing `carl9170_rx_untie_cmds`**
Alright, time to dive into `carl9170_rx_untie_cmds`. That name itself is a pretty big clue, suggesting it's directly tied to the reception process in a `carl9170` context, specifically addressing the "untie" or de-coupling of some command structure relating to receiving data. This likely has to do with how the driver handles potentially out-of-order packets, fragmented data, or other complexities of the receive path. We have to understand this function because it's in the critical path of all the received packets.
I'm immediately thinking about the potential for race conditions here. Are we dealing with shared data structures, spinlocks, or other synchronization primitives? The use of the word "untie" makes me wonder if there's some kind of initial binding or association happening, and this function is responsible for releasing that relationship. Perhaps it's untangling DMA descriptors, freeing up buffers, or notifying higher layers of the stack about a completed frame. I'll have to investigate the surrounding code to determine how this happens. The potential for memory leaks or corruption is always there, especially if we have asynchronous operations.
Let's begin by looking for the definition.
|
| 63/4 |
2026/04/29 10:10 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/rx.c IncludeLines:true Name:carl9170_rx_untie_cmds]
Results: map[SourceCode: 825: static void carl9170_rx_untie_cmds(struct ar9170 *ar, const u8 *respbuf,
826: const unsigned int resplen)
827: {
828: struct carl9170_rsp *cmd;
829: int i = 0;
830:
831: while (i < resplen) {
832: cmd = (void *) &respbuf[i];
833:
834: i += cmd->hdr.len + 4;
835: if (unlikely(i > resplen))
836: break;
837:
838: if (carl9170_check_sequence(ar, cmd->hdr.seq))
839: break;
840:
841: carl9170_handle_command_response(ar, cmd, cmd->hdr.len + 4);
842: }
843:
844: if (unlikely(i != resplen)) {
845: if (!net_ratelimit())
846: return;
847:
848: wiphy_err(ar->hw->wiphy, "malformed firmware trap:\n");
849: print_hex_dump_bytes("rxcmd:", DUMP_PREFIX_OFFSET,
850: respbuf, resplen);
851: }
852: }
SourceFile:drivers/net/wireless/ath/carl9170/rx.c]
|
| 64/4 |
2026/04/29 10:10 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 23633
output: 60
thoughts: 61
Thoughts: Okay, let's dive into this code.
**Analyzing `carl9170_rx_untie_cmds` and `carl9170_rx_untie_data`**
Alright, I'm taking a look at these functions. Specifically, I'm focusing on the logic within `carl9170_rx_untie_cmds`. From what I see, it appears to be iterating through the command buffer. The critical part is this conditional: `i > resplen`. It's essential to understand this: `resplen` is likely the length of the response buffer. The loop condition effectively enforces a bound check, ensuring we don't read beyond the allocated space. It's a fundamental safety measure, and as far as I can see, it seems sound.
Now, my next move is to pivot and analyze the `carl9170_rx_untie_data` function. I need to understand how the data handling is implemented there, to have a complete picture. Are there similar checks? Are they consistent with the approach used in `carl9170_rx_untie_cmds`? I need to verify that we're maintaining the same safety guarantees when processing the data as we did when processing the commands. It's all about consistent error handling and protecting against buffer overflows and memory corruption. Let's see what's in `carl9170_rx_untie_data`.
|
| 65/4 |
2026/04/29 10:10 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/rx.c IncludeLines:true Name:carl9170_rx_untie_data]
Results: map[SourceCode: 688: /*
689: * If the frame alignment is right (or the kernel has
690: * CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS), and there
691: * is only a single MPDU in the USB frame, then we could
692: * submit to mac80211 the SKB directly. However, since
693: * there may be multiple packets in one SKB in stream
694: * mode, and we need to observe the proper ordering,
695: * this is non-trivial.
696: */
697: static void carl9170_rx_untie_data(struct ar9170 *ar, u8 *buf, int len)
698: {
699: struct ar9170_rx_head *head;
700: struct ar9170_rx_macstatus *mac;
701: struct ar9170_rx_phystatus *phy = NULL;
702: struct ieee80211_rx_status status;
703: int mpdu_len;
704: u8 mac_status;
705:
706: if (!IS_STARTED(ar))
707: return;
708:
709: if (unlikely(len < sizeof(*mac)))
710: goto drop;
711:
712: memset(&status, 0, sizeof(status));
713:
714: mpdu_len = len - sizeof(*mac);
715:
716: mac = (void *)(buf + mpdu_len);
717: mac_status = mac->status;
718: switch (mac_status & AR9170_RX_STATUS_MPDU) {
719: case AR9170_RX_STATUS_MPDU_FIRST:
720: ar->ampdu_ref++;
721: /* Aggregated MPDUs start with an PLCP header */
722: if (likely(mpdu_len >= sizeof(struct ar9170_rx_head))) {
723: head = (void *) buf;
724:
725: /*
726: * The PLCP header needs to be cached for the
727: * following MIDDLE + LAST A-MPDU packets.
728: *
729: * So, if you are wondering why all frames seem
730: * to share a common RX status information,
731: * then you have the answer right here...
732: */
733: memcpy(&ar->rx_plcp, (void *) buf,
734: sizeof(struct ar9170_rx_head));
735:
736: mpdu_len -= sizeof(struct ar9170_rx_head);
737: buf += sizeof(struct ar9170_rx_head);
738:
739: ar->rx_has_plcp = true;
740: } else {
741: if (net_ratelimit()) {
742: wiphy_err(ar->hw->wiphy, "plcp info "
743: "is clipped.\n");
744: }
745:
746: goto drop;
747: }
748: break;
749:
750: case AR9170_RX_STATUS_MPDU_LAST:
751: status.flag |= RX_FLAG_AMPDU_IS_LAST;
752:
753: /*
754: * The last frame of an A-MPDU has an extra tail
755: * which does contain the phy status of the whole
756: * aggregate.
757: */
758: if (likely(mpdu_len >= sizeof(struct ar9170_rx_phystatus))) {
759: mpdu_len -= sizeof(struct ar9170_rx_phystatus);
760: phy = (void *)(buf + mpdu_len);
761: } else {
762: if (net_ratelimit()) {
763: wiphy_err(ar->hw->wiphy, "frame tail "
764: "is clipped.\n");
765: }
766:
767: goto drop;
768: }
769: fallthrough;
770:
771: case AR9170_RX_STATUS_MPDU_MIDDLE:
772: /* These are just data + mac status */
773: if (unlikely(!ar->rx_has_plcp)) {
774: if (!net_ratelimit())
775: return;
776:
777: wiphy_err(ar->hw->wiphy, "rx stream does not start "
778: "with a first_mpdu frame tag.\n");
779:
780: goto drop;
781: }
782:
783: head = &ar->rx_plcp;
784: break;
785:
786: case AR9170_RX_STATUS_MPDU_SINGLE:
787: /* single mpdu has both: plcp (head) and phy status (tail) */
788: head = (void *) buf;
789:
790: mpdu_len -= sizeof(struct ar9170_rx_head);
791: mpdu_len -= sizeof(struct ar9170_rx_phystatus);
792:
793: buf += sizeof(struct ar9170_rx_head);
794: phy = (void *)(buf + mpdu_len);
795: break;
796:
797: default:
798: BUG();
799: break;
800: }
801:
802: /* FC + DU + RA + FCS */
803: if (unlikely(mpdu_len < (2 + 2 + ETH_ALEN + FCS_LEN)))
804: goto drop;
805:
806: if (unlikely(carl9170_rx_mac_status(ar, head, mac, &status)))
807: goto drop;
808:
809: if (!carl9170_ampdu_check(ar, buf, mac_status, &status))
810: goto drop;
811:
812: if (phy)
813: carl9170_rx_phy_status(ar, phy, &status);
814: else
815: status.flag |= RX_FLAG_NO_SIGNAL_VAL;
816:
817: if (carl9170_handle_mpdu(ar, buf, mpdu_len, &status))
818: goto drop;
819:
820: return;
821: drop:
822: ar->rx_dropped++;
823: }
SourceFile:drivers/net/wireless/ath/carl9170/rx.c]
|
| 66/4 |
2026/04/29 10:10 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 26129
output: 57
thoughts: 45
Thoughts: Okay, here's my take on those thoughts, framed as my own mental processing:
**Analyzing the RX Path: A Quick Safety Check**
Right, let's see, the initial thought process is focusing on packet processing in the `carl9170` driver. I see that the function `carl9170_rx_untie_data` has a solid first step: length checks. It's good to see that invalid lengths trigger a drop; that's the expected and safe behavior we need to prevent any buffer overflows or malformed packets from causing issues down the line. I always appreciate proactive error handling like that in a critical path.
Now, that part seems solid, a good start. Let me shift my focus to the next stage, the `carl9170_rx_stream` function. That's the next point in the data flow, and where I should be concentrating next.
|
| 67/4 |
2026/04/29 10:10 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/rx.c IncludeLines:true Name:carl9170_rx_stream]
Results: map[SourceCode: 875: static void carl9170_rx_stream(struct ar9170 *ar, void *buf, unsigned int len)
876: {
877: unsigned int tlen, wlen = 0, clen = 0;
878: struct ar9170_stream *rx_stream;
879: u8 *tbuf;
880:
881: tbuf = buf;
882: tlen = len;
883:
884: while (tlen >= 4) {
885: rx_stream = (void *) tbuf;
886: clen = le16_to_cpu(rx_stream->length);
887: wlen = ALIGN(clen, 4);
888:
889: /* check if this is stream has a valid tag.*/
890: if (rx_stream->tag != cpu_to_le16(AR9170_RX_STREAM_TAG)) {
891: /*
892: * TODO: handle the highly unlikely event that the
893: * corrupted stream has the TAG at the right position.
894: */
895:
896: /* check if the frame can be repaired. */
897: if (!ar->rx_failover_missing) {
898:
899: /* this is not "short read". */
900: if (net_ratelimit()) {
901: wiphy_err(ar->hw->wiphy,
902: "missing tag!\n");
903: }
904:
905: __carl9170_rx(ar, tbuf, tlen);
906: return;
907: }
908:
909: if (ar->rx_failover_missing > tlen) {
910: if (net_ratelimit()) {
911: wiphy_err(ar->hw->wiphy,
912: "possible multi "
913: "stream corruption!\n");
914: goto err_telluser;
915: } else {
916: goto err_silent;
917: }
918: }
919:
920: skb_put_data(ar->rx_failover, tbuf, tlen);
921: ar->rx_failover_missing -= tlen;
922:
923: if (ar->rx_failover_missing <= 0) {
924: /*
925: * nested carl9170_rx_stream call!
926: *
927: * termination is guaranteed, even when the
928: * combined frame also have an element with
929: * a bad tag.
930: */
931:
932: ar->rx_failover_missing = 0;
933: carl9170_rx_stream(ar, ar->rx_failover->data,
934: ar->rx_failover->len);
935:
936: skb_reset_tail_pointer(ar->rx_failover);
937: skb_trim(ar->rx_failover, 0);
938: }
939:
940: return;
941: }
942:
943: /* check if stream is clipped */
944: if (wlen > tlen - 4) {
945: if (ar->rx_failover_missing) {
946: /* TODO: handle double stream corruption. */
947: if (net_ratelimit()) {
948: wiphy_err(ar->hw->wiphy, "double rx "
949: "stream corruption!\n");
950: goto err_telluser;
951: } else {
952: goto err_silent;
953: }
954: }
955:
956: /*
957: * save incomplete data set.
958: * the firmware will resend the missing bits when
959: * the rx - descriptor comes round again.
960: */
961:
962: skb_put_data(ar->rx_failover, tbuf, tlen);
963: ar->rx_failover_missing = clen - tlen;
964: return;
965: }
966: __carl9170_rx(ar, rx_stream->payload, clen);
967:
968: tbuf += wlen + 4;
969: tlen -= wlen + 4;
970: }
971:
972: if (tlen) {
973: if (net_ratelimit()) {
974: wiphy_err(ar->hw->wiphy, "%d bytes of unprocessed "
975: "data left in rx stream!\n", tlen);
976: }
977:
978: goto err_telluser;
979: }
980:
981: return;
982:
983: err_telluser:
984: wiphy_err(ar->hw->wiphy, "damaged RX stream data [want:%d, "
985: "data:%d, rx:%d, pending:%d ]\n", clen, wlen, tlen,
986: ar->rx_failover_missing);
987:
988: if (ar->rx_failover_missing)
989: print_hex_dump_bytes("rxbuf:", DUMP_PREFIX_OFFSET,
990: ar->rx_failover->data,
991: ar->rx_failover->len);
992:
993: print_hex_dump_bytes("stream:", DUMP_PREFIX_OFFSET,
994: buf, len);
995:
996: wiphy_err(ar->hw->wiphy, "please check your hardware and cables, if "
997: "you see this message frequently.\n");
998:
999: err_silent:
1000: if (ar->rx_failover_missing) {
1001: skb_reset_tail_pointer(ar->rx_failover);
1002: skb_trim(ar->rx_failover, 0);
1003: ar->rx_failover_missing = 0;
1004: }
1005: }
SourceFile:drivers/net/wireless/ath/carl9170/rx.c]
|
| 68/4 |
2026/04/29 10:10 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 28350
output: 58
thoughts: 1235
Thoughts: **Analyzing Potential Corruption in carl9170_rx_stream**
Okay, I'm diving into this `carl9170_rx_stream` function, and something's immediately jumping out at me. Specifically, that check for `wlen > tlen - 4`. `wlen` is the aligned stream length, and `tlen` is the remaining buffer length. If that condition is true, we have a clipped stream. The code then attempts to handle this with `rx_failover`.
Here's the bit that's snagging my attention: the calculation of `ar->rx_failover_missing`. It's set to `clen - tlen`. Now, `clen` comes from `rx_stream->length`, which is a little-endian 16-bit value converted to CPU endianness. `tlen` is simply the remaining length in the buffer. `wlen` is the 4-byte aligned version of `clen`.
The question that pops into my head is, should `ar->rx_failover_missing` really be `clen - tlen`? It seems like a potential off-by-4 error. Let me think this through carefully.
`clen` represents the *payload* length according to the documentation, I'm pretty sure. The header itself is 4 bytes. So, if `tlen` is the *remaining* length, which *includes* the 4-byte header, then the amount of missing payload should be the total intended length including the header minus what we've received, or `(clen + 4) - tlen`.
But the code is doing `clen - tlen`. That would be off by exactly 4.
I need to make sure my logic is correct and double check my assumption here. I'm going to look at how `rx_failover_missing` is *used* later on. Specifically, the following snippet:
```c
if (rx_stream->tag != cpu_to_le16(AR9170_RX_STREAM_TAG)) {
/* ... */
if (ar->rx_failover_missing > tlen) {
/* ... */
}
skb_put_data(ar->rx_failover, tbuf, tlen);
ar->rx_failover_missing -= tlen;
```
Okay, it looks like `ar->rx_failover_missing` is checked to determine if the *next* received chunk has enough data to complete the stream. Then it's decremented by `tlen`. If the first setting of `ar->rx_failover_missing` is `clen - tlen`, that is off by exactly 4 as determined earlier.
So, if my understanding is correct, this is probably a bug. Specifically, it looks like it is off by exactly 4 bytes. I need to investigate further to confirm if this is a known issue or an unreported one. I'll need to check the definition of `AR9170_RX_STREAM_TAG`.
|
| 69/4 |
2026/04/29 10:11 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/rx.c IncludeLines:true Name:AR9170_RX_STREAM_TAG]
Results: map[SourceCode: SourceFile:]
|
| 70/4 |
2026/04/29 10:11 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 30339
output: 25
thoughts: 12
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Identifying and Locating the Macro**
Okay, so this is about a macro. That's the starting point. My initial thought process is geared toward rapid identification and localization. Given my experience, I'm already mentally running through potential avenues: the obvious candidates like `\newcommand`, `\def`, `\newenvironment`, and more esoteric options like those constructed through packages. The context would certainly influence my approach here. Are we looking at a document, a package, or something else entirely? A quick search strategy is immediately forming in my mind. Keywords, regular expressions... it all depends on the scale and complexity I'm expecting. The key is to find this sucker, quickly and efficiently.
|
| 71/4 |
2026/04/29 10:11 |
tool |
grepper |
0m
Args: map[Expression:AR9170_RX_STREAM_TAG]
Results: map[Output:drivers/net/wireless/ath/carl9170/hw.h=835=enum ar9170_tx_queues {
--
drivers/net/wireless/ath/carl9170/hw.h-846-#define AR9170_TX_STREAM_TAG 0x697e
drivers/net/wireless/ath/carl9170/hw.h:847:#define AR9170_RX_STREAM_TAG 0x4e00
drivers/net/wireless/ath/carl9170/hw.h-848-#define AR9170_RX_STREAM_MAX_SIZE 0xffff
--
drivers/net/wireless/ath/carl9170/rx.c=875=static void carl9170_rx_stream(struct ar9170 *ar, void *buf, unsigned int len)
--
drivers/net/wireless/ath/carl9170/rx.c-889- /* check if this is stream has a valid tag.*/
drivers/net/wireless/ath/carl9170/rx.c:890: if (rx_stream->tag != cpu_to_le16(AR9170_RX_STREAM_TAG)) {
drivers/net/wireless/ath/carl9170/rx.c-891- /*
]
|
| 72/4 |
2026/04/29 10:11 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 30892
output: 54
thoughts: 14
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into `ar9170_stream`**
Okay, time to get my hands dirty. I need to understand the data flow within the AR9170 driver, so I'm going to start by examining the `struct ar9170_stream` structure. This is where the core of the data handling probably resides. I'm expecting this structure to contain pointers to buffers, potentially tracking state like transmit or receive queues, and definitely some synchronization primitives, like mutexes or semaphores, to manage concurrent access. Iām also looking for counters to track packets, errors, and possibly statistics. I'll need to pay close attention to the definition of this structure, the field names, and data types. Knowing these fields will allow me to build a stronger mental model of how data is passed and processed, and likely reveal the bottlenecks in the stream or other potential points of improvement.
|
| 73/4 |
2026/04/29 10:11 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/net/wireless/ath/carl9170/hw.h IncludeLines:true Name:ar9170_stream]
Results: map[SourceCode: 850: struct ar9170_stream {
851: __le16 length;
852: __le16 tag;
853:
854: u8 payload[];
855: } __packed __aligned(4);
SourceFile:drivers/net/wireless/ath/carl9170/hw.h]
|
| 74/4 |
2026/04/29 10:11 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 31284
output: 23
thoughts: 1405
Thoughts: **Reviewing the `carl9170_cmd_callback` Fix and Related Code**
Okay, so `length` is the payload length, got it. The `ar->rx_failover_missing = clen - tlen;` line, that's a potential separate bug, but not the current focus. The core issue is that missing `return;` in `carl9170_cmd_callback`. I've already put the `return;` in that function. Let me walk through my understanding of the fix and what's around it.
Specifically, inside the `carl9170_cmd_callback` function, there's this block that needs attention:
```c
if (unlikely(ar->readlen != (len - 4))) {
dev_warn(&ar->udev->dev, "received invalid command response:"
"got %d, instead of %d\n", len - 4, ar->readlen);
print_hex_dump_bytes("carl9170 cmd:", DUMP_PREFIX_OFFSET,
ar->cmd_buf, (ar->cmd.hdr.len + 4) & 0x3f);
print_hex_dump_bytes("carl9170 rsp:", DUMP_PREFIX_OFFSET,
buffer, len);
/*
* Do not complete. The command times out,
* and we get a stack trace from there.
*/
carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
// Missing return; here
}
```
Okay, the fix is straightforward. If the received response length doesn't match the expected length, print a warning, dump some hex, and restart the device. The critical part is *not* completing the command and letting it timeout, which the original comment indicates. The missing `return;` ensures the code doesn't proceed to incorrectly complete the command. The fix is to add that `return;`
Now, is there anywhere else in this function that's problematic? Looking at the spinlock-protected section:
```c
spin_lock(&ar->cmd_lock);
if (ar->readbuf) {
if (len >= 4)
memcpy(ar->readbuf, buffer + 4, len - 4);
ar->readbuf = NULL;
}
complete(&ar->cmd_wait);
spin_unlock(&ar->cmd_lock);
```
If `len` is less than 4, the `memcpy` isn't called, which is fine, but the `ar->readlen != (len - 4)` check will be triggered due to unsigned integer wrap-around. So this will return from the above block. Let me think about that unsigned integer wrap around. If `len < 4`, then `len - 4` is a very large number, and the test should catch it.
Let's think. If `len` is 0, then `len - 4` would be `0xFFFFFFFC`. If `ar->readlen` is also a huge number, this could cause a bypass of the early return. It's theoretically possible that `ar->readlen` and `len - 4` are the same (huge number) and the check is bypassed. But `ar->readlen` is initialized in `carl9170_exec_cmd` from `outlen`, which is the command length and should usually be small. It *should* be fine.
Now, let's look for other instances where `carl9170_restart` is called without an immediate `return;`. In `carl9170_rx_stream`, I see:
```c
if (wlen > tlen - 4) {
if (ar->rx_failover_missing) {
/* TODO: handle double stream corruption. */
if (net_ratelimit()) {
wiphy_err(ar->hw->wiphy, "double rx "
"stream corruption!\n");
goto err_telluser;
} else {
goto err_silent;
}
}
```
This looks okay, there's a `goto` instead of a `return`, which is valid.
In `carl9170_rx_untie_data`:
```c
if (unlikely(len < sizeof(*mac)))
goto drop;
```
Also fine, using a `goto`.
Back to the `carl917
|
| 75/4 |
2026/04/29 10:11 |
tool |
grepper |
0m
Args: map[Expression:carl9170_restart.*]
Results: map[Output:drivers/net/wireless/ath/carl9170/carl9170.h=200=struct carl9170_led {
--
drivers/net/wireless/ath/carl9170/carl9170.h-209-
drivers/net/wireless/ath/carl9170/carl9170.h:210:enum carl9170_restart_reasons {
drivers/net/wireless/ath/carl9170/carl9170.h-211- CARL9170_RR_NO_REASON = 0,
--
drivers/net/wireless/ath/carl9170/carl9170.h=236=struct ar9170 {
--
drivers/net/wireless/ath/carl9170/carl9170.h-241- spinlock_t state_lock;
drivers/net/wireless/ath/carl9170/carl9170.h:242: enum carl9170_restart_reasons last_reason;
drivers/net/wireless/ath/carl9170/carl9170.h-243- bool registered;
--
drivers/net/wireless/ath/carl9170/carl9170.h=539=void carl9170_free(struct ar9170 *ar);
drivers/net/wireless/ath/carl9170/carl9170.h:540:void carl9170_restart(struct ar9170 *ar, const enum carl9170_restart_reasons r);
drivers/net/wireless/ath/carl9170/carl9170.h-541-void carl9170_ps_check(struct ar9170 *ar);
--
drivers/net/wireless/ath/carl9170/debug.c=612=static ssize_t carl9170_debugfs_bug_write(struct ar9170 *ar, const char *buf,
--
drivers/net/wireless/ath/carl9170/debug.c-652-
drivers/net/wireless/ath/carl9170/debug.c:653: carl9170_restart(ar, CARL9170_RR_USER_REQUEST);
drivers/net/wireless/ath/carl9170/debug.c-654-
--
drivers/net/wireless/ath/carl9170/main.c=442=static void carl9170_op_stop(struct ieee80211_hw *hw, bool suspend)
--
drivers/net/wireless/ath/carl9170/main.c-466-
drivers/net/wireless/ath/carl9170/main.c:467:static void carl9170_restart_work(struct work_struct *work)
drivers/net/wireless/ath/carl9170/main.c-468-{
--
drivers/net/wireless/ath/carl9170/main.c-505-
drivers/net/wireless/ath/carl9170/main.c:506:void carl9170_restart(struct ar9170 *ar, const enum carl9170_restart_reasons r)
drivers/net/wireless/ath/carl9170/main.c-507-{
--
drivers/net/wireless/ath/carl9170/main.c=543=static void carl9170_ping_work(struct work_struct *work)
--
drivers/net/wireless/ath/carl9170/main.c-553- if (err)
drivers/net/wireless/ath/carl9170/main.c:554: carl9170_restart(ar, CARL9170_RR_UNRESPONSIVE_DEVICE);
drivers/net/wireless/ath/carl9170/main.c-555- mutex_unlock(&ar->mutex);
--
drivers/net/wireless/ath/carl9170/main.c=1741=void *carl9170_alloc(size_t priv_size)
--
drivers/net/wireless/ath/carl9170/main.c-1796- INIT_WORK(&ar->ping_work, carl9170_ping_work);
drivers/net/wireless/ath/carl9170/main.c:1797: INIT_WORK(&ar->restart_work, carl9170_restart_work);
drivers/net/wireless/ath/carl9170/main.c-1798- INIT_WORK(&ar->ampdu_work, carl9170_ampdu_work);
--
drivers/net/wireless/ath/carl9170/phy.c=1570=int carl9170_set_channel(struct ar9170 *ar, struct ieee80211_channel *channel,
--
drivers/net/wireless/ath/carl9170/phy.c-1701- */
drivers/net/wireless/ath/carl9170/phy.c:1702: carl9170_restart(ar, CARL9170_RR_TOO_MANY_PHY_ERRORS);
drivers/net/wireless/ath/carl9170/phy.c-1703- return 0;
--
drivers/net/wireless/ath/carl9170/rx.c=49=static void carl9170_dbg_message(struct ar9170 *ar, const char *buf, u32 len)
--
drivers/net/wireless/ath/carl9170/rx.c-51- bool restart = false;
drivers/net/wireless/ath/carl9170/rx.c:52: enum carl9170_restart_reasons reason = CARL9170_RR_NO_REASON;
drivers/net/wireless/ath/carl9170/rx.c-53-
--
drivers/net/wireless/ath/carl9170/rx.c-72- if (restart)
drivers/net/wireless/ath/carl9170/rx.c:73: carl9170_restart(ar, reason);
drivers/net/wireless/ath/carl9170/rx.c-74-}
--
drivers/net/wireless/ath/carl9170/rx.c=96=static int carl9170_check_sequence(struct ar9170 *ar, unsigned int seq)
--
drivers/net/wireless/ath/carl9170/rx.c-120-
drivers/net/wireless/ath/carl9170/rx.c:121: carl9170_restart(ar, CARL9170_RR_LOST_RSP);
drivers/net/wireless/ath/carl9170/rx.c-122- return -EIO;
--
drivers/net/wireless/ath/carl9170/rx.c=129=static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)
--
drivers/net/wireless/ath/carl9170/rx.c-146- */
drivers/net/wireless/ath/carl9170/rx.c:147: carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
drivers/net/wireless/ath/carl9170/rx.c-148- }
--
drivers/net/wireless/ath/carl9170/rx.c=161=void carl9170_handle_command_response(struct ar9170 *ar, void *buf, u32 len)
--
drivers/net/wireless/ath/carl9170/rx.c-238- /* Watchdog Interrupt */
drivers/net/wireless/ath/carl9170/rx.c:239: carl9170_restart(ar, CARL9170_RR_WATCHDOG);
drivers/net/wireless/ath/carl9170/rx.c-240- break;
--
drivers/net/wireless/ath/carl9170/tx.c=558=static void carl9170_check_queue_stop_timeout(struct ar9170 *ar)
--
drivers/net/wireless/ath/carl9170/tx.c-598- */
drivers/net/wireless/ath/carl9170/tx.c:599: carl9170_restart(ar, CARL9170_RR_STUCK_TX);
drivers/net/wireless/ath/carl9170/tx.c-600- }
--
drivers/net/wireless/ath/carl9170/usb.c=659=int carl9170_exec_cmd(struct ar9170 *ar, const enum carl9170_cmd_oids cmd,
--
drivers/net/wireless/ath/carl9170/usb.c-709-
drivers/net/wireless/ath/carl9170/usb.c:710: carl9170_restart(ar, CARL9170_RR_COMMAND_TIMEOUT);
drivers/net/wireless/ath/carl9170/usb.c-711- }
]
|
| 76/4 |
2026/04/29 10:11 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 36214
output: 783
thoughts: 2031
Thoughts: **Code Review and Bug Fix for `carl9170_cmd_callback`**
Okay, let's go through this systematically. I started by examining all the call sites of `carl9170_restart` to get a handle on the overall error handling strategy in this driver. I checked `carl9170_debugfs_bug_write`, `carl9170_ping_work`, `carl9170_set_channel`, `carl9170_dbg_message`, `carl9170_check_sequence`, `carl9170_handle_command_response`, `carl9170_check_queue_stop_timeout`, and `carl9170_exec_cmd`. Each seemed to handle its respective error condition correctly, typically by restarting the device.
Then, I focused on the specific function in question: `carl9170_cmd_callback`. The critical section I zeroed in on was where the driver processes a command response:
```c
if (unlikely(ar->readlen != (len - 4))) {
dev_warn(&ar->udev->dev, "received invalid command response:"
"got %d, instead of %d\n", len - 4, ar->readlen);
print_hex_dump_bytes("carl9170 cmd:", DUMP_PREFIX_OFFSET,
ar->cmd_buf, (ar->cmd.hdr.len + 4) & 0x3f);
print_hex_dump_bytes("carl9170 rsp:", DUMP_PREFIX_OFFSET,
buffer, len);
/*
* Do not complete. The command times out,
* and we get a stack trace from there.
*/
carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
return;
}
spin_lock(&ar->cmd_lock);
if (ar->readbuf) {
if (len >= 4)
memcpy(ar->readbuf, buffer + 4, len - 4);
ar->readbuf = NULL;
}
complete(&ar->cmd_wait);
spin_unlock(&ar->cmd_lock);
```
The bug was staring me in the face: if `ar->readlen` does not equal `len - 4`, the code calls `carl9170_restart`, indicating an invalid response. However, it *didn't* return immediately. This meant execution flowed into the `memcpy` which could cause a stack out of bounds write.
The fix is straightforward: add a `return;` *after* the `carl9170_restart` call. This aligns with the comment in the code, indicating that the command should time out in this scenario, so that a stack trace is created. Returning immediately ensures that the problematic `memcpy` is skipped, preventing the crash.
After adding the fix, I then meticulously re-evaluated the `memcpy` logic, especially the case where `len < 4`. I confirmed that the check for `ar->readlen != (len - 4)` would prevent this case too. Even if `len` is less than 4, `len - 4` will wrap around and create a large value. The `if` condition will always be true in that case and return early.
Then, I looked at other places in the code where `len` was used without any kind of bounds check. I confirmed that no similar issues exist.
Given these considerations, I am confident that adding the `return` statement in `carl9170_cmd_callback` resolves the identified issue and produces no regressions. It properly handles all cases in `carl9170_cmd_callback`, preventing out-of-bounds writes. The fix is now complete.
|
| 77/3 |
2026/04/29 10:12 |
action |
test-patch |
17m
Results: map[PatchDiff:diff --git a/drivers/net/wireless/ath/carl9170/rx.c b/drivers/net/wireless/ath/carl9170/rx.c
index 683343013..ea3f435fb 100644
--- a/drivers/net/wireless/ath/carl9170/rx.c
+++ b/drivers/net/wireless/ath/carl9170/rx.c
@@ -145,6 +145,7 @@ static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)
* and we get a stack trace from there.
*/
carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
+ return;
}
spin_lock(&ar->cmd_lock);
TestError:]
|
| 78/1 |
2026/04/29 10:30 |
action |
get-maintainers |
0m
Results: map[Recipients:[map[Email:chunkeey@googlemail.com Name:Christian Lamparter To:true] map[Email:linux-kernel@vger.kernel.org Name: To:false] map[Email:linux-wireless@vger.kernel.org Name: To:true]]]
|
| 79/1 |
2026/04/29 10:30 |
action |
get-recent-commits |
0m
Results: map[RecentCommits:wifi: mac80211: support parsing S1G TIM PVB
carl9170: Use fallthrough pseudo-keyword
wireless: carl9170: fix clang build warning
carl9170: clean up a clamp() call
carl9170: rx: mark expected switch fall-through
networking: introduce and use skb_put_data()
mac80211: separate encoding/bandwidth from flags
mac80211: clean up rate encoding bits in RX status
cfg80211: remove enum ieee80211_band
carl9170: fix bad rssi reading
carl9170: Remove casts of pointer to same type
carl9170: use ath_is_mybeacon
wireless: delete non-required instances of include <linux/init.h>
carl9170: use ether_addr_equal_64bits
drivers/net: Convert uses of compare_ether_addr to ether_addr_equal
carl9170: fix copy and paste mishap in carl9170_handle_mpdu
carl9170: fix signal strength reporting issues
carl9170: split up carl9170_handle_mpdu
carl9170: handle traps from firmware loader
carl9170: report A-MPDU status
]
|
| 80/1 |
2026/04/29 10:30 |
agent |
description-generator |
0m
Model:
Instruction:
You are an experienced Linux kernel developer tasked with writing a commit description for
a kernel bug fixing commit. The description should start with a one-line summary,
and then include description of the bug being fixed, and how it's fixed by the provided patch.
Your final reply should contain only the text of the commit description.
Phrase the one-line summary so that it is not longer than 72 characters.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash that corresponds to the bug is:
usb 4-1: received invalid command response:got -2, instead of 0
usb 4-1: received invalid command response:got 60, instead of 4
==================================================================
BUG: KASAN: stack-out-of-bounds in carl9170_cmd_callback drivers/net/wireless/ath/carl9170/rx.c:153 [inline]
BUG: KASAN: stack-out-of-bounds in carl9170_handle_command_response+0x21c/0x11b0 drivers/net/wireless/ath/carl9170/rx.c:168
Write of size 60 at addr ffffc900002c7930 by task swapper/1/0
CPU: 1 UID: 0 PID: 0 Comm: swapper/1 Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<IRQ>
dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
print_address_description+0x55/0x1e0 mm/kasan/report.c:378
print_report+0x58/0x70 mm/kasan/report.c:482
kasan_report+0x117/0x150 mm/kasan/report.c:595
check_region_inline mm/kasan/generic.c:-1 [inline]
kasan_check_range+0x264/0x2c0 mm/kasan/generic.c:200
__asan_memcpy+0x40/0x70 mm/kasan/shadow.c:106
carl9170_cmd_callback drivers/net/wireless/ath/carl9170/rx.c:153 [inline]
carl9170_handle_command_response+0x21c/0x11b0 drivers/net/wireless/ath/carl9170/rx.c:168
carl9170_usb_rx_irq_complete+0xce/0x1a0 drivers/net/wireless/ath/carl9170/usb.c:307
__usb_hcd_giveback_urb+0x376/0x540 drivers/usb/core/hcd.c:1657
dummy_timer+0xbc0/0x4650 drivers/usb/gadget/udc/dummy_hcd.c:2005
__run_hrtimer kernel/time/hrtimer.c:1930 [inline]
__hrtimer_run_queues+0x3c0/0xa20 kernel/time/hrtimer.c:1994
hrtimer_run_softirq+0x17a/0x240 kernel/time/hrtimer.c:2011
handle_softirqs+0x21b/0x830 kernel/softirq.c:622
__do_softirq kernel/softirq.c:656 [inline]
invoke_softirq kernel/softirq.c:496 [inline]
__irq_exit_rcu+0xc0/0x210 kernel/softirq.c:735
irq_exit_rcu+0x9/0x30 kernel/softirq.c:752
instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1061 [inline]
sysvec_apic_timer_interrupt+0x92/0xb0 arch/x86/kernel/apic/apic.c:1061
</IRQ>
<TASK>
asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:697
RIP: 0010:pv_native_safe_halt+0xf/0x20 arch/x86/kernel/paravirt.c:63
Code: 24 b3 01 e9 13 a2 02 00 cc cc cc 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 f3 0f 1e fa eb 07 0f 00 2d 93 77 15 00 fb f4 <c3> cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc 90 90 90 90 90
RSP: 0018:ffffc9000013fe20 EFLAGS: 00000202
RAX: 00000000000b70a1 RBX: ffffffff815b4fea RCX: 0000000080000001
RDX: 0000000000000001 RSI: ffffffff8927d953 RDI: ffffffff87c938c0
RBP: ffffc9000013ff20 R08: ffff88806b9336d3 R09: 1ffff1100d7266da
R10: dffffc0000000000 R11: ffffed100d7266db R12: 0000000000000001
R13: 1ffff11002bd5390 R14: 0000000000000001 R15: 1ffff11002bd5390
arch_safe_halt arch/x86/kernel/process.c:766 [inline]
default_idle+0x9/0x20 arch/x86/kernel/process.c:767
default_idle_call+0x72/0xb0 kernel/sched/idle.c:122
cpuidle_idle_call kernel/sched/idle.c:199 [inline]
do_idle+0x36a/0x5f0 kernel/sched/idle.c:352
cpu_startup_entry+0x43/0x60 kernel/sched/idle.c:451
start_secondary+0x101/0x110 arch/x86/kernel/smpboot.c:312
common_startup_64+0x13e/0x147
</TASK>
The buggy address belongs to a 8-page vmalloc region starting at 0xffffc900002c0000 allocated at copy_process+0x89b/0x4380 kernel/fork.c:2088
The buggy address belongs to the physical page:
page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1a16f
flags: 0x100000000000000(node=0|zone=1)
raw: 0100000000000000 ffffea0000685bc8 ffffea0000685bc8 0000000000000000
raw: 0000000000000000 0000000000000000 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x29c2(GFP_NOWAIT|__GFP_HIGHMEM|__GFP_IO|__GFP_FS|__GFP_ZERO), pid 2, tgid 2 (kthreadd), ts 2604993278, free_ts 0
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x231/0x280 mm/page_alloc.c:1858
prep_new_page mm/page_alloc.c:1866 [inline]
get_page_from_freelist+0x2274/0x2370 mm/page_alloc.c:3946
__alloc_frozen_pages_noprof+0x18d/0x380 mm/page_alloc.c:5226
__alloc_pages_noprof+0x10/0x100 mm/page_alloc.c:5260
__alloc_pages_node_noprof include/linux/gfp.h:289 [inline]
alloc_pages_node_noprof include/linux/gfp.h:316 [inline]
vm_area_alloc_pages mm/vmalloc.c:3655 [inline]
__vmalloc_area_node mm/vmalloc.c:3878 [inline]
__vmalloc_node_range_noprof+0x7ca/0x1750 mm/vmalloc.c:4064
__vmalloc_node_noprof+0xc2/0x100 mm/vmalloc.c:4124
alloc_thread_stack_node kernel/fork.c:357 [inline]
dup_task_struct+0x298/0x830 kernel/fork.c:926
copy_process+0x89b/0x4380 kernel/fork.c:2088
kernel_clone+0x284/0x8f0 kernel/fork.c:2723
kernel_thread+0x13f/0x1b0 kernel/fork.c:2784
create_kthread kernel/kthread.c:459 [inline]
kthreadd+0x4ec/0x6e0 kernel/kthread.c:817
ret_from_fork+0x491/0xad0 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
page_owner free stack trace missing
Memory state around the buggy address:
ffffc900002c7800: f3 f3 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00
ffffc900002c7880: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffffc900002c7900: f1 f1 f1 f1 04 f2 04 f3 00 00 00 00 00 00 00 00
^
ffffc900002c7980: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ffffc900002c7a00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
==================================================================
----------------
Code disassembly (best guess):
0: 24 b3 and $0xb3,%al
2: 01 e9 add %ebp,%ecx
4: 13 a2 02 00 cc cc adc -0x3333fffe(%rdx),%esp
a: cc int3
b: 90 nop
c: 90 nop
d: 90 nop
e: 90 nop
f: 90 nop
10: 90 nop
11: 90 nop
12: 90 nop
13: 90 nop
14: 90 nop
15: 90 nop
16: 90 nop
17: 90 nop
18: 90 nop
19: 90 nop
1a: 90 nop
1b: f3 0f 1e fa endbr64
1f: eb 07 jmp 0x28
21: 0f 00 2d 93 77 15 00 verw 0x157793(%rip) # 0x1577bb
28: fb sti
29: f4 hlt
* 2a: c3 ret <-- trapping instruction
2b: cc int3
2c: cc int3
2d: cc int3
2e: cc int3
2f: cc int3
30: cc int3
31: cc int3
32: cc int3
33: cc int3
34: cc int3
35: cc int3
36: cc int3
37: cc int3
38: cc int3
39: cc int3
3a: cc int3
3b: 90 nop
3c: 90 nop
3d: 90 nop
3e: 90 nop
3f: 90 nop
The explanation of the root cause of the bug is:
The root cause of this crash is a missing `return` statement in the command response handler, which leads to a stack-out-of-bounds write when the device sends a response that is larger than expected.
### Root Cause Analysis
When the driver sends a command to the firmware using `carl9170_exec_cmd()`, it provides an output buffer `out` (which is often a local stack variable) and its length `outlen`. The function sets up `ar->readbuf` and `ar->readlen` to point to this buffer and waits for the completion:
```c
// drivers/net/wireless/ath/carl9170/usb.c:677
spin_lock_bh(&ar->cmd_lock);
ar->readbuf = out;
ar->readlen = outlen;
spin_unlock_bh(&ar->cmd_lock);
reinit_completion(&ar->cmd_wait);
err = __carl9170_exec_cmd(ar, &ar->cmd, false);
if (!(cmd & CARL9170_CMD_ASYNC_FLAG)) {
time_left = wait_for_completion_timeout(&ar->cmd_wait, HZ);
// ...
```
When the device sends the command response back, it is handled by `carl9170_cmd_callback()`. This function checks if the received response length matches the expected length (`ar->readlen`). If it doesn't, it prints a warning and schedules a device restart:
```c
// drivers/net/wireless/ath/carl9170/rx.c:136
if (unlikely(ar->readlen != (len - 4))) {
dev_warn(&ar->udev->dev, "received invalid command response:"
"got %d, instead of %d\n", len - 4, ar->readlen);
print_hex_dump_bytes("carl9170 cmd:", DUMP_PREFIX_OFFSET,
ar->cmd_buf, (ar->cmd.hdr.len + 4) & 0x3f);
print_hex_dump_bytes("carl9170 rsp:", DUMP_PREFIX_OFFSET,
buffer, len);
/*
* Do not complete. The command times out,
* and we get a stack trace from there.
*/
carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
// BUG: Missing return statement here!
}
spin_lock(&ar->cmd_lock);
if (ar->readbuf) {
if (len >= 4)
memcpy(ar->readbuf, buffer + 4, len - 4);
ar->readbuf = NULL;
}
complete(&ar->cmd_wait);
spin_unlock(&ar->cmd_lock);
```
Because there is no `return;` statement after `carl9170_restart()`, the execution falls through to the `memcpy()`. If the received response is larger than expected (`len - 4 > ar->readlen`), the `memcpy()` will write `len - 4` bytes into `ar->readbuf`, overflowing the buffer (which is sized `ar->readlen`).
In your crash log, we can see exactly this happening:
```text
usb 4-1: received invalid command response:got 60, instead of 4
```
The driver expected a 4-byte response but received a 60-byte one. It warned about it, but then proceeded to `memcpy` 60 bytes into the 4-byte stack variable, causing the KASAN stack-out-of-bounds crash.
### The Fix
To fix this bug, you simply need to add a `return;` statement inside the `if` block. This perfectly aligns with the author's original comment right above it (`Do not complete. The command times out...`).
By returning early, `carl9170_exec_cmd()` will eventually time out, print a timeout error, and safely clean up `ar->readbuf` and `ar->readlen` under the `cmd_lock` in its `err_unbuf` error path.
```diff
--- a/drivers/net/wireless/ath/carl9170/rx.c
+++ b/drivers/net/wireless/ath/carl9170/rx.c
@@ -145,6 +145,7 @@ static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)
* and we get a stack trace from there.
*/
carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
+ return;
}
spin_lock(&ar->cmd_lock);
```
The diff of the bug fix is:
diff --git a/drivers/net/wireless/ath/carl9170/rx.c b/drivers/net/wireless/ath/carl9170/rx.c
index 683343013..ea3f435fb 100644
--- a/drivers/net/wireless/ath/carl9170/rx.c
+++ b/drivers/net/wireless/ath/carl9170/rx.c
@@ -145,6 +145,7 @@ static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)
* and we get a stack trace from there.
*/
carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
+ return;
}
spin_lock(&ar->cmd_lock);
Additional description of the patch:
I have analyzed the crash report and the root cause explanation. The issue is indeed a missing `return;` statement in `carl9170_cmd_callback()` after calling `carl9170_restart()`.
When the device sends a response that is larger than expected, the driver correctly detects the mismatch, prints a warning, and schedules a device restart. However, because it doesn't return early, the execution falls through to the `memcpy()` call. This causes the driver to copy the oversized response into the smaller stack-allocated buffer `ar->readbuf`, leading to a KASAN stack-out-of-bounds write.
I have applied the fix by adding the missing `return;` statement.
### Code changes made:
```c
--- a/drivers/net/wireless/ath/carl9170/rx.c
+++ b/drivers/net/wireless/ath/carl9170/rx.c
@@ -145,6 +145,7 @@ static void carl9170_cmd_callback(struct ar9170 *ar, u32 len, void *buffer)
* and we get a stack trace from there.
*/
carl9170_restart(ar, CARL9170_RR_INVALID_RSP);
+ return;
}
spin_lock(&ar->cmd_lock);
```
### Why this is the best fix:
1. **Prevents Buffer Overflow:** By returning early, we completely bypass the `memcpy()` and `complete()` calls, preventing the out-of-bounds memory write.
2. **Aligns with Design Intent:** The original author explicitly commented `Do not complete. The command times out...`. Adding the `return` statement fulfills this intent. The command will now correctly time out in `carl9170_exec_cmd()`, which will safely clean up `ar->readbuf` and `ar->readlen` under the `cmd_lock` in its `err_unbuf` error path.
3. **Safe Multiple Restarts:** `carl9170_exec_cmd()` will eventually trigger another `carl9170_restart(ar, CARL9170_RR_COMMAND_TIMEOUT)` upon timeout. This is perfectly safe because `carl9170_restart()` uses an atomic counter (`atomic_inc_return(&ar->pending_restarts)`) to ignore subsequent surplus restart requests while a restart is already pending.
4. **Handles Undersized Responses:** If `len < 4`, `len - 4` will wrap around to a huge `u32` value. Since `ar->readlen` is typically small (e.g., size of a struct), the condition `ar->readlen != (len - 4)` will evaluate to true, and the function will safely return early, preventing a `memcpy()` with a huge length.
I also audited the rest of the `carl9170` driver for similar missing `return` statements after `carl9170_restart()` calls (e.g., in `carl9170_check_sequence()`, `carl9170_handle_command_response()`, `carl9170_check_queue_stop_timeout()`, etc.). All other invocations either correctly return immediately or are placed at the very end of their respective functions, meaning this specific bug was isolated to `carl9170_cmd_callback()`.
Here are summaries of recent commits that touched the same files.
Format the summary line consistently with these, look how prefixes
are specified, letter capitalization, style, etc.
wifi: mac80211: support parsing S1G TIM PVB
carl9170: Use fallthrough pseudo-keyword
wireless: carl9170: fix clang build warning
carl9170: clean up a clamp() call
carl9170: rx: mark expected switch fall-through
networking: introduce and use skb_put_data()
mac80211: separate encoding/bandwidth from flags
mac80211: clean up rate encoding bits in RX status
cfg80211: remove enum ieee80211_band
carl9170: fix bad rssi reading
carl9170: Remove casts of pointer to same type
carl9170: use ath_is_mybeacon
wireless: delete non-required instances of include <linux/init.h>
carl9170: use ether_addr_equal_64bits
drivers/net: Convert uses of compare_ether_addr to ether_addr_equal
carl9170: fix copy and paste mishap in carl9170_handle_mpdu
carl9170: fix signal strength reporting issues
carl9170: split up carl9170_handle_mpdu
carl9170: handle traps from firmware loader
carl9170: report A-MPDU status
Reply: carl9170: fix stack-out-of-bounds in carl9170_cmd_callback()
When the driver sends a command to the firmware, it provides an output
buffer and its length. If the device sends a response that is larger
than expected, carl9170_cmd_callback() detects the mismatch, prints a
warning, and schedules a device restart.
However, it misses a return statement after calling carl9170_restart().
This causes the execution to fall through to the memcpy() call, which
copies the oversized response into the smaller stack-allocated buffer,
leading to a KASAN stack-out-of-bounds write.
Fix this by adding the missing return statement. This aligns with the
original author's explicit comment ("Do not complete. The command times
out..."), preventing the out-of-bounds memory write and allowing the
command to correctly time out and safely clean up the buffer.
|
| 81/2 |
2026/04/29 10:30 |
llm |
description-generator |
0m
Model:
Tokens:
input: 8881
output: 208
thoughts: 963
Thoughts: **Crafting the `carl9170` Driver Bug Fix Commit**
Okay, so I've got this bug fix for the `carl9170` driver. I'm aiming for a clear and concise commit message. The user provided crash logs, root cause analysis, a patch diff, and some context from recent commits, which is great. I need to make this digestible and understandable.
First, the summary line. It needs to be precise and under 72 characters. After reviewing the information, I'm leaning toward "carl9170: fix stack-out-of-bounds in carl9170_cmd_callback()". Another option could be "carl9170: add missing return in carl9170_cmd_callback()" or "carl9170: fix out-of-bounds write in carl9170_cmd_callback()", but the first option feels most direct. I checked line lengths for the summary, all good.
The issue is a stack-out-of-bounds write in `carl9170_cmd_callback` within `drivers/net/wireless/ath/carl9170/rx.c`. The root cause is that after `carl9170_restart()` is called, a `return` statement is missing. If the device sends a response that's larger than the buffer the driver expects, a warning is printed, and a restart is scheduled. However, the lack of the `return` allows the code to continue, falling through to a `memcpy()` that then writes more data than the stack buffer can hold, causing the stack corruption.
I'm thinking the description should explain:
1. How the driver handles commands with the firmware.
2. The scenario that triggers the bug (mismatched response length).
3. The consequence of the missing `return` (the out-of-bounds write).
4. The fix (adding the missing `return` statement).
The user's explanation provides a good starting point. I'll structure the commit message like this:
```
carl9170: fix stack-out-of-bounds in carl9170_cmd_callback()
When the driver sends a command to the firmware, it provides an output
buffer and its length. If the device sends a response that is larger
than expected, carl9170_cmd_callback() detects the mismatch, prints a
warning, and schedules a device restart.
However, it misses a return statement after calling carl9170_restart().
This causes the execution to fall through to the memcpy() call, which
copies the oversized response into the smaller stack-allocated buffer,
leading to a KASAN stack-out-of-bounds write.
Fix this by adding the missing return statement. This aligns with the
original author's explicit comment ("Do not complete. The command times
out..."), preventing the out-of-bounds memory write and allowing the
command to correctly time out and safely clean up the buffer.
```
This should be pretty clear and accurate, including the relevant context. It's a clean fix with a clear explanation of *why*. Looks good to me, and it should address the bug effectively. Time to ship it.
|
| 82/1 |
2026/04/29 10:30 |
action |
format-patch-description |
0m
Results: map[PatchDescription:carl9170: fix stack-out-of-bounds in carl9170_cmd_callback()
When the driver sends a command to the firmware, it provides an output
buffer and its length. If the device sends a response that is larger
than expected, carl9170_cmd_callback() detects the mismatch, prints a
warning, and schedules a device restart.
However, it misses a return statement after calling carl9170_restart().
This causes the execution to fall through to the memcpy() call, which
copies the oversized response into the smaller stack-allocated buffer,
leading to a KASAN stack-out-of-bounds write.
Fix this by adding the missing return statement. This aligns with the
original author's explicit comment ("Do not complete. The command times
out..."), preventing the out-of-bounds memory write and allowing the
command to correctly time out and safely clean up the buffer.]
|