| 0/0 |
2026/08/17 20:34 |
flow |
patching |
1h36m
Results: map[AckedBy:[] Fixes:map[AuthorEmail:torvalds@ppc970.osdl.org AuthorName:Linus Torvalds Hash:1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Title:Linux-2.6.12-rc2] KernelBranch:master KernelCommit:8d3ae59288f1e7d58d76558a6ee96d533bc5019f KernelRepo:git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git PatchDescription:media: ttusb-dec: fix buffer overflow in ttusb_dec_send_command()
The ttusb_dec_send_command() function allocates a 64-byte buffer
(COMMAND_PACKET_SIZE + 4) for USB communication. After receiving a
response, it reads the payload length from b[3] (which is fully controlled
by the USB device) and copies the payload into the caller-provided
cmd_result buffer. There are two missing bounds checks. First, b[3] can be
up to 255, exceeding the 60-byte payload capacity of the allocated buffer,
leading to an out-of-bounds read. Second, the size of cmd_result is not
passed to the function, so a large b[3] can cause a buffer overflow in the
destination buffer (e.g., a 4-byte buffer in
ttusbdecfe_dvbt_read_status()).
This can result in a fortify panic:
memcpy: detected buffer overflow: 75 byte read of buffer size 60
WARNING: lib/string_helpers.c:1037 at __fortify_report+0xa0/0xb8
lib/string_helpers.c:1036
...
Call trace:
__fortify_report+0xa0/0xb8 lib/string_helpers.c:1036 (P)
__fortify_panic+0x10/0x14 lib/string_helpers.c:1043
fortify_memcpy_chk include/linux/fortify-string.h:549 [inline]
ttusb_dec_start_feed+0x0/0x10ac
drivers/media/usb/ttusb-dec/ttusb_dec.c:372
ttusb_dec_get_stb_state drivers/media/usb/ttusb-dec/ttusb_dec.c:392
[inline]
ttusb_dec_init_stb drivers/media/usb/ttusb-dec/ttusb_dec.c:1413 [inline]
ttusb_dec_probe+0x724/0x1aa0 drivers/media/usb/ttusb-dec/ttusb_dec.c:1671
Fix this by adding a cmd_result_len parameter to ttusb_dec_send_command()
and the send_command callback in ttusbdecfe_config. Update all callers to
pass the correct buffer size. Inside ttusb_dec_send_command(), validate
param_length, ensure actual_len is at least 4 bytes, and check that b[3]
does not exceed COMMAND_PACKET_SIZE, actual_len - 4, or cmd_result_len. PatchDiff:diff --git a/drivers/media/usb/ttusb-dec/ttusb_dec.c b/drivers/media/usb/ttusb-dec/ttusb_dec.c
index 825a38759..b54b7b4bb 100644
--- a/drivers/media/usb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/usb/ttusb-dec/ttusb_dec.c
@@ -314,13 +314,17 @@ static u16 crc16(u16 crc, const u8 *buf, size_t len)
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
int result, actual_len;
u8 *b;
dprintk("%s\n", __func__);
+ if (param_length > COMMAND_PACKET_SIZE)
+ return -EINVAL;
+
b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
if (!b)
return -ENOMEM;
@@ -366,10 +370,25 @@ static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
__func__, actual_len, b);
}
+ if (actual_len < 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
+ if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
if (result_length)
*result_length = b[3];
- if (cmd_result && b[3] > 0)
+ if (cmd_result && b[3] > 0) {
+ if (b[3] > cmd_result_len) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
memcpy(cmd_result, &b[4], b[3]);
+ }
}
err_mutex_unlock:
@@ -389,7 +408,8 @@ static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
dprintk("%s\n", __func__);
- result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
+ result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c,
+ sizeof(c));
if (result)
return result;
@@ -448,7 +468,7 @@ static void ttusb_dec_set_pids(struct ttusb_dec *dec)
memcpy(&b[2], &audio, 2);
memcpy(&b[4], &video, 2);
- ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL, 0);
dvb_filter_pes2ts_init(&dec->a_pes2ts, dec->pid[DMX_PES_AUDIO],
ttusb_dec_audio_pes2ts_cb, dec);
@@ -902,7 +922,7 @@ static int ttusb_dec_set_interface(struct ttusb_dec *dec,
break;
case TTUSB_DEC_INTERFACE_IN:
result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
- b, NULL, NULL);
+ b, NULL, NULL, 0);
if (result)
return result;
result = usb_set_interface(dec->udev, 0, 8);
@@ -1021,7 +1041,7 @@ static int ttusb_dec_start_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
}
- result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL, 0);
if (result)
return result;
@@ -1056,7 +1076,7 @@ static int ttusb_dec_start_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
memcpy(&b0[5], &dvbdmxfeed->filter->filter.filter_value[0], 1);
result = ttusb_dec_send_command(dec, 0x60, sizeof(b0), b0,
- &c_length, c);
+ &c_length, c, sizeof(c));
if (!result) {
if (c_length == 2) {
@@ -1114,7 +1134,7 @@ static int ttusb_dec_stop_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
u8 b0[] = { 0x00 };
- ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL, 0);
dec->pva_stream_count--;
@@ -1135,7 +1155,7 @@ static int ttusb_dec_stop_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
list_del(&finfo->filter_info_list);
spin_unlock_irqrestore(&dec->filter_info_list_lock, flags);
kfree(finfo);
- ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL, 0);
dec->filter_stream_count--;
@@ -1238,7 +1258,7 @@ static int ttusb_init_rc( struct ttusb_dec *dec)
if (usb_submit_urb(dec->irq_urb, GFP_KERNEL))
printk("%s: usb_submit_urb failed\n",__func__);
/* enable irq pipe */
- ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
+ ttusb_dec_send_command(dec, 0xb0, sizeof(b), b, NULL, NULL, 0);
return 0;
}
@@ -1354,7 +1374,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
firmware_csum_ns = htons(firmware_csum);
memcpy(&b0[6], &firmware_csum_ns, 2);
- result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL, 0);
if (result) {
release_firmware(fw_entry);
@@ -1395,7 +1415,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
}
}
- result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL, 0);
release_firmware(fw_entry);
kfree(b);
@@ -1621,10 +1641,13 @@ static void ttusb_dec_exit_filters(struct ttusb_dec *dec)
static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
struct ttusb_dec* dec = fe->dvb->priv;
- return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
+ return ttusb_dec_send_command(dec, command, param_length, params,
+ result_length, cmd_result,
+ cmd_result_len);
}
static const struct ttusbdecfe_config fe_config = {
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.c b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
index 215221370..b013d6dfc 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.c
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
@@ -44,7 +44,8 @@ static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
*status=0;
- ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
+ ret = state->config->send_command(fe, 0x73, sizeof(b), b, &len, result,
+ sizeof(result));
if(ret)
return ret;
@@ -85,7 +86,7 @@ static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend *fe)
__be32 freq = htonl(p->frequency / 1000);
memcpy(&b[4], &freq, sizeof (u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
@@ -130,7 +131,7 @@ static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend *fe)
lnb_voltage = htonl(state->voltage);
memcpy(&b[28], &lnb_voltage, sizeof(u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
@@ -149,7 +150,7 @@ static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struc
state->config->send_command(fe, 0x72,
sizeof(b) - (6 - cmd->msg_len), b,
- NULL, NULL);
+ NULL, NULL, 0);
return 0;
}
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.h b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
index 73828bb22..96600ad4c 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.h
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
@@ -14,7 +14,8 @@ struct ttusbdecfe_config
{
int (*send_command)(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[]);
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len);
};
extern struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config);
Recipients:[map[Email:kees@kernel.org Name:Kees Cook To:false] map[Email:linux-kernel@vger.kernel.org Name: To:false] map[Email:linux-media@vger.kernel.org Name: To:true] map[Email:mchehab@kernel.org Name:Mauro Carvalho Chehab To:true] map[Email:torvalds@ppc970.osdl.org Name:Linus Torvalds To:true]] ReportedBy:[] ReviewedBy:[] SuggestedBy:[] TestedBy:[]]
|
| 1/1 |
2026/08/17 20:34 |
action |
base-commit-picker |
0m
Results: map[KernelBranch:master KernelCommit:8d3ae59288f1e7d58d76558a6ee96d533bc5019f KernelRepo:git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git]
|
| 2/1 |
2026/08/17 20:34 |
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>
#ifndef __NR_mmap
#define __NR_mmap 222
#endif
static unsigned long long procid;
static void sleep_ms(uint64_t ms)
{
usleep(ms * 1000);
}
#define MAX_FDS 30
#define USB_MAX_IFACE_NUM 4
#define USB_MAX_EP_NUM 32
#define USB_MAX_FDS 6
struct usb_endpoint_index {
struct usb_endpoint_descriptor desc;
int handle;
};
struct usb_iface_index {
struct usb_interface_descriptor* iface;
uint8_t bInterfaceNumber;
uint8_t bAlternateSetting;
uint8_t bInterfaceClass;
struct usb_endpoint_index eps[USB_MAX_EP_NUM];
int eps_num;
};
struct usb_device_index {
struct usb_device_descriptor* dev;
struct usb_config_descriptor* config;
uint8_t bDeviceClass;
uint8_t bMaxPower;
int config_length;
struct usb_iface_index ifaces[USB_MAX_IFACE_NUM];
int ifaces_num;
int iface_cur;
};
struct usb_info {
int fd;
struct usb_device_index index;
};
static struct usb_info usb_devices[USB_MAX_FDS];
static struct usb_device_index* lookup_usb_index(int fd)
{
for (int i = 0; i < USB_MAX_FDS; i++) {
if (__atomic_load_n(&usb_devices[i].fd, __ATOMIC_ACQUIRE) == fd)
return &usb_devices[i].index;
}
return NULL;
}
static int usb_devices_num;
static bool parse_usb_descriptor(const char* buffer, size_t length, struct usb_device_index* index)
{
if (length < sizeof(*index->dev) + sizeof(*index->config))
return false;
memset(index, 0, sizeof(*index));
index->dev = (struct usb_device_descriptor*)buffer;
index->config = (struct usb_config_descriptor*)(buffer + sizeof(*index->dev));
index->bDeviceClass = index->dev->bDeviceClass;
index->bMaxPower = index->config->bMaxPower;
index->config_length = length - sizeof(*index->dev);
index->iface_cur = -1;
size_t offset = 0;
while (true) {
if (offset + 1 >= length)
break;
uint8_t desc_length = buffer[offset];
uint8_t desc_type = buffer[offset + 1];
if (desc_length <= 2)
break;
if (offset + desc_length > length)
break;
if (desc_type == USB_DT_INTERFACE && index->ifaces_num < USB_MAX_IFACE_NUM) {
struct usb_interface_descriptor* iface = (struct usb_interface_descriptor*)(buffer + offset);
index->ifaces[index->ifaces_num].iface = iface;
index->ifaces[index->ifaces_num].bInterfaceNumber = iface->bInterfaceNumber;
index->ifaces[index->ifaces_num].bAlternateSetting = iface->bAlternateSetting;
index->ifaces[index->ifaces_num].bInterfaceClass = iface->bInterfaceClass;
index->ifaces_num++;
}
if (desc_type == USB_DT_ENDPOINT && index->ifaces_num > 0) {
struct usb_iface_index* iface = &index->ifaces[index->ifaces_num - 1];
if (iface->eps_num < USB_MAX_EP_NUM) {
memcpy(&iface->eps[iface->eps_num].desc, buffer + offset, sizeof(iface->eps[iface->eps_num].desc));
iface->eps_num++;
}
}
offset += desc_length;
}
return true;
}
static struct usb_device_index* add_usb_index(int fd, const char* dev, size_t dev_len)
{
int i = __atomic_fetch_add(&usb_devices_num, 1, __ATOMIC_RELAXED);
if (i >= USB_MAX_FDS)
return NULL;
if (!parse_usb_descriptor(dev, dev_len, &usb_devices[i].index))
return NULL;
__atomic_store_n(&usb_devices[i].fd, fd, __ATOMIC_RELEASE);
return &usb_devices[i].index;
}
struct vusb_connect_string_descriptor {
uint32_t len;
char* str;
} __attribute__((packed));
struct vusb_connect_descriptors {
uint32_t qual_len;
char* qual;
uint32_t bos_len;
char* bos;
uint32_t strs_len;
struct vusb_connect_string_descriptor strs[0];
} __attribute__((packed));
static const char default_string[] = {
8, USB_DT_STRING,
's', 0, 'y', 0, 'z', 0
};
static const char default_lang_id[] = {
4, USB_DT_STRING,
0x09, 0x04
};
static bool lookup_connect_response_in(int fd, const struct vusb_connect_descriptors* descs,
const struct usb_ctrlrequest* ctrl,
struct usb_qualifier_descriptor* qual,
char** response_data, uint32_t* response_length)
{
struct usb_device_index* index = lookup_usb_index(fd);
uint8_t str_idx;
if (!index)
return false;
switch (ctrl->bRequestType & USB_TYPE_MASK) {
case USB_TYPE_STANDARD:
switch (ctrl->bRequest) {
case USB_REQ_GET_DESCRIPTOR:
switch (ctrl->wValue >> 8) {
case USB_DT_DEVICE:
*response_data = (char*)index->dev;
*response_length = sizeof(*index->dev);
return true;
case USB_DT_CONFIG:
*response_data = (char*)index->config;
*response_length = index->config_length;
return true;
case USB_DT_STRING:
str_idx = (uint8_t)ctrl->wValue;
if (descs && str_idx < descs->strs_len) {
*response_data = descs->strs[str_idx].str;
*response_length = descs->strs[str_idx].len;
return true;
}
if (str_idx == 0) {
*response_data = (char*)&default_lang_id[0];
*response_length = default_lang_id[0];
return true;
}
*response_data = (char*)&default_string[0];
*response_length = default_string[0];
return true;
case USB_DT_BOS:
*response_data = descs->bos;
*response_length = descs->bos_len;
return true;
case USB_DT_DEVICE_QUALIFIER:
if (!descs->qual) {
qual->bLength = sizeof(*qual);
qual->bDescriptorType = USB_DT_DEVICE_QUALIFIER;
qual->bcdUSB = index->dev->bcdUSB;
qual->bDeviceClass = index->dev->bDeviceClass;
qual->bDeviceSubClass = index->dev->bDeviceSubClass;
qual->bDeviceProtocol = index->dev->bDeviceProtocol;
qual->bMaxPacketSize0 = index->dev->bMaxPacketSize0;
qual->bNumConfigurations = index->dev->bNumConfigurations;
qual->bRESERVED = 0;
*response_data = (char*)qual;
*response_length = sizeof(*qual);
return true;
}
*response_data = descs->qual;
*response_length = descs->qual_len;
return true;
default:
break;
}
break;
default:
break;
}
break;
default:
break;
}
return false;
}
typedef bool (*lookup_connect_out_response_t)(int fd, const struct vusb_connect_descriptors* descs,
const struct usb_ctrlrequest* ctrl, bool* done);
static bool lookup_connect_response_out_generic(int fd, const struct vusb_connect_descriptors* descs,
const struct usb_ctrlrequest* ctrl, bool* done)
{
switch (ctrl->bRequestType & USB_TYPE_MASK) {
case USB_TYPE_STANDARD:
switch (ctrl->bRequest) {
case USB_REQ_SET_CONFIGURATION:
*done = true;
return true;
default:
break;
}
break;
}
return false;
}
#define UDC_NAME_LENGTH_MAX 128
struct usb_raw_init {
__u8 driver_name[UDC_NAME_LENGTH_MAX];
__u8 device_name[UDC_NAME_LENGTH_MAX];
__u8 speed;
};
enum usb_raw_event_type {
USB_RAW_EVENT_INVALID = 0,
USB_RAW_EVENT_CONNECT = 1,
USB_RAW_EVENT_CONTROL = 2,
};
struct usb_raw_event {
__u32 type;
__u32 length;
__u8 data[0];
};
struct usb_raw_ep_io {
__u16 ep;
__u16 flags;
__u32 length;
__u8 data[0];
};
#define USB_RAW_EPS_NUM_MAX 30
#define USB_RAW_EP_NAME_MAX 16
#define USB_RAW_EP_ADDR_ANY 0xff
struct usb_raw_ep_caps {
__u32 type_control : 1;
__u32 type_iso : 1;
__u32 type_bulk : 1;
__u32 type_int : 1;
__u32 dir_in : 1;
__u32 dir_out : 1;
};
struct usb_raw_ep_limits {
__u16 maxpacket_limit;
__u16 max_streams;
__u32 reserved;
};
struct usb_raw_ep_info {
__u8 name[USB_RAW_EP_NAME_MAX];
__u32 addr;
struct usb_raw_ep_caps caps;
struct usb_raw_ep_limits limits;
};
struct usb_raw_eps_info {
struct usb_raw_ep_info eps[USB_RAW_EPS_NUM_MAX];
};
#define USB_RAW_IOCTL_INIT _IOW('U', 0, struct usb_raw_init)
#define USB_RAW_IOCTL_RUN _IO('U', 1)
#define USB_RAW_IOCTL_EVENT_FETCH _IOR('U', 2, struct usb_raw_event)
#define USB_RAW_IOCTL_EP0_WRITE _IOW('U', 3, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_EP0_READ _IOWR('U', 4, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_EP_ENABLE _IOW('U', 5, struct usb_endpoint_descriptor)
#define USB_RAW_IOCTL_EP_DISABLE _IOW('U', 6, __u32)
#define USB_RAW_IOCTL_EP_WRITE _IOW('U', 7, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_EP_READ _IOWR('U', 8, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_CONFIGURE _IO('U', 9)
#define USB_RAW_IOCTL_VBUS_DRAW _IOW('U', 10, __u32)
#define USB_RAW_IOCTL_EPS_INFO _IOR('U', 11, struct usb_raw_eps_info)
#define USB_RAW_IOCTL_EP0_STALL _IO('U', 12)
#define USB_RAW_IOCTL_EP_SET_HALT _IOW('U', 13, __u32)
#define USB_RAW_IOCTL_EP_CLEAR_HALT _IOW('U', 14, __u32)
#define USB_RAW_IOCTL_EP_SET_WEDGE _IOW('U', 15, __u32)
static int usb_raw_open()
{
return open("/dev/raw-gadget", O_RDWR);
}
static int usb_raw_init(int fd, uint32_t speed, const char* driver, const char* device)
{
struct usb_raw_init arg;
strncpy((char*)&arg.driver_name[0], driver, sizeof(arg.driver_name));
strncpy((char*)&arg.device_name[0], device, sizeof(arg.device_name));
arg.speed = speed;
return ioctl(fd, USB_RAW_IOCTL_INIT, &arg);
}
static int usb_raw_run(int fd)
{
return ioctl(fd, USB_RAW_IOCTL_RUN, 0);
}
static int usb_raw_ep_write(int fd, struct usb_raw_ep_io* io)
{
return ioctl(fd, USB_RAW_IOCTL_EP_WRITE, io);
}
static int usb_raw_ep_read(int fd, struct usb_raw_ep_io* io)
{
return ioctl(fd, USB_RAW_IOCTL_EP_READ, 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_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_ep_read(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;
int rv = usb_raw_ep_read(fd, (struct usb_raw_ep_io*)&io_data);
if (rv < 0) {
return rv;
}
memcpy(&data[0], &io_data.data[0], io_data.inner.length);
sleep_ms(200);
return 0;
}
uint64_t r[1] = {0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000, /*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 arguments: [
// speed: usb_device_speed = 0x3 (8 bytes)
// dev_len: len = 0x9f (8 bytes)
// dev: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// union ANYUNION {
// ANYBLOB: buffer: {12 01 00 02 00 00 00 40 48 0b 08 10 00 01 00 00 00 01 09 02 8d 00 01 01 00 80 fa 09 04 00 00 05 ff ff ff 00 07 05 03 02 00 02 00 07 05 84 02 00 02} (length 0x31)
// }
// }
// }
// conn_descs: nil
// ]
// returns fd_usb
memcpy((void*)0x20000000, "... [truncated large byte array] ...", 49);
res = -1;
res = syz_usb_connect(/*speed=USB_SPEED_HIGH*/3, /*dev_len=*/0x9f, /*dev=*/0x20000000, /*conn_descs=*/0);
if (res != -1)
r[0] = res;
// syz_usb_ep_read arguments: [
// fd: fd_usb (resource)
// ep: int8 = 0x3 (1 bytes)
// len: len = 0x0 (8 bytes)
// data: nil
// ]
syz_usb_ep_read(/*fd=*/r[0], /*ep=*/3, /*len=*/0, /*data=*/0);
// syz_usb_ep_write arguments: [
// fd: fd_usb (resource)
// ep: int8 = 0x84 (1 bytes)
// len: len = 0xc (8 bytes)
// data: ptr[in, buffer] {
// buffer: {aa 00 9e 4b 65 1d 00 c4 45 ed b0 6d} (length 0xc)
// }
// ]
memcpy((void*)0x20000700, "\xaa\x00\x9e\x4b\x65\x1d\x00\xc4\x45\xed\xb0\x6d", 12);
syz_usb_ep_write(/*fd=*/r[0], /*ep=*/0x84, /*len=*/0xc, /*data=*/0x20000700);
return 0;
}
]
|
| 3/1 |
2026/08/17 20:34 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/b5692495be56e63dd0879dd861d23f69899ae44d]
|
| 4/1 |
2026/08/17 20:34 |
action |
kernel-builder |
15m
Results: map[KernelObj:/app/workdir/cache/build/cdafb00a1dfb92e70c80cffdb37b69e6b1b280c8]
|
| 5/1 |
2026/08/17 20:49 |
action |
crash-reproducer |
5m
Results: map[OtherCrashReports:<nil> ReproducedBugTitle:WARNING in ttusb_dec_start_feed ReproducedCrashReport:usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
------------[ cut here ]------------
memcpy: detected buffer overflow: 75 byte read of buffer size 60
WARNING: lib/string_helpers.c:1037 at __fortify_report+0xa0/0xb8 lib/string_helpers.c:1036, CPU#0: kworker/0:4/4798
Modules linked in:
CPU: 0 UID: 0 PID: 4798 Comm: kworker/0:4 Not tainted syzkaller #1 PREEMPT
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/07/2026
Workqueue: usb_hub_wq hub_event
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : __fortify_report+0xa0/0xb8 lib/string_helpers.c:1036
lr : __fortify_report+0xa0/0xb8 lib/string_helpers.c:1036
sp : ffff800098516d20
x29: ffff800098516d20 x28: dfff800000000000 x27: ffff7000130a2db0
x26: 0000000000000000 x25: ffff0000d1862683 x24: ffff800098516ea0
x23: 000000000000004b x22: ffff800086d0a338 x21: 0000000000000000
x20: 000000000000004b x19: 000000000000003c x18: 1fffe00035ba8028
x17: 0000000000000003 x16: ffff800088ba7000 x15: ffff8000824ea6c8
x14: 0000000000000000 x13: 0000000000000001 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000002 x9 : 653dfa0a2f6c5200
x8 : 653dfa0a2f6c5200 x7 : ffff80008048e0c4 x6 : 0000000000000000
x5 : 0000000000000000 x4 : 0000000000000000 x3 : ffff8000802f8054
x2 : 0000000100000000 x1 : ffff0000c57d1d40 x0 : 0000000000000000
Call trace:
__fortify_report+0xa0/0xb8 lib/string_helpers.c:1036 (P)
__fortify_panic+0x10/0x14 lib/string_helpers.c:1043
fortify_memcpy_chk include/linux/fortify-string.h:549 [inline]
ttusb_dec_start_feed+0x0/0x10ac drivers/media/usb/ttusb-dec/ttusb_dec.c:372
ttusb_dec_get_stb_state drivers/media/usb/ttusb-dec/ttusb_dec.c:392 [inline]
ttusb_dec_init_stb drivers/media/usb/ttusb-dec/ttusb_dec.c:1413 [inline]
ttusb_dec_probe+0x724/0x1aa0 drivers/media/usb/ttusb-dec/ttusb_dec.c:1671
usb_probe_interface+0x308/0x788 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_set_configuration+0x1184/0x158c drivers/usb/core/message.c:2268
usb_generic_driver_probe+0x8c/0x148 drivers/usb/core/generic.c:250
usb_probe_device+0x114/0x2b0 drivers/usb/core/driver.c:291
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_new_device+0x9c4/0x11f8 drivers/usb/core/hub.c:2703
hub_port_connect drivers/usb/core/hub.c:5575 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5715 [inline]
port_event drivers/usb/core/hub.c:5879 [inline]
hub_event+0x1ef0/0x39fc drivers/usb/core/hub.c:5961
process_one_work kernel/workqueue.c:3322 [inline]
process_scheduled_works+0x788/0x10b8 kernel/workqueue.c:3405
worker_thread+0x798/0xbd0 kernel/workqueue.c:3486
kthread+0x304/0x3d4 kernel/kthread.c:436
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:842
irq event stamp: 16196
hardirqs last enabled at (16195): [<ffff8000868fc7b4>] irqentry_exit_to_kernel_mode_after_preempt include/linux/irq-entry-common.h:507 [inline]
hardirqs last enabled at (16195): [<ffff8000868fc7b4>] arm64_exit_to_kernel_mode+0x80/0x94 arch/arm64/kernel/entry-common.c:62
hardirqs last disabled at (16196): [<ffff8000868f86e0>] el1_brk64+0x20/0x54 arch/arm64/kernel/entry-common.c:425
softirqs last enabled at (16128): [<ffff80008030ff18>] softirq_handle_end kernel/softirq.c:468 [inline]
softirqs last enabled at (16128): [<ffff80008030ff18>] handle_softirqs+0xc28/0xd98 kernel/softirq.c:650
softirqs last disabled at (16119): [<ffff8000800204b0>] __do_softirq+0x14/0x20 kernel/softirq.c:656
---[ end trace 0000000000000000 ]---
------------[ cut here ]------------
kernel BUG at lib/string_helpers.c:1044!
Internal error: Oops - BUG: 00000000f2000800 [#1] SMP
Modules linked in:
CPU: 0 UID: 0 PID: 4798 Comm: kworker/0:4 Tainted: G W syzkaller #1 PREEMPT
Tainted: [W]=WARN
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/07/2026
Workqueue: usb_hub_wq hub_event
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : __fortify_panic+0x10/0x14 lib/string_helpers.c:1043
lr : __fortify_panic+0x10/0x14 lib/string_helpers.c:1043
sp : ffff800098516d50
x29: ffff800098516d50 x28: dfff800000000000 x27: ffff7000130a2db0
x26: 0000000000000000 x25: ffff0000d1862683 x24: ffff800098516ea0
x23: 000000000000004b x22: 000000000000004b x21: ffff0000d1862680
x20: 1fffe0001a30c4d0 x19: ffff0000c3014000 x18: 1fffe00035ba8028
x17: 0000000000000003 x16: ffff800088ba7000 x15: ffff8000824ea6c8
x14: 0000000000000000 x13: 0000000000000001 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000002 x9 : 653dfa0a2f6c5200
x8 : 653dfa0a2f6c5200 x7 : ffff80008048e0c4 x6 : 0000000000000000
x5 : 0000000000000000 x4 : 0000000000000000 x3 : ffff8000802f8054
x2 : 0000000100000000 x1 : ffff0000c57d1d40 x0 : 0000000000000000
Call trace:
__fortify_panic+0x10/0x14 lib/string_helpers.c:1043 (P)
fortify_memcpy_chk include/linux/fortify-string.h:549 [inline]
ttusb_dec_start_feed+0x0/0x10ac drivers/media/usb/ttusb-dec/ttusb_dec.c:372
ttusb_dec_get_stb_state drivers/media/usb/ttusb-dec/ttusb_dec.c:392 [inline]
ttusb_dec_init_stb drivers/media/usb/ttusb-dec/ttusb_dec.c:1413 [inline]
ttusb_dec_probe+0x724/0x1aa0 drivers/media/usb/ttusb-dec/ttusb_dec.c:1671
usb_probe_interface+0x308/0x788 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_set_configuration+0x1184/0x158c drivers/usb/core/message.c:2268
usb_generic_driver_probe+0x8c/0x148 drivers/usb/core/generic.c:250
usb_probe_device+0x114/0x2b0 drivers/usb/core/driver.c:291
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_new_device+0x9c4/0x11f8 drivers/usb/core/hub.c:2703
hub_port_connect drivers/usb/core/hub.c:5575 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5715 [inline]
port_event drivers/usb/core/hub.c:5879 [inline]
hub_event+0x1ef0/0x39fc drivers/usb/core/hub.c:5961
process_one_work kernel/workqueue.c:3322 [inline]
process_scheduled_works+0x788/0x10b8 kernel/workqueue.c:3405
worker_thread+0x798/0xbd0 kernel/workqueue.c:3486
kthread+0x304/0x3d4 kernel/kthread.c:436
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:842
Code: d503233f a9bf7bfd 910003fd 94619ee8 (d4210000)
---[ end trace 0000000000000000 ]---
ReproducedFaultInjection:]
|
| 6/1 |
2026/08/17 20:55 |
action |
codesearch-prepare |
11m
Results: map[Index:codesearch-index]
|
| 7/1 |
2026/08/17 21:06 |
agent |
debugger |
4m
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.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash is:
usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
------------[ cut here ]------------
memcpy: detected buffer overflow: 75 byte read of buffer size 60
WARNING: lib/string_helpers.c:1037 at __fortify_report+0xa0/0xb8 lib/string_helpers.c:1036, CPU#0: kworker/0:4/4798
Modules linked in:
CPU: 0 UID: 0 PID: 4798 Comm: kworker/0:4 Not tainted syzkaller #1 PREEMPT
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/07/2026
Workqueue: usb_hub_wq hub_event
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : __fortify_report+0xa0/0xb8 lib/string_helpers.c:1036
lr : __fortify_report+0xa0/0xb8 lib/string_helpers.c:1036
sp : ffff800098516d20
x29: ffff800098516d20 x28: dfff800000000000 x27: ffff7000130a2db0
x26: 0000000000000000 x25: ffff0000d1862683 x24: ffff800098516ea0
x23: 000000000000004b x22: ffff800086d0a338 x21: 0000000000000000
x20: 000000000000004b x19: 000000000000003c x18: 1fffe00035ba8028
x17: 0000000000000003 x16: ffff800088ba7000 x15: ffff8000824ea6c8
x14: 0000000000000000 x13: 0000000000000001 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000002 x9 : 653dfa0a2f6c5200
x8 : 653dfa0a2f6c5200 x7 : ffff80008048e0c4 x6 : 0000000000000000
x5 : 0000000000000000 x4 : 0000000000000000 x3 : ffff8000802f8054
x2 : 0000000100000000 x1 : ffff0000c57d1d40 x0 : 0000000000000000
Call trace:
__fortify_report+0xa0/0xb8 lib/string_helpers.c:1036 (P)
__fortify_panic+0x10/0x14 lib/string_helpers.c:1043
fortify_memcpy_chk include/linux/fortify-string.h:549 [inline]
ttusb_dec_start_feed+0x0/0x10ac drivers/media/usb/ttusb-dec/ttusb_dec.c:372
ttusb_dec_get_stb_state drivers/media/usb/ttusb-dec/ttusb_dec.c:392 [inline]
ttusb_dec_init_stb drivers/media/usb/ttusb-dec/ttusb_dec.c:1413 [inline]
ttusb_dec_probe+0x724/0x1aa0 drivers/media/usb/ttusb-dec/ttusb_dec.c:1671
usb_probe_interface+0x308/0x788 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_set_configuration+0x1184/0x158c drivers/usb/core/message.c:2268
usb_generic_driver_probe+0x8c/0x148 drivers/usb/core/generic.c:250
usb_probe_device+0x114/0x2b0 drivers/usb/core/driver.c:291
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_new_device+0x9c4/0x11f8 drivers/usb/core/hub.c:2703
hub_port_connect drivers/usb/core/hub.c:5575 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5715 [inline]
port_event drivers/usb/core/hub.c:5879 [inline]
hub_event+0x1ef0/0x39fc drivers/usb/core/hub.c:5961
process_one_work kernel/workqueue.c:3322 [inline]
process_scheduled_works+0x788/0x10b8 kernel/workqueue.c:3405
worker_thread+0x798/0xbd0 kernel/workqueue.c:3486
kthread+0x304/0x3d4 kernel/kthread.c:436
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:842
irq event stamp: 16196
hardirqs last enabled at (16195): [<ffff8000868fc7b4>] irqentry_exit_to_kernel_mode_after_preempt include/linux/irq-entry-common.h:507 [inline]
hardirqs last enabled at (16195): [<ffff8000868fc7b4>] arm64_exit_to_kernel_mode+0x80/0x94 arch/arm64/kernel/entry-common.c:62
hardirqs last disabled at (16196): [<ffff8000868f86e0>] el1_brk64+0x20/0x54 arch/arm64/kernel/entry-common.c:425
softirqs last enabled at (16128): [<ffff80008030ff18>] softirq_handle_end kernel/softirq.c:468 [inline]
softirqs last enabled at (16128): [<ffff80008030ff18>] handle_softirqs+0xc28/0xd98 kernel/softirq.c:650
softirqs last disabled at (16119): [<ffff8000800204b0>] __do_softirq+0x14/0x20 kernel/softirq.c:656
---[ end trace 0000000000000000 ]---
------------[ cut here ]------------
kernel BUG at lib/string_helpers.c:1044!
Internal error: Oops - BUG: 00000000f2000800 [#1] SMP
Modules linked in:
CPU: 0 UID: 0 PID: 4798 Comm: kworker/0:4 Tainted: G W syzkaller #1 PREEMPT
Tainted: [W]=WARN
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/07/2026
Workqueue: usb_hub_wq hub_event
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : __fortify_panic+0x10/0x14 lib/string_helpers.c:1043
lr : __fortify_panic+0x10/0x14 lib/string_helpers.c:1043
sp : ffff800098516d50
x29: ffff800098516d50 x28: dfff800000000000 x27: ffff7000130a2db0
x26: 0000000000000000 x25: ffff0000d1862683 x24: ffff800098516ea0
x23: 000000000000004b x22: 000000000000004b x21: ffff0000d1862680
x20: 1fffe0001a30c4d0 x19: ffff0000c3014000 x18: 1fffe00035ba8028
x17: 0000000000000003 x16: ffff800088ba7000 x15: ffff8000824ea6c8
x14: 0000000000000000 x13: 0000000000000001 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000002 x9 : 653dfa0a2f6c5200
x8 : 653dfa0a2f6c5200 x7 : ffff80008048e0c4 x6 : 0000000000000000
x5 : 0000000000000000 x4 : 0000000000000000 x3 : ffff8000802f8054
x2 : 0000000100000000 x1 : ffff0000c57d1d40 x0 : 0000000000000000
Call trace:
__fortify_panic+0x10/0x14 lib/string_helpers.c:1043 (P)
fortify_memcpy_chk include/linux/fortify-string.h:549 [inline]
ttusb_dec_start_feed+0x0/0x10ac drivers/media/usb/ttusb-dec/ttusb_dec.c:372
ttusb_dec_get_stb_state drivers/media/usb/ttusb-dec/ttusb_dec.c:392 [inline]
ttusb_dec_init_stb drivers/media/usb/ttusb-dec/ttusb_dec.c:1413 [inline]
ttusb_dec_probe+0x724/0x1aa0 drivers/media/usb/ttusb-dec/ttusb_dec.c:1671
usb_probe_interface+0x308/0x788 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_set_configuration+0x1184/0x158c drivers/usb/core/message.c:2268
usb_generic_driver_probe+0x8c/0x148 drivers/usb/core/generic.c:250
usb_probe_device+0x114/0x2b0 drivers/usb/core/driver.c:291
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_new_device+0x9c4/0x11f8 drivers/usb/core/hub.c:2703
hub_port_connect drivers/usb/core/hub.c:5575 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5715 [inline]
port_event drivers/usb/core/hub.c:5879 [inline]
hub_event+0x1ef0/0x39fc drivers/usb/core/hub.c:5961
process_one_work kernel/workqueue.c:3322 [inline]
process_scheduled_works+0x788/0x10b8 kernel/workqueue.c:3405
worker_thread+0x798/0xbd0 kernel/workqueue.c:3486
kthread+0x304/0x3d4 kernel/kthread.c:436
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:842
Code: d503233f a9bf7bfd 910003fd 94619ee8 (d4210000)
---[ end trace 0000000000000000 ]---
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>
#ifndef __NR_mmap
#define __NR_mmap 222
#endif
static unsigned long long procid;
static void sleep_ms(uint64_t ms)
{
usleep(ms * 1000);
}
#define MAX_FDS 30
#define USB_MAX_IFACE_NUM 4
#define USB_MAX_EP_NUM 32
#define USB_MAX_FDS 6
struct usb_endpoint_index {
struct usb_endpoint_descriptor desc;
int handle;
};
struct usb_iface_index {
struct usb_interface_descriptor* iface;
uint8_t bInterfaceNumber;
uint8_t bAlternateSetting;
uint8_t bInterfaceClass;
struct usb_endpoint_index eps[USB_MAX_EP_NUM];
int eps_num;
};
struct usb_device_index {
struct usb_device_descriptor* dev;
struct usb_config_descriptor* config;
uint8_t bDeviceClass;
uint8_t bMaxPower;
int config_length;
struct usb_iface_index ifaces[USB_MAX_IFACE_NUM];
int ifaces_num;
int iface_cur;
};
struct usb_info {
int fd;
struct usb_device_index index;
};
static struct usb_info usb_devices[USB_MAX_FDS];
static struct usb_device_index* lookup_usb_index(int fd)
{
for (int i = 0; i < USB_MAX_FDS; i++) {
if (__atomic_load_n(&usb_devices[i].fd, __ATOMIC_ACQUIRE) == fd)
return &usb_devices[i].index;
}
return NULL;
}
static int usb_devices_num;
static bool parse_usb_descriptor(const char* buffer, size_t length, struct usb_device_index* index)
{
if (length < sizeof(*index->dev) + sizeof(*index->config))
return false;
memset(index, 0, sizeof(*index));
index->dev = (struct usb_device_descriptor*)buffer;
index->config = (struct usb_config_descriptor*)(buffer + sizeof(*index->dev));
index->bDeviceClass = index->dev->bDeviceClass;
index->bMaxPower = index->config->bMaxPower;
index->config_length = length - sizeof(*index->dev);
index->iface_cur = -1;
size_t offset = 0;
while (true) {
if (offset + 1 >= length)
break;
uint8_t desc_length = buffer[offset];
uint8_t desc_type = buffer[offset + 1];
if (desc_length <= 2)
break;
if (offset + desc_length > length)
break;
if (desc_type == USB_DT_INTERFACE && index->ifaces_num < USB_MAX_IFACE_NUM) {
struct usb_interface_descriptor* iface = (struct usb_interface_descriptor*)(buffer + offset);
index->ifaces[index->ifaces_num].iface = iface;
index->ifaces[index->ifaces_num].bInterfaceNumber = iface->bInterfaceNumber;
index->ifaces[index->ifaces_num].bAlternateSetting = iface->bAlternateSetting;
index->ifaces[index->ifaces_num].bInterfaceClass = iface->bInterfaceClass;
index->ifaces_num++;
}
if (desc_type == USB_DT_ENDPOINT && index->ifaces_num > 0) {
struct usb_iface_index* iface = &index->ifaces[index->ifaces_num - 1];
if (iface->eps_num < USB_MAX_EP_NUM) {
memcpy(&iface->eps[iface->eps_num].desc, buffer + offset, sizeof(iface->eps[iface->eps_num].desc));
iface->eps_num++;
}
}
offset += desc_length;
}
return true;
}
static struct usb_device_index* add_usb_index(int fd, const char* dev, size_t dev_len)
{
int i = __atomic_fetch_add(&usb_devices_num, 1, __ATOMIC_RELAXED);
if (i >= USB_MAX_FDS)
return NULL;
if (!parse_usb_descriptor(dev, dev_len, &usb_devices[i].index))
return NULL;
__atomic_store_n(&usb_devices[i].fd, fd, __ATOMIC_RELEASE);
return &usb_devices[i].index;
}
struct vusb_connect_string_descriptor {
uint32_t len;
char* str;
} __attribute__((packed));
struct vusb_connect_descriptors {
uint32_t qual_len;
char* qual;
uint32_t bos_len;
char* bos;
uint32_t strs_len;
struct vusb_connect_string_descriptor strs[0];
} __attribute__((packed));
static const char default_string[] = {
8, USB_DT_STRING,
's', 0, 'y', 0, 'z', 0
};
static const char default_lang_id[] = {
4, USB_DT_STRING,
0x09, 0x04
};
static bool lookup_connect_response_in(int fd, const struct vusb_connect_descriptors* descs,
const struct usb_ctrlrequest* ctrl,
struct usb_qualifier_descriptor* qual,
char** response_data, uint32_t* response_length)
{
struct usb_device_index* index = lookup_usb_index(fd);
uint8_t str_idx;
if (!index)
return false;
switch (ctrl->bRequestType & USB_TYPE_MASK) {
case USB_TYPE_STANDARD:
switch (ctrl->bRequest) {
case USB_REQ_GET_DESCRIPTOR:
switch (ctrl->wValue >> 8) {
case USB_DT_DEVICE:
*response_data = (char*)index->dev;
*response_length = sizeof(*index->dev);
return true;
case USB_DT_CONFIG:
*response_data = (char*)index->config;
*response_length = index->config_length;
return true;
case USB_DT_STRING:
str_idx = (uint8_t)ctrl->wValue;
if (descs && str_idx < descs->strs_len) {
*response_data = descs->strs[str_idx].str;
*response_length = descs->strs[str_idx].len;
return true;
}
if (str_idx == 0) {
*response_data = (char*)&default_lang_id[0];
*response_length = default_lang_id[0];
return true;
}
*response_data = (char*)&default_string[0];
*response_length = default_string[0];
return true;
case USB_DT_BOS:
*response_data = descs->bos;
*response_length = descs->bos_len;
return true;
case USB_DT_DEVICE_QUALIFIER:
if (!descs->qual) {
qual->bLength = sizeof(*qual);
qual->bDescriptorType = USB_DT_DEVICE_QUALIFIER;
qual->bcdUSB = index->dev->bcdUSB;
qual->bDeviceClass = index->dev->bDeviceClass;
qual->bDeviceSubClass = index->dev->bDeviceSubClass;
qual->bDeviceProtocol = index->dev->bDeviceProtocol;
qual->bMaxPacketSize0 = index->dev->bMaxPacketSize0;
qual->bNumConfigurations = index->dev->bNumConfigurations;
qual->bRESERVED = 0;
*response_data = (char*)qual;
*response_length = sizeof(*qual);
return true;
}
*response_data = descs->qual;
*response_length = descs->qual_len;
return true;
default:
break;
}
break;
default:
break;
}
break;
default:
break;
}
return false;
}
typedef bool (*lookup_connect_out_response_t)(int fd, const struct vusb_connect_descriptors* descs,
const struct usb_ctrlrequest* ctrl, bool* done);
static bool lookup_connect_response_out_generic(int fd, const struct vusb_connect_descriptors* descs,
const struct usb_ctrlrequest* ctrl, bool* done)
{
switch (ctrl->bRequestType & USB_TYPE_MASK) {
case USB_TYPE_STANDARD:
switch (ctrl->bRequest) {
case USB_REQ_SET_CONFIGURATION:
*done = true;
return true;
default:
break;
}
break;
}
return false;
}
#define UDC_NAME_LENGTH_MAX 128
struct usb_raw_init {
__u8 driver_name[UDC_NAME_LENGTH_MAX];
__u8 device_name[UDC_NAME_LENGTH_MAX];
__u8 speed;
};
enum usb_raw_event_type {
USB_RAW_EVENT_INVALID = 0,
USB_RAW_EVENT_CONNECT = 1,
USB_RAW_EVENT_CONTROL = 2,
};
struct usb_raw_event {
__u32 type;
__u32 length;
__u8 data[0];
};
struct usb_raw_ep_io {
__u16 ep;
__u16 flags;
__u32 length;
__u8 data[0];
};
#define USB_RAW_EPS_NUM_MAX 30
#define USB_RAW_EP_NAME_MAX 16
#define USB_RAW_EP_ADDR_ANY 0xff
struct usb_raw_ep_caps {
__u32 type_control : 1;
__u32 type_iso : 1;
__u32 type_bulk : 1;
__u32 type_int : 1;
__u32 dir_in : 1;
__u32 dir_out : 1;
};
struct usb_raw_ep_limits {
__u16 maxpacket_limit;
__u16 max_streams;
__u32 reserved;
};
struct usb_raw_ep_info {
__u8 name[USB_RAW_EP_NAME_MAX];
__u32 addr;
struct usb_raw_ep_caps caps;
struct usb_raw_ep_limits limits;
};
struct usb_raw_eps_info {
struct usb_raw_ep_info eps[USB_RAW_EPS_NUM_MAX];
};
#define USB_RAW_IOCTL_INIT _IOW('U', 0, struct usb_raw_init)
#define USB_RAW_IOCTL_RUN _IO('U', 1)
#define USB_RAW_IOCTL_EVENT_FETCH _IOR('U', 2, struct usb_raw_event)
#define USB_RAW_IOCTL_EP0_WRITE _IOW('U', 3, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_EP0_READ _IOWR('U', 4, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_EP_ENABLE _IOW('U', 5, struct usb_endpoint_descriptor)
#define USB_RAW_IOCTL_EP_DISABLE _IOW('U', 6, __u32)
#define USB_RAW_IOCTL_EP_WRITE _IOW('U', 7, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_EP_READ _IOWR('U', 8, struct usb_raw_ep_io)
#define USB_RAW_IOCTL_CONFIGURE _IO('U', 9)
#define USB_RAW_IOCTL_VBUS_DRAW _IOW('U', 10, __u32)
#define USB_RAW_IOCTL_EPS_INFO _IOR('U', 11, struct usb_raw_eps_info)
#define USB_RAW_IOCTL_EP0_STALL _IO('U', 12)
#define USB_RAW_IOCTL_EP_SET_HALT _IOW('U', 13, __u32)
#define USB_RAW_IOCTL_EP_CLEAR_HALT _IOW('U', 14, __u32)
#define USB_RAW_IOCTL_EP_SET_WEDGE _IOW('U', 15, __u32)
static int usb_raw_open()
{
return open("/dev/raw-gadget", O_RDWR);
}
static int usb_raw_init(int fd, uint32_t speed, const char* driver, const char* device)
{
struct usb_raw_init arg;
strncpy((char*)&arg.driver_name[0], driver, sizeof(arg.driver_name));
strncpy((char*)&arg.device_name[0], device, sizeof(arg.device_name));
arg.speed = speed;
return ioctl(fd, USB_RAW_IOCTL_INIT, &arg);
}
static int usb_raw_run(int fd)
{
return ioctl(fd, USB_RAW_IOCTL_RUN, 0);
}
static int usb_raw_ep_write(int fd, struct usb_raw_ep_io* io)
{
return ioctl(fd, USB_RAW_IOCTL_EP_WRITE, io);
}
static int usb_raw_ep_read(int fd, struct usb_raw_ep_io* io)
{
return ioctl(fd, USB_RAW_IOCTL_EP_READ, 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_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_ep_read(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;
int rv = usb_raw_ep_read(fd, (struct usb_raw_ep_io*)&io_data);
if (rv < 0) {
return rv;
}
memcpy(&data[0], &io_data.data[0], io_data.inner.length);
sleep_ms(200);
return 0;
}
uint64_t r[1] = {0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000, /*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 arguments: [
// speed: usb_device_speed = 0x3 (8 bytes)
// dev_len: len = 0x9f (8 bytes)
// dev: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// union ANYUNION {
// ANYBLOB: buffer: {12 01 00 02 00 00 00 40 48 0b 08 10 00 01 00 00 00 01 09 02 8d 00 01 01 00 80 fa 09 04 00 00 05 ff ff ff 00 07 05 03 02 00 02 00 07 05 84 02 00 02} (length 0x31)
// }
// }
// }
// conn_descs: nil
// ]
// returns fd_usb
memcpy((void*)0x20000000, "... [truncated large byte array] ...", 49);
res = -1;
res = syz_usb_connect(/*speed=USB_SPEED_HIGH*/3, /*dev_len=*/0x9f, /*dev=*/0x20000000, /*conn_descs=*/0);
if (res != -1)
r[0] = res;
// syz_usb_ep_read arguments: [
// fd: fd_usb (resource)
// ep: int8 = 0x3 (1 bytes)
// len: len = 0x0 (8 bytes)
// data: nil
// ]
syz_usb_ep_read(/*fd=*/r[0], /*ep=*/3, /*len=*/0, /*data=*/0);
// syz_usb_ep_write arguments: [
// fd: fd_usb (resource)
// ep: int8 = 0x84 (1 bytes)
// len: len = 0xc (8 bytes)
// data: ptr[in, buffer] {
// buffer: {aa 00 9e 4b 65 1d 00 c4 45 ed b0 6d} (length 0xc)
// }
// ]
memcpy((void*)0x20000700, "\xaa\x00\x9e\x4b\x65\x1d\x00\xc4\x45\xed\xb0\x6d", 12);
syz_usb_ep_write(/*fd=*/r[0], /*ep=*/0x84, /*len=*/0xc, /*data=*/0x20000700);
return 0;
}
Reply: The crash is caused by a buffer overflow (both an out-of-bounds read and an out-of-bounds write) in the `ttusb_dec_send_command()` function, triggered by a malicious or malfunctioning USB device returning an unexpectedly large payload length.
### Detailed Analysis
In `drivers/media/usb/ttusb-dec/ttusb_dec.c`, the `ttusb_dec_send_command()` function allocates a buffer `b` to send a command and receive the response via `usb_bulk_msg()`:
```c
b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
```
Here, `COMMAND_PACKET_SIZE` is defined as `0x3c` (60), so the allocated buffer `b` is exactly 64 bytes.
After receiving the response from the USB device, the driver reads the payload length directly from `b[3]` (which is fully controlled by the USB device) and copies the payload into the caller-provided `cmd_result` buffer:
```c
if (result_length)
*result_length = b[3];
if (cmd_result && b[3] > 0)
memcpy(cmd_result, &b[4], b[3]);
```
There are two major flaws in this logic:
1. **No bounds check against the received data or the allocated buffer `b`**: `b[3]` is an 8-bit value and can be up to 255. If the device returns a value greater than `COMMAND_PACKET_SIZE` (60), the `memcpy()` will read past the end of the 64-byte buffer `b`. In the syzkaller crash, `b[3]` was `75`, leading to a 75-byte read from `&b[4]` (which only has 60 bytes allocated). This triggers the `fortify_memcpy_chk` panic (`75 byte read of buffer size 60`).
2. **No bounds check against the destination buffer `cmd_result`**: The size of `cmd_result` is never passed to `ttusb_dec_send_command()`. While callers like `ttusb_dec_get_stb_state()` pass a 60-byte buffer (`u8 c[COMMAND_PACKET_SIZE]`), other callers like `ttusbdecfe_dvbt_read_status()` in `ttusbdecfe.c` pass a much smaller buffer (`u8 result[4]`). If the device returns `b[3] = 60` for the latter, it will result in a severe stack buffer overflow.
### Proposed Fix
To fix this comprehensively, the API needs to be updated to pass the size of the destination buffer, and `ttusb_dec_send_command()` must validate `b[3]` against the received length, the maximum packet size, and the destination buffer size.
**1. Update `ttusbdecfe_config` in `drivers/media/usb/ttusb-dec/ttusbdecfe.h`:**
Add `cmd_result_len` to the `send_command` callback signature.
```c
struct ttusbdecfe_config
{
int (*send_command)(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len);
};
```
**2. Update `ttusb_dec_send_command()` in `ttusb_dec.c`:**
Add `cmd_result_len` to the signature and implement the necessary bounds checks.
```c
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len)
{
// ...
result = usb_bulk_msg(dec->udev, dec->result_pipe, b,
COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
if (result) {
printk("%s: result bulk message failed: error %d\n",
__func__, result);
goto err_mutex_unlock;
} else {
if (debug) {
printk(KERN_DEBUG "%s: result: %*ph\n",
__func__, actual_len, b);
}
/* Ensure we received at least the 4-byte header */
if (actual_len < 4) {
result = -EIO;
goto err_mutex_unlock;
}
/* Ensure the device isn't claiming more data than it sent or than fits in b */
if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
result = -EIO;
goto err_mutex_unlock;
}
if (result_length)
*result_length = b[3];
if (cmd_result && b[3] > 0) {
/* Ensure we don't overflow the caller's buffer */
if (b[3] > cmd_result_len) {
result = -EIO;
goto err_mutex_unlock;
}
memcpy(cmd_result, &b[4], b[3]);
}
}
// ...
```
**3. Update all callers:**
You will need to update all callers of `ttusb_dec_send_command()` in `ttusb_dec.c` and `state->config->send_command()` in `ttusbdecfe.c` to pass the correct buffer size.
For example:
- In `ttusb_dec_get_stb_state()`: pass `sizeof(c)` instead of just `c`.
- In `ttusbdecfe_dvbt_read_status()`: pass `sizeof(result)` instead of just `result`.
- For calls where `cmd_result` is `NULL`, simply pass `0` as the length.
|
| 8/2 |
2026/08/17 21:06 |
llm |
debugger |
0m
Model:
Tokens:
input: 15725
output: 45
thoughts: 624
Thoughts: **Analyzing a Kernel Crash: USB Buffer Overflow**
Okay, so I've got a kernel crash report here. First things first, it mentions a new USB device being plugged in – nothing unusual there, just standard device enumeration. However, then we get to the core issue: a `memcpy` buffer overflow. The system detected a 75-byte read exceeding a 60-byte buffer. The warning points to `lib/string_helpers.c` and specifically `__fortify_report`, indicating that the `fortify_memcpy_chk` check caught the issue.
Now, let's trace this back. The call stack leads me to `ttusb_dec_start_feed` within the `ttusb-dec` USB driver. The trace shows `ttusb_dec_start_feed` being called directly, but also notes that `ttusb_dec_get_stb_state` and `ttusb_dec_init_stb` are inlined functions within the call stack and lead to `ttusb_dec_probe`. The overflow itself is being caught within `ttusb_dec_start_feed` or possibly, a function that calls `ttusb_dec_start_feed`.
My immediate next step is to examine the code in `drivers/media/usb/ttusb-dec/ttusb_dec.c`. I need to pinpoint the exact `memcpy` call that's causing the problem, identify the source and destination buffers, and understand the data flow to figure out why the read size is exceeding the buffer size. It's likely a simple off-by-one or an unchecked data size assumption. Time to dig in and debug!
|
| 9/2 |
2026/08/17 21:06 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusb_dec.c FirstLine:360 LineCount:50]
Results: map[Contents: 360: printk("%s: result bulk message failed: error %d\n",
361: __func__, result);
362: goto err_mutex_unlock;
363: } else {
364: if (debug) {
365: printk(KERN_DEBUG "%s: result: %*ph\n",
366: __func__, actual_len, b);
367: }
368:
369: if (result_length)
370: *result_length = b[3];
371: if (cmd_result && b[3] > 0)
372: memcpy(cmd_result, &b[4], b[3]);
373: }
374:
375: err_mutex_unlock:
376: mutex_unlock(&dec->usb_mutex);
377: err_free:
378: kfree(b);
379: return result;
380: }
381:
382: static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
383: unsigned int *model, unsigned int *version)
384: {
385: u8 c[COMMAND_PACKET_SIZE];
386: int c_length;
387: int result;
388: __be32 tmp;
389:
390: dprintk("%s\n", __func__);
391:
392: result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
393: if (result)
394: return result;
395:
396: if (c_length >= 0x0c) {
397: if (mode != NULL) {
398: memcpy(&tmp, c, 4);
399: *mode = ntohl(tmp);
400: }
401: if (model != NULL) {
402: memcpy(&tmp, &c[4], 4);
403: *model = ntohl(tmp);
404: }
405: if (version != NULL) {
406: memcpy(&tmp, &c[8], 4);
407: *version = ntohl(tmp);
408: }
409: return 0;
]
|
| 10/2 |
2026/08/17 21:06 |
llm |
debugger |
0m
Model:
Tokens:
input: 17459
output: 45
thoughts: 137
Thoughts: **Debugging a Tricky USB Decoder Crash**
Okay, so I've got a crash, and the initial report points me to `ttusb_dec.c:372`. The line is a `memcpy`: `memcpy(cmd_result, &b[4], b[3]);`. Classic memory corruption suspect. But hold on, the trace log is a bit... off. It's actually showing `ttusb_dec_start_feed+0x0/0x10ac drivers/media/usb/ttusb-dec/ttusb_dec.c:372`, but that's *not* the function at that line. It seems the compiler or linker might have put the wrong symbol there, and at line 372 is actually the `ttusb_dec_send_command` function. Time to double-check that function, maybe the issue is there and the backtrace is misleading.
|
| 11/2 |
2026/08/17 21:06 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusb_dec.c FirstLine:300 LineCount:60]
Results: map[Contents: 300: }
301:
302: static u16 crc16(u16 crc, const u8 *buf, size_t len)
303: {
304: u16 tmp;
305:
306: while (len--) {
307: crc ^= *buf++;
308: crc ^= (u8)crc >> 4;
309: tmp = (u8)crc;
310: crc ^= (tmp ^ (tmp << 1)) << 4;
311: }
312: return crc;
313: }
314:
315: static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
316: int param_length, const u8 params[],
317: int *result_length, u8 cmd_result[])
318: {
319: int result, actual_len;
320: u8 *b;
321:
322: dprintk("%s\n", __func__);
323:
324: b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
325: if (!b)
326: return -ENOMEM;
327:
328: result = mutex_lock_interruptible(&dec->usb_mutex);
329: if (result) {
330: printk("%s: Failed to lock usb mutex.\n", __func__);
331: goto err_free;
332: }
333:
334: b[0] = 0xaa;
335: b[1] = ++dec->trans_count;
336: b[2] = command;
337: b[3] = param_length;
338:
339: if (params)
340: memcpy(&b[4], params, param_length);
341:
342: if (debug) {
343: printk(KERN_DEBUG "%s: command: %*ph\n",
344: __func__, param_length, b);
345: }
346:
347: result = usb_bulk_msg(dec->udev, dec->command_pipe, b,
348: COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
349:
350: if (result) {
351: printk("%s: command bulk message failed: error %d\n",
352: __func__, result);
353: goto err_mutex_unlock;
354: }
355:
356: result = usb_bulk_msg(dec->udev, dec->result_pipe, b,
357: COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
358:
359: if (result) {
]
|
| 12/2 |
2026/08/17 21:06 |
llm |
debugger |
0m
Model:
Tokens:
input: 18701
output: 45
thoughts: 62
Thoughts: **Analyzing a USB Command Allocation**
Okay, so I'm looking at this `ttusb_dec_send_command` function, and it looks like it's allocating memory with `b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);`. The important bit here is `COMMAND_PACKET_SIZE`. My initial gut feel is that `COMMAND_PACKET_SIZE` is likely to be around 60, but I need to confirm that. Gotta double-check the definition of `COMMAND_PACKET_SIZE` to be sure. It's a critical parameter for buffer allocation, so I need the precise value.
|
| 13/2 |
2026/08/17 21:06 |
tool |
grepper |
0m
Args: map[Expression:#define COMMAND_PACKET_SIZE PathPrefix:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results: map[Output:drivers/media/usb/ttusb-dec/ttusb_dec.c=41=DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-52-
drivers/media/usb/ttusb-dec/ttusb_dec.c:53:#define COMMAND_PACKET_SIZE 0x3c
drivers/media/usb/ttusb-dec/ttusb_dec.c-54-#define ARM_PACKET_SIZE 0x1000
]
|
| 14/2 |
2026/08/17 21:06 |
llm |
debugger |
0m
Model:
Tokens:
input: 19094
output: 73
thoughts: 599
Thoughts: **Analyzing a Buffer Overflow in `ttusb_dec_send_command`**
Okay, let's break this down. `COMMAND_PACKET_SIZE` is defined as 0x3c, which translates to 60. So, `b` gets allocated with a size of 64 bytes. In the `ttusb_dec_get_stb_state` function, `c` is allocated as `u8 c[COMMAND_PACKET_SIZE]`, meaning 60 bytes. That's our target buffer for this function.
Now, looking at `ttusb_dec_send_command`, the critical section is the `usb_bulk_msg` call. Here, the code reads data from the USB device into `b`. The interesting part is the `memcpy` that follows:
```c
memcpy(cmd_result, &b[4], b[3]);
```
Here, `b[3]` contains a length value that comes directly from the USB device. The core issue is that the USB device could return any value for `b[3]`. If `b[3]` is greater than `COMMAND_PACKET_SIZE` (60), the `memcpy` will overflow `cmd_result`, which is our 60-byte buffer (`c`). The crash report confirms this: "memcpy: detected buffer overflow: 75 byte read of buffer size 60". So, the device sent a length of 75 in `b[3]`.
The size of `b` is `COMMAND_PACKET_SIZE + 4` = 64 bytes. The `memcpy` tries to read 75 bytes from `&b[4]`, starting 4 bytes into `b`. This means the `memcpy` will read 60 bytes from inside `b` and 15 bytes out of bounds of `b`. And, it will write 75 bytes to `cmd_result`, which is our 60 byte buffer `c`, so it will write out of bounds of `c`. This is a classic buffer overflow scenario. The code is reading out of the `b` buffer to read the command response from the device, which also overflows `c`, the local command response, since the size provided by the device exceeds the intended buffer size.
It is necessary to inspect any other functions which call `ttusb_dec_send_command` to see if there is any place where a smaller buffer might be passed.
|
| 15/2 |
2026/08/17 21:06 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusb_dec.c IncludeSnippetLines:2 Name:ttusb_dec_send_command SourceTreePrefix:drivers/media/usb/ttusb-dec/]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:fe_send_command SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1627 SourceSnippet:1625: {
1626: struct ttusb_dec* dec = fe->dvb->priv;
1627: return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
1628: }
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_boot_dsp SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1357 SourceSnippet:1355: memcpy(&b0[6], &firmware_csum_ns, 2);
1356:
1357: result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL);
1358:
1359: if (result) {
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_boot_dsp SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1398 SourceSnippet:1396: }
1397:
1398: result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL);
1399:
1400: release_firmware(fw_entry);
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_get_stb_state SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:392 SourceSnippet: 390: dprintk("%s\n", __func__);
391:
392: result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
393: if (result)
394: return result;
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_set_interface SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:904 SourceSnippet: 902: break;
903: case TTUSB_DEC_INTERFACE_IN:
904: result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
905: b, NULL, NULL);
906: if (result)
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_set_pids SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:451 SourceSnippet: 449: memcpy(&b[4], &video, 2);
450:
451: ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL);
452:
453: dvb_filter_pes2ts_init(&dec->a_pes2ts, dec->pid[DMX_PES_AUDIO],
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_start_sec_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1058 SourceSnippet:1056: memcpy(&b0[5], &dvbdmxfeed->filter->filter.filter_value[0], 1);
1057:
1058: result = ttusb_dec_send_command(dec, 0x60, sizeof(b0), b0,
1059: &c_length, c);
1060:
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_start_ts_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1024 SourceSnippet:1022: }
1023:
1024: result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL);
1025: if (result)
1026: return result;
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_stop_sec_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1138 SourceSnippet:1136: spin_unlock_irqrestore(&dec->filter_info_list_lock, flags);
1137: kfree(finfo);
1138: ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL);
1139:
1140: dec->filter_stream_count--;
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_stop_ts_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1117 SourceSnippet:1115: u8 b0[] = { 0x00 };
1116:
1117: ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL);
1118:
1119: dec->pva_stream_count--;
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_init_rc SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1241 SourceSnippet:1239: printk("%s: usb_submit_urb failed\n",__func__);
1240: /* enable irq pipe */
1241: ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
1242:
1243: return 0;
]] TruncatedOutput:false]
|
| 16/2 |
2026/08/17 21:06 |
llm |
debugger |
0m
Model:
Tokens:
input: 22022
output: 46
thoughts: 16
Thoughts: Okay, here's my attempt at summarizing that thought process, assuming I'm a seasoned professional in the field (likely embedded systems or audio/video processing, given the "ttusb" and "dec" keywords):
**Checking the `ttusb_dec_start_sec_feed` Function**
Alright, time to dig into this. My initial instinct is to go straight for `ttusb_dec_start_sec_feed`. This function name, based on my experience, strongly suggests it's a critical component related to the USB transport (probably related to a specific tuner type that I am familiar with) and the decoding process. The "start" implies an initiation, and "sec_feed" likely hints at the feeding of a secondary data stream, potentially related to section data, tables, or other control information vital for the decoder's operation. I need to understand exactly what this function does: does it initialize a specific data pipe? Does it enable an interrupt? Does it allocate and set up buffers? Is it directly called by the USB driver or is it called from the decoding section? I need to analyze its structure. Now let's see what that function does.
|
| 17/2 |
2026/08/17 21:06 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusb_dec.c FirstLine:1040 LineCount:40]
Results: map[Contents:1040: 0x00, 0x00, 0x00, 0x00,
1041: 0x00, 0x00, 0x00, 0x00,
1042: 0x00 };
1043: __be16 pid;
1044: u8 c[COMMAND_PACKET_SIZE];
1045: int c_length;
1046: int result;
1047: struct filter_info *finfo;
1048: unsigned long flags;
1049: u8 x = 1;
1050:
1051: dprintk("%s\n", __func__);
1052:
1053: pid = htons(dvbdmxfeed->pid);
1054: memcpy(&b0[0], &pid, 2);
1055: memcpy(&b0[4], &x, 1);
1056: memcpy(&b0[5], &dvbdmxfeed->filter->filter.filter_value[0], 1);
1057:
1058: result = ttusb_dec_send_command(dec, 0x60, sizeof(b0), b0,
1059: &c_length, c);
1060:
1061: if (!result) {
1062: if (c_length == 2) {
1063: if (!(finfo = kmalloc_obj(struct filter_info, GFP_ATOMIC)))
1064: return -ENOMEM;
1065:
1066: finfo->stream_id = c[1];
1067: finfo->filter = dvbdmxfeed->filter;
1068:
1069: spin_lock_irqsave(&dec->filter_info_list_lock, flags);
1070: list_add_tail(&finfo->filter_info_list,
1071: &dec->filter_info_list);
1072: spin_unlock_irqrestore(&dec->filter_info_list_lock,
1073: flags);
1074:
1075: dvbdmxfeed->priv = finfo;
1076:
1077: dec->filter_stream_count++;
1078: return ttusb_dec_start_iso_xfer(dec);
1079: }
]
|
| 18/2 |
2026/08/17 21:06 |
llm |
debugger |
0m
Model:
Tokens:
input: 22991
output: 45
thoughts: 227
Thoughts: **Analyzing a Potential Heap Buffer Over-Read and Stack Buffer Overflow Vulnerability**
Okay, let me break this down. In the `ttusb_dec_start_sec_feed` function, `c` is defined as a `u8` array, sized `COMMAND_PACKET_SIZE`. And now I'm looking at `ttusb_dec_send_command`, the buffer `b` is allocated with a size of `COMMAND_PACKET_SIZE + 4` bytes. Hmm, that looks like it could be a problem, given the context.
If the device throws back a packet and the value of `b[3]` is *greater* than `COMMAND_PACKET_SIZE`, then it's going to overflow `c`. Wait a minute, hold up! `b[3]` is a `u8`, so it maxes out at 255. That's a good start to pinpoint the problem.
Alright, so if `b[3]` is 255, then `memcpy(cmd_result, &b[4], 255)` is going to read 255 bytes from `&b[4]`. The trouble is, `b` is only 64 bytes! That means the read will be out of bounds of `b` - a heap buffer over-read. Then, it will write out of bounds of `cmd_result`, which I'm assuming is a stack buffer, so...stack buffer overflow.
I should probably double-check `ttusb_dec_send_command` one more time, just to be sure I'm not missing anything.
|
| 19/2 |
2026/08/17 21:06 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusb_dec.c FirstLine:315 LineCount:60]
Results: map[Contents: 315: static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
316: int param_length, const u8 params[],
317: int *result_length, u8 cmd_result[])
318: {
319: int result, actual_len;
320: u8 *b;
321:
322: dprintk("%s\n", __func__);
323:
324: b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
325: if (!b)
326: return -ENOMEM;
327:
328: result = mutex_lock_interruptible(&dec->usb_mutex);
329: if (result) {
330: printk("%s: Failed to lock usb mutex.\n", __func__);
331: goto err_free;
332: }
333:
334: b[0] = 0xaa;
335: b[1] = ++dec->trans_count;
336: b[2] = command;
337: b[3] = param_length;
338:
339: if (params)
340: memcpy(&b[4], params, param_length);
341:
342: if (debug) {
343: printk(KERN_DEBUG "%s: command: %*ph\n",
344: __func__, param_length, b);
345: }
346:
347: result = usb_bulk_msg(dec->udev, dec->command_pipe, b,
348: COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
349:
350: if (result) {
351: printk("%s: command bulk message failed: error %d\n",
352: __func__, result);
353: goto err_mutex_unlock;
354: }
355:
356: result = usb_bulk_msg(dec->udev, dec->result_pipe, b,
357: COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
358:
359: if (result) {
360: printk("%s: result bulk message failed: error %d\n",
361: __func__, result);
362: goto err_mutex_unlock;
363: } else {
364: if (debug) {
365: printk(KERN_DEBUG "%s: result: %*ph\n",
366: __func__, actual_len, b);
367: }
368:
369: if (result_length)
370: *result_length = b[3];
371: if (cmd_result && b[3] > 0)
372: memcpy(cmd_result, &b[4], b[3]);
373: }
374:
]
|
| 20/2 |
2026/08/17 21:06 |
llm |
debugger |
0m
Model:
Tokens:
input: 24502
output: 55
thoughts: 1384
Thoughts: **Analyzing a Potential Buffer Overflow in USB Communication**
Okay, so I'm looking at this USB communication code, and I see a potential vulnerability. It starts with a simple observation: `b[3]` represents the length of the result data. Now, if `b[3]` is larger than `COMMAND_PACKET_SIZE`, we're going to overflow the `cmd_result` buffer, which is allocated to `COMMAND_PACKET_SIZE` bytes, or sometimes passed as `NULL`. There's no check for this initially, which is a red flag.
The `b` buffer itself is allocated as `COMMAND_PACKET_SIZE + 4`. So, `b[3]` *shouldn't* exceed `COMMAND_PACKET_SIZE`, but is this enforced? That's the question. Then I remember that `actual_len` contains the number of bytes actually *received* from the device. The device might not always send the full `COMMAND_PACKET_SIZE + 4` bytes. In that case, the value in `b[3]` could be anything, potentially larger than what the `cmd_result` can handle.
If the device sends `b[3]` > `COMMAND_PACKET_SIZE`, `memcpy` will read and write beyond the bounds of both buffers. The solution is clear: add a check. We *must* verify if `b[3]` is greater than `COMMAND_PACKET_SIZE` before using it in `memcpy`.
I also have to consider that `actual_len` might be less than `COMMAND_PACKET_SIZE + 4`. If this happens, the `memcpy` will read from `b` and write to `cmd_result` as though all the data is present which it is not. This needs to be considered. Then it hits me: the `usb_bulk_msg` call receives *up to* `COMMAND_PACKET_SIZE + 4` bytes, but it doesn't clear the buffer. If `actual_len` is less than 4, `b[3]` could contain stale data from the *command* message, which could be a problem. The command message uses `b` as well.
So, I need to check `actual_len` to determine if the header is valid. If it's less than 4, then we've had a short read, and `b[3]` could contain garbage. I'll need to check the function, `ttusb_dec_send_command` more closely.
Looking at `ttusb_dec_send_command`, if `actual_len` < 4, `b[3]` would contain old data from `b`. But `b` is allocated with `kzalloc`, and therefore will be zeroed. Still, a device might send a partial header (less than 4 bytes), which is definitely not valid.
If `actual_len` is less than 4, the device is misbehaving, and the code needs to handle this. Also, if `b[3] > actual_len - 4`, `memcpy` will read beyond the end of the `b` buffer (although it's initialized, so it's not a security issue). The right check is:
```c
if (b[3] > COMMAND_PACKET_SIZE) {
/* error */
}
if (b[3] > actual_len - 4 && actual_len >= 4){
/* error */
}
memcpy(cmd_result, &b[4], min_t(int, b[3], actual_len - 4));
```
So I think the fix boils down to checking if `b[3]` is greater than both `COMMAND_PACKET_SIZE` and `actual_len - 4`, and that we need to ensure that the header length is valid, and the bytes copied is not greater than the available received bytes. I'll search for other similar fixes in the kernel to be certain.
|
| 21/2 |
2026/08/17 21:07 |
tool |
git-log |
0m
Args: map[CodeRegexp:b\[3\] > COMMAND_PACKET_SIZE Count:5 PathPrefix:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 22/2 |
2026/08/17 21:07 |
llm |
debugger |
0m
Model:
Tokens:
input: 26816
output: 38
thoughts: 24
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Investigating Recent Changes in `ttusb_dec.c`**
Alright, before I dive too deep into this issue, a good starting point is always the version control history. I need to get a handle on what's been happening with `ttusb_dec.c` recently. My instinct is that the problem I'm seeing might be related to a recent bug fix or perhaps a refactoring that inadvertently introduced a regression. A quick `git log` should tell the story; a few well-placed `grep`s and some filtering on the commit messages and author information may save me a lot of debugging time. I'll focus on the commits that specifically touch `ttusb_dec.c` and see if anything jumps out. Hopefully, there's a clear culprit I can zero in on, perhaps a particularly tricky commit message or some suspicious code changes. If not, this at least gives me a solid baseline, a starting point to start my investigation.
|
| 23/2 |
2026/08/17 21:07 |
tool |
git-log |
0m
Args: map[Count:10 PathPrefix:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results: map[Output:bf4afc53b77a Convert 'alloc_obj' family to use the new default GFP_KERNEL argument
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
1021dd010d21 media: Convert from tasklet to BH workqueue
eff540df5f80 media: usb: remove unnecessary (void*) conversions
517a28133832 media: ttusb-dec: fix memory leak in ttusb_dec_exit_dvb()
36b9d695aa6f media: ttusb-dec: avoid release of non-acquired mutex
dba328bab4c6 media: ttusb-dec: cleanup an error handling logic
c3bf67e80532 media: media/usb:Remove superfluous "breaks" in the ttusb_dec.c
f3b60b066a5b media: ttusb-dec: convert tasklets to use new tasklet_setup() API
f933d160b1e7 media: usb: ttusb-dec: reduce the number of memory reads in ttusb_dec_handle_irq()
]
|
| 24/2 |
2026/08/17 21:07 |
llm |
debugger |
0m
Model:
Tokens:
input: 27392
output: 73
thoughts: 192
Thoughts: **Analyzing a Persistent Buffer Overflow**
Okay, so I'm dealing with a buffer overflow, and it's been around for a bit – no recent commits seem to have addressed it. Let's dig in. The crash report says `memcpy` detected a buffer overflow: a 75-byte read from a 60-byte buffer. Right, `b[3]` was the offending value, 75. That's a classic overflow scenario.
Looking at the code, it looks like `cmd_result` is `c` within `ttusb_dec_get_stb_state`. And `c` is, as I recall, defined as `u8 c[COMMAND_PACKET_SIZE];`. Let me just confirm... Yup, `COMMAND_PACKET_SIZE` is 0x3c, or 60. So, the size mismatch is clear – `b[3]` is 75, which blows right past the 60-byte limit.
The fix, logically, seems to be a straightforward bounds check. I need to compare `b[3]` against either `COMMAND_PACKET_SIZE` or, potentially, `actual_len - 4`. But... a thought occurs to me. Is `cmd_result` always *exactly* `COMMAND_PACKET_SIZE` bytes? That's a critical assumption. I need to be absolutely sure.
Okay, I'll need to check *every* single call site of `ttusb_dec_send_command`. Gotta verify how the length information is used there before I commit to a fix. Don't want to introduce a regression by over-simplifying the solution.
|
| 25/2 |
2026/08/17 21:07 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusb_dec.c IncludeSnippetLines:5 Name:ttusb_dec_send_command SourceTreePrefix:drivers/media/usb/ttusb-dec/]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:fe_send_command SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1627 SourceSnippet:1622: static int fe_send_command(struct dvb_frontend* fe, const u8 command,
1623: int param_length, const u8 params[],
1624: int *result_length, u8 cmd_result[])
1625: {
1626: struct ttusb_dec* dec = fe->dvb->priv;
1627: return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
1628: }
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_boot_dsp SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1357 SourceSnippet:1352: memcpy(b0, &firmware_size_nl, 4);
1353: firmware_csum = crc16(~0, firmware, firmware_size) ^ ~0;
1354: firmware_csum_ns = htons(firmware_csum);
1355: memcpy(&b0[6], &firmware_csum_ns, 2);
1356:
1357: result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL);
1358:
1359: if (result) {
1360: release_firmware(fw_entry);
1361: return result;
1362: }
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_boot_dsp SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1398 SourceSnippet:1393: j - COMMAND_PACKET_SIZE + size,
1394: &actual_len, 100);
1395: }
1396: }
1397:
1398: result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL);
1399:
1400: release_firmware(fw_entry);
1401: kfree(b);
1402:
1403: return result;
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_get_stb_state SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:392 SourceSnippet: 387: int result;
388: __be32 tmp;
389:
390: dprintk("%s\n", __func__);
391:
392: result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
393: if (result)
394: return result;
395:
396: if (c_length >= 0x0c) {
397: if (mode != NULL) {
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_set_interface SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:904 SourceSnippet: 899: switch (interface) {
900: case TTUSB_DEC_INTERFACE_INITIAL:
901: result = usb_set_interface(dec->udev, 0, 0);
902: break;
903: case TTUSB_DEC_INTERFACE_IN:
904: result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
905: b, NULL, NULL);
906: if (result)
907: return result;
908: result = usb_set_interface(dec->udev, 0, 8);
909: break;
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_set_pids SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:451 SourceSnippet: 446:
447: memcpy(&b[0], &pcr, 2);
448: memcpy(&b[2], &audio, 2);
449: memcpy(&b[4], &video, 2);
450:
451: ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL);
452:
453: dvb_filter_pes2ts_init(&dec->a_pes2ts, dec->pid[DMX_PES_AUDIO],
454: ttusb_dec_audio_pes2ts_cb, dec);
455: dvb_filter_pes2ts_init(&dec->v_pes2ts, dec->pid[DMX_PES_VIDEO],
456: ttusb_dec_video_pes2ts_cb, dec);
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_start_sec_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1058 SourceSnippet:1053: pid = htons(dvbdmxfeed->pid);
1054: memcpy(&b0[0], &pid, 2);
1055: memcpy(&b0[4], &x, 1);
1056: memcpy(&b0[5], &dvbdmxfeed->filter->filter.filter_value[0], 1);
1057:
1058: result = ttusb_dec_send_command(dec, 0x60, sizeof(b0), b0,
1059: &c_length, c);
1060:
1061: if (!result) {
1062: if (c_length == 2) {
1063: if (!(finfo = kmalloc_obj(struct filter_info, GFP_ATOMIC)))
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_start_ts_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1024 SourceSnippet:1019: dprintk(" pes_type: unknown (%d)\n", dvbdmxfeed->pes_type);
1020: return -EINVAL;
1021:
1022: }
1023:
1024: result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL);
1025: if (result)
1026: return result;
1027:
1028: dec->pva_stream_count++;
1029: return ttusb_dec_start_iso_xfer(dec);
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_stop_sec_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1138 SourceSnippet:1133: b0[1] = finfo->stream_id;
1134: spin_lock_irqsave(&dec->filter_info_list_lock, flags);
1135: list_del(&finfo->filter_info_list);
1136: spin_unlock_irqrestore(&dec->filter_info_list_lock, flags);
1137: kfree(finfo);
1138: ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL);
1139:
1140: dec->filter_stream_count--;
1141:
1142: ttusb_dec_stop_iso_xfer(dec);
1143:
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_stop_ts_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1117 SourceSnippet:1112: static int ttusb_dec_stop_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
1113: {
1114: struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
1115: u8 b0[] = { 0x00 };
1116:
1117: ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL);
1118:
1119: dec->pva_stream_count--;
1120:
1121: ttusb_dec_stop_iso_xfer(dec);
1122:
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_init_rc SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1241 SourceSnippet:1236:
1237: dec->rc_input_dev = input_dev;
1238: if (usb_submit_urb(dec->irq_urb, GFP_KERNEL))
1239: printk("%s: usb_submit_urb failed\n",__func__);
1240: /* enable irq pipe */
1241: ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
1242:
1243: return 0;
1244: }
]] TruncatedOutput:false]
|
| 26/2 |
2026/08/17 21:07 |
llm |
debugger |
0m
Model:
Tokens:
input: 30761
output: 46
thoughts: 37
Thoughts: Here's my take on the thought process:
**Diving into the Function Call**
Okay, hold on a second. I seem to recall `fe_send_command` being invoked from deep within the `ttusb_dec_fe.c` file, or something along those lines. Just need to confirm. I should probably double-check that by looking at the function. That's a good starting point to trace the calling hierarchy. Let's start with `fe_send_command`.
|
| 27/2 |
2026/08/17 21:07 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusb_dec.c FirstLine:1620 LineCount:20]
Results: map[Contents:1620: }
1621:
1622: static int fe_send_command(struct dvb_frontend* fe, const u8 command,
1623: int param_length, const u8 params[],
1624: int *result_length, u8 cmd_result[])
1625: {
1626: struct ttusb_dec* dec = fe->dvb->priv;
1627: return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
1628: }
1629:
1630: static const struct ttusbdecfe_config fe_config = {
1631: .send_command = fe_send_command
1632: };
1633:
1634: static int ttusb_dec_probe(struct usb_interface *intf,
1635: const struct usb_device_id *id)
1636: {
1637: struct usb_device *udev;
1638: struct ttusb_dec *dec;
1639: int result;
]
|
| 28/2 |
2026/08/17 21:07 |
llm |
debugger |
0m
Model:
Tokens:
input: 31266
output: 68
thoughts: 62
Thoughts: Okay, here's my take on those thoughts, framed as my own mental process, given my expertise:
**Checking `ttusbdecfe_attach` and Command Packet Handling**
Alright, so `fe_config` is being passed into `ttusbdecfe_attach`, got it. That's the starting point. My immediate thought is, "Okay, what's happening *inside* that function, specifically concerning how it interacts with the command results?" I need to confirm something crucial about the command structure.
Right, I need to verify how `cmd_result` is being handled within the `ttusbdecfe.c` driver code, in `drivers/media/usb/ttusb-dec/ttusbdecfe.c`. I need to confirm if the size is consistent. I suspect there may be assumptions or dependencies on `cmd_result` *always* being `COMMAND_PACKET_SIZE` bytes. Any potential deviation from that could cause issues with how results are interpreted, right? So let's crack open that file and make sure there aren't any sneaky assumptions or potential buffer overflows lurking. Gotta be thorough, you know, especially with driver code.
|
| 29/2 |
2026/08/17 21:07 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c IncludeSnippetLines:5 Name:send_command SourceTreePrefix:drivers/media/usb/ttusb-dec/]
Results: map[References:<nil> TruncatedOutput:false]
|
| 30/2 |
2026/08/17 21:07 |
llm |
debugger |
0m
Model:
Tokens:
input: 31661
output: 40
thoughts: 19
Thoughts: Here's my understanding of the thought process, summarized as you requested:
**Navigating Configuration Data Structures**
Okay, let me think this through. I was just working with the `ttusbdecfe_config` structure, and something clicked. *Wait a minute...* I've been staring at this code for a while now, and it just hit me. `send_command` isn't some standalone function call I was imagining. It's actually a *field* within the `ttusbdecfe_config` structure itself! It's right there, embedded within the configuration data. This changes how I approach it.
|
| 31/2 |
2026/08/17 21:07 |
tool |
grepper |
0m
Args: map[Expression:send_command PathPrefix:drivers/media/usb/ttusb-dec/ttusbdecfe.c]
Results: map[Output:drivers/media/usb/ttusb-dec/ttusbdecfe.c=36=static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
--
drivers/media/usb/ttusb-dec/ttusbdecfe.c-46-
drivers/media/usb/ttusb-dec/ttusbdecfe.c:47: ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
drivers/media/usb/ttusb-dec/ttusbdecfe.c-48- if(ret)
--
drivers/media/usb/ttusb-dec/ttusbdecfe.c=76=static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend *fe)
--
drivers/media/usb/ttusb-dec/ttusbdecfe.c-87- memcpy(&b[4], &freq, sizeof (u32));
drivers/media/usb/ttusb-dec/ttusbdecfe.c:88: state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
drivers/media/usb/ttusb-dec/ttusbdecfe.c-89-
--
drivers/media/usb/ttusb-dec/ttusbdecfe.c=103=static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend *fe)
--
drivers/media/usb/ttusb-dec/ttusbdecfe.c-132-
drivers/media/usb/ttusb-dec/ttusbdecfe.c:133: state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
drivers/media/usb/ttusb-dec/ttusbdecfe.c-134-
--
drivers/media/usb/ttusb-dec/ttusbdecfe.c=138=static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *cmd)
--
drivers/media/usb/ttusb-dec/ttusbdecfe.c-149-
drivers/media/usb/ttusb-dec/ttusbdecfe.c:150: state->config->send_command(fe, 0x72,
drivers/media/usb/ttusb-dec/ttusbdecfe.c-151- sizeof(b) - (6 - cmd->msg_len), b,
]
|
| 32/2 |
2026/08/17 21:07 |
llm |
debugger |
0m
Model:
Tokens:
input: 32486
output: 44
thoughts: 26
Thoughts: Here's my summary, as if I were thinking these thoughts:
**Analyzing the DVB-T Status Reading Function**
Okay, time to dive in. I need to get a handle on how this DVB-T demodulator status is being read. Let's start by looking closely at the `ttusbdecfe_dvbt_read_status` function within the `ttusbdecfe.c` file. I'm going to need to trace through this and understand the exact sequence of registers being polled, any error handling it implements, and how the data is being interpreted to determine things like signal lock, signal quality, and any other relevant DVB-T parameters. I want to see how robust this code is and if there are any potential areas for improvement or optimization. Hopefully, it's well-commented, and I can quickly get a good grasp of the underlying logic. Let's get to it.
|
| 33/2 |
2026/08/17 21:07 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusbdecfe.c FirstLine:36 LineCount:20]
Results: map[Contents: 36: static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
37: enum fe_status *status)
38: {
39: struct ttusbdecfe_state* state = fe->demodulator_priv;
40: u8 b[] = { 0x00, 0x00, 0x00, 0x00,
41: 0x00, 0x00, 0x00, 0x00 };
42: u8 result[4];
43: int len, ret;
44:
45: *status=0;
46:
47: ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
48: if(ret)
49: return ret;
50:
51: if(len != 4) {
52: printk(KERN_ERR "%s: unexpected reply\n", __func__);
53: return -EIO;
54: }
55:
]
|
| 34/2 |
2026/08/17 21:07 |
llm |
debugger |
0m
Model:
Tokens:
input: 33068
output: 43
thoughts: 465
Thoughts: **Buffer Overflow Analysis and Proposed Fix**
Okay, so I've spotted it! The `result` buffer is defined as `u8 result[4];`. And if `b[3]` is 75, this `memcpy(cmd_result, &b[4], 75)` is going to overflow `result[4]` by a whopping 71 bytes! This means `cmd_result` isn't always going to be the fixed `COMMAND_PACKET_SIZE` we might have assumed. The killer is that `ttusb_dec_send_command` has no idea about the size of `cmd_result`. It's just blindly copying `b[3]` bytes into it, and that's precisely where the overflow happens. The classic buffer overflow vulnerability.
The fix? We have to pass the actual size of `cmd_result` to `ttusb_dec_send_command`. Looking at the prototype, I think we can modify the function signature. I'm going to add an additional `cmd_result_len` to track the actual size:
```c
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[], int cmd_result_len)
```
But, wait! The `fe_config` struct, the one with `send_command`, is going to need to be changed too. I'll need to update that to reflect the new `send_command` signature. Let's see... I'll check `drivers/media/usb/ttusb-dec/ttusbdecfe.h` to make sure I update the definition there as well.
|
| 35/2 |
2026/08/17 21:07 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusbdecfe.h FirstLine:1 LineCount:20]
Results: map[Contents: 1: /* SPDX-License-Identifier: GPL-2.0-or-later */
2: /*
3: * TTUSB DEC Driver
4: *
5: * Copyright (C) 2003-2004 Alex Woods <linux-dvb@giblets.org>
6: */
7:
8: #ifndef TTUSBDECFE_H
9: #define TTUSBDECFE_H
10:
11: #include <linux/dvb/frontend.h>
12:
13: struct ttusbdecfe_config
14: {
15: int (*send_command)(struct dvb_frontend* fe, const u8 command,
16: int param_length, const u8 params[],
17: int *result_length, u8 cmd_result[]);
18: };
19:
20: extern struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config);
]
|
| 36/2 |
2026/08/17 21:07 |
llm |
debugger |
0m
Model:
Tokens:
input: 34245
output: 60
thoughts: 42
Thoughts: Okay, let me think this through.
**Analyzing the Impact of a Function Modification**
Hmm, so if I'm understanding this correctly, we're talking about modifying the `send_command` function within `ttusbdecfe_config`. That's a pretty low-level function, suggesting it's likely a core component. The first thing that jumps out is the ripple effect. If we're making a change here, we absolutely *have* to meticulously check every single piece of code that calls `ttusbdecfe_config`. We can't just assume it'll be fine.
The next immediate question I have is, are there any *other* drivers using `ttusbdecfe_config`? This isn't just about the immediate implementation. If multiple drivers are relying on this, the scope of impact and the testing required skyrockets. We need to identify all dependencies, and carefully assess how each one interacts with the current command structure, before even thinking of a modification. I need to make sure I haven't missed any.
|
| 37/2 |
2026/08/17 21:07 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusbdecfe.h IncludeSnippetLines:2 Name:ttusbdecfe_config SourceTreePrefix:]
Results: map[References:[map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:ttusbdecfe_dvbs_attach SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c SourceLine:216 SourceSnippet: 216: struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config)
217: {
218: struct ttusbdecfe_state* state = NULL;
] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:ttusbdecfe_dvbt_attach SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c SourceLine:196 SourceSnippet: 196: struct dvb_frontend* ttusbdecfe_dvbt_attach(const struct ttusbdecfe_config* config)
197: {
198: struct ttusbdecfe_state* state = NULL;
] map[ReferenceKind:uses ReferencingEntityKind:global_variable ReferencingEntityName:fe_config SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1630 SourceSnippet:1630: static const struct ttusbdecfe_config fe_config = {
1631: .send_command = fe_send_command
1632: };
]] TruncatedOutput:false]
|
| 38/2 |
2026/08/17 21:07 |
llm |
debugger |
0m
Model:
Tokens:
input: 34960
output: 45
thoughts: 1694
Thoughts: **Refactoring `ttusb_dec_send_command` for Robustness**
Okay, so the immediate goal here is to introduce a `cmd_result_len` parameter to `ttusbdecfe_config` and ultimately to `ttusb_dec_send_command` in order to provide safer bounds checking on the command result data. The scope is confined to `ttusb_dec.c` and `ttusbdecfe.c`, so that makes this a fairly isolated change, which is good.
First, I need to revisit the `ttusbdecfe_dvbt_read_status` function, focusing on how it currently handles command results. Specifically, I see a potential for overflow if the `send_command` function returns more data than the `result` buffer can hold. Currently, the code in `ttusbdecfe_dvbt_read_status` is this:
```c
ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
```
Where `result` is a `u8 result[4];`.
Now, if I change the function signature of `send_command` to include a `cmd_result_len` parameter, things get a bit more interesting. The revised `ttusbdecfe_dvbt_read_status` would call it like this:
```c
ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result, sizeof(result));
```
And then, `fe_send_command` would be modified to call `ttusb_dec_send_command`. This would allow the callee to know the size of the buffer it is writing into.
The next step is to examine how `ttusb_dec_send_command` would handle the `cmd_result_len` parameter and the return data length (`b[3]`). I'm concerned about scenarios where the result length reported by the device (`b[3]`) exceeds the allocated buffer size. Should I clip it, return an error, or something else? If the device returns more data than expected, it might indicate a bug or a malicious attempt.
If I were to simply copy `min(b[3], cmd_result_len)` to avoid overflows, what would happen with `*result_length`? The calling code reads `*result_length` and might assume that many bytes were copied into `cmd_result`.
Looking back at the calling code, particularly in `ttusbdecfe_dvbt_read_status`, I realize that the overflow might actually not be as big of a deal as I initially thought since there is a check after the send_command call to make sure the expected data size is returned. The code will return an error if it doesn't receive the expected data size, meaning a read overflow will trigger an error. However, while an error is returned, the overflow could still have happened.
I have to consider the potential for out-of-bounds reads. The code allocates `COMMAND_PACKET_SIZE + 4` bytes. If `b[3]` contains a value larger than `COMMAND_PACKET_SIZE` it would cause an out of bounds read, and that is very bad!
The actual number of received bytes is in `actual_len`. I must ensure that I do not read past `actual_len - 4` bytes when copying data from `&b[4]`.
However, the current code checks that.
```c
if (result_length)
*result_length = b[3];
if (cmd_result && b[3] > 0) {
int copy_len = b[3];
if (copy_len > COMMAND_PACKET_SIZE)
copy_len = COMMAND_PACKET_SIZE;
if (copy_len > cmd_result_len)
copy_len = cmd_result_len;
memcpy(cmd_result, &b[4], copy_len);
}
```
This code looks like it is already taking care of this overflow.
But what if `actual_len < 4`? In that case, I might be reading uninitialized data or data from the command itself. I should check for `actual_len >= 4` before proceeding with any data copying. In fact, the code *does* check this!
```c
if (actual_len < 4) {
result = -EIO;
goto err_mutex_unlock;
}
```
Now, the final thing I must consider is that changing the prototype of `ttusb_dec_send_
|
| 39/2 |
2026/08/17 21:08 |
tool |
grepper |
0m
Args: map[Expression:ttusb_dec_send_command PathPrefix:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results: map[Output:drivers/media/usb/ttusb-dec/ttusb_dec.c=302=static u16 crc16(u16 crc, const u8 *buf, size_t len)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-314-
drivers/media/usb/ttusb-dec/ttusb_dec.c:315:static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
drivers/media/usb/ttusb-dec/ttusb_dec.c-316- int param_length, const u8 params[],
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=382=static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-391-
drivers/media/usb/ttusb-dec/ttusb_dec.c:392: result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
drivers/media/usb/ttusb-dec/ttusb_dec.c-393- if (result)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=435=static void ttusb_dec_set_pids(struct ttusb_dec *dec)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-450-
drivers/media/usb/ttusb-dec/ttusb_dec.c:451: ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL);
drivers/media/usb/ttusb-dec/ttusb_dec.c-452-
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=892=static int ttusb_dec_set_interface(struct ttusb_dec *dec,
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-903- case TTUSB_DEC_INTERFACE_IN:
drivers/media/usb/ttusb-dec/ttusb_dec.c:904: result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
drivers/media/usb/ttusb-dec/ttusb_dec.c-905- b, NULL, NULL);
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=964=static int ttusb_dec_start_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-1023-
drivers/media/usb/ttusb-dec/ttusb_dec.c:1024: result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL);
drivers/media/usb/ttusb-dec/ttusb_dec.c-1025- if (result)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=1032=static int ttusb_dec_start_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-1057-
drivers/media/usb/ttusb-dec/ttusb_dec.c:1058: result = ttusb_dec_send_command(dec, 0x60, sizeof(b0), b0,
drivers/media/usb/ttusb-dec/ttusb_dec.c-1059- &c_length, c);
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=1112=static int ttusb_dec_stop_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-1116-
drivers/media/usb/ttusb-dec/ttusb_dec.c:1117: ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL);
drivers/media/usb/ttusb-dec/ttusb_dec.c-1118-
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=1126=static int ttusb_dec_stop_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-1137- kfree(finfo);
drivers/media/usb/ttusb-dec/ttusb_dec.c:1138: ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL);
drivers/media/usb/ttusb-dec/ttusb_dec.c-1139-
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=1207=static int ttusb_init_rc( struct ttusb_dec *dec)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-1240- /* enable irq pipe */
drivers/media/usb/ttusb-dec/ttusb_dec.c:1241: ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
drivers/media/usb/ttusb-dec/ttusb_dec.c-1242-
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=1298=static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-1356-
drivers/media/usb/ttusb-dec/ttusb_dec.c:1357: result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL);
drivers/media/usb/ttusb-dec/ttusb_dec.c-1358-
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-1397-
drivers/media/usb/ttusb-dec/ttusb_dec.c:1398: result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL);
drivers/media/usb/ttusb-dec/ttusb_dec.c-1399-
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=1622=static int fe_send_command(struct dvb_frontend* fe, const u8 command,
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-1626- struct ttusb_dec* dec = fe->dvb->priv;
drivers/media/usb/ttusb-dec/ttusb_dec.c:1627: return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
drivers/media/usb/ttusb-dec/ttusb_dec.c-1628-}
]
|
| 40/2 |
2026/08/17 21:08 |
llm |
debugger |
0m
Model:
Tokens:
input: 39571
output: 40
thoughts: 301
Thoughts: **Analyzing the `cmd_result` Variable**
Okay, so I'm looking at this `cmd_result` variable, and something's immediately jumping out at me: it's *NULL* in a ton of cases. That's a red flag, right? Let's break this down systematically.
When it *isn't* `NULL`, I see a couple of functions using it where `c` is a `u8 c[COMMAND_PACKET_SIZE];` buffer: `ttusb_dec_get_stb_state` and `ttusb_dec_start_sec_feed`. Another one is `fe_send_command`, which looks like the `cmd_result` is passed from `ttusbdecfe.c`, so it originates from there. That gives me a clue about where to look.
Now, diving into `ttusbdecfe.c`, I see `send_command` is getting called from a few places. Crucially, I see that the `result` is `u8 result[4];` buffer in `ttusbdecfe_dvbt_read_status`, but is *NULL* in all the others. This makes me wonder about the implications of passing `NULL` to this function when it clearly expects a buffer sometimes. In the other cases it is `NULL` in `ttusbdecfe_dvbt_set_frontend`, `ttusbdecfe_dvbs_set_frontend`, `ttusbdecfe_dvbs_diseqc_send_master_cmd`, `ttusbdecfe_dvbs_diseqc_send_burst`, `ttusbdecfe_dvbs_set_tone` and `ttusbdecfe_dvbs_set_voltage`. Does the function handle the `NULL` correctly?
Now I need to take a step back and make sure that there aren't any other callers in this file. It looks like it is a call graph and I need to check the entire breadth of the call graph to be sure.
|
| 41/2 |
2026/08/17 21:08 |
tool |
grepper |
0m
Args: map[Expression:send_command PathPrefix:drivers/media/usb/ttusb-dec/ttusbdecfe.c]
Results: map[Output:drivers/media/usb/ttusb-dec/ttusbdecfe.c=36=static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
--
drivers/media/usb/ttusb-dec/ttusbdecfe.c-46-
drivers/media/usb/ttusb-dec/ttusbdecfe.c:47: ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
drivers/media/usb/ttusb-dec/ttusbdecfe.c-48- if(ret)
--
drivers/media/usb/ttusb-dec/ttusbdecfe.c=76=static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend *fe)
--
drivers/media/usb/ttusb-dec/ttusbdecfe.c-87- memcpy(&b[4], &freq, sizeof (u32));
drivers/media/usb/ttusb-dec/ttusbdecfe.c:88: state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
drivers/media/usb/ttusb-dec/ttusbdecfe.c-89-
--
drivers/media/usb/ttusb-dec/ttusbdecfe.c=103=static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend *fe)
--
drivers/media/usb/ttusb-dec/ttusbdecfe.c-132-
drivers/media/usb/ttusb-dec/ttusbdecfe.c:133: state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
drivers/media/usb/ttusb-dec/ttusbdecfe.c-134-
--
drivers/media/usb/ttusb-dec/ttusbdecfe.c=138=static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *cmd)
--
drivers/media/usb/ttusb-dec/ttusbdecfe.c-149-
drivers/media/usb/ttusb-dec/ttusbdecfe.c:150: state->config->send_command(fe, 0x72,
drivers/media/usb/ttusb-dec/ttusbdecfe.c-151- sizeof(b) - (6 - cmd->msg_len), b,
]
|
| 42/2 |
2026/08/17 21:08 |
llm |
debugger |
0m
Model:
Tokens:
input: 40973
output: 44
thoughts: 3081
Thoughts: **Refining the Command Result Handling in `ttusb_dec`**
Okay, so I've been digging into this `ttusb_dec` code, specifically the `send_command` functionality. The initial concern revolves around how the command results are handled, particularly the `cmd_result` buffer. It appears that only `ttusbdecfe_dvbt_read_status` uses a non-NULL `cmd_result` and passes a 4-byte buffer.
My initial thought was to simply adjust `ttusb_dec_send_command` to take a `cmd_result_len` parameter to ensure safety, but that looked like a bigger change, requiring updates to several call sites, including `ttusbdecfe_config`. Instead, I considered a simpler approach: have `ttusb_dec_send_command` always assume a `COMMAND_PACKET_SIZE` byte buffer for `cmd_result` and fix `ttusbdecfe_dvbt_read_status` to pass a buffer of that size.
I then realized that `COMMAND_PACKET_SIZE` is defined in `ttusb_dec.c`, which `ttusbdecfe.c` doesn't know about. I could just use a 60-byte buffer. But this raised some questions about buffer overflows, specifically, what if the data to be copied (`b[3]`) exceeds the buffer size (even if it's 60 bytes)? And what if `b[3]` is a value larger than 60? It looks like I NEED to add a check in `ttusb_dec_send_command` to prevent that.
Given this, I realized I would need to check for two things: `b[3]` exceeding `COMMAND_PACKET_SIZE` and `b[3]` exceeding `cmd_result_len`. This makes the code robust. But also, this exposes a problem in `ttusbdecfe_dvbt_read_status`. If `b[3]` is 60, it will still overflow the 4-byte buffer. The API should be changed to pass the buffer size.
Let's do this correctly. Changing the API to pass the buffer size is much more robust and kernel-like. I then scoped out the modifications required. It looks like it touches the `ttusbdecfe.h` header, and I'd need to modify the calls in `ttusbdecfe.c` and `ttusb_dec.c` to update the API signature. Quite a bit of churn but the right fix.
However, I started to explore another option. What if I just change `ttusbdecfe_dvbt_read_status` to use a 60-byte buffer and keep it isolated? Since `ttusbdecfe.c` doesn't include `ttusb_dec.h`, the size can be hardcoded. Then, I just need to update `ttusb_dec_send_command` to check that `b[3]` does not exceed `COMMAND_PACKET_SIZE` to prevent any overflows. I would modify `ttusbdecfe_dvbt_read_status` to use a 60-byte buffer, and that's it. This approach offers a significantly lower impact. This is more attractive than changing the function signature.
Is this acceptable? I need to weigh the trade-offs now.
|
| 43/2 |
2026/08/17 21:08 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusbdecfe.c FirstLine:36 LineCount:20]
Results: map[Contents: 36: static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
37: enum fe_status *status)
38: {
39: struct ttusbdecfe_state* state = fe->demodulator_priv;
40: u8 b[] = { 0x00, 0x00, 0x00, 0x00,
41: 0x00, 0x00, 0x00, 0x00 };
42: u8 result[4];
43: int len, ret;
44:
45: *status=0;
46:
47: ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
48: if(ret)
49: return ret;
50:
51: if(len != 4) {
52: printk(KERN_ERR "%s: unexpected reply\n", __func__);
53: return -EIO;
54: }
55:
]
|
| 44/2 |
2026/08/17 21:08 |
llm |
debugger |
0m
Model:
Tokens:
input: 45137
output: 45
thoughts: 233
Thoughts: **Reflecting on a Localized Optimization**
Okay, so I'm looking at this buffer `u8 result[4];` and thinking, "Can we make this bigger without breaking things?" It's clear that bumping it up to `u8 result[60];` will consume 56 more bytes on the stack, which is generally not a concern. But as any good engineer knows, you have to think about the impact of the change.
Wait a moment, I need to consider: Does another driver even *use* `ttusbdecfe_config`? I know we looked at that earlier and confirmed that only `ttusb_dec.c` actually calls it. Right, so we know `cmd_result` is always either `NULL`, or if it's not `NULL`, it's `c` (which is already size 60) in `ttusb_dec.c`, or it's `result` in `ttusbdecfe_dvbt_read_status`.
If we change `result` to size 60, then anytime `cmd_result` is not null, it will *always* be at least 60 bytes. This means that we can then just add a simple check in `ttusb_dec_send_command` like `if (b[3] > COMMAND_PACKET_SIZE)`. This is a pretty focused change, making it a low-risk, easy win.
However, let's just make *absolutely* sure there isn't any other place where `cmd_result` is passed around. I'll need to go back and double check `ttusb_dec.c`.
|
| 45/2 |
2026/08/17 21:08 |
tool |
grepper |
0m
Args: map[Expression:ttusb_dec_send_command PathPrefix:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results: map[Output:drivers/media/usb/ttusb-dec/ttusb_dec.c=302=static u16 crc16(u16 crc, const u8 *buf, size_t len)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-314-
drivers/media/usb/ttusb-dec/ttusb_dec.c:315:static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
drivers/media/usb/ttusb-dec/ttusb_dec.c-316- int param_length, const u8 params[],
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=382=static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-391-
drivers/media/usb/ttusb-dec/ttusb_dec.c:392: result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
drivers/media/usb/ttusb-dec/ttusb_dec.c-393- if (result)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=435=static void ttusb_dec_set_pids(struct ttusb_dec *dec)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-450-
drivers/media/usb/ttusb-dec/ttusb_dec.c:451: ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL);
drivers/media/usb/ttusb-dec/ttusb_dec.c-452-
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=892=static int ttusb_dec_set_interface(struct ttusb_dec *dec,
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-903- case TTUSB_DEC_INTERFACE_IN:
drivers/media/usb/ttusb-dec/ttusb_dec.c:904: result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
drivers/media/usb/ttusb-dec/ttusb_dec.c-905- b, NULL, NULL);
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=964=static int ttusb_dec_start_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-1023-
drivers/media/usb/ttusb-dec/ttusb_dec.c:1024: result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL);
drivers/media/usb/ttusb-dec/ttusb_dec.c-1025- if (result)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=1032=static int ttusb_dec_start_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-1057-
drivers/media/usb/ttusb-dec/ttusb_dec.c:1058: result = ttusb_dec_send_command(dec, 0x60, sizeof(b0), b0,
drivers/media/usb/ttusb-dec/ttusb_dec.c-1059- &c_length, c);
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=1112=static int ttusb_dec_stop_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-1116-
drivers/media/usb/ttusb-dec/ttusb_dec.c:1117: ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL);
drivers/media/usb/ttusb-dec/ttusb_dec.c-1118-
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=1126=static int ttusb_dec_stop_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-1137- kfree(finfo);
drivers/media/usb/ttusb-dec/ttusb_dec.c:1138: ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL);
drivers/media/usb/ttusb-dec/ttusb_dec.c-1139-
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=1207=static int ttusb_init_rc( struct ttusb_dec *dec)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-1240- /* enable irq pipe */
drivers/media/usb/ttusb-dec/ttusb_dec.c:1241: ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
drivers/media/usb/ttusb-dec/ttusb_dec.c-1242-
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=1298=static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-1356-
drivers/media/usb/ttusb-dec/ttusb_dec.c:1357: result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL);
drivers/media/usb/ttusb-dec/ttusb_dec.c-1358-
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-1397-
drivers/media/usb/ttusb-dec/ttusb_dec.c:1398: result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL);
drivers/media/usb/ttusb-dec/ttusb_dec.c-1399-
--
drivers/media/usb/ttusb-dec/ttusb_dec.c=1622=static int fe_send_command(struct dvb_frontend* fe, const u8 command,
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-1626- struct ttusb_dec* dec = fe->dvb->priv;
drivers/media/usb/ttusb-dec/ttusb_dec.c:1627: return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
drivers/media/usb/ttusb-dec/ttusb_dec.c-1628-}
]
|
| 46/2 |
2026/08/17 21:08 |
llm |
debugger |
0m
Model:
Tokens:
input: 47617
output: 26
thoughts: 436
Thoughts: **Reflecting on Buffer Size Discrepancies**
Okay, so I'm looking at these buffer sizes and how they're being passed around in this driver code. It seems like only `ttusb_dec_get_stb_state` and `ttusb_dec_start_sec_feed` use the `c` buffer, which is a `u8 c[COMMAND_PACKET_SIZE]`. Then, `fe_send_command` uses `cmd_result` that it receives from `ttusbdecfe.c`. Diving into `ttusbdecfe.c`, I see that only `ttusbdecfe_dvbt_read_status` passes the `result` buffer, which is currently defined as `u8 result[4]`.
The problem is, if I simply bump up the size of `result` in `ttusbdecfe.c` to at least 60 bytes—like `u8 result[60];` or, ideally, `u8 result[COMMAND_PACKET_SIZE];` if that macro were accessible there—then all the `cmd_result` buffers would be sufficiently sized. However, wait a minute, `ttusbdecfe.c` doesn't have access to `COMMAND_PACKET_SIZE`.
So, where is `COMMAND_PACKET_SIZE` defined? Ah, it's in `ttusb_dec.c`:
```c
#define COMMAND_PACKET_SIZE 0x3c
```
The simplest fix is to just hardcode `60` in `ttusbdecfe.c`, but that's not the best approach. Really, the *correct* way to handle this, the way that will be most robust and prevent future headaches if someone expands the command set, is to change the API itself. Passing the buffer size explicitly is the "right" kernel way. It's a bit more work, but it future-proofs the code. So, let's go with the API change.
Okay, let's write down what that entails. It shouldn't be too much churn. I'll need to modify:
* `drivers/media/usb/ttusb-dec/ttusbdecfe.h`
* `drivers/media/usb/ttusb-dec/ttusbdecfe.c`
* `drivers/media/usb/ttusb-dec/ttusb_dec.c`
Hold on, I should double-check and make sure that this is the only places that will need modification.
|
| 47/2 |
2026/08/17 21:09 |
tool |
grepper |
0m
Args: map[Expression:ttusbdecfe_config PathPrefix:]
Results: map[Output:drivers/media/usb/ttusb-dec/ttusb_dec.c=1622=static int fe_send_command(struct dvb_frontend* fe, const u8 command,
--
drivers/media/usb/ttusb-dec/ttusb_dec.c-1629-
drivers/media/usb/ttusb-dec/ttusb_dec.c:1630:static const struct ttusbdecfe_config fe_config = {
drivers/media/usb/ttusb-dec/ttusb_dec.c-1631- .send_command = fe_send_command
--
drivers/media/usb/ttusb-dec/ttusbdecfe.c=15=struct ttusbdecfe_state {
--
drivers/media/usb/ttusb-dec/ttusbdecfe.c-17- /* configuration settings */
drivers/media/usb/ttusb-dec/ttusbdecfe.c:18: const struct ttusbdecfe_config* config;
drivers/media/usb/ttusb-dec/ttusbdecfe.c-19-
--
drivers/media/usb/ttusb-dec/ttusbdecfe.c=194=static const struct dvb_frontend_ops ttusbdecfe_dvbt_ops;
drivers/media/usb/ttusb-dec/ttusbdecfe.c-195-
drivers/media/usb/ttusb-dec/ttusbdecfe.c:196:struct dvb_frontend* ttusbdecfe_dvbt_attach(const struct ttusbdecfe_config* config)
drivers/media/usb/ttusb-dec/ttusbdecfe.c-197-{
--
drivers/media/usb/ttusb-dec/ttusbdecfe.c=214=static const struct dvb_frontend_ops ttusbdecfe_dvbs_ops;
drivers/media/usb/ttusb-dec/ttusbdecfe.c-215-
drivers/media/usb/ttusb-dec/ttusbdecfe.c:216:struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config)
drivers/media/usb/ttusb-dec/ttusbdecfe.c-217-{
--
drivers/media/usb/ttusb-dec/ttusbdecfe.h-12-
drivers/media/usb/ttusb-dec/ttusbdecfe.h:13:struct ttusbdecfe_config
drivers/media/usb/ttusb-dec/ttusbdecfe.h-14-{
--
drivers/media/usb/ttusb-dec/ttusbdecfe.h-19-
drivers/media/usb/ttusb-dec/ttusbdecfe.h:20:extern struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config);
drivers/media/usb/ttusb-dec/ttusbdecfe.h-21-
drivers/media/usb/ttusb-dec/ttusbdecfe.h:22:extern struct dvb_frontend* ttusbdecfe_dvbt_attach(const struct ttusbdecfe_config* config);
drivers/media/usb/ttusb-dec/ttusbdecfe.h-23-
]
|
| 48/2 |
2026/08/17 21:09 |
llm |
debugger |
1m
Model:
Tokens:
input: 49421
output: 1403
thoughts: 7485
Thoughts: **Summary of Proposed Fix for Potential Buffer Overflow in ttusb-dec Driver**
Okay, so we're looking at a potential buffer overflow vulnerability in the `ttusb-dec` driver. Specifically, it's located in the `ttusb_dec_send_command()` function. The core of the problem stems from the driver not properly validating the size of the data returned by the USB device, which could lead to both an out-of-bounds read and write. We need to address this to prevent crashes and potential security risks.
Here’s the breakdown of what’s happening and the proposed solution:
The `ttusb_dec_send_command` function allocates a buffer, `b`, of size `COMMAND_PACKET_SIZE + 4` (64 bytes). This buffer is used to send commands to the USB device and receive responses via `usb_bulk_msg`. The crucial issue is that the USB device can return a data length in `b[3]` and there aren’t adequate checks in place to prevent a buffer overflow when this data is copied from the response buffer (`&b[4]`) into the provided `cmd_result` buffer. This is handled by a call to `memcpy`.
There are two main vulnerabilities:
1. **Over-read of the `b` buffer**: The USB device can specify a data length (`b[3]`) larger than `COMMAND_PACKET_SIZE` (60 bytes) - for example 75 bytes. If that happens, then `memcpy` will attempt to read beyond the allocated 60 bytes of usable memory from `&b[4]`. This can cause a crash.
2. **Over-write of the `cmd_result` buffer**: The caller passes a `cmd_result` buffer. Some callers may pass a buffer smaller than `COMMAND_PACKET_SIZE`, potentially causing a stack buffer overflow. A prime example is `ttusbdecfe_dvbt_read_status` in `ttusbdecfe.c`, where a small 4-byte buffer `result` is used. If `b[3]` is a value greater than 4 (but less than 60), the `memcpy` call will attempt to write more data than the buffer can hold, causing data corruption.
The most robust solution involves changing the API and adding rigorous checks. Here's what needs to be done:
1. **API Change:** Update the `ttusbdecfe_config` struct in `drivers/media/usb/ttusb-dec/ttusbdecfe.h` by adding `cmd_result_len` to the `send_command` function pointer:
```c
struct ttusbdecfe_config
{
int (*send_command)(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len);
};
```
2. **Modify `ttusb_dec_send_command()` in `ttusb_dec.c`:** Update this function to validate the data length (`b[3]`) and use the provided `cmd_result_len` to avoid buffer overflows. Also validate that a short USB message has not been sent by checking that the number of bytes returned by the USB is at least 4.
```c
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len)
{
...
result = usb_bulk_msg(dec->udev, dec->result_pipe, b,
COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
if (result) {
printk("%s: result bulk message failed: error %d\n",
__func__, result);
goto err_mutex_unlock;
} else {
if (debug) {
printk(KERN_DEBUG "%s: result: %*ph\n",
__func__, actual_len, b);
}
if (actual_len < 4) {
result = -EIO;
goto err_mutex_unlock;
}
if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
result
|
| 49/1 |
2026/08/17 21:10 |
agent |
history-explorer |
1m
Model:
Instruction:
You are an experienced Linux kernel developer researching prior art for fixing a kernel bug.
You are given a bug explanation. This explanation details the root cause of the bug resulting
from debugging, but does not provide the final fix strategy. Your goal is to explore how
similar bugs were fixed in the past in the same subsystem or files.
CRITICAL: Do NOT attempt to debug the issue further or write a patch for it yourself.
Your ONLY objective is to research and provide the necessary historical context.
Use the git-log tool with the Since parameter set to "3 years" to focus on recent history.
Search for commits that address issues with similar root causes (e.g. similar missing locks,
incorrect refcounting, or similar error path bugs) in the affected files.
Your final reply must summarize your findings: what idioms, locking rules, or common patterns
should be followed when writing a fix for this bug based on how previous similar bugs were addressed.
If you find no relevant past fixes, clearly state that.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash is:
usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
------------[ cut here ]------------
memcpy: detected buffer overflow: 75 byte read of buffer size 60
WARNING: lib/string_helpers.c:1037 at __fortify_report+0xa0/0xb8 lib/string_helpers.c:1036, CPU#0: kworker/0:4/4798
Modules linked in:
CPU: 0 UID: 0 PID: 4798 Comm: kworker/0:4 Not tainted syzkaller #1 PREEMPT
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/07/2026
Workqueue: usb_hub_wq hub_event
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : __fortify_report+0xa0/0xb8 lib/string_helpers.c:1036
lr : __fortify_report+0xa0/0xb8 lib/string_helpers.c:1036
sp : ffff800098516d20
x29: ffff800098516d20 x28: dfff800000000000 x27: ffff7000130a2db0
x26: 0000000000000000 x25: ffff0000d1862683 x24: ffff800098516ea0
x23: 000000000000004b x22: ffff800086d0a338 x21: 0000000000000000
x20: 000000000000004b x19: 000000000000003c x18: 1fffe00035ba8028
x17: 0000000000000003 x16: ffff800088ba7000 x15: ffff8000824ea6c8
x14: 0000000000000000 x13: 0000000000000001 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000002 x9 : 653dfa0a2f6c5200
x8 : 653dfa0a2f6c5200 x7 : ffff80008048e0c4 x6 : 0000000000000000
x5 : 0000000000000000 x4 : 0000000000000000 x3 : ffff8000802f8054
x2 : 0000000100000000 x1 : ffff0000c57d1d40 x0 : 0000000000000000
Call trace:
__fortify_report+0xa0/0xb8 lib/string_helpers.c:1036 (P)
__fortify_panic+0x10/0x14 lib/string_helpers.c:1043
fortify_memcpy_chk include/linux/fortify-string.h:549 [inline]
ttusb_dec_start_feed+0x0/0x10ac drivers/media/usb/ttusb-dec/ttusb_dec.c:372
ttusb_dec_get_stb_state drivers/media/usb/ttusb-dec/ttusb_dec.c:392 [inline]
ttusb_dec_init_stb drivers/media/usb/ttusb-dec/ttusb_dec.c:1413 [inline]
ttusb_dec_probe+0x724/0x1aa0 drivers/media/usb/ttusb-dec/ttusb_dec.c:1671
usb_probe_interface+0x308/0x788 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_set_configuration+0x1184/0x158c drivers/usb/core/message.c:2268
usb_generic_driver_probe+0x8c/0x148 drivers/usb/core/generic.c:250
usb_probe_device+0x114/0x2b0 drivers/usb/core/driver.c:291
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_new_device+0x9c4/0x11f8 drivers/usb/core/hub.c:2703
hub_port_connect drivers/usb/core/hub.c:5575 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5715 [inline]
port_event drivers/usb/core/hub.c:5879 [inline]
hub_event+0x1ef0/0x39fc drivers/usb/core/hub.c:5961
process_one_work kernel/workqueue.c:3322 [inline]
process_scheduled_works+0x788/0x10b8 kernel/workqueue.c:3405
worker_thread+0x798/0xbd0 kernel/workqueue.c:3486
kthread+0x304/0x3d4 kernel/kthread.c:436
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:842
irq event stamp: 16196
hardirqs last enabled at (16195): [<ffff8000868fc7b4>] irqentry_exit_to_kernel_mode_after_preempt include/linux/irq-entry-common.h:507 [inline]
hardirqs last enabled at (16195): [<ffff8000868fc7b4>] arm64_exit_to_kernel_mode+0x80/0x94 arch/arm64/kernel/entry-common.c:62
hardirqs last disabled at (16196): [<ffff8000868f86e0>] el1_brk64+0x20/0x54 arch/arm64/kernel/entry-common.c:425
softirqs last enabled at (16128): [<ffff80008030ff18>] softirq_handle_end kernel/softirq.c:468 [inline]
softirqs last enabled at (16128): [<ffff80008030ff18>] handle_softirqs+0xc28/0xd98 kernel/softirq.c:650
softirqs last disabled at (16119): [<ffff8000800204b0>] __do_softirq+0x14/0x20 kernel/softirq.c:656
---[ end trace 0000000000000000 ]---
------------[ cut here ]------------
kernel BUG at lib/string_helpers.c:1044!
Internal error: Oops - BUG: 00000000f2000800 [#1] SMP
Modules linked in:
CPU: 0 UID: 0 PID: 4798 Comm: kworker/0:4 Tainted: G W syzkaller #1 PREEMPT
Tainted: [W]=WARN
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/07/2026
Workqueue: usb_hub_wq hub_event
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : __fortify_panic+0x10/0x14 lib/string_helpers.c:1043
lr : __fortify_panic+0x10/0x14 lib/string_helpers.c:1043
sp : ffff800098516d50
x29: ffff800098516d50 x28: dfff800000000000 x27: ffff7000130a2db0
x26: 0000000000000000 x25: ffff0000d1862683 x24: ffff800098516ea0
x23: 000000000000004b x22: 000000000000004b x21: ffff0000d1862680
x20: 1fffe0001a30c4d0 x19: ffff0000c3014000 x18: 1fffe00035ba8028
x17: 0000000000000003 x16: ffff800088ba7000 x15: ffff8000824ea6c8
x14: 0000000000000000 x13: 0000000000000001 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000002 x9 : 653dfa0a2f6c5200
x8 : 653dfa0a2f6c5200 x7 : ffff80008048e0c4 x6 : 0000000000000000
x5 : 0000000000000000 x4 : 0000000000000000 x3 : ffff8000802f8054
x2 : 0000000100000000 x1 : ffff0000c57d1d40 x0 : 0000000000000000
Call trace:
__fortify_panic+0x10/0x14 lib/string_helpers.c:1043 (P)
fortify_memcpy_chk include/linux/fortify-string.h:549 [inline]
ttusb_dec_start_feed+0x0/0x10ac drivers/media/usb/ttusb-dec/ttusb_dec.c:372
ttusb_dec_get_stb_state drivers/media/usb/ttusb-dec/ttusb_dec.c:392 [inline]
ttusb_dec_init_stb drivers/media/usb/ttusb-dec/ttusb_dec.c:1413 [inline]
ttusb_dec_probe+0x724/0x1aa0 drivers/media/usb/ttusb-dec/ttusb_dec.c:1671
usb_probe_interface+0x308/0x788 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_set_configuration+0x1184/0x158c drivers/usb/core/message.c:2268
usb_generic_driver_probe+0x8c/0x148 drivers/usb/core/generic.c:250
usb_probe_device+0x114/0x2b0 drivers/usb/core/driver.c:291
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_new_device+0x9c4/0x11f8 drivers/usb/core/hub.c:2703
hub_port_connect drivers/usb/core/hub.c:5575 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5715 [inline]
port_event drivers/usb/core/hub.c:5879 [inline]
hub_event+0x1ef0/0x39fc drivers/usb/core/hub.c:5961
process_one_work kernel/workqueue.c:3322 [inline]
process_scheduled_works+0x788/0x10b8 kernel/workqueue.c:3405
worker_thread+0x798/0xbd0 kernel/workqueue.c:3486
kthread+0x304/0x3d4 kernel/kthread.c:436
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:842
Code: d503233f a9bf7bfd 910003fd 94619ee8 (d4210000)
---[ end trace 0000000000000000 ]---
The explanation of the root cause of the bug is:
The crash is caused by a buffer overflow (both an out-of-bounds read and an out-of-bounds write) in the `ttusb_dec_send_command()` function, triggered by a malicious or malfunctioning USB device returning an unexpectedly large payload length.
### Detailed Analysis
In `drivers/media/usb/ttusb-dec/ttusb_dec.c`, the `ttusb_dec_send_command()` function allocates a buffer `b` to send a command and receive the response via `usb_bulk_msg()`:
```c
b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
```
Here, `COMMAND_PACKET_SIZE` is defined as `0x3c` (60), so the allocated buffer `b` is exactly 64 bytes.
After receiving the response from the USB device, the driver reads the payload length directly from `b[3]` (which is fully controlled by the USB device) and copies the payload into the caller-provided `cmd_result` buffer:
```c
if (result_length)
*result_length = b[3];
if (cmd_result && b[3] > 0)
memcpy(cmd_result, &b[4], b[3]);
```
There are two major flaws in this logic:
1. **No bounds check against the received data or the allocated buffer `b`**: `b[3]` is an 8-bit value and can be up to 255. If the device returns a value greater than `COMMAND_PACKET_SIZE` (60), the `memcpy()` will read past the end of the 64-byte buffer `b`. In the syzkaller crash, `b[3]` was `75`, leading to a 75-byte read from `&b[4]` (which only has 60 bytes allocated). This triggers the `fortify_memcpy_chk` panic (`75 byte read of buffer size 60`).
2. **No bounds check against the destination buffer `cmd_result`**: The size of `cmd_result` is never passed to `ttusb_dec_send_command()`. While callers like `ttusb_dec_get_stb_state()` pass a 60-byte buffer (`u8 c[COMMAND_PACKET_SIZE]`), other callers like `ttusbdecfe_dvbt_read_status()` in `ttusbdecfe.c` pass a much smaller buffer (`u8 result[4]`). If the device returns `b[3] = 60` for the latter, it will result in a severe stack buffer overflow.
### Proposed Fix
To fix this comprehensively, the API needs to be updated to pass the size of the destination buffer, and `ttusb_dec_send_command()` must validate `b[3]` against the received length, the maximum packet size, and the destination buffer size.
**1. Update `ttusbdecfe_config` in `drivers/media/usb/ttusb-dec/ttusbdecfe.h`:**
Add `cmd_result_len` to the `send_command` callback signature.
```c
struct ttusbdecfe_config
{
int (*send_command)(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len);
};
```
**2. Update `ttusb_dec_send_command()` in `ttusb_dec.c`:**
Add `cmd_result_len` to the signature and implement the necessary bounds checks.
```c
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len)
{
// ...
result = usb_bulk_msg(dec->udev, dec->result_pipe, b,
COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
if (result) {
printk("%s: result bulk message failed: error %d\n",
__func__, result);
goto err_mutex_unlock;
} else {
if (debug) {
printk(KERN_DEBUG "%s: result: %*ph\n",
__func__, actual_len, b);
}
/* Ensure we received at least the 4-byte header */
if (actual_len < 4) {
result = -EIO;
goto err_mutex_unlock;
}
/* Ensure the device isn't claiming more data than it sent or than fits in b */
if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
result = -EIO;
goto err_mutex_unlock;
}
if (result_length)
*result_length = b[3];
if (cmd_result && b[3] > 0) {
/* Ensure we don't overflow the caller's buffer */
if (b[3] > cmd_result_len) {
result = -EIO;
goto err_mutex_unlock;
}
memcpy(cmd_result, &b[4], b[3]);
}
}
// ...
```
**3. Update all callers:**
You will need to update all callers of `ttusb_dec_send_command()` in `ttusb_dec.c` and `state->config->send_command()` in `ttusbdecfe.c` to pass the correct buffer size.
For example:
- In `ttusb_dec_get_stb_state()`: pass `sizeof(c)` instead of just `c`.
- In `ttusbdecfe_dvbt_read_status()`: pass `sizeof(result)` instead of just `result`.
- For calls where `cmd_result` is `NULL`, simply pass `0` as the length.
Reply: Based on a review of the recent history in the `drivers/media/usb/` and `drivers/usb/` subsystems, there are no recent commits addressing this specific type of bug in the `ttusb-dec` driver itself. However, there is extensive prior art for fixing identical root causes—trusting device-supplied length fields without validation—across other USB media and serial drivers.
### Relevant Prior Art
Similar vulnerabilities where a USB device returns a malicious or unexpectedly large length field have been fixed using the exact same principles you proposed. Notable recent examples include:
1. **`8c6314489550` ("usb: misc: usbio: bound bulk IN response length to the received transfer")**
- **Issue:** The driver read a length field (`bpkt->len`) from the device and used it in a `memcpy()` without checking if it exceeded the actual received data or the destination buffer size, leading to a slab-out-of-bounds read.
- **Fix:** Added explicit checks to ensure the device-supplied length did not exceed the actual received length (`act`) minus the header size.
2. **`183c1076eca4` ("USB: serial: io_ti: fix heap overflow in get_manuf_info()")**
- **Issue:** The driver read a `Size` field from the device's EEPROM and used it to copy data into a fixed-size 10-byte buffer. A malicious device could set `Size` to a large value, causing a heap overflow.
- **Fix:** Validated the device-provided `Size` against the expected `sizeof(struct edge_ti_manuf_descriptor)` before performing the read.
3. **`b91e6aafe8d3` ("media: dvb-usb: dtv5100: fix out-of-bounds in dtv5100_i2c_msg()")**
- **Issue:** An untrusted length value (`rlen`) was used in a `memcpy()` to a fixed-size buffer (`st->data`), causing an out-of-bounds write.
- **Fix:** Added a simple `if (rlen > sizeof(st->data))` check, returning `-EINVAL` if the condition was met.
4. **`782b6a718651` ("media: uvcvideo: Fix 1-byte out-of-bounds read in uvc_parse_format()")**
- **Issue:** The driver accessed `buffer[3]` without verifying that the actual received buffer length was at least 4 bytes.
- **Fix:** Added a strict `if (buflen < 4)` check before accessing the payload.
### Common Patterns and Idioms for the Fix
Based on how these similar bugs were addressed, your proposed fix aligns perfectly with kernel best practices. When writing the patch, you should follow these established idioms:
1. **Never Trust Device-Provided Lengths:** Any length field originating from a USB device (in your case, `b[3]`) must be treated as untrusted user input.
2. **Double Bounds Checking:** The untrusted length must be validated against two distinct boundaries:
- **The Source Boundary:** Ensure `b[3]` does not exceed the actual data received from the USB transfer (`actual_len - 4`). This prevents the out-of-bounds read (the `75 byte read of buffer size 60` panic).
- **The Destination Boundary:** Ensure `b[3]` does not exceed the size of the caller-provided buffer (`cmd_result_len`). This prevents the out-of-bounds write/stack corruption.
3. **Explicit Buffer Sizing:** Passing the destination buffer size down the call stack (e.g., adding `cmd_result_len` to `ttusb_dec_send_command` and the `send_command` callback) is the standard and correct way to handle dynamic copies where the destination size varies by caller.
4. **Fail Securely:** If any bounds check fails, the driver should immediately abort the operation, unlock any held mutexes, and return an appropriate error code (e.g., `-EIO`, `-EPROTO`, or `-EMSGSIZE`). Logging a rate-limited warning or debug message is also common practice in these error paths.
|
| 50/2 |
2026/08/17 21:10 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 9836
output: 34
thoughts: 353
Thoughts: **My Analysis of the ttusb-dec USB Driver Bug and Research Plan**
Okay, so I've got a new bug report in `drivers/media/usb/ttusb-dec/ttusb_dec.c`. The core issue is a classic buffer overflow vulnerability in `ttusb_dec_send_command()`. The function reads an 8-bit length value (`b[3]`) from a USB bulk message response and then uses this *unvalidated* length to copy data into a caller-provided buffer (`cmd_result`). This is a huge red flag – we're essentially trusting the USB device to tell us how much data it's sending, without any sanity checks. The fix is straightforward on the surface: add a `cmd_result_len` parameter to validate the length before the copy operation. This would involve changes to `ttusb_dec_send_command` and the corresponding `send_command` callback in the `ttusbdecfe_config` struct. We need to validate `b[3]` against `COMMAND_PACKET_SIZE`, `actual_len - 4`, and `cmd_result_len`.
Now, the important part: Before I just blindly implement this fix, I need to understand the historical context of similar bugs in this part of the kernel. This is where the real work begins. The user is asking me to find "prior art" – similar bugs and their solutions. My plan is to use `git log` to dig through the git history. I'll focus on the `drivers/media/usb/ttusb-dec/` directory, looking back at the last three years of commits. I need to be on the lookout for commits that address the same *kind* of problem, even if they aren't exactly the same. I'm looking for issues related to missing or incorrect bounds checks on USB device responses, which is the crux of the problem. Also, any commits related to locking, refcounting, or other error paths in those files should be useful. That will give me a better understanding of the subsystem, and avoid repeating any fixes that have already been made.
|
| 51/2 |
2026/08/17 21:10 |
tool |
git-log |
0m
Args: map[PathPrefix:drivers/media/usb/ttusb-dec/ Since:3 years]
Results: map[Output:bf4afc53b77a Convert 'alloc_obj' family to use the new default GFP_KERNEL argument
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
1021dd010d21 media: Convert from tasklet to BH workqueue
]
|
| 52/2 |
2026/08/17 21:10 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 10762
output: 51
thoughts: 126
Thoughts: **USB Media Driver Security Analysis**
Okay, so I'm looking into potential vulnerabilities in the Linux kernel's media drivers, specifically within the USB subsystem. My initial focus is the `drivers/media/usb/ttusb-dec/` directory. Hmm, only three commits in the last three years there... that's a bit concerning, especially when I'm looking for buffer overflow vulnerabilities due to unchecked USB responses. And none of those commits seem to address any bounds checking issues, which is my main area of interest.
Alright, time to broaden the scope. Let's expand the search to `drivers/media/usb/` first, and if that doesn't yield enough, then maybe even the broader `drivers/media/`. The core of the problem here is untrusted data from USB devices – things like length fields, which, if not validated, could lead to a classic buffer overflow. So, I need to look for instances where the driver blindly trusts the device's response.
I'll craft a targeted search query. I need to use keywords like "bounds," "overflow," "length," "usb," "malicious," and "validate" within the `drivers/media/usb/` directory. That should hopefully uncover code sections where these issues are likely to be present. I'm hoping I can find a pattern, something that I can potentially use to automate the search.
|
| 53/2 |
2026/08/17 21:10 |
tool |
git-log |
0m
Args: map[MessageRegexps:[(bounds|overflow|length|validate|check) usb] PathPrefix:drivers/media/usb/ Since:3 years]
Results:
|
| 54/2 |
2026/08/17 21:10 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 11244
output: 37
thoughts: 34
Thoughts: **Investigating USB Media Driver Issues**
Okay, so I've hit a dead end. No leads from my initial query. Time to narrow the focus. Let's dig deeper into the `drivers/media/usb/` directory. That's where I suspect the problem lies, given the context. And I'm going to leverage `MessageRegexps` – that's the key. I need to be more precise in my search. My gut tells me this is likely a buffer overflow, out-of-bounds access, or a length issue within one of the USB media drivers. I'm going to search specifically for error messages containing "overflow," "bounds," or "length." This should hopefully surface some meaningful results and provide a direction for debugging. Time to refine that search and see what we get.
|
| 55/2 |
2026/08/17 21:10 |
tool |
git-log |
0m
Args: map[MessageRegexps:[overflow] PathPrefix:drivers/media/usb/ Since:3 years]
Results: map[Output:7e40e0bb7789 media: usbtv: Lock resolution while streaming
8deb1e2a392b media: usb: use kmalloc_array() to replace kmalloc()
4510319676bd media: pvrusb2: Use kmemdup_array instead of kmemdup for multiple allocation
8676a5e796fa media: uvcvideo: Fix integer overflow calculating timestamp
1c73d0b29d04 media: dw2102: fix a potential buffer overflow
faa4364bef2e media: stk1160: fix bounds checking in stk1160_copy_video()
]
|
| 56/2 |
2026/08/17 21:10 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 11659
output: 50
thoughts: 29
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Analyzing Potential Code Commit References**
Okay, I need to investigate a couple of potentially relevant commit hashes: `1c73d0b29d04` and `faa4364bef2e`. Based on the context, I'm assuming these are commit identifiers within a version control system like Git. I should probably start by pulling up the associated diffs and logs for each. My initial hypothesis is that these hashes are related to a specific bug, feature implementation, or perhaps a refactoring effort. The next step is to examine the code changes introduced by each to determine their relevance to the task at hand. I'll be looking for keywords, function names, and any patterns in the changes that align with the problem. I'll also check the commit messages for any clues about the intention and context of these commits. It's possible, given the identifiers alone, that these relate to an internal testing environment that would require additional contextual information to assess.
|
| 57/2 |
2026/08/17 21:10 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 1c73d0b29d04bf4082e7beb6a508895e118ee30d
Author: Mauro Carvalho Chehab <mchehab@kernel.org>
Date: Mon Apr 29 15:15:05 2024 +0100
media: dw2102: fix a potential buffer overflow
As pointed by smatch:
drivers/media/usb/dvb-usb/dw2102.c:802 su3000_i2c_transfer() error: __builtin_memcpy() '&state->data[4]' too small (64 vs 67)
That seemss to be due to a wrong copy-and-paste.
Fixes: 0e148a522b84 ("media: dw2102: Don't translate i2c read into write")
Reported-by: Hans Verkuil <hverkuil@xs4all.nl>
Reviewed-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
index 03b411ad64bb..79e2ccf974c9 100644
--- a/drivers/media/usb/dvb-usb/dw2102.c
+++ b/drivers/media/usb/dvb-usb/dw2102.c
@@ -789,7 +789,7 @@ static int su3000_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
if (msg[j].flags & I2C_M_RD) {
/* single read */
- if (1 + msg[j].len > sizeof(state->data)) {
+ if (4 + msg[j].len > sizeof(state->data)) {
warn("i2c rd: len=%d is too big!\n", msg[j].len);
num = -EOPNOTSUPP;
break;
]
|
| 58/2 |
2026/08/17 21:10 |
tool |
git-show |
0m
Args:
Results: map[Output:commit faa4364bef2ec0060de381ff028d1d836600a381
Author: Dan Carpenter <error27@gmail.com>
Date: Mon Apr 22 12:32:44 2024 +0300
media: stk1160: fix bounds checking in stk1160_copy_video()
The subtract in this condition is reversed. The ->length is the length
of the buffer. The ->bytesused is how many bytes we have copied thus
far. When the condition is reversed that means the result of the
subtraction is always negative but since it's unsigned then the result
is a very high positive value. That means the overflow check is never
true.
Additionally, the ->bytesused doesn't actually work for this purpose
because we're not writing to "buf->mem + buf->bytesused". Instead, the
math to calculate the destination where we are writing is a bit
involved. You calculate the number of full lines already written,
multiply by two, skip a line if necessary so that we start on an odd
numbered line, and add the offset into the line.
To fix this buffer overflow, just take the actual destination where we
are writing, if the offset is already out of bounds print an error and
return. Otherwise, write up to buf->length bytes.
Fixes: 9cb2173e6ea8 ("[media] media: Add stk1160 new driver (easycap replacement)")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Ricardo Ribalda <ribalda@chromium.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
diff --git a/drivers/media/usb/stk1160/stk1160-video.c b/drivers/media/usb/stk1160/stk1160-video.c
index 366f0e4a5dc0..e79c45db60ab 100644
--- a/drivers/media/usb/stk1160/stk1160-video.c
+++ b/drivers/media/usb/stk1160/stk1160-video.c
@@ -99,7 +99,7 @@ void stk1160_buffer_done(struct stk1160 *dev)
static inline
void stk1160_copy_video(struct stk1160 *dev, u8 *src, int len)
{
- int linesdone, lineoff, lencopy;
+ int linesdone, lineoff, lencopy, offset;
int bytesperline = dev->width * 2;
struct stk1160_buffer *buf = dev->isoc_ctl.buf;
u8 *dst = buf->mem;
@@ -139,8 +139,13 @@ void stk1160_copy_video(struct stk1160 *dev, u8 *src, int len)
* Check if we have enough space left in the buffer.
* In that case, we force loop exit after copy.
*/
- if (lencopy > buf->bytesused - buf->length) {
- lencopy = buf->bytesused - buf->length;
+ offset = dst - (u8 *)buf->mem;
+ if (offset > buf->length) {
+ dev_warn_ratelimited(dev->dev, "out of bounds offset\n");
+ return;
+ }
+ if (lencopy > buf->length - offset) {
+ lencopy = buf->length - offset;
remain = lencopy;
}
@@ -182,8 +187,13 @@ void stk1160_copy_video(struct stk1160 *dev, u8 *src, int len)
* Check if we have enough space left in the buffer.
* In that case, we force loop exit after copy.
*/
- if (lencopy > buf->bytesused - buf->length) {
- lencopy = buf->bytesused - buf->length;
+ offset = dst - (u8 *)buf->mem;
+ if (offset > buf->length) {
+ dev_warn_ratelimited(dev->dev, "offset out of bounds\n");
+ return;
+ }
+ if (lencopy > buf->length - offset) {
+ lencopy = buf->length - offset;
remain = lencopy;
}
]
|
| 59/2 |
2026/08/17 21:10 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 13716
output: 27
thoughts: 231
Thoughts: **Analyzing the Request and Refining My Search**
Okay, so I'm trying to find commits in related areas that might address similar issues to the ones I'm troubleshooting. The initial thought was to search for overly large lengths returned by USB devices, which are often corrected with `if (len > sizeof(buf))` checks, but that feels a bit too specific, even though it's a good starting point. I considered expanding the search to terms like "buffer overflow," "bounds," or "malicious" within `drivers/media/usb/` and `drivers/usb/`.
Wait a minute, the user's instructions were much more targeted: they want commits addressing *similar root causes* (missing locks, incorrect refcounting, error path bugs) *within the affected files*. Crucially, they specified *affected files* meaning I should not expand the search beyond the specific files in question.
I've already checked the git log for `drivers/media/usb/ttusb-dec/` but only with a three-year window, which didn't turn up anything promising. So, let me double-check the git log *without* that time restriction, just to make sure I haven't missed older, potentially relevant commits. Sometimes those older ones can provide the historical context needed to identify a common pattern or a similar fix implemented in the past. It is critical that I remember the context, and stick to the affected files, even if I start to get broader ideas.
|
| 60/2 |
2026/08/17 21:10 |
tool |
git-log |
0m
Args: map[PathPrefix:drivers/media/usb/ttusb-dec/]
Results: map[Output:bf4afc53b77a Convert 'alloc_obj' family to use the new default GFP_KERNEL argument
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
1021dd010d21 media: Convert from tasklet to BH workqueue
da9b2c59743d media: ttusb-dec: remove unnecessary (void*) conversions
eff540df5f80 media: usb: remove unnecessary (void*) conversions
517a28133832 media: ttusb-dec: fix memory leak in ttusb_dec_exit_dvb()
36b9d695aa6f media: ttusb-dec: avoid release of non-acquired mutex
dba328bab4c6 media: ttusb-dec: cleanup an error handling logic
c3bf67e80532 media: media/usb:Remove superfluous "breaks" in the ttusb_dec.c
f3b60b066a5b media: ttusb-dec: convert tasklets to use new tasklet_setup() API
]
|
| 61/2 |
2026/08/17 21:10 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 14564
output: 45
thoughts: 37
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Analyzing Potential USB Driver Vulnerabilities**
Alright, let's get down to brass tacks. I'm taking a look at the `drivers/media/usb/ttusb-dec/` directory. My immediate concern, as always, is memory safety, specifically in a USB driver. These are often juicy targets for exploits. So, I need to see if there's been any past work done in this area, any previous commits that might have touched upon potential overflow scenarios or bounds checking issues related to data lengths. I'm thinking I need to search through the commit history for that directory. I'll search for mentions of "overflow," "bounds," or "length." This should give me a good starting point for assessing the codebase's current state and identifying any previously addressed problems or, more critically, any potential regressions or lingering vulnerabilities. If I find any, I can then dive deeper into those commits and related code to understand the context and how the issues were addressed or weren't. This quick search is a good way to see if there are any obvious red flags I might otherwise miss.
|
| 62/2 |
2026/08/17 21:10 |
tool |
git-log |
0m
Args: map[MessageRegexps:[(overflow|bounds|length|validate|check)] PathPrefix:drivers/media/usb/ttusb-dec/]
Results:
|
| 63/2 |
2026/08/17 21:10 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 14905
output: 47
thoughts: 292
Thoughts: **My Approach to Bug Analysis**
Okay, so the user wants me to delve into past fixes for similar bugs. Let me make sure I understand the task correctly. It's about finding common patterns, idioms, or locking rules used to resolve issues related to a specific subsystem or files. The core of the exercise is to explore how similar bugs have been fixed in the past to inform how a new bug should be resolved. The user wants me to use `git-log` with a "3 years" time window. The affected file seems to be in `drivers/media/usb/ttusb-dec/`, but I haven't found any relevant past fixes there.
Now, because I found nothing in the target file, I will search the surrounding subsystems: `drivers/media/usb/`, `drivers/media/`, and `drivers/usb/`. Since the user emphasized similar *root causes*, I should look for commits related to things like "buffer overflow," "malicious" input, issues with "bounds" checking, or problems with "length" handling. These seem like likely areas where similar problems could arise. I'll focus on these keywords in my search of the last three years of commit history.
|
| 64/2 |
2026/08/17 21:11 |
tool |
git-log |
0m
Args: map[MessageRegexps:[(overflow|bounds|length|validate|check)] PathPrefix:drivers/media/usb/ Since:3 years]
Results:
|
| 65/2 |
2026/08/17 21:11 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 15509
output: 74
thoughts: 105
Thoughts: **Debugging a Code Search Query**
Okay, so I was expecting some results back when I broadened my search, but I'm getting nothing back! That's odd. I initially searched for "overflow" within the `drivers/media/usb/` directory, and that worked fine. Now, I tried a more general regex with `(overflow|bounds|length|validate|check)` and got zilch. Something's clearly wrong with the way I'm constructing this query.
My first thought is that the regex engine in this tool might not support the OR operator, the pipe `|`. Or, perhaps it interprets the list within `MessageRegexps` as AND, rather than OR. That would explain the behavior. The correct syntax might be to have multiple `MessageRegexps` entries, one for each keyword I'm looking for.
I'll try running the searches separately, one for "overflow" and then one for "bounds". That should isolate the issue and confirm whether it is an operator issue.
|
| 66/2 |
2026/08/17 21:11 |
tool |
git-log |
0m
Args: map[MessageRegexps:[bounds] PathPrefix:drivers/media/usb/ Since:3 years]
Results: map[Output:7c39f48568e0 media: uvcvideo: Fix bug in error path of uvc_alloc_urb_buffers
b91e6aafe8d3 media: dvb-usb: dtv5100: fix out-of-bounds in dtv5100_i2c_msg()
aef89c0b2417 media: gspca: Add bounds checking to firmware parser
782b6a718651 media: uvcvideo: Fix 1-byte out-of-bounds read in uvc_parse_format()
ecf2b43018da media: uvcvideo: Skip parsing frames of type UVC_VS_UNDEFINED in uvc_parse_format
faa4364bef2e media: stk1160: fix bounds checking in stk1160_copy_video()
099be1822d1f media: gspca: cpia1: shift-out-of-bounds in set_flicker
]
|
| 67/2 |
2026/08/17 21:11 |
tool |
git-log |
0m
Args: map[MessageRegexps:[length] PathPrefix:drivers/media/usb/ Since:3 years]
Results: map[Output:f0487a90b2c5 media: uvcvideo: UVC minimum relative pan/tilt/zoom speed fix.
1a31cb278210 media: dvb-usb: pctv452e: move snd/rcv len check before kmalloc
bda2859bff0b media: uvcvideo: Do not mark valid metadata as invalid
aef89c0b2417 media: gspca: Add bounds checking to firmware parser
b5ae5a79825b media: usb: hdpvr: disable zero-length read messages
782b6a718651 media: uvcvideo: Fix 1-byte out-of-bounds read in uvc_parse_format()
53b0b80e5240 media: uvcvideo: Add quirk for HP Webcam HD 2300
8c54e58f94ed media: uvcvideo: Add quirk for Actions UVC05
b2ec92bb5605 media: uvcvideo: Add a quirk for the Kaiweets KTI-W02 infrared camera
8676a5e796fa media: uvcvideo: Fix integer overflow calculating timestamp
]
|
| 68/2 |
2026/08/17 21:11 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 16456
output: 51
thoughts: 31
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Analyzing Potential Artifacts**
Okay, so I'm diving into these two identifiers: `b91e6aafe8d3` and `1a31cb278210`. Immediately, my mind starts sifting through possibilities. Are these commit hashes? File identifiers? Object IDs from a database? The format suggests a hexadecimal representation, which is common in a variety of contexts – could be version control, checksums, or cryptographic keys. I need more context to understand their significance, but they're definitely drawing my attention. This is where the real work begins. I'm mentally starting to build a mental map of what system they might be associated with.
|
| 69/2 |
2026/08/17 21:11 |
tool |
git-show |
0m
Args:
Results: map[Output:commit b91e6aafe8d356086cc621bc03e35ba2299e4788
Author: Jeongjun Park <aha310510@gmail.com>
Date: Mon Apr 21 21:52:44 2025 +0900
media: dvb-usb: dtv5100: fix out-of-bounds in dtv5100_i2c_msg()
rlen value is a user-controlled value, but dtv5100_i2c_msg() does not
check the size of the rlen value. Therefore, if it is set to a value
larger than sizeof(st->data), an out-of-bounds vuln occurs for st->data.
Therefore, we need to add proper range checking to prevent this vuln.
Fixes: 60688d5e6e6e ("V4L/DVB (8735): dtv5100: replace dummy frontend by zl10353")
Cc: stable@vger.kernel.org
Signed-off-by: Jeongjun Park <aha310510@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
diff --git a/drivers/media/usb/dvb-usb/dtv5100.c b/drivers/media/usb/dvb-usb/dtv5100.c
index 3d85c6f7f6ec..c448e2ebda1a 100644
--- a/drivers/media/usb/dvb-usb/dtv5100.c
+++ b/drivers/media/usb/dvb-usb/dtv5100.c
@@ -55,6 +55,11 @@ static int dtv5100_i2c_msg(struct dvb_usb_device *d, u8 addr,
}
index = (addr << 8) + wbuf[0];
+ if (rlen > sizeof(st->data)) {
+ warn("rlen = %x is too big!\n", rlen);
+ return -EINVAL;
+ }
+
memcpy(st->data, rbuf, rlen);
msleep(1); /* avoid I2C errors */
return usb_control_msg(d->udev, pipe, request,
]
|
| 70/2 |
2026/08/17 21:11 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 1a31cb2782104969e48c7ce7e4fc06e403fcb5cf
Author: Edward Adam Davis <eadavis@qq.com>
Date: Mon Nov 3 19:57:49 2025 +0800
media: dvb-usb: pctv452e: move snd/rcv len check before kmalloc
syzbot reported a uninit-value in pctv452e_i2c_msg. [1]
When the snd_len or rcv_len check fails and jumps to failed, buf is
uninitialized, triggering the uninit-value issue.
Move the snd/rcv length check before kmalloc, and return -EINVAL directly
if the condition is met.
[1]
BUG: KMSAN: uninit-value in hex_string+0x681/0x740 lib/vsprintf.c:1220
pctv452e_i2c_msg+0x82a/0x8f0 drivers/media/usb/dvb-usb/pctv452e.c:467
pctv452e_i2c_xfer+0x2e6/0x4c0 drivers/media/usb/dvb-usb/pctv452e.c:502
Reported-by: syzbot+480edd2cadb85ddb4bbe@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=480edd2cadb85ddb4bbe
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
diff --git a/drivers/media/usb/dvb-usb/pctv452e.c b/drivers/media/usb/dvb-usb/pctv452e.c
index 5094de9a312e..bc7a224d829e 100644
--- a/drivers/media/usb/dvb-usb/pctv452e.c
+++ b/drivers/media/usb/dvb-usb/pctv452e.c
@@ -422,16 +422,15 @@ static int pctv452e_i2c_msg(struct dvb_usb_device *d, u8 addr,
u8 id;
int ret;
+ if (snd_len > 64 - 7 || rcv_len > 64 - 7)
+ return -EINVAL;
+
buf = kmalloc(64, GFP_KERNEL);
if (!buf)
return -ENOMEM;
id = state->c++;
- ret = -EINVAL;
- if (snd_len > 64 - 7 || rcv_len > 64 - 7)
- goto failed;
-
buf[0] = SYNC_BYTE_OUT;
buf[1] = id;
buf[2] = PCTV_CMD_I2C;
]
|
| 71/2 |
2026/08/17 21:11 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 18142
output: 78
thoughts: 42
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Investigating USB Media Driver Command Handling**
Alright, time to dig into this. I'm thinking, "result_length," "cmd_result," and "send_command" – those are pretty common naming conventions in driver code, particularly when dealing with the kind of USB media communication I'm familiar with. I'm going to leverage that by focusing my search within the `drivers/media/usb/` directory. That's the logical place to start looking for other instances of this pattern. The goal is to see how other USB media drivers handle similar command and result processing, looking for established paradigms or potential code reuse that might be helpful or concerning. It's a targeted hunt for relevant code segments to gain broader context for whatever I'm currently working on.
|
| 72/2 |
2026/08/17 21:11 |
tool |
git-log |
0m
Args: map[MessageRegexps:[send_command] PathPrefix:drivers/media/usb/ Since:3 years]
Results:
|
| 73/2 |
2026/08/17 21:11 |
tool |
git-log |
0m
Args: map[MessageRegexps:[cmd_result] PathPrefix:drivers/media/usb/ Since:3 years]
Results:
|
| 74/2 |
2026/08/17 21:11 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 18468
output: 80
thoughts: 43
Thoughts: Okay, here's my summary, taking on the persona you requested:
**Digging into Potential USB Driver Vulnerabilities**
Alright, time to get my hands dirty. I need to take a look at the `drivers/media/usb/` directory. Given my experience, I'm thinking the best starting point to find potential issues related to length vulnerabilities would be to search for two keywords: `"actual_len"` and `"usb_bulk_msg"`. I'm specifically looking for any instances where `actual_len` – the actual number of bytes transferred in a USB bulk transfer – isn't being properly checked against the expected length or some reasonable bounds. Bulk transfers are a common attack vector, and a missing or improper check on `actual_len` could easily lead to a buffer overflow or other memory corruption issues. It is a reasonable heuristic based on my experience and it is likely a good strategy to start with those keywords. I need to see if any of the drivers in this area are making assumptions or skipping crucial validation steps. Let's see what we can find.
|
| 75/2 |
2026/08/17 21:11 |
tool |
git-log |
0m
Args: map[MessageRegexps:[actual_len] PathPrefix:drivers/media/usb/ Since:3 years]
Results:
|
| 76/2 |
2026/08/17 21:11 |
tool |
git-log |
0m
Args: map[MessageRegexps:[usb_bulk_msg] PathPrefix:drivers/media/usb/ Since:3 years]
Results: map[Output:73fb3b92da84 media: cxusb: no longer judge rbuf when the write fails
2052138b7da5 media: dvb-usb: Fix unexpected infinite loop in dvb_usb_read_remote_control()
]
|
| 77/2 |
2026/08/17 21:11 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 18898
output: 51
thoughts: 31
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Analyzing Potential Code Components**
Okay, let's dive in. My initial focus is on these two identifiers: `73fb3b92da84` and `2052138b7da5`. Without more context, these strongly suggest either version control commit hashes (highly likely), or perhaps, unique identifiers generated by some system. My immediate instinct is to cross-reference them with the version control history, especially if we have access to the repository. The hexadecimal format certainly supports that assumption.
Depending on the project structure, I will examine the surrounding code context. I'll check for relationships, dependencies, and any significant events tied to these IDs. Are they associated with bug fixes, feature additions, performance improvements, or regressions? Are there any patterns with regard to which components have been altered, and at what points in the project's lifespan? I'll probably start with a `git log -p` or similar, depending on the tooling in place. Understanding the timeline and changes associated with each ID will inform what I do next.
|
| 78/2 |
2026/08/17 21:11 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 73fb3b92da84637e3817580fa205d48065924e15
Author: Edward Adam Davis <eadavis@qq.com>
Date: Sat Apr 5 19:56:41 2025 +0800
media: cxusb: no longer judge rbuf when the write fails
syzbot reported a uninit-value in cxusb_i2c_xfer. [1]
Only when the write operation of usb_bulk_msg() in dvb_usb_generic_rw()
succeeds and rlen is greater than 0, the read operation of usb_bulk_msg()
will be executed to read rlen bytes of data from the dvb device into the
rbuf.
In this case, although rlen is 1, the write operation failed which resulted
in the dvb read operation not being executed, and ultimately variable i was
not initialized.
[1]
BUG: KMSAN: uninit-value in cxusb_gpio_tuner drivers/media/usb/dvb-usb/cxusb.c:124 [inline]
BUG: KMSAN: uninit-value in cxusb_i2c_xfer+0x153a/0x1a60 drivers/media/usb/dvb-usb/cxusb.c:196
cxusb_gpio_tuner drivers/media/usb/dvb-usb/cxusb.c:124 [inline]
cxusb_i2c_xfer+0x153a/0x1a60 drivers/media/usb/dvb-usb/cxusb.c:196
__i2c_transfer+0xe25/0x3150 drivers/i2c/i2c-core-base.c:-1
i2c_transfer+0x317/0x4a0 drivers/i2c/i2c-core-base.c:2315
i2c_transfer_buffer_flags+0x125/0x1e0 drivers/i2c/i2c-core-base.c:2343
i2c_master_send include/linux/i2c.h:109 [inline]
i2cdev_write+0x210/0x280 drivers/i2c/i2c-dev.c:183
do_loop_readv_writev fs/read_write.c:848 [inline]
vfs_writev+0x963/0x14e0 fs/read_write.c:1057
do_writev+0x247/0x5c0 fs/read_write.c:1101
__do_sys_writev fs/read_write.c:1169 [inline]
__se_sys_writev fs/read_write.c:1166 [inline]
__x64_sys_writev+0x98/0xe0 fs/read_write.c:1166
x64_sys_call+0x2229/0x3c80 arch/x86/include/generated/asm/syscalls_64.h:21
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xcd/0x1e0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Reported-by: syzbot+526bd95c0ec629993bf3@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=526bd95c0ec629993bf3
Tested-by: syzbot+526bd95c0ec629993bf3@syzkaller.appspotmail.com
Fixes: 22c6d93a7310 ("[PATCH] dvb: usb: support Medion hybrid USB2.0 DVB-T/analogue box")
Cc: stable@vger.kernel.org
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
index f44529b40989..d0501c1e81d6 100644
--- a/drivers/media/usb/dvb-usb/cxusb.c
+++ b/drivers/media/usb/dvb-usb/cxusb.c
@@ -119,9 +119,8 @@ static void cxusb_gpio_tuner(struct dvb_usb_device *d, int onoff)
o[0] = GPIO_TUNER;
o[1] = onoff;
- cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);
- if (i != 0x01)
+ if (!cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1) && i != 0x01)
dev_info(&d->udev->dev, "gpio_write failed.\n");
st->gpio_write_state[GPIO_TUNER] = onoff;
]
|
| 79/2 |
2026/08/17 21:11 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 2052138b7da52ad5ccaf74f736d00f39a1c9198c
Author: Zheng Yejian <zhengyejian1@huawei.com>
Date: Thu May 9 20:44:14 2024 +0800
media: dvb-usb: Fix unexpected infinite loop in dvb_usb_read_remote_control()
Infinite log printing occurs during fuzz test:
rc rc1: DViCO FusionHDTV DVB-T USB (LGZ201) as ...
...
dvb-usb: schedule remote query interval to 100 msecs.
dvb-usb: DViCO FusionHDTV DVB-T USB (LGZ201) successfully initialized ...
dvb-usb: bulk message failed: -22 (1/0)
dvb-usb: bulk message failed: -22 (1/0)
dvb-usb: bulk message failed: -22 (1/0)
...
dvb-usb: bulk message failed: -22 (1/0)
Looking into the codes, there is a loop in dvb_usb_read_remote_control(),
that is in rc_core_dvb_usb_remote_init() create a work that will call
dvb_usb_read_remote_control(), and this work will reschedule itself at
'rc_interval' intervals to recursively call dvb_usb_read_remote_control(),
see following code snippet:
rc_core_dvb_usb_remote_init() {
...
INIT_DELAYED_WORK(&d->rc_query_work, dvb_usb_read_remote_control);
schedule_delayed_work(&d->rc_query_work,
msecs_to_jiffies(rc_interval));
...
}
dvb_usb_read_remote_control() {
...
err = d->props.rc.core.rc_query(d);
if (err)
err(...) // Did not return even if query failed
schedule_delayed_work(&d->rc_query_work,
msecs_to_jiffies(rc_interval));
}
When the infinite log printing occurs, the query callback
'd->props.rc.core.rc_query' is cxusb_rc_query(). And the log is due to
the failure of finding a valid 'generic_bulk_ctrl_endpoint'
in usb_bulk_msg(), see following code snippet:
cxusb_rc_query() {
cxusb_ctrl_msg() {
dvb_usb_generic_rw() {
ret = usb_bulk_msg(d->udev, usb_sndbulkpipe(d->udev,
d->props.generic_bulk_ctrl_endpoint),...);
if (ret)
err("bulk message failed: %d (%d/%d)",ret,wlen,actlen);
...
}
...
}
By analyzing the corresponding USB descriptor, it shows that the
bNumEndpoints is 0 in its interface descriptor, but
the 'generic_bulk_ctrl_endpoint' is 1, that means user don't configure
a valid endpoint for 'generic_bulk_ctrl_endpoint', therefore this
'invalid' USB device should be rejected before it calls into
dvb_usb_read_remote_control().
To fix it, we need to add endpoint check for 'generic_bulk_ctrl_endpoint'.
And as Sean suggested, the same check and clear halts should be done for
'generic_bulk_ctrl_endpoint_response'. So introduce
dvb_usb_check_bulk_endpoint() to do it for both of them.
Fixes: 4d43e13f723e ("V4L/DVB (4643): Multi-input patch for DVB-USB device")
Signed-off-by: Zheng Yejian <zhengyejian1@huawei.com>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
diff --git a/drivers/media/usb/dvb-usb/dvb-usb-init.c b/drivers/media/usb/dvb-usb/dvb-usb-init.c
index fbf58012becd..22d83ac18eb7 100644
--- a/drivers/media/usb/dvb-usb/dvb-usb-init.c
+++ b/drivers/media/usb/dvb-usb/dvb-usb-init.c
@@ -23,11 +23,40 @@ static int dvb_usb_force_pid_filter_usage;
module_param_named(force_pid_filter_usage, dvb_usb_force_pid_filter_usage, int, 0444);
MODULE_PARM_DESC(force_pid_filter_usage, "force all dvb-usb-devices to use a PID filter, if any (default: 0).");
+static int dvb_usb_check_bulk_endpoint(struct dvb_usb_device *d, u8 endpoint)
+{
+ if (endpoint) {
+ int ret;
+
+ ret = usb_pipe_type_check(d->udev, usb_sndbulkpipe(d->udev, endpoint));
+ if (ret)
+ return ret;
+ ret = usb_pipe_type_check(d->udev, usb_rcvbulkpipe(d->udev, endpoint));
+ if (ret)
+ return ret;
+ }
+ return 0;
+}
+
+static void dvb_usb_clear_halt(struct dvb_usb_device *d, u8 endpoint)
+{
+ if (endpoint) {
+ usb_clear_halt(d->udev, usb_sndbulkpipe(d->udev, endpoint));
+ usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, endpoint));
+ }
+}
+
static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs)
{
struct dvb_usb_adapter *adap;
int ret, n, o;
+ ret = dvb_usb_check_bulk_endpoint(d, d->props.generic_bulk_ctrl_endpoint);
+ if (ret)
+ return ret;
+ ret = dvb_usb_check_bulk_endpoint(d, d->props.generic_bulk_ctrl_endpoint_response);
+ if (ret)
+ return ret;
for (n = 0; n < d->props.num_adapters; n++) {
adap = &d->adapter[n];
adap->dev = d;
@@ -103,10 +132,8 @@ static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs)
* when reloading the driver w/o replugging the device
* sometimes a timeout occurs, this helps
*/
- if (d->props.generic_bulk_ctrl_endpoint != 0) {
- usb_clear_halt(d->udev, usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
- usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
- }
+ dvb_usb_clear_halt(d, d->props.generic_bulk_ctrl_endpoint);
+ dvb_usb_clear_halt(d, d->props.generic_bulk_ctrl_endpoint_response);
return 0;
]
|
| 80/2 |
2026/08/17 21:11 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 22578
output: 60
thoughts: 37
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Investigating Potential USB Driver Vulnerabilities**
Alright, I need to expand my search. The recent analysis in `drivers/media/usb/` highlighted some interesting issues related to "bounds" and "overflow," but I'm feeling there might be more to uncover. I'm going to broaden my search in that directory, removing any artificial date restrictions. I want to see a comprehensive picture, not just the last three years. This broader scope should reveal if these problems are isolated incidents or represent a recurring pattern within the USB media driver codebase. The absence of a time limit is crucial for identifying any latent vulnerabilities that might have been present for an extended duration. This comprehensive search could reveal historical issues.
|
| 81/2 |
2026/08/17 21:11 |
tool |
git-log |
0m
Args: map[MessageRegexps:[bounds] PathPrefix:drivers/media/usb/]
Results: map[Output:7c39f48568e0 media: uvcvideo: Fix bug in error path of uvc_alloc_urb_buffers
b91e6aafe8d3 media: dvb-usb: dtv5100: fix out-of-bounds in dtv5100_i2c_msg()
aef89c0b2417 media: gspca: Add bounds checking to firmware parser
782b6a718651 media: uvcvideo: Fix 1-byte out-of-bounds read in uvc_parse_format()
ecf2b43018da media: uvcvideo: Skip parsing frames of type UVC_VS_UNDEFINED in uvc_parse_format
faa4364bef2e media: stk1160: fix bounds checking in stk1160_copy_video()
099be1822d1f media: gspca: cpia1: shift-out-of-bounds in set_flicker
389b6a226188 media: usb: pwc-uncompress: Use flex array destination for memcpy()
471bec68457a media: pvrusb2: fix array-index-out-of-bounds in pvr2_i2c_core_init
171994e498a0 media: uvcvideo: Silence shift-out-of-bounds warning
]
|
| 82/2 |
2026/08/17 21:11 |
tool |
git-log |
0m
Args: map[MessageRegexps:[overflow] PathPrefix:drivers/media/usb/]
Results: map[Output:7e40e0bb7789 media: usbtv: Lock resolution while streaming
8deb1e2a392b media: usb: use kmalloc_array() to replace kmalloc()
4510319676bd media: pvrusb2: Use kmemdup_array instead of kmemdup for multiple allocation
8676a5e796fa media: uvcvideo: Fix integer overflow calculating timestamp
1c73d0b29d04 media: dw2102: fix a potential buffer overflow
faa4364bef2e media: stk1160: fix bounds checking in stk1160_copy_video()
b83921298857 media: uvcvideo: Silence memcpy() run-time false positive warnings
1c8af8e93748 media: uvcvideo: Fix bit overflow in uvc_probe_video
dca4f5fdbcd7 media: usb: pwc-uncompress: Use struct_size() helper in pwc_decompress()
f7b77ebe6d2f media: dib0700: fix undefined behavior in tuner shutdown
]
|
| 83/2 |
2026/08/17 21:11 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 23476
output: 53
thoughts: 32
Thoughts: Here's my take on those thought processes:
**Quick Scan of Those Hashes**
Right, let's just make sure I'm on the right track with this. My immediate thought is to take a look at `aef89c0b2417` and `782b6a718651`. Nothing too in-depth, just a quick visual check. Based on the context and the potential source of these hashes, my expert intuition is that I should be able to deduce the nature of these elements with a little effort. Let's see if they're in the expected form.
|
| 84/2 |
2026/08/17 21:11 |
tool |
git-show |
0m
Args:
Results: map[Output:commit aef89c0b2417da79cb2062a95476288f9f203ab0
Author: Dan Carpenter <error27@gmail.com>
Date: Wed May 28 23:22:14 2025 +0300
media: gspca: Add bounds checking to firmware parser
This sd_init() function reads the firmware. The firmware data holds a
series of records and the function reads each record and sends the data
to the device. The request_ihex_firmware() function
calls ihex_validate_fw() which ensures that the total length of all the
records won't read out of bounds of the fw->data[].
However, a potential issue is if there is a single very large
record (larger than PAGE_SIZE) and that would result in memory
corruption. Generally we trust the firmware, but it's always better to
double check.
Fixes: 49b61ec9b5af ("[media] gspca: Add new vicam subdriver")
Cc: stable@vger.kernel.org
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
diff --git a/drivers/media/usb/gspca/vicam.c b/drivers/media/usb/gspca/vicam.c
index d98343fd33fe..91e177aa8136 100644
--- a/drivers/media/usb/gspca/vicam.c
+++ b/drivers/media/usb/gspca/vicam.c
@@ -227,6 +227,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
const struct ihex_binrec *rec;
const struct firmware *fw;
u8 *firmware_buf;
+ int len;
ret = request_ihex_firmware(&fw, VICAM_FIRMWARE,
&gspca_dev->dev->dev);
@@ -241,9 +242,14 @@ static int sd_init(struct gspca_dev *gspca_dev)
goto exit;
}
for (rec = (void *)fw->data; rec; rec = ihex_next_binrec(rec)) {
- memcpy(firmware_buf, rec->data, be16_to_cpu(rec->len));
+ len = be16_to_cpu(rec->len);
+ if (len > PAGE_SIZE) {
+ ret = -EINVAL;
+ break;
+ }
+ memcpy(firmware_buf, rec->data, len);
ret = vicam_control_msg(gspca_dev, 0xff, 0, 0, firmware_buf,
- be16_to_cpu(rec->len));
+ len);
if (ret < 0)
break;
}
]
|
| 85/2 |
2026/08/17 21:11 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 782b6a718651eda3478b1824b37a8b3185d2740c
Author: Youngjun Lee <yjjuny.lee@samsung.com>
Date: Tue Jun 10 21:41:07 2025 +0900
media: uvcvideo: Fix 1-byte out-of-bounds read in uvc_parse_format()
The buffer length check before calling uvc_parse_format() only ensured
that the buffer has at least 3 bytes (buflen > 2), buf the function
accesses buffer[3], requiring at least 4 bytes.
This can lead to an out-of-bounds read if the buffer has exactly 3 bytes.
Fix it by checking that the buffer has at least 4 bytes in
uvc_parse_format().
Signed-off-by: Youngjun Lee <yjjuny.lee@samsung.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Fixes: c0efd232929c ("V4L/DVB (8145a): USB Video Class driver")
Cc: stable@vger.kernel.org
Reviewed-by: Ricardo Ribalda <ribalda@chromium.org>
Link: https://lore.kernel.org/r/20250610124107.37360-1-yjjuny.lee@samsung.com
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
index 916c2d13e268..62eb45435d8b 100644
--- a/drivers/media/usb/uvc/uvc_driver.c
+++ b/drivers/media/usb/uvc/uvc_driver.c
@@ -344,6 +344,9 @@ static int uvc_parse_format(struct uvc_device *dev,
u8 ftype;
int ret;
+ if (buflen < 4)
+ return -EINVAL;
+
format->type = buffer[2];
format->index = buffer[3];
format->frames = frames;
]
|
| 86/2 |
2026/08/17 21:11 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 25133
output: 70
thoughts: 35
Thoughts: Okay, here's my take on those thoughts, framed as an expert in the field:
**Hunting for USB Response Vulnerabilities**
Alright, time to dig into those USB drivers again. I'm thinking, let's zero in on potential vulnerabilities related to handling USB responses. I need to see if we've missed any edge cases. Specifically, I'm going to search the `drivers/usb/` directory. The key terms I'm using as a starting point are "bounds" and "overflow." That should quickly surface instances where developers might have neglected to properly check the sizes of incoming data or the capacity of buffers when processing USB data. I'm hoping to find more examples of patches or fixes that explicitly address missing bounds checks and data overflow issues on the USB response side. A proactive approach here is always better than chasing down obscure crashes later on.
|
| 87/2 |
2026/08/17 21:11 |
tool |
git-log |
0m
Args: map[MessageRegexps:[bounds] PathPrefix:drivers/usb/ Since:3 years]
Results: map[Output:6b1c8a9403a2 usb: gadget: f_ncm: Use unsigned int for ndp_index
71132cedd1ec usb: atm: ueagle-atm: reject descriptors that confuse probe and disconnect
d5e5cd3654d2 usb: gadget: dummy_hcd: prevent fifo_req reuse during giveback
1febec7e47cd usb: gadget: f_ncm: validate datagram bounds in ncm_unwrap_ntb()
8c6314489550 usb: misc: usbio: bound bulk IN response length to the received transfer
7b681dd5fbf6 usb: typec: tcpm: Validate SVID index in svdm_consume_modes()
96d47e40bf9d USB: serial: kl5kusb105: fix bulk-out buffer overflow
183c1076eca4 USB: serial: io_ti: fix heap overflow in get_manuf_info()
9f9bfc80c67f USB: serial: cypress_m8: validate interrupt packet headers
cff06b03b530 usb: host: max3421: Fix shift-out-of-bounds in max3421_hub_control()
]
|
| 88/2 |
2026/08/17 21:11 |
tool |
git-log |
0m
Args: map[MessageRegexps:[overflow] PathPrefix:drivers/usb/ Since:3 years]
Results: map[Output:6b1c8a9403a2 usb: gadget: f_ncm: Use unsigned int for ndp_index
96d47e40bf9d USB: serial: kl5kusb105: fix bulk-out buffer overflow
0fd2b00b2d3d USB: serial: io_ti: fix heap overflow in build_i2c_fw_hdr()
183c1076eca4 USB: serial: io_ti: fix heap overflow in get_manuf_info()
727d045d064b usb: core: Fix up Interrupt IN endpoints with bogus wBytesPerInterval
8f993d30b95d usb: gadget: f_ncm: validate minimum block_len in ncm_unwrap_ntb()
c088d5dd2fff usb: gadget: f_phonet: fix skb frags[] overflow in pn_rx_complete()
2ab833a16a82 usbip: validate number_of_packets in usbip_pack_ret_submit()
1897852293fa usb: usbip: fix integer overflow in usbip_recv_iso()
8479891d1f04 usb: gadget: f_mass_storage: Fix potential integer overflow in check_command_size_in_blocks()
]
|
| 89/2 |
2026/08/17 21:11 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 26061
output: 52
thoughts: 31
Thoughts: Okay, let's dive into this. I need to take a look at these two identifiers: `8c6314489550` and `183c1076eca4`. My intuition suggests they're related, probably in close proximity to one another. I need to determine their context and function within the system. I'll need to identify what these might be referencing within the project – might they be database keys, file hashes, commit IDs, object identifiers, or something else entirely? The format suggests some sort of key or identifier, so I'll start with that assumption. I'll need to quickly correlate these with any recent activity or error logs. I'm going to start by pulling up my tools, logs and databases and see what information I can get.
|
| 90/2 |
2026/08/17 21:11 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 8c6314489550fa81d41723a0ff33f655b5b6c7b6
Author: HE WEI (ギカク) <skyexpoc@gmail.com>
Date: Wed Jun 24 18:09:52 2026 +0900
usb: misc: usbio: bound bulk IN response length to the received transfer
usbio_bulk_msg() copies bpkt_len = le16_to_cpu(bpkt->len) bytes out of
the bulk IN buffer (usbio->rxbuf, allocated with size usbio->rxbuf_len)
into the caller's buffer. bpkt_len is fully controlled by the device
and is only checked against ibuf_len; ibuf_len in turn is checked
against usbio->txbuf_len, not against rxbuf_len:
if ((obuf_len > (usbio->txbuf_len - sizeof(*bpkt))) ||
(ibuf_len > (usbio->txbuf_len - sizeof(*bpkt))))
return -EMSGSIZE;
txbuf_len and rxbuf_len are taken independently from the bulk OUT and
bulk IN endpoint wMaxPacketSize in usbio_probe(). A malicious or
malfunctioning device that advertises a large bulk OUT endpoint and a
small bulk IN endpoint (e.g. by claiming one of the quirk-free IDs such
as the Lattice NX33U, 0x2ac1:0x20cb) therefore makes ibuf_len, and
hence the device-supplied bpkt_len, exceed rxbuf_len. memcpy() then
reads up to txbuf_len - rxbuf_len bytes past the end of the rxbuf slab
object. The over-read bytes are handed back to the i2c layer and on to
user space through i2c-dev, disclosing adjacent slab memory; with KASAN
this is reported as a slab-out-of-bounds read.
The number of bytes actually received is already known: act equals the
URB actual_length and is bounded by rxbuf_len. Reject any response
that claims more payload than was received, mirroring the existing
"act < sizeof(*bpkt)" check just above.
The control path (usbio_ctrl_msg()) is not affected: it uses a single
buffer (ctrlbuf) for both directions, so its analogous copy can never
leave the allocation.
Found by code review. The out-of-bounds read was confirmed under
AddressSanitizer with a faithful userspace model of usbio_bulk_msg()'s
receive path (an rxbuf_len-sized buffer, the same act/ibuf_len/bpkt_len
checks and the memcpy). A USB raw-gadget + dummy_hcd reproducer is
also available.
Fixes: 121a0f839dbb ("usb: misc: Add Intel USBIO bridge driver")
Cc: stable <stable@kernel.org>
Signed-off-by: HE WEI (ギカク) <skyexpoc@gmail.com>
Link: https://patch.msgid.link/20260624090952.86439-1-skyexpoc@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
diff --git a/drivers/usb/misc/usbio.c b/drivers/usb/misc/usbio.c
index 02d1e0760f0c..24c4cd0df829 100644
--- a/drivers/usb/misc/usbio.c
+++ b/drivers/usb/misc/usbio.c
@@ -344,6 +344,10 @@ int usbio_bulk_msg(struct auxiliary_device *adev, u8 type, u8 cmd, bool last,
if (ibuf_len < bpkt_len)
return -ENOSPC;
+ /* The device must not claim more payload than it actually sent. */
+ if (bpkt_len > act - sizeof(*bpkt))
+ return -EPROTO;
+
memcpy(ibuf, bpkt->data, bpkt_len);
return bpkt_len;
]
|
| 91/2 |
2026/08/17 21:11 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 183c1076eca43bbb3e7bdf597456f91d81c73e74
Author: Adrian Korwel <adriank20047@gmail.com>
Date: Mon May 25 09:58:31 2026 -0500
USB: serial: io_ti: fix heap overflow in get_manuf_info()
get_manuf_info() reads le16_to_cpu(rom_desc->Size) bytes from the
device I2C EEPROM into a buffer allocated with kmalloc_obj(), which
is sizeof(struct edge_ti_manuf_descriptor) = 10 bytes.
The Size field comes from the device and is only validated (in
check_i2c_image()) to make sure the descriptor fits within
TI_MAX_I2C_SIZE (16384 bytes), not against the destination buffer size.
A malicious USB device can therefore set Size to any value up to 16377,
causing a heap overflow of up to 16367 bytes when plugged into a host
running this driver.
valid_csum() is called after read_rom() and also iterates
buffer[0..Size-1], compounding the out-of-bounds access.
Fix by rejecting descriptors with unexpected length before calling
read_rom().
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Adrian Korwel <adriank20047@gmail.com>
[ johan: amend commit message; also check for short descriptors ]
Signed-off-by: Johan Hovold <johan@kernel.org>
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index cb55370e036f..6e0d4c38911b 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -773,6 +773,12 @@ static int get_manuf_info(struct edgeport_serial *serial, u8 *buffer)
}
/* Read the descriptor data */
+ if (le16_to_cpu(rom_desc->Size) != sizeof(struct edge_ti_manuf_descriptor)) {
+ dev_err(dev, "unexpected Edge descriptor length: %u\n",
+ le16_to_cpu(rom_desc->Size));
+ status = -EINVAL;
+ goto exit;
+ }
status = read_rom(serial, start_address+sizeof(struct ti_i2c_desc),
le16_to_cpu(rom_desc->Size), buffer);
if (status)
]
|
| 92/2 |
2026/08/17 21:11 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 28125
output: 52
thoughts: 195
Thoughts: **Prior Art Confirmation and Validation**
Okay, these two commits, `8c6314489550` and `183c1076eca4`, are hitting the mark *exactly* in terms of the kind of prior art I need. They're demonstrating crucial principles, which I'll summarize to make sure I grasp them completely:
* First, when we get a length field coming in from a USB device – something like `bpkt_len` or `rom_desc->Size` – it's absolutely vital that we *immediately* validate that against a few things. We need to compare it to the *actual* data we've received (like `act` or `actual_length`), and critically, to the size of the destination buffer. That's our primary defense against overruns.
* Second, and this is non-negotiable, if that length field *exceeds* what we can safely handle – if it's too big, we **have** to return an error. Not just any error, but the right ones. Something that clearly signals a protocol error like `-EPROTO`, an invalid argument situation like `-EINVAL`, or a message size issue like `-EMSGSIZE`. The goal is to halt the flow, report the problem and stop potentially corrupting the memory.
* Third, what they've done to *fix* these problems is simple and elegant: add these explicit bounds checks. Right before we `memcpy` data or try to read it, we must verify that the length provided doesn't take us outside the allocated memory space.
Now, let's broaden the scope a little. I need to get some more examples, so let's cross-reference and examine commits `0fd2b00b2d3d` and `96d47e40bf9d` to see if they follow the same patterns or illustrate alternative scenarios of these validations.
|
| 93/2 |
2026/08/17 21:11 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 0fd2b00b2d3d05e3eaa13342b3dfb0fa85c226ae
Author: Adrian Korwel <adriank20047@gmail.com>
Date: Mon May 25 09:58:32 2026 -0500
USB: serial: io_ti: fix heap overflow in build_i2c_fw_hdr()
build_i2c_fw_hdr() allocates a fixed-size buffer of
(16*1024 - 512) + sizeof(struct ti_i2c_firmware_rec) bytes, then
copies le16_to_cpu(img_header->Length) bytes into it without
validating that Length fits within the available space after the
firmware record header.
img_header->Length is a __le16 from the firmware file and can be
up to 65535. check_fw_sanity() validates the total firmware size
but not img_header->Length specifically.
Fix by rejecting images where img_header->Length exceeds the
available destination space.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Adrian Korwel <adriank20047@gmail.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index 6e0d4c38911b..d48819d785ef 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -844,6 +844,11 @@ static int build_i2c_fw_hdr(u8 *header, const struct firmware *fw)
/* Pointer to fw_down memory image */
img_header = (struct ti_i2c_image_header *)&fw->data[4];
+ if (le16_to_cpu(img_header->Length) >
+ buffer_size - sizeof(struct ti_i2c_firmware_rec)) {
+ kfree(buffer);
+ return -EINVAL;
+ }
memcpy(buffer + sizeof(struct ti_i2c_firmware_rec),
&fw->data[4 + sizeof(struct ti_i2c_image_header)],
le16_to_cpu(img_header->Length));
]
|
| 94/2 |
2026/08/17 21:11 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 96d47e40bf9db4a9efd5c8fb53287a508d165f14
Author: HyeongJun An <sammiee5311@gmail.com>
Date: Mon Jun 8 18:09:26 2026 +0900
USB: serial: kl5kusb105: fix bulk-out buffer overflow
klsi_105_prepare_write_buffer() is called by the generic write path
with the bulk-out buffer and its size (bulk_out_size, 64 bytes). It
stores a two-byte length header at the start of the buffer and copies
the payload from the write fifo starting at buf + KLSI_HDR_LEN, but
passes the full buffer size as the number of bytes to copy:
count = kfifo_out_locked(&port->write_fifo, buf + KLSI_HDR_LEN,
size, &port->lock);
When the fifo holds at least size bytes, size bytes are copied starting
two bytes into the size-byte buffer, writing KLSI_HDR_LEN bytes past its
end. Copy at most size - KLSI_HDR_LEN bytes instead, leaving room for
the header as safe_serial already does.
Writing bulk_out_size or more bytes to the tty triggers a slab
out-of-bounds write, observed with KASAN by emulating the device with
dummy_hcd and raw-gadget:
BUG: KASAN: slab-out-of-bounds in kfifo_copy_out+0x83/0xc0
Write of size 64 at addr ffff888112c62202 by task python3
kfifo_copy_out
klsi_105_prepare_write_buffer [kl5kusb105]
usb_serial_generic_write_start [usbserial]
Allocated by task 139:
usb_serial_probe [usbserial]
The buggy address is located 2 bytes inside of allocated 64-byte region
The out-of-bounds write no longer occurs with this change applied.
Fixes: 60b3013cdaf3 ("USB: kl5usb105: reimplement using generic framework")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: HyeongJun An <sammiee5311@gmail.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index ed8531a64768..e72a0b45a707 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -330,8 +330,8 @@ static int klsi_105_prepare_write_buffer(struct usb_serial_port *port,
unsigned char *buf = dest;
int count;
- count = kfifo_out_locked(&port->write_fifo, buf + KLSI_HDR_LEN, size,
- &port->lock);
+ count = kfifo_out_locked(&port->write_fifo, buf + KLSI_HDR_LEN,
+ size - KLSI_HDR_LEN, &port->lock);
put_unaligned_le16(count, buf);
return count + KLSI_HDR_LEN;
]
|
| 95/2 |
2026/08/17 21:11 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 30392
output: 940
thoughts: 756
Thoughts: **My Analysis of USB Length Field Vulnerabilities**
Alright, I've got a solid grasp on this. Based on my review of the prior art, here's the pattern that consistently emerges in handling length fields from USB devices:
1. **Never Trust the Length:** I've seen it time and again – any length field provided by a USB device within its payload (like the `b[3]` in the current scenario, or instances like `bpkt->len` or `rom_desc->Size` in these other examples) *cannot* be blindly trusted. It's user input. It needs to be treated as such.
2. **Double Validation is Key:** The length field needs to be rigorously validated against *two* critical factors:
a) The actual number of bytes *received* from the USB device. This is the `actual_len` we get back from functions like `usb_bulk_msg` or the `act` value returned by something like `usbio_bulk_msg`. We need to make sure we haven't read more bytes than the device indicated.
b) The size of the *destination buffer* where the payload will eventually be copied. This is absolutely critical to avoid overflows. This is where something like the proposed `cmd_result_len` comes into play, or the `sizeof(struct edge_ti_manuf_descriptor)` that I saw in a different example.
3. **Error Out Gracefully:** If either of those validation checks fails, the driver *must* return a suitable error code – things like `-EIO`, `-EPROTO`, `-EINVAL`, or `-EMSGSIZE`. And, critically, the operation must be aborted at that point. We need to prevent any out-of-bounds reads or writes. This is non-negotiable.
4. **Buffer Size Visibility:** I've noticed that if the size of the destination buffer isn't known within the function responsible for copying the data, the buffer's size needs to be explicitly passed down the call stack. This is exemplified by the proposed addition of `cmd_result_len`. This gives the lower-level function the information it needs to perform the bounds checking correctly.
Let's drill down into the historical record I found that reflects these insights:
* `8c6314489550` ("usb: misc: usbio: bound bulk IN response length to the received transfer"): This one validates the device-supplied length against both the actual received length *and* the buffer size. This exemplifies the double-check.
* `183c1076eca4` ("USB: serial: io\_ti: fix heap overflow in get\_manuf\_info()"): It validates device-supplied lengths against the destination buffer size *before* attempting to read any data. This is what we are after.
* `b91e6aafe8d3` ("media: dvb-usb: dtv5100: fix out-of-bounds in dtv5100\_i2c\_msg()"): Here, they validated user or device-controlled lengths against `sizeof(st->data)`.
* `1a31cb278210` ("media: dvb-usb: pctv452e: move snd/rcv len check before kmalloc"): They validated the length *before* allocating memory and copying, which is good defensive programming.
While I didn't find any *recent* direct fixes within `drivers/media/usb/ttusb-dec/`, I've seen ample evidence of similar bugs being addressed within the broader `drivers/media/usb/` and `drivers/usb/` subsystems.
In short, there are some clear, consistent patterns. To recap my idioms to follow:
* **Zero Trust for Device Lengths:** Assume any length received from the USB endpoint is a hostile input.
* **Two-Pronged Bounds Checking:** Check the length against *both* the actual data received (DMA buffer) and the destination buffer size.
* **Explicit Buffer Size Propagation:** Pass destination buffer sizes down through the call stack when needed.
* **Secure Failure:** Return an error code and *do not copy* if the checks fail.
These principles align perfectly with the proposed fix and provides the required historical context. We need to ensure that the code follows these best practices.
|
| 96/1 |
2026/08/17 21:12 |
action |
kernel-scratch-checkouter |
0m
Results: map[KernelScratchSrc:/app/workdir/cache/tmp/tmp2795212180]
|
| 97/1 |
2026/08/17 21:12 |
loop |
|
30m
|
| 98/2 |
2026/08/17 21:12 |
iteration |
0 |
30m
|
| 99/3 |
2026/08/17 21:12 |
agent |
patch-generator |
5m
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, an initial explanation of the root cause done by another
kernel expert, and a summary of how similar bugs were fixed in the past.
Use the codeeditor tool to do code edits.
Note: you will not see your changes when looking at the code using codesearch tools.
Use the patch-diff tool to review the modifications you applied.
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.
If you will end up removing the WARN_ON macro because the condition can legitimately happen,
add a pr_err/dev_err/... (whatever is the macro for printing runtime errors used in the file)
call that logs that the unlikely condition has happened. The pr_err/dev_err/... message
must not include "WARNING" nor "BUG" strings.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash that corresponds to the bug is:
usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
------------[ cut here ]------------
memcpy: detected buffer overflow: 75 byte read of buffer size 60
WARNING: lib/string_helpers.c:1037 at __fortify_report+0xa0/0xb8 lib/string_helpers.c:1036, CPU#0: kworker/0:4/4798
Modules linked in:
CPU: 0 UID: 0 PID: 4798 Comm: kworker/0:4 Not tainted syzkaller #1 PREEMPT
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/07/2026
Workqueue: usb_hub_wq hub_event
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : __fortify_report+0xa0/0xb8 lib/string_helpers.c:1036
lr : __fortify_report+0xa0/0xb8 lib/string_helpers.c:1036
sp : ffff800098516d20
x29: ffff800098516d20 x28: dfff800000000000 x27: ffff7000130a2db0
x26: 0000000000000000 x25: ffff0000d1862683 x24: ffff800098516ea0
x23: 000000000000004b x22: ffff800086d0a338 x21: 0000000000000000
x20: 000000000000004b x19: 000000000000003c x18: 1fffe00035ba8028
x17: 0000000000000003 x16: ffff800088ba7000 x15: ffff8000824ea6c8
x14: 0000000000000000 x13: 0000000000000001 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000002 x9 : 653dfa0a2f6c5200
x8 : 653dfa0a2f6c5200 x7 : ffff80008048e0c4 x6 : 0000000000000000
x5 : 0000000000000000 x4 : 0000000000000000 x3 : ffff8000802f8054
x2 : 0000000100000000 x1 : ffff0000c57d1d40 x0 : 0000000000000000
Call trace:
__fortify_report+0xa0/0xb8 lib/string_helpers.c:1036 (P)
__fortify_panic+0x10/0x14 lib/string_helpers.c:1043
fortify_memcpy_chk include/linux/fortify-string.h:549 [inline]
ttusb_dec_start_feed+0x0/0x10ac drivers/media/usb/ttusb-dec/ttusb_dec.c:372
ttusb_dec_get_stb_state drivers/media/usb/ttusb-dec/ttusb_dec.c:392 [inline]
ttusb_dec_init_stb drivers/media/usb/ttusb-dec/ttusb_dec.c:1413 [inline]
ttusb_dec_probe+0x724/0x1aa0 drivers/media/usb/ttusb-dec/ttusb_dec.c:1671
usb_probe_interface+0x308/0x788 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_set_configuration+0x1184/0x158c drivers/usb/core/message.c:2268
usb_generic_driver_probe+0x8c/0x148 drivers/usb/core/generic.c:250
usb_probe_device+0x114/0x2b0 drivers/usb/core/driver.c:291
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_new_device+0x9c4/0x11f8 drivers/usb/core/hub.c:2703
hub_port_connect drivers/usb/core/hub.c:5575 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5715 [inline]
port_event drivers/usb/core/hub.c:5879 [inline]
hub_event+0x1ef0/0x39fc drivers/usb/core/hub.c:5961
process_one_work kernel/workqueue.c:3322 [inline]
process_scheduled_works+0x788/0x10b8 kernel/workqueue.c:3405
worker_thread+0x798/0xbd0 kernel/workqueue.c:3486
kthread+0x304/0x3d4 kernel/kthread.c:436
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:842
irq event stamp: 16196
hardirqs last enabled at (16195): [<ffff8000868fc7b4>] irqentry_exit_to_kernel_mode_after_preempt include/linux/irq-entry-common.h:507 [inline]
hardirqs last enabled at (16195): [<ffff8000868fc7b4>] arm64_exit_to_kernel_mode+0x80/0x94 arch/arm64/kernel/entry-common.c:62
hardirqs last disabled at (16196): [<ffff8000868f86e0>] el1_brk64+0x20/0x54 arch/arm64/kernel/entry-common.c:425
softirqs last enabled at (16128): [<ffff80008030ff18>] softirq_handle_end kernel/softirq.c:468 [inline]
softirqs last enabled at (16128): [<ffff80008030ff18>] handle_softirqs+0xc28/0xd98 kernel/softirq.c:650
softirqs last disabled at (16119): [<ffff8000800204b0>] __do_softirq+0x14/0x20 kernel/softirq.c:656
---[ end trace 0000000000000000 ]---
------------[ cut here ]------------
kernel BUG at lib/string_helpers.c:1044!
Internal error: Oops - BUG: 00000000f2000800 [#1] SMP
Modules linked in:
CPU: 0 UID: 0 PID: 4798 Comm: kworker/0:4 Tainted: G W syzkaller #1 PREEMPT
Tainted: [W]=WARN
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/07/2026
Workqueue: usb_hub_wq hub_event
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : __fortify_panic+0x10/0x14 lib/string_helpers.c:1043
lr : __fortify_panic+0x10/0x14 lib/string_helpers.c:1043
sp : ffff800098516d50
x29: ffff800098516d50 x28: dfff800000000000 x27: ffff7000130a2db0
x26: 0000000000000000 x25: ffff0000d1862683 x24: ffff800098516ea0
x23: 000000000000004b x22: 000000000000004b x21: ffff0000d1862680
x20: 1fffe0001a30c4d0 x19: ffff0000c3014000 x18: 1fffe00035ba8028
x17: 0000000000000003 x16: ffff800088ba7000 x15: ffff8000824ea6c8
x14: 0000000000000000 x13: 0000000000000001 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000002 x9 : 653dfa0a2f6c5200
x8 : 653dfa0a2f6c5200 x7 : ffff80008048e0c4 x6 : 0000000000000000
x5 : 0000000000000000 x4 : 0000000000000000 x3 : ffff8000802f8054
x2 : 0000000100000000 x1 : ffff0000c57d1d40 x0 : 0000000000000000
Call trace:
__fortify_panic+0x10/0x14 lib/string_helpers.c:1043 (P)
fortify_memcpy_chk include/linux/fortify-string.h:549 [inline]
ttusb_dec_start_feed+0x0/0x10ac drivers/media/usb/ttusb-dec/ttusb_dec.c:372
ttusb_dec_get_stb_state drivers/media/usb/ttusb-dec/ttusb_dec.c:392 [inline]
ttusb_dec_init_stb drivers/media/usb/ttusb-dec/ttusb_dec.c:1413 [inline]
ttusb_dec_probe+0x724/0x1aa0 drivers/media/usb/ttusb-dec/ttusb_dec.c:1671
usb_probe_interface+0x308/0x788 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_set_configuration+0x1184/0x158c drivers/usb/core/message.c:2268
usb_generic_driver_probe+0x8c/0x148 drivers/usb/core/generic.c:250
usb_probe_device+0x114/0x2b0 drivers/usb/core/driver.c:291
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_new_device+0x9c4/0x11f8 drivers/usb/core/hub.c:2703
hub_port_connect drivers/usb/core/hub.c:5575 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5715 [inline]
port_event drivers/usb/core/hub.c:5879 [inline]
hub_event+0x1ef0/0x39fc drivers/usb/core/hub.c:5961
process_one_work kernel/workqueue.c:3322 [inline]
process_scheduled_works+0x788/0x10b8 kernel/workqueue.c:3405
worker_thread+0x798/0xbd0 kernel/workqueue.c:3486
kthread+0x304/0x3d4 kernel/kthread.c:436
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:842
Code: d503233f a9bf7bfd 910003fd 94619ee8 (d4210000)
---[ end trace 0000000000000000 ]---
The explanation of the root cause of the bug is:
The crash is caused by a buffer overflow (both an out-of-bounds read and an out-of-bounds write) in the `ttusb_dec_send_command()` function, triggered by a malicious or malfunctioning USB device returning an unexpectedly large payload length.
### Detailed Analysis
In `drivers/media/usb/ttusb-dec/ttusb_dec.c`, the `ttusb_dec_send_command()` function allocates a buffer `b` to send a command and receive the response via `usb_bulk_msg()`:
```c
b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
```
Here, `COMMAND_PACKET_SIZE` is defined as `0x3c` (60), so the allocated buffer `b` is exactly 64 bytes.
After receiving the response from the USB device, the driver reads the payload length directly from `b[3]` (which is fully controlled by the USB device) and copies the payload into the caller-provided `cmd_result` buffer:
```c
if (result_length)
*result_length = b[3];
if (cmd_result && b[3] > 0)
memcpy(cmd_result, &b[4], b[3]);
```
There are two major flaws in this logic:
1. **No bounds check against the received data or the allocated buffer `b`**: `b[3]` is an 8-bit value and can be up to 255. If the device returns a value greater than `COMMAND_PACKET_SIZE` (60), the `memcpy()` will read past the end of the 64-byte buffer `b`. In the syzkaller crash, `b[3]` was `75`, leading to a 75-byte read from `&b[4]` (which only has 60 bytes allocated). This triggers the `fortify_memcpy_chk` panic (`75 byte read of buffer size 60`).
2. **No bounds check against the destination buffer `cmd_result`**: The size of `cmd_result` is never passed to `ttusb_dec_send_command()`. While callers like `ttusb_dec_get_stb_state()` pass a 60-byte buffer (`u8 c[COMMAND_PACKET_SIZE]`), other callers like `ttusbdecfe_dvbt_read_status()` in `ttusbdecfe.c` pass a much smaller buffer (`u8 result[4]`). If the device returns `b[3] = 60` for the latter, it will result in a severe stack buffer overflow.
### Proposed Fix
To fix this comprehensively, the API needs to be updated to pass the size of the destination buffer, and `ttusb_dec_send_command()` must validate `b[3]` against the received length, the maximum packet size, and the destination buffer size.
**1. Update `ttusbdecfe_config` in `drivers/media/usb/ttusb-dec/ttusbdecfe.h`:**
Add `cmd_result_len` to the `send_command` callback signature.
```c
struct ttusbdecfe_config
{
int (*send_command)(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len);
};
```
**2. Update `ttusb_dec_send_command()` in `ttusb_dec.c`:**
Add `cmd_result_len` to the signature and implement the necessary bounds checks.
```c
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len)
{
// ...
result = usb_bulk_msg(dec->udev, dec->result_pipe, b,
COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
if (result) {
printk("%s: result bulk message failed: error %d\n",
__func__, result);
goto err_mutex_unlock;
} else {
if (debug) {
printk(KERN_DEBUG "%s: result: %*ph\n",
__func__, actual_len, b);
}
/* Ensure we received at least the 4-byte header */
if (actual_len < 4) {
result = -EIO;
goto err_mutex_unlock;
}
/* Ensure the device isn't claiming more data than it sent or than fits in b */
if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
result = -EIO;
goto err_mutex_unlock;
}
if (result_length)
*result_length = b[3];
if (cmd_result && b[3] > 0) {
/* Ensure we don't overflow the caller's buffer */
if (b[3] > cmd_result_len) {
result = -EIO;
goto err_mutex_unlock;
}
memcpy(cmd_result, &b[4], b[3]);
}
}
// ...
```
**3. Update all callers:**
You will need to update all callers of `ttusb_dec_send_command()` in `ttusb_dec.c` and `state->config->send_command()` in `ttusbdecfe.c` to pass the correct buffer size.
For example:
- In `ttusb_dec_get_stb_state()`: pass `sizeof(c)` instead of just `c`.
- In `ttusbdecfe_dvbt_read_status()`: pass `sizeof(result)` instead of just `result`.
- For calls where `cmd_result` is `NULL`, simply pass `0` as the length.
Historical context on how similar bugs were fixed in the past:
Based on a review of the recent history in the `drivers/media/usb/` and `drivers/usb/` subsystems, there are no recent commits addressing this specific type of bug in the `ttusb-dec` driver itself. However, there is extensive prior art for fixing identical root causes—trusting device-supplied length fields without validation—across other USB media and serial drivers.
### Relevant Prior Art
Similar vulnerabilities where a USB device returns a malicious or unexpectedly large length field have been fixed using the exact same principles you proposed. Notable recent examples include:
1. **`8c6314489550` ("usb: misc: usbio: bound bulk IN response length to the received transfer")**
- **Issue:** The driver read a length field (`bpkt->len`) from the device and used it in a `memcpy()` without checking if it exceeded the actual received data or the destination buffer size, leading to a slab-out-of-bounds read.
- **Fix:** Added explicit checks to ensure the device-supplied length did not exceed the actual received length (`act`) minus the header size.
2. **`183c1076eca4` ("USB: serial: io_ti: fix heap overflow in get_manuf_info()")**
- **Issue:** The driver read a `Size` field from the device's EEPROM and used it to copy data into a fixed-size 10-byte buffer. A malicious device could set `Size` to a large value, causing a heap overflow.
- **Fix:** Validated the device-provided `Size` against the expected `sizeof(struct edge_ti_manuf_descriptor)` before performing the read.
3. **`b91e6aafe8d3` ("media: dvb-usb: dtv5100: fix out-of-bounds in dtv5100_i2c_msg()")**
- **Issue:** An untrusted length value (`rlen`) was used in a `memcpy()` to a fixed-size buffer (`st->data`), causing an out-of-bounds write.
- **Fix:** Added a simple `if (rlen > sizeof(st->data))` check, returning `-EINVAL` if the condition was met.
4. **`782b6a718651` ("media: uvcvideo: Fix 1-byte out-of-bounds read in uvc_parse_format()")**
- **Issue:** The driver accessed `buffer[3]` without verifying that the actual received buffer length was at least 4 bytes.
- **Fix:** Added a strict `if (buflen < 4)` check before accessing the payload.
### Common Patterns and Idioms for the Fix
Based on how these similar bugs were addressed, your proposed fix aligns perfectly with kernel best practices. When writing the patch, you should follow these established idioms:
1. **Never Trust Device-Provided Lengths:** Any length field originating from a USB device (in your case, `b[3]`) must be treated as untrusted user input.
2. **Double Bounds Checking:** The untrusted length must be validated against two distinct boundaries:
- **The Source Boundary:** Ensure `b[3]` does not exceed the actual data received from the USB transfer (`actual_len - 4`). This prevents the out-of-bounds read (the `75 byte read of buffer size 60` panic).
- **The Destination Boundary:** Ensure `b[3]` does not exceed the size of the caller-provided buffer (`cmd_result_len`). This prevents the out-of-bounds write/stack corruption.
3. **Explicit Buffer Sizing:** Passing the destination buffer size down the call stack (e.g., adding `cmd_result_len` to `ttusb_dec_send_command` and the `send_command` callback) is the standard and correct way to handle dynamic copies where the destination size varies by caller.
4. **Fail Securely:** If any bounds check fails, the driver should immediately abort the operation, unlock any held mutexes, and return an appropriate error code (e.g., `-EIO`, `-EPROTO`, or `-EMSGSIZE`). Logging a rate-limited warning or debug message is also common practice in these error paths.
Reply: I have analyzed the root cause and implemented the fix as proposed, with an additional safeguard.
### Changes made:
1. **Updated `ttusbdecfe_config`**: Added `cmd_result_len` to the `send_command` callback signature in `drivers/media/usb/ttusb-dec/ttusbdecfe.h`.
2. **Updated `ttusb_dec_send_command`**:
- Added `cmd_result_len` to the function signature.
- Added a check to ensure `param_length` does not exceed `COMMAND_PACKET_SIZE` before allocating and copying into the buffer `b`. This prevents a potential out-of-bounds write when copying `params` into `b`.
- Added bounds checks to ensure the received payload length (`b[3]`) does not exceed `COMMAND_PACKET_SIZE`, the actual received data length (`actual_len - 4`), or the caller-provided buffer size (`cmd_result_len`).
- Added a check to ensure `actual_len` is at least 4 bytes to safely read the header.
3. **Updated all callers**: Updated all invocations of `ttusb_dec_send_command` in `ttusb_dec.c` and `state->config->send_command` in `ttusbdecfe.c` to pass the correct destination buffer size (using `sizeof()`) or `0` when `cmd_result` is `NULL`.
### Why these changes were made:
The primary issue was trusting the device-provided length field (`b[3]`) without validating it against the bounds of the allocated buffer or the caller's destination buffer. By passing the destination buffer size down the call stack and validating `b[3]` against both the source (actual received data) and destination (caller's buffer size) boundaries, we ensure that malicious or malfunctioning USB devices cannot trigger out-of-bounds reads or writes.
Additionally, I added a check for `param_length > COMMAND_PACKET_SIZE` at the beginning of `ttusb_dec_send_command`. While current callers pass safe values, this prevents future callers from accidentally overflowing the allocated command buffer `b` when copying `params`.
|
| 100/4 |
2026/08/17 21:12 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 11315
output: 36
thoughts: 284
Thoughts: **My Analysis of the ttusb-dec Driver Vulnerability and Proposed Fix**
Alright, let's break this down. It seems we've got a classic buffer overflow vulnerability lurking in `drivers/media/usb/ttusb-dec/ttusb_dec.c`. The core issue is in `ttusb_dec_send_command()`. It's reading a length from `b[3]`, an untrusted value, and then using that to copy data into `cmd_result` via `memcpy(cmd_result, &b[4], b[3])`. The buffer `b` is only 64 bytes, allocated using `COMMAND_PACKET_SIZE + 4` which I'm assuming, given the context, results in 60 bytes of usable space.
The crux of the matter is that `b[3]` is unchecked. If `b[3]` is greater than 60, we're reading out of bounds from `b`. But even worse, if `b[3]` is larger than the size of `cmd_result`, we're writing past the end of that buffer, leading to a heap-based buffer overflow. That's a serious security risk.
The proposed fix seems reasonable, it is a good plan. The fix involves three steps:
1. Adding `cmd_result_len` to the `ttusbdecfe_config` structure within `ttusbdecfe.h`. This is the right place to store this value.
2. Then, inside `ttusb_dec_send_command()`, the code will get the `cmd_result_len` and check that the size of `b[3]` is within the boundaries of `cmd_result_len`. This bounds check will protect the vulnerable memcpy.
3. Finally, we need to update all the callers of `ttusb_dec_send_command()` and `state->config->send_command()` with the right buffer size. This is a crucial step to make sure the fix is complete.
I'll need to dig into the code, and assess the implementation. I'll check that the bounds checks are robust and handle all edge cases correctly. Also, I'll review all the call sites to ensure that the correct lengths are passed and that no other similar vulnerabilities exist nearby. I will need to be very thorough to minimize the potential for missed conditions, especially when dealing with untrusted lengths and potentially complex data structures.
|
| 101/4 |
2026/08/17 21:12 |
tool |
codesearch-file-index |
0m
Args: map[SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results: map[Entities:[map[Kind:function Name:__check_adapter_nr] map[Kind:function Name:__check_debug] map[Kind:function Name:__check_enable_rc] map[Kind:function Name:__check_output_pva] map[Kind:function Name:crc16] map[Kind:function Name:dvb_filter_pes2ts] map[Kind:function Name:dvb_filter_pes2ts_init] map[Kind:function Name:fe_send_command] map[Kind:function Name:swap_bytes] map[Kind:function Name:ttusb_dec_alloc_iso_urbs] map[Kind:function Name:ttusb_dec_audio_pes2ts_cb] map[Kind:function Name:ttusb_dec_boot_dsp] map[Kind:function Name:ttusb_dec_disconnect] map[Kind:function Name:ttusb_dec_driver_exit] map[Kind:function Name:ttusb_dec_driver_init] map[Kind:function Name:ttusb_dec_exit_bh_work] map[Kind:function Name:ttusb_dec_exit_dvb] map[Kind:function Name:ttusb_dec_exit_filters] map[Kind:function Name:ttusb_dec_exit_rc] map[Kind:function Name:ttusb_dec_exit_usb] map[Kind:function Name:ttusb_dec_free_iso_urbs] map[Kind:function Name:ttusb_dec_get_stb_state] map[Kind:function Name:ttusb_dec_handle_irq] map[Kind:function Name:ttusb_dec_init_bh_work] map[Kind:function Name:ttusb_dec_init_dvb] map[Kind:function Name:ttusb_dec_init_filters] map[Kind:function Name:ttusb_dec_init_stb] map[Kind:function Name:ttusb_dec_init_usb] map[Kind:function Name:ttusb_dec_init_v_pes] map[Kind:function Name:ttusb_dec_probe] map[Kind:function Name:ttusb_dec_process_filter] map[Kind:function Name:ttusb_dec_process_packet] map[Kind:function Name:ttusb_dec_process_pva] map[Kind:function Name:ttusb_dec_process_urb] map[Kind:function Name:ttusb_dec_process_urb_frame] map[Kind:function Name:ttusb_dec_process_urb_frame_list] map[Kind:function Name:ttusb_dec_send_command] map[Kind:function Name:ttusb_dec_set_interface] map[Kind:function Name:ttusb_dec_set_model] map[Kind:function Name:ttusb_dec_set_pids] map[Kind:function Name:ttusb_dec_setup_urbs] map[Kind:function Name:ttusb_dec_start_feed] map[Kind:function Name:ttusb_dec_start_iso_xfer] map[Kind:function Name:ttusb_dec_start_sec_feed] map[Kind:function Name:ttusb_dec_start_ts_feed] map[Kind:function Name:ttusb_dec_stop_feed] map[Kind:function Name:ttusb_dec_stop_iso_xfer] map[Kind:function Name:ttusb_dec_stop_sec_feed] map[Kind:function Name:ttusb_dec_stop_ts_feed] map[Kind:function Name:ttusb_dec_video_pes2ts_cb] map[Kind:function Name:ttusb_init_rc] map[Kind:struct Name:dvb_filter_pes2ts] map[Kind:struct Name:filter_info] map[Kind:struct Name:ttusb_dec] map[Kind:struct Name:urb_frame] map[Kind:global_variable Name:__UNIQUE_ID_addressable_ttusb_dec_driver_init_685] map[Kind:global_variable Name:__UNIQUE_ID_modinfo_676] map[Kind:global_variable Name:__UNIQUE_ID_modinfo_677] map[Kind:global_variable Name:__UNIQUE_ID_modinfo_678] map[Kind:global_variable Name:__UNIQUE_ID_modinfo_679] map[Kind:global_variable Name:__UNIQUE_ID_modinfo_680] map[Kind:global_variable Name:__UNIQUE_ID_modinfo_681] map[Kind:global_variable Name:__UNIQUE_ID_modinfo_682] map[Kind:global_variable Name:__UNIQUE_ID_modinfo_683] map[Kind:global_variable Name:__UNIQUE_ID_modinfo_686] map[Kind:global_variable Name:__UNIQUE_ID_modinfo_687] map[Kind:global_variable Name:__UNIQUE_ID_modinfo_688] map[Kind:global_variable Name:__UNIQUE_ID_modinfo_689] map[Kind:global_variable Name:__exitcall_ttusb_dec_driver_exit] map[Kind:global_variable Name:__mod_device_table__kmod_ttusb_dec__usb__ttusb_dec_table] map[Kind:global_variable Name:__param_adapter_nr] map[Kind:global_variable Name:__param_arr_adapter_nr] map[Kind:global_variable Name:__param_debug] map[Kind:global_variable Name:__param_enable_rc] map[Kind:global_variable Name:__param_output_pva] map[Kind:global_variable Name:__param_str_adapter_nr] map[Kind:global_variable Name:__param_str_debug] map[Kind:global_variable Name:__param_str_enable_rc] map[Kind:global_variable Name:__param_str_output_pva] map[Kind:global_variable Name:adapter_nr] map[Kind:global_variable Name:fe_config] map[Kind:global_variable Name:rc_keys] map[Kind:global_variable Name:ttusb_dec_driver] map[Kind:global_variable Name:ttusb_dec_table] map[Kind:enum Name:ttusb_dec_interface] map[Kind:enum Name:ttusb_dec_model] map[Kind:enum Name:ttusb_dec_packet_type] map[Kind:typedef Name:dvb_filter_pes2ts_cb_t]]]
|
| 102/4 |
2026/08/17 21:12 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 13946
output: 49
thoughts: 35
Thoughts: Here's my summary, as if I were thinking these thoughts:
**Analyzing the `ttusb_dec_send_command` Function**
Okay, time to dive into the `ttusb_dec_send_command` function. Let's start with where it lives: `drivers/media/usb/ttusb-dec/ttusb_dec.c`. Given what I know about USB media devices and the overall structure of the kernel, I'm already anticipating how it's likely architected. I'll be looking for command queuing, URB management, error handling related to USB communication, and any device-specific quirks. I expect to see data structures related to the USB device itself and likely some low-level control of endpoints. I'll need to figure out what type of commands it's sending, whether it's synchronous or asynchronous, and how it handles potential timeouts or retries. Knowing the context of this function, I'll be able to get to the core of this driver and see how it is interacting with the underlying hardware, how it is exposed to the user space, and any potential security vulnerabilities.
|
| 103/4 |
2026/08/17 21:12 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusb_dec.c Name:ttusb_dec_send_command]
Results: map[SourceCode: 315: static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
316: int param_length, const u8 params[],
317: int *result_length, u8 cmd_result[])
318: {
319: int result, actual_len;
320: u8 *b;
321:
322: dprintk("%s\n", __func__);
323:
324: b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
325: if (!b)
326: return -ENOMEM;
327:
328: result = mutex_lock_interruptible(&dec->usb_mutex);
329: if (result) {
330: printk("%s: Failed to lock usb mutex.\n", __func__);
331: goto err_free;
332: }
333:
334: b[0] = 0xaa;
335: b[1] = ++dec->trans_count;
336: b[2] = command;
337: b[3] = param_length;
338:
339: if (params)
340: memcpy(&b[4], params, param_length);
341:
342: if (debug) {
343: printk(KERN_DEBUG "%s: command: %*ph\n",
344: __func__, param_length, b);
345: }
346:
347: result = usb_bulk_msg(dec->udev, dec->command_pipe, b,
348: COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
349:
350: if (result) {
351: printk("%s: command bulk message failed: error %d\n",
352: __func__, result);
353: goto err_mutex_unlock;
354: }
355:
356: result = usb_bulk_msg(dec->udev, dec->result_pipe, b,
357: COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
358:
359: if (result) {
360: printk("%s: result bulk message failed: error %d\n",
361: __func__, result);
362: goto err_mutex_unlock;
363: } else {
364: if (debug) {
365: printk(KERN_DEBUG "%s: result: %*ph\n",
366: __func__, actual_len, b);
367: }
368:
369: if (result_length)
370: *result_length = b[3];
371: if (cmd_result && b[3] > 0)
372: memcpy(cmd_result, &b[4], b[3]);
373: }
374:
375: err_mutex_unlock:
376: mutex_unlock(&dec->usb_mutex);
377: err_free:
378: kfree(b);
379: return result;
380: }
SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
|
| 104/4 |
2026/08/17 21:12 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 15256
output: 62
thoughts: 17
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Analyzing `ttusb_dec_send_command` Callers**
Okay, so the immediate goal is to understand the calling contexts of `ttusb_dec_send_command`. I need to figure out how this function is being used. This isn't just about a simple search; I need to understand the *why* behind its invocations.
First, I'll identify all direct callers. A basic grep or find in the code base will get me a list, but that's just the starting point. I need to quickly filter that list to highlight the most important. I'll need to use tools to provide the call graph, to analyze the context of each call.
Then I'll start with the most likely culprits - what subsystems or drivers are likely managing USB-related communication? Anything related to the transport layer, data parsing, or the device control flow will be immediately relevant. The function name itself suggests some interaction with a USB device, likely a decoder of some sort, so I should be looking at the driver source, and how it interacts with the USB device.
I'll be paying close attention to any parameters passed to `ttusb_dec_send_command`. The arguments are going to be key. They'll tell me what kind of commands are being sent and, by extension, what the function's responsibility is. Are we talking about control requests, data transfers, or something else entirely? A quick look at the function's prototype and associated data structures will give me a head start.
Finally, I'm expecting some level of complexity. There might be indirect calls through function pointers or macro expansions. I'll need to be ready to trace through those layers to get the complete picture. The goal is to build a mental map of how `ttusb_dec_send_command` fits into the broader architecture. Essentially, I'm looking for a roadmap of its influence.
|
| 105/4 |
2026/08/17 21:12 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusb_dec.c IncludeSnippetLines:0 Name:ttusb_dec_send_command SourceTreePrefix:]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:fe_send_command SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1627] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_boot_dsp SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1357] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_boot_dsp SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1398] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_get_stb_state SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:392] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_set_interface SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:904] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_set_pids SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:451] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_start_sec_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1058] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_start_ts_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1024] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_stop_sec_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1138] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_stop_ts_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1117] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_init_rc SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1241]] TruncatedOutput:false]
|
| 106/4 |
2026/08/17 21:12 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 16468
output: 46
thoughts: 32
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Diving into the `ttusb-dec` Driver**
Alright, time to dig into the `ttusb-dec` driver, specifically that `fe_send_command` function within `ttusb_dec.c`. Let's see what we're working with here. I need to get a clear picture of how this specific function is handling the communication with the front-end. What are the key aspects of its operation? Are there any potential bottlenecks or areas where performance could be optimized? Are there any obvious areas for review that might need extra attention? Let's get to work.
|
| 107/4 |
2026/08/17 21:12 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusb_dec.c Name:fe_send_command]
Results: map[SourceCode:1622: static int fe_send_command(struct dvb_frontend* fe, const u8 command,
1623: int param_length, const u8 params[],
1624: int *result_length, u8 cmd_result[])
1625: {
1626: struct ttusb_dec* dec = fe->dvb->priv;
1627: return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
1628: }
SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
|
| 108/4 |
2026/08/17 21:12 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 16871
output: 59
thoughts: 15
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Investigating `fe_send_command` Usage**
Alright, let's dive in. I need to get a clear understanding of how the `fe_send_command` function is being utilized within this system. My immediate instinct is to identify all its call sites. I need to know the context of its calls, the arguments being passed, and the overall control flow surrounding each invocation. This will help me quickly grasp its purpose and potential impact, especially considering its potentially fundamental role, given the naming convention (assuming this is related to a frontend-backend interaction). I'll look for both direct calls and any indirect usage through function pointers or macro expansions. I'll need to consider how to navigate the codebase efficiently to find all instances. I'll have to consider all possible source files in order to do this correctly, whether it requires some clever regex or the appropriate tools.
|
| 109/4 |
2026/08/17 21:12 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusb_dec.c IncludeSnippetLines:0 Name:fe_send_command SourceTreePrefix:]
Results: map[References:[map[ReferenceKind:takes-address-of ReferencingEntityKind:global_variable ReferencingEntityName:fe_config SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1631]] TruncatedOutput:false]
|
| 110/4 |
2026/08/17 21:12 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 17228
output: 44
thoughts: 9
Thoughts: Okay, here's my attempt at summarizing that thought process, keeping in mind I'm speaking to a fellow expert and adopting a first-person perspective:
**Diving into the Configuration**
Alright, let's get down to brass tacks. Time to take a look at the `fe_config`. I need to understand the front-end configuration and how it's structured. We both know that's the bedrock of how everything renders, how the application behaves on the user's end, and quite often, where we find the roots of any behavioral eccentricities. This usually holds the keys to understanding how the application interacts with the user, handles data, and, well, everything. Gotta see how this thing is actually put together. I need to get familiar with every setting within this config file.
|
| 111/4 |
2026/08/17 21:12 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusb_dec.c Name:fe_config]
Results: map[SourceCode:1630: static const struct ttusbdecfe_config fe_config = {
1631: .send_command = fe_send_command
1632: };
SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
|
| 112/4 |
2026/08/17 21:12 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 17535
output: 47
thoughts: 15
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into the `ttusbdecfe_config` Struct**
Okay, let's get down to brass tacks. I need to take a look at the definition of the `ttusbdecfe_config` structure. I'm assuming it's the core configuration data structure for the TechniSat USB DVB demodulator front-end. I'm hoping it's well-documented and reasonably self-explanatory, but you know how these things can go... I need to understand exactly what parameters are configurable, what the data types are, and the ranges/semantics of each field. This struct likely encapsulates everything from the demodulator's carrier frequency and symbol rate to various FEC settings, modulation schemes, and maybe even some driver-specific tuning parameters. I need a clear picture of this structure to understand how to interact with and control the demodulator. The success of my work hinges on a complete understanding of this struct.
|
| 113/4 |
2026/08/17 21:13 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusb_dec.c Name:ttusbdecfe_config]
Results: map[SourceCode: 13: struct ttusbdecfe_config
14: {
15: int (*send_command)(struct dvb_frontend* fe, const u8 command,
16: int param_length, const u8 params[],
17: int *result_length, u8 cmd_result[]);
18: };
SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.h]
|
| 114/4 |
2026/08/17 21:13 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 17937
output: 174
thoughts: 22
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Adding `cmd_result_len` to `ttusbdecfe_config`**
Okay, I'm thinking I need to modify `ttusbdecfe_config`. Specifically, it needs a new member: `int cmd_result_len`. This is crucial because...well, I've got a situation where I'm dealing with command responses and the lengths of those responses are variable. Right now, I'm probably relying on a fixed-size buffer or some other clunky method. That's just asking for trouble with potential buffer overflows or inefficient memory allocation, depending on the implementation. Adding `cmd_result_len` allows the caller to determine and handle the length of the returned result directly and appropriately. Essentially, it centralizes and clarifies how command results' lengths are handled, making the interface more robust and maintainable. This also means I'll likely have to update all functions that interact with `ttusbdecfe_config` to correctly handle the new field. I'll need to double check any assumptions about command response size throughout the codebase. The implementation of that new field, how I use it, and how it is updated by different functions should be clear and consistent.
|
| 115/4 |
2026/08/17 21:13 |
tool |
codeeditor |
0m
Args: map[CurrentCode:struct ttusbdecfe_config
{
int (*send_command)(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[]);
}; NewCode:struct ttusbdecfe_config
{
int (*send_command)(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len);
}; SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.h]
Results:
|
| 116/4 |
2026/08/17 21:13 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 18407
output: 64
thoughts: 22
Thoughts: Here's my thought process, as if I were working on this task:
**Locating Callers of `send_command` in `ttusbdecfe.c`**
Okay, so I need to track down every instance where the `send_command` function is called within the `ttusbdecfe.c` file. This is a pretty straightforward task, and depending on the tools available, could be handled in a few different ways. I could use `grep` (or a similar command-line tool) with a pattern search, or if I'm using a decent IDE, it should have a built-in "find all references" or "find usages" feature that would be perfect for this. I'd definitely prefer the IDE approach if it's available; it's generally much faster and can handle more complex cases, such as identifying calls within macros or conditional blocks. If the IDE method is too cumbersome, or if I'm working with a less feature-rich environment, then `grep` would be my go-to. I would start by grepping the file for "send_command" and filter for the name by not picking up other uses of `send_command` such as its definition or comments. That will get me a list of lines with those calls, and from there I can examine them to get the necessary context for my task.
|
| 117/4 |
2026/08/17 21:13 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c IncludeSnippetLines:0 Name:ttusbdecfe_config::send_command SourceTreePrefix:]
Results: map[References:[map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:ttusbdecfe_dvbs_diseqc_send_master_cmd SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c SourceLine:150] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:ttusbdecfe_dvbs_set_frontend SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c SourceLine:133] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:ttusbdecfe_dvbt_read_status SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c SourceLine:47] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:ttusbdecfe_dvbt_set_frontend SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c SourceLine:88]] TruncatedOutput:false]
|
| 118/4 |
2026/08/17 21:13 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 19062
output: 57
thoughts: 23
Thoughts: Okay, here's my attempt at summarizing the thought process, as if it were my own, assuming I'm an expert in the field:
**Analyzing the `ttusbdecfe_dvbs_diseqc_send_master_cmd` Function**
Alright, let's dive into this `ttusbdecfe_dvbs_diseqc_send_master_cmd` function. My initial thought is to immediately consider the context; this is clearly related to DISEqC control, specifically within a DVB-S system, likely involving a Terratec USB DVB decoder front-end. Given that, I'm expecting to see the low-level interactions with the hardware: probably register manipulation, bit-banging, or interaction with some sort of hardware abstraction layer.
I'm mentally preparing for a fairly low-level view: the function likely deals with formatting the DISEqC command, possibly calculating checksums (though DISEqC checksums can sometimes be handled elsewhere), and then transmitting this command to the relevant hardware component. I’ll be looking for things like:
* **Data Structures:** What structures are used to represent the DISEqC command? Is it a simple array of bytes, or is there a more complex structure?
* **Hardware Interface:** How is this function communicating with the actual hardware? Is it through direct memory access, some kind of I2C interface, SPI, or a custom protocol? I'm anticipating some calls to functions related to hardware access.
* **Timing:** DISEqC has specific timing requirements. I'll be looking for any delays, timing loops, or related code that ensure the command is sent at the correct speed and with the necessary pauses.
* **Error Handling:** What kind of error checking is implemented? Does it check for transmission errors, timeouts, or hardware failures?
Basically, I'm looking at it to understand the flow of data and control, the low-level details of DISEqC command generation and transmission, and what kind of checks are incorporated to ensure it is handled correctly. Let's see how well it's implemented.
|
| 119/4 |
2026/08/17 21:13 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c Name:ttusbdecfe_dvbs_diseqc_send_master_cmd]
Results: map[SourceCode: 138: static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *cmd)
139: {
140: struct ttusbdecfe_state *state = fe->demodulator_priv;
141: u8 b[] = { 0x00, 0xff, 0x00, 0x00,
142: 0x00, 0x00, 0x00, 0x00,
143: 0x00, 0x00 };
144:
145: if (cmd->msg_len > sizeof(b) - 4)
146: return -EINVAL;
147:
148: memcpy(&b[4], cmd->msg, cmd->msg_len);
149:
150: state->config->send_command(fe, 0x72,
151: sizeof(b) - (6 - cmd->msg_len), b,
152: NULL, NULL);
153:
154: return 0;
155: }
SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c]
|
| 120/4 |
2026/08/17 21:13 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 19955
output: 133
thoughts: 38
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Subtle Improvement in Diseqc Command Sending**
Alright, looking at this `ttusbdecfe_dvbs_diseqc_send_master_cmd` function… the core logic seems sound, but I've spotted a minor, albeit potentially significant, area for improvement. Specifically, the call `NULL, NULL);` needs a second look.
While technically correct in many scenarios, the intended function call is meant to also accommodate a flag parameter. While currently unused, it's good practice to provide a default value for that optional parameter. Setting the third argument of `ttusbdecfe_dvbs_diseqc_send_master_cmd` as `NULL, NULL, 0);` provides some assurance against future regressions when it comes to the function call.
This change is small, but it highlights a commitment to robustness. It's a subtle tweak, but ensuring all parameters, even optional ones, are properly initialized or defaulted to a known good state often heads off headaches down the line, particularly when dealing with low-level hardware interactions like Diseqc commands. It's the kind of thing that makes debugging easier and code maintainability better over time.
|
| 121/4 |
2026/08/17 21:13 |
tool |
codeeditor |
0m
Args: map[CurrentCode: state->config->send_command(fe, 0x72,
sizeof(b) - (6 - cmd->msg_len), b,
NULL, NULL); NewCode: state->config->send_command(fe, 0x72,
sizeof(b) - (6 - cmd->msg_len), b,
NULL, NULL, 0); SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c]
Results:
|
| 122/4 |
2026/08/17 21:13 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 20396
output: 52
thoughts: 18
Thoughts: Okay, let's dive into this `ttusbdecfe_dvbs_set_frontend` function. I need to understand its role within the larger system. My initial thought is to figure out what it's responsible for; is it setting up the demodulator, configuring the tuner, or maybe handling both? The name suggests it's related to DVB-S, so I'll need to remember all the nuances of that modulation scheme. I need to quickly recall the typical parameters involved - symbol rate, FEC, polarization, frequency, and so on.
**Analyzing the Frontend Configuration Function**
From my understanding, I need to immediately consider how this function interacts with the hardware, probably through some low-level drivers or registers. I'm going to quickly look for any hints, like defined structures or enum types, that might suggest the way parameters are passed to the hardware. Hopefully, it's well-documented! I'm hoping it's also designed to handle error conditions gracefully; I don't want any silent failures that will be difficult to debug later. I will want to think through any possible sequences of register writes or commands. Any conditional logic should be of interest. Are there any dependencies? Does this function have an associated lock or critical section? I'll also check if there are any specific initialization routines that need to be called before this function can be used. Ultimately, I'll analyze how effectively this function handles any specific hardware quirks or errata. I need to see how robustly it sets up the frontend to receive a DVB-S signal. I'll need to know whether the function includes any logic for auto-detection or adaptation to different DVB-S configurations. And finally, I must be certain it is thread-safe.
|
| 123/4 |
2026/08/17 21:13 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c Name:ttusbdecfe_dvbs_set_frontend]
Results: map[SourceCode: 103: static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend *fe)
104: {
105: struct dtv_frontend_properties *p = &fe->dtv_property_cache;
106: struct ttusbdecfe_state *state = fe->demodulator_priv;
107:
108: u8 b[] = { 0x00, 0x00, 0x00, 0x01,
109: 0x00, 0x00, 0x00, 0x00,
110: 0x00, 0x00, 0x00, 0x01,
111: 0x00, 0x00, 0x00, 0x00,
112: 0x00, 0x00, 0x00, 0x00,
113: 0x00, 0x00, 0x00, 0x00,
114: 0x00, 0x00, 0x00, 0x00,
115: 0x00, 0x00, 0x00, 0x00,
116: 0x00, 0x00, 0x00, 0x00,
117: 0x00, 0x00, 0x00, 0x00 };
118: __be32 freq;
119: __be32 sym_rate;
120: __be32 band;
121: __be32 lnb_voltage;
122:
123: freq = htonl(p->frequency +
124: (state->hi_band ? LOF_HI : LOF_LO));
125: memcpy(&b[4], &freq, sizeof(u32));
126: sym_rate = htonl(p->symbol_rate);
127: memcpy(&b[12], &sym_rate, sizeof(u32));
128: band = htonl(state->hi_band ? LOF_HI : LOF_LO);
129: memcpy(&b[24], &band, sizeof(u32));
130: lnb_voltage = htonl(state->voltage);
131: memcpy(&b[28], &lnb_voltage, sizeof(u32));
132:
133: state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
134:
135: return 0;
136: }
SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c]
|
| 124/4 |
2026/08/17 21:13 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 21613
output: 101
thoughts: 33
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm the expert and considering the potential implications:
**Refactoring the DVB-S Frontend Initialization**
Right, looking at the `ttusbdecfe_dvbs_set_frontend` function... I need to update the call with a more modern approach. I'm seeing the current initialization of this function as `NULL, NULL);`. The concern is that `0` may be the missing third parameter. The current version may work, but to make this more robust and future-proof, I should change that to `NULL, NULL, 0);`. It's a subtle change, likely related to default values or initialization flags within the DVB-S frontend driver. Making this update will make this better and it is a good idea to perform this update.
|
| 125/4 |
2026/08/17 21:13 |
tool |
codeeditor |
0m
Error:
Args: map[CurrentCode: state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL); NewCode: state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0); SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c]
Results:
|
| 126/4 |
2026/08/17 21:13 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 21949
output: 181
thoughts: 7
Thoughts: Okay, I'm ready. Here's my attempt to summarize the prompt's instructions, adopting a first-person perspective, as if I'm processing them myself:
**Understanding the Task**
Alright, let's break this down. The core request is clear: I'm being asked to summarize a given text, but with a specific twist. The summary needs to represent my *internal thought process* in doing so. This isn't just a simple factual paraphrase; it's about capturing the mental steps, the analytical lens, as I engage with the provided text. I need to convey my interpretive journey, not just the destination.
The user is presumed to be an expert. This informs my approach; I won't need to over-explain basic concepts or definitions. I can assume a higher level of understanding and focus on the nuances, the inferred meanings, and the potentially subtle implications of my analysis. The aim is to create a response that is accurate but also insightful and sophisticated. My goal is to add value, and convey that value with the appropriate level of specificity for an expert.
|
| 127/4 |
2026/08/17 21:13 |
tool |
codeeditor |
0m
Args: map[CurrentCode: lnb_voltage = htonl(state->voltage);
memcpy(&b[28], &lnb_voltage, sizeof(u32));
state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
return 0; NewCode: lnb_voltage = htonl(state->voltage);
memcpy(&b[28], &lnb_voltage, sizeof(u32));
state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0; SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c]
Results:
|
| 128/4 |
2026/08/17 21:13 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 22372
output: 52
thoughts: 18
Thoughts: Okay, let's dive into this `ttusbdecfe_dvbt_read_status` function. I need to understand its role within the larger system. My initial thought is to figure out what it's responsible for; what status information is it reading? Is this related to signal strength, error rates, demodulator lock, or something else entirely? I should probably start by quickly glancing at its definition and any associated documentation, if there is any, to get a handle on its inputs, outputs, and any potential side effects. I'll need to consider the context of the calling function as well to see what's driving this status read. Why is this specific status needed at this point in the program? Finally, I need to know how it handles error conditions. Does it return error codes, throw exceptions, or simply set a global error flag? This is critical for robust error handling further up the line.
|
| 129/4 |
2026/08/17 21:13 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c Name:ttusbdecfe_dvbt_read_status]
Results: map[SourceCode: 36: static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
37: enum fe_status *status)
38: {
39: struct ttusbdecfe_state* state = fe->demodulator_priv;
40: u8 b[] = { 0x00, 0x00, 0x00, 0x00,
41: 0x00, 0x00, 0x00, 0x00 };
42: u8 result[4];
43: int len, ret;
44:
45: *status=0;
46:
47: ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
48: if(ret)
49: return ret;
50:
51: if(len != 4) {
52: printk(KERN_ERR "%s: unexpected reply\n", __func__);
53: return -EIO;
54: }
55:
56: switch(result[3]) {
57: case 1: /* not tuned yet */
58: case 2: /* no signal/no lock*/
59: break;
60: case 3: /* signal found and locked*/
61: *status = FE_HAS_SIGNAL | FE_HAS_VITERBI |
62: FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK;
63: break;
64: case 4:
65: *status = FE_TIMEDOUT;
66: break;
67: default:
68: pr_info("%s: returned unknown value: %d\n",
69: __func__, result[3]);
70: return -EIO;
71: }
72:
73: return 0;
74: }
SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c]
|
| 130/4 |
2026/08/17 21:13 |
llm |
patch-generator |
1m
Model:
Tokens:
input: 23220
output: 146
thoughts: 36
Thoughts: Okay, here's my take on those thoughts, framed as an expert in the field:
**Refactoring `ttusbdecfe_dvbt_read_status` for Enhanced Safety**
Alright, I'm looking at this `ttusbdecfe_dvbt_read_status` function, and something's just nagging at me. Specifically, that line: `&len, result);`. I'm immediately thinking, "That's asking for trouble down the line." We're passing the address of `len` and `result` which implies a read and write operation, but what's the buffer size for `result`? Without explicitly providing the size of `result` to the function, we're leaving ourselves open to potential buffer overflows or underruns.
In my experience, omitting that crucial piece of information, the size of `result` has lead to some nasty bugs in the past, hard to track down, and even harder to debug. And let's face it, these sorts of drivers are usually dealing with some pretty tight memory constraints anyway.
So, yeah, it's clear to me: I need to change that line to `&len, result, sizeof(result));`. Passing `sizeof(result)` guarantees that the function knows exactly how much data it can safely write into `result` and ensures that data integrity is maintained. It's a simple, proactive measure, but it's the kind of thing that prevents headaches and strengthens the overall robustness of the code. This will save me from having to revisit this function, or worse, have someone else find a bug from not following this practice.
|
| 131/4 |
2026/08/17 21:15 |
tool |
codeeditor |
0m
Args: map[CurrentCode: *status=0;
ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
if(ret)
return ret; NewCode: *status=0;
ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result,
sizeof(result));
if(ret)
return ret; SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c]
Results:
|
| 132/4 |
2026/08/17 21:15 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 23751
output: 52
thoughts: 18
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Analyzing `ttusbdecfe_dvbt_set_frontend`**
Okay, let's dive into this `ttusbdecfe_dvbt_set_frontend` function. My first instinct is to understand its role within the broader DVB-T demodulation flow. It's obviously responsible for configuring the frontend, but I need to quickly establish *what* specific parameters it's setting and how that impacts the overall signal acquisition and demodulation pipeline. Are we talking about tuning frequency, symbol rate, modulation scheme, guard interval, hierarchical modulation... the whole shebang? I need to quickly identify the input parameters and their data types; I need to know the structure it's using to store frontend configuration; a quick glance at the header should tell me.
Next, I need to understand the hardware interaction. Does this function directly interface with registers on the demodulator IC, or is there an abstraction layer or a more complex communication protocol involved? Is it using I2C, SPI, or some other interface? Are there any device-specific quirks I need to keep in mind? Are there any error handling mechanisms, particularly related to the write operations? I'd expect some level of validation on the input parameters to prevent out-of-bounds register writes or unsupported configurations. Are there any timeouts or retry mechanisms for potentially unreliable communication channels?
The return value will be important. I need to understand the error codes returned in case of a problem, and the general way the return codes are implemented in this driver. Are we talking about a simple integer error code, or a more sophisticated error structure that includes more detailed information? Any logging within the function would be helpful in diagnosing potential problems. I hope it’s reasonably well-commented; this is a core piece of the demodulator setup.
Finally, I'm going to have to consider potential side effects. Does this function potentially impact other related components or subsystems? Does it need to handle any interdependencies with other functions in the driver? Are there any resource locks or other considerations for concurrent access? This is going to be my thought process as I start digging into the details.
|
| 133/4 |
2026/08/17 21:15 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c Name:ttusbdecfe_dvbt_set_frontend]
Results: map[SourceCode: 76: static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend *fe)
77: {
78: struct dtv_frontend_properties *p = &fe->dtv_property_cache;
79: struct ttusbdecfe_state *state = fe->demodulator_priv;
80: u8 b[] = { 0x00, 0x00, 0x00, 0x03,
81: 0x00, 0x00, 0x00, 0x00,
82: 0x00, 0x00, 0x00, 0x01,
83: 0x00, 0x00, 0x00, 0xff,
84: 0x00, 0x00, 0x00, 0xff };
85:
86: __be32 freq = htonl(p->frequency / 1000);
87: memcpy(&b[4], &freq, sizeof (u32));
88: state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
89:
90: return 0;
91: }
SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c]
|
| 134/4 |
2026/08/17 21:15 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 24661
output: 187
thoughts: 33
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**Refactoring a DVB-T Frontend Initialization**
Right, let me see... I'm looking at the `ttusbdecfe_dvbt_set_frontend` function again. I recall we had a discussion a while back about potential ambiguity in how the frontend is initialized. Specifically, that line, the one with `NULL, NULL);`. My instinct is screaming that we should clarify that call. It's not *wrong* per se, but it lacks explicitness. We're relying on some default behavior, likely in the underlying DVB API, for a third argument. I bet it is related to an initial tuning or parameters, which are currently being defaulted to zero.
So, to enhance clarity and future-proof the code, I'm thinking I'll change that to `NULL, NULL, 0);`. Explicitly stating `0` as the third parameter immediately tells anyone reading the code that we are intentionally not providing any initial tuning/parameter information. This adds a layer of robustness. This change explicitly communicates the default behavior.
It won't likely change the runtime performance at all; I'm pretty sure that the underlying layers are already handling the default of zero if an optional argument is omitted. However, making this change is better for maintainability, and it documents the function call explicitly and more clearly.
|
| 135/4 |
2026/08/17 21:15 |
tool |
codeeditor |
0m
Args: map[CurrentCode: __be32 freq = htonl(p->frequency / 1000);
memcpy(&b[4], &freq, sizeof (u32));
state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
return 0; NewCode: __be32 freq = htonl(p->frequency / 1000);
memcpy(&b[4], &freq, sizeof (u32));
state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0; SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c]
Results:
|
| 136/4 |
2026/08/17 21:15 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 25191
output: 260
thoughts: 21
Thoughts: Here's my summary, as if I were thinking these thoughts:
**Updating `fe_send_command` in `ttusb_dec.c`**
Okay, time to get to the core of this. Let's dig into `fe_send_command` within the `ttusb_dec.c` file. I'm already visualizing the structure, the probable calls, and the dependencies. I need to make sure this update is seamless, non-disruptive, and, of course, absolutely correct given the downstream implications within the system. Let's see what needs to be changed and, most importantly, *why*. I'm anticipating potential issues with data flow, command serialization, or even interrupt handling, so a thorough review is a must. No shortcuts here. Let's get to work.
|
| 137/4 |
2026/08/17 21:15 |
tool |
codeeditor |
0m
Args: map[CurrentCode:static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[])
{
struct ttusb_dec* dec = fe->dvb->priv;
return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
} NewCode:static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len)
{
struct ttusb_dec* dec = fe->dvb->priv;
return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result, cmd_result_len);
} SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 138/4 |
2026/08/17 21:15 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 25651
output: 194
thoughts: 24
Thoughts: Okay, here's my take on those thoughts, framed from my perspective, assuming I'm a seasoned expert:
**Refactoring the `ttusb_dec_send_command` Function**
Alright, time to get my hands dirty. I'm going to revisit `ttusb_dec_send_command` in `ttusb_dec.c`. This function is likely the linchpin for how the driver communicates with the USB device, so it's critical to ensure its reliability and efficiency. I'll need to carefully consider any changes to avoid regressions, particularly in how it handles error conditions and command sequences. I’ll be thinking about:
* **Concurrency:** Are there any potential race conditions? Does it correctly handle multiple commands sent concurrently or in rapid succession?
* **Error Handling:** What's the current error reporting like? Does it provide enough diagnostic information for debugging? Does it handle device disconnects gracefully?
* **Command Structure:** Is the command packet structure optimal? Can it be streamlined or optimized for the specific hardware? Are there redundant fields or inefficient data types?
* **Performance:** Does this function introduce any significant latency? Can I improve its efficiency through better buffering, more efficient data transfers, or optimized loop constructs? I know this driver intimately, so I know I can identify the bottlenecks.
* **Clarity and Maintainability:** Can I refactor the code to improve its readability and make it easier to maintain in the future? Maybe some comments here and there would be useful.
* **Potential Side Effects:** It is critical to ensure that changing this function will not break other functions in the driver or related modules.
Essentially, I need to methodically dissect this function, consider its implications, and make well-informed decisions to improve its robustness and overall performance. No room for guesswork here; this requires a deep understanding of the hardware, the USB protocol, and the existing driver architecture. Let's make this rock-solid.
|
| 139/4 |
2026/08/17 21:15 |
tool |
codeeditor |
0m
Args: map[CurrentCode:static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[])
{
int result, actual_len;
u8 *b; NewCode:static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len)
{
int result, actual_len;
u8 *b; SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 140/4 |
2026/08/17 21:15 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 26288
output: 445
thoughts: 27
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Refactoring the `ttusb_dec_send_command` Function**
Alright, time to get my hands dirty and refactor `ttusb_dec_send_command` within `ttusb_dec.c`. We're talking about a core function here, likely a bottleneck or a critical point of failure in the entire USB-to-TTL decoding process. I need to be methodical. The goal isn't just to make it work, but to ensure it's robust, efficient, and easily maintainable going forward. Let's make sure it handles error checking properly. There's probably opportunity to improve this function.
|
| 141/4 |
2026/08/17 21:15 |
tool |
codeeditor |
0m
Args: map[CurrentCode: if (result) {
printk("%s: result bulk message failed: error %d\n",
__func__, result);
goto err_mutex_unlock;
} else {
if (debug) {
printk(KERN_DEBUG "%s: result: %*ph\n",
__func__, actual_len, b);
}
if (result_length)
*result_length = b[3];
if (cmd_result && b[3] > 0)
memcpy(cmd_result, &b[4], b[3]);
} NewCode: if (result) {
printk("%s: result bulk message failed: error %d\n",
__func__, result);
goto err_mutex_unlock;
} else {
if (debug) {
printk(KERN_DEBUG "%s: result: %*ph\n",
__func__, actual_len, b);
}
if (actual_len < 4) {
result = -EIO;
goto err_mutex_unlock;
}
if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
result = -EIO;
goto err_mutex_unlock;
}
if (result_length)
*result_length = b[3];
if (cmd_result && b[3] > 0) {
if (b[3] > cmd_result_len) {
result = -EIO;
goto err_mutex_unlock;
}
memcpy(cmd_result, &b[4], b[3]);
}
} SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 142/4 |
2026/08/17 21:15 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 26918
output: 62
thoughts: 28
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Refactoring Implications and Call Site Impact**
Alright, so I've just modified `ttusb_dec_send_command` in `ttusb_dec.c`. Now the real work begins. I can't just assume I'm the only one who uses this function; far from it. My immediate concern is updating *every single caller* of `ttusb_dec_send_command` throughout the codebase. I need to methodically identify each instance where this function is called, analyze the context of the call, and determine the necessary adjustments to maintain correct behavior, now that I've changed how `ttusb_dec_send_command` operates. This isn't just a search-and-replace; it's a careful analysis to ensure that the calling code still functions as intended and integrates properly with the broader system after my change.
|
| 143/4 |
2026/08/17 21:15 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusb_dec.c IncludeSnippetLines:2 Name:ttusb_dec_send_command SourceTreePrefix:]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:fe_send_command SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1627 SourceSnippet:1625: {
1626: struct ttusb_dec* dec = fe->dvb->priv;
1627: return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
1628: }
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_boot_dsp SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1357 SourceSnippet:1355: memcpy(&b0[6], &firmware_csum_ns, 2);
1356:
1357: result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL);
1358:
1359: if (result) {
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_boot_dsp SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1398 SourceSnippet:1396: }
1397:
1398: result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL);
1399:
1400: release_firmware(fw_entry);
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_get_stb_state SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:392 SourceSnippet: 390: dprintk("%s\n", __func__);
391:
392: result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
393: if (result)
394: return result;
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_set_interface SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:904 SourceSnippet: 902: break;
903: case TTUSB_DEC_INTERFACE_IN:
904: result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
905: b, NULL, NULL);
906: if (result)
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_set_pids SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:451 SourceSnippet: 449: memcpy(&b[4], &video, 2);
450:
451: ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL);
452:
453: dvb_filter_pes2ts_init(&dec->a_pes2ts, dec->pid[DMX_PES_AUDIO],
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_start_sec_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1058 SourceSnippet:1056: memcpy(&b0[5], &dvbdmxfeed->filter->filter.filter_value[0], 1);
1057:
1058: result = ttusb_dec_send_command(dec, 0x60, sizeof(b0), b0,
1059: &c_length, c);
1060:
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_start_ts_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1024 SourceSnippet:1022: }
1023:
1024: result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL);
1025: if (result)
1026: return result;
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_stop_sec_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1138 SourceSnippet:1136: spin_unlock_irqrestore(&dec->filter_info_list_lock, flags);
1137: kfree(finfo);
1138: ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL);
1139:
1140: dec->filter_stream_count--;
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_stop_ts_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1117 SourceSnippet:1115: u8 b0[] = { 0x00 };
1116:
1117: ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL);
1118:
1119: dec->pva_stream_count--;
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_init_rc SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1241 SourceSnippet:1239: printk("%s: usb_submit_urb failed\n",__func__);
1240: /* enable irq pipe */
1241: ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
1242:
1243: return 0;
]] TruncatedOutput:false]
|
| 144/4 |
2026/08/17 21:15 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 28933
output: 46
thoughts: 54
Thoughts: Okay, here's the summary of those thoughts, tailored for an expert audience, presented in the first person:
**Revisiting `fe_send_command`**
Alright, I need to revisit `fe_send_command` again. Damn it, I thought I'd caught everything, but I'm having a nagging feeling about `cmd_result_len` and its passing to `ttusb_dec_send_command`. Did I account for that correctly? Let me just double-check that `fe_send_command` one more time...I know I went back in there and made changes, but I need to make sure I caught that subtle nuance. I need to be absolutely certain that's correct, or this is going to bite me later.
|
| 145/4 |
2026/08/17 21:15 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusb_dec.c Name:fe_send_command]
Results: map[SourceCode:1622: static int fe_send_command(struct dvb_frontend* fe, const u8 command,
1623: int param_length, const u8 params[],
1624: int *result_length, u8 cmd_result[])
1625: {
1626: struct ttusb_dec* dec = fe->dvb->priv;
1627: return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
1628: }
SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
|
| 146/4 |
2026/08/17 21:15 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 29374
output: 260
thoughts: 28
Thoughts: Okay, here's my summary, in the first person, as requested:
**Resending the Command**
Right, that `fe_send_command` call didn't seem to go through as expected, or maybe the application wasn't ready for it. No problem; let's give it another shot. It's a common debugging step – assume failure and retry. Time to resend the command and confirm it's now applied. Hopefully the second time's the charm!
|
| 147/4 |
2026/08/17 21:15 |
tool |
codeeditor |
0m
Error:
Args: map[CurrentCode:static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[])
{
struct ttusb_dec* dec = fe->dvb->priv;
return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
} NewCode:static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len)
{
struct ttusb_dec* dec = fe->dvb->priv;
return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result, cmd_result_len);
} SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 148/4 |
2026/08/17 21:15 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 29796
output: 46
thoughts: 23
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into `fe_send_command` within `ttusb_dec.c`**
Alright, let's get down to brass tacks. I need to understand the intricacies of how commands are being dispatched from the higher-level framework down to the hardware within this `ttusb_dec.c` module. Specifically, I'm zeroing in on `fe_send_command`. I'm going to want to see how this function handles the raw command construction, how it interacts with the underlying USB transaction layers, and if there are any interesting optimizations or error-handling strategies employed. I'm hoping to get a clear picture of its role in the overall data flow and how it fits within the larger architecture. I'll be looking for potential bottlenecks, race conditions, or areas ripe for further performance tuning or debugging. Understanding the calling context is important, too. Where is this function being invoked from, and what kind of data structures are being passed to it? The devil is always in the details, so let's start digging.
|
| 149/4 |
2026/08/17 21:15 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusb_dec.c Name:fe_send_command]
Results: map[SourceCode:1622: static int fe_send_command(struct dvb_frontend* fe, const u8 command,
1623: int param_length, const u8 params[],
1624: int *result_length, u8 cmd_result[])
1625: {
1626: struct ttusb_dec* dec = fe->dvb->priv;
1627: return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
1628: }
SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
|
| 150/4 |
2026/08/17 21:15 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 30280
output: 260
thoughts: 31
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Code Synchronization Concerns**
Hold on a second... I *know* I just patched the `ttusb_dec_send_command` function not long ago, making sure its interactions were aligned. But did I also update the `fe_send_command` function? I need to be absolutely sure that they're both harmonized, given the likely dependencies. The last thing I need is a subtle divergence leading to flaky behavior down the line. To avoid any room for doubt, let's go straight to the code. No room for guesswork on this critical piece. I'll compare the revisions side-by-side to verify everything is in order.
|
| 151/4 |
2026/08/17 21:15 |
tool |
codeeditor |
0m
Error:
Args: map[CurrentCode:static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[])
{
struct ttusb_dec* dec = fe->dvb->priv;
return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
} NewCode:static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len)
{
struct ttusb_dec* dec = fe->dvb->priv;
return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result, cmd_result_len);
} SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 152/4 |
2026/08/17 21:15 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 30758
output: 46
thoughts: 14
Thoughts: Here's the summary, assuming I'm an expert reading the text:
**Focusing on a Specific File Section**
Okay, let's zero in on a particular part of the code, around line 1622 of the file. I need to understand the context, and what's happening at that line. Often, targeted analysis is more effective than broad sweeps, particularly when dealing with complex systems. Identifying this specific area allows me to quickly assess the immediate situation and how it relates to the bigger picture. From my expertise, a focused review will offer insights, saving valuable time.
|
| 153/4 |
2026/08/17 21:16 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusb_dec.c FirstLine:1620 LineCount:15]
Results: map[Contents:1620: }
1621:
1622: static int fe_send_command(struct dvb_frontend* fe, const u8 command,
1623: int param_length, const u8 params[],
1624: int *result_length, u8 cmd_result[])
1625: {
1626: struct ttusb_dec* dec = fe->dvb->priv;
1627: return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
1628: }
1629:
1630: static const struct ttusbdecfe_config fe_config = {
1631: .send_command = fe_send_command
1632: };
1633:
1634: static int ttusb_dec_probe(struct usb_interface *intf,
]
|
| 154/4 |
2026/08/17 21:16 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 31193
output: 260
thoughts: 35
Thoughts: Okay, here's my interpretation of those thoughts, framed as an expert's internal monologue:
**Investigating a Discrepancy in Command Handling**
Right, so I'm picking up on something here. I'm noticing a discrepancy in the command sending routines. `ttusb_dec_send_command` has been recently updated, presumably to address some issue or incorporate a new feature. But, the companion function, `fe_send_command`, appears to have been overlooked. This immediately raises a red flag. It's possible that the changes in `ttusb_dec_send_command` introduced an incompatibility, or perhaps a duplicated function, or maybe a missed opportunity. This could cause the system to behave erratically. My next step will be to examine the relationship between those two functions and determine what changes are needed to ensure consistency and prevent regressions. Let's dig in and see if this requires adjustment.
|
| 155/4 |
2026/08/17 21:16 |
tool |
codeeditor |
0m
Error:
Args: map[CurrentCode:static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[])
{
struct ttusb_dec* dec = fe->dvb->priv;
return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
} NewCode:static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len)
{
struct ttusb_dec* dec = fe->dvb->priv;
return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result, cmd_result_len);
} SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
|
| 156/4 |
2026/08/17 21:16 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 31814
output: 63
thoughts: 38
Thoughts: Okay, here's my interpretation of those thoughts, crafted with the expectation that I'm discussing this with a fellow expert:
**Debugging a Code Discrepancy**
Right, that "CurrentCode snippet does not match anything in the source file" error is seriously throwing me off. I was pretty sure the code was there, so now I'm thinking I must have missed something. I need to take another look at the callers of `ttusb_dec_send_command`. Clearly, something's not lining up, and I need to figure out how the code is *actually* being called in its current context. Maybe there's a version mismatch somewhere, or a preprocessor condition I'm overlooking that's excluding the relevant code path. Time to dive back in and trace those calls.
|
| 157/4 |
2026/08/17 21:16 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusb_dec.c IncludeSnippetLines:2 Name:ttusb_dec_send_command SourceTreePrefix:]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:fe_send_command SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1627 SourceSnippet:1625: {
1626: struct ttusb_dec* dec = fe->dvb->priv;
1627: return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
1628: }
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_boot_dsp SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1357 SourceSnippet:1355: memcpy(&b0[6], &firmware_csum_ns, 2);
1356:
1357: result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL);
1358:
1359: if (result) {
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_boot_dsp SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1398 SourceSnippet:1396: }
1397:
1398: result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL);
1399:
1400: release_firmware(fw_entry);
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_get_stb_state SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:392 SourceSnippet: 390: dprintk("%s\n", __func__);
391:
392: result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
393: if (result)
394: return result;
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_set_interface SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:904 SourceSnippet: 902: break;
903: case TTUSB_DEC_INTERFACE_IN:
904: result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
905: b, NULL, NULL);
906: if (result)
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_set_pids SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:451 SourceSnippet: 449: memcpy(&b[4], &video, 2);
450:
451: ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL);
452:
453: dvb_filter_pes2ts_init(&dec->a_pes2ts, dec->pid[DMX_PES_AUDIO],
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_start_sec_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1058 SourceSnippet:1056: memcpy(&b0[5], &dvbdmxfeed->filter->filter.filter_value[0], 1);
1057:
1058: result = ttusb_dec_send_command(dec, 0x60, sizeof(b0), b0,
1059: &c_length, c);
1060:
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_start_ts_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1024 SourceSnippet:1022: }
1023:
1024: result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL);
1025: if (result)
1026: return result;
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_stop_sec_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1138 SourceSnippet:1136: spin_unlock_irqrestore(&dec->filter_info_list_lock, flags);
1137: kfree(finfo);
1138: ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL);
1139:
1140: dec->filter_stream_count--;
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_dec_stop_ts_feed SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1117 SourceSnippet:1115: u8 b0[] = { 0x00 };
1116:
1117: ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL);
1118:
1119: dec->pva_stream_count--;
] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ttusb_init_rc SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1241 SourceSnippet:1239: printk("%s: usb_submit_urb failed\n",__func__);
1240: /* enable irq pipe */
1241: ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
1242:
1243: return 0;
]] TruncatedOutput:false]
|
| 158/4 |
2026/08/17 21:16 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 33811
output: 15
thoughts: 31
Thoughts: Okay, here's my interpretation of those thoughts, summarized from a first-person perspective, assuming I'm deeply familiar with code editors and patch diffing:
**Initial Success & Next Steps**
Right, that's encouraging. My initial attempt at using the `fe_send_command` function within the code editor seems to have worked without a hitch. Good! Now, the next logical step, given that the foundation is sound, is to rigorously test the `patch-diff` functionality. I need to confirm that the changes have been correctly applied and that the diff tool is behaving as expected, considering the successful command execution. This is the critical next point.
|
| 159/4 |
2026/08/17 21:16 |
tool |
patch-diff |
0m
Args:
Results: map[Output:diff --git a/drivers/media/usb/ttusb-dec/ttusb_dec.c b/drivers/media/usb/ttusb-dec/ttusb_dec.c
index 825a38759..200a57927 100644
--- a/drivers/media/usb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/usb/ttusb-dec/ttusb_dec.c
@@ -307,76 +307,92 @@ static u16 crc16(u16 crc, const u8 *buf, size_t len)
crc ^= *buf++;
crc ^= (u8)crc >> 4;
tmp = (u8)crc;
crc ^= (tmp ^ (tmp << 1)) << 4;
}
return crc;
}
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
int result, actual_len;
u8 *b;
dprintk("%s\n", __func__);
b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
if (!b)
return -ENOMEM;
result = mutex_lock_interruptible(&dec->usb_mutex);
if (result) {
printk("%s: Failed to lock usb mutex.\n", __func__);
goto err_free;
}
b[0] = 0xaa;
b[1] = ++dec->trans_count;
b[2] = command;
b[3] = param_length;
if (params)
memcpy(&b[4], params, param_length);
if (debug) {
printk(KERN_DEBUG "%s: command: %*ph\n",
__func__, param_length, b);
}
result = usb_bulk_msg(dec->udev, dec->command_pipe, b,
COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
if (result) {
printk("%s: command bulk message failed: error %d\n",
__func__, result);
goto err_mutex_unlock;
}
result = usb_bulk_msg(dec->udev, dec->result_pipe, b,
COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
if (result) {
printk("%s: result bulk message failed: error %d\n",
__func__, result);
goto err_mutex_unlock;
} else {
if (debug) {
printk(KERN_DEBUG "%s: result: %*ph\n",
__func__, actual_len, b);
}
+ if (actual_len < 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
+ if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
if (result_length)
*result_length = b[3];
- if (cmd_result && b[3] > 0)
+ if (cmd_result && b[3] > 0) {
+ if (b[3] > cmd_result_len) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
memcpy(cmd_result, &b[4], b[3]);
+ }
}
err_mutex_unlock:
mutex_unlock(&dec->usb_mutex);
err_free:
kfree(b);
return result;
}
static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
@@ -1614,24 +1630,25 @@ static void ttusb_dec_exit_filters(struct ttusb_dec *dec)
while ((item = dec->filter_info_list.next) != &dec->filter_info_list) {
finfo = list_entry(item, struct filter_info, filter_info_list);
list_del(&finfo->filter_info_list);
kfree(finfo);
}
}
static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
struct ttusb_dec* dec = fe->dvb->priv;
- return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
+ return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result, cmd_result_len);
}
static const struct ttusbdecfe_config fe_config = {
.send_command = fe_send_command
};
static int ttusb_dec_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
struct usb_device *udev;
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.c b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
index 215221370..0bd80ade4 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.c
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
@@ -36,39 +36,40 @@ static int ttusbdecfe_dvbs_read_status(struct dvb_frontend *fe,
static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
enum fe_status *status)
{
struct ttusbdecfe_state* state = fe->demodulator_priv;
u8 b[] = { 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
u8 result[4];
int len, ret;
*status=0;
- ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
+ ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result,
+ sizeof(result));
if(ret)
return ret;
if(len != 4) {
printk(KERN_ERR "%s: unexpected reply\n", __func__);
return -EIO;
}
switch(result[3]) {
case 1: /* not tuned yet */
case 2: /* no signal/no lock*/
break;
case 3: /* signal found and locked*/
*status = FE_HAS_SIGNAL | FE_HAS_VITERBI |
FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK;
break;
case 4:
*status = FE_TIMEDOUT;
break;
default:
pr_info("%s: returned unknown value: %d\n",
__func__, result[3]);
return -EIO;
}
return 0;
}
@@ -76,23 +77,23 @@ static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend *fe)
{
struct dtv_frontend_properties *p = &fe->dtv_property_cache;
struct ttusbdecfe_state *state = fe->demodulator_priv;
u8 b[] = { 0x00, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0xff,
0x00, 0x00, 0x00, 0xff };
__be32 freq = htonl(p->frequency / 1000);
memcpy(&b[4], &freq, sizeof (u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
static int ttusbdecfe_dvbt_get_tune_settings(struct dvb_frontend* fe,
struct dvb_frontend_tune_settings* fesettings)
{
fesettings->min_delay_ms = 1500;
/* Drift compensation makes no sense for DVB-T */
fesettings->step_size = 0;
@@ -103,60 +104,60 @@ static int ttusbdecfe_dvbt_get_tune_settings(struct dvb_frontend* fe,
static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend *fe)
{
struct dtv_frontend_properties *p = &fe->dtv_property_cache;
struct ttusbdecfe_state *state = fe->demodulator_priv;
u8 b[] = { 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
__be32 freq;
__be32 sym_rate;
__be32 band;
__be32 lnb_voltage;
freq = htonl(p->frequency +
(state->hi_band ? LOF_HI : LOF_LO));
memcpy(&b[4], &freq, sizeof(u32));
sym_rate = htonl(p->symbol_rate);
memcpy(&b[12], &sym_rate, sizeof(u32));
band = htonl(state->hi_band ? LOF_HI : LOF_LO);
memcpy(&b[24], &band, sizeof(u32));
lnb_voltage = htonl(state->voltage);
memcpy(&b[28], &lnb_voltage, sizeof(u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *cmd)
{
struct ttusbdecfe_state *state = fe->demodulator_priv;
u8 b[] = { 0x00, 0xff, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00 };
if (cmd->msg_len > sizeof(b) - 4)
return -EINVAL;
memcpy(&b[4], cmd->msg, cmd->msg_len);
state->config->send_command(fe, 0x72,
sizeof(b) - (6 - cmd->msg_len), b,
- NULL, NULL);
+ NULL, NULL, 0);
return 0;
}
static int ttusbdecfe_dvbs_set_tone(struct dvb_frontend *fe,
enum fe_sec_tone_mode tone)
{
struct ttusbdecfe_state *state = fe->demodulator_priv;
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.h b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
index 73828bb22..96600ad4c 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.h
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
@@ -7,18 +7,19 @@
#ifndef TTUSBDECFE_H
#define TTUSBDECFE_H
#include <linux/dvb/frontend.h>
struct ttusbdecfe_config
{
int (*send_command)(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[]);
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len);
};
extern struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config);
extern struct dvb_frontend* ttusbdecfe_dvbt_attach(const struct ttusbdecfe_config* config);
#endif // TTUSBDECFE_H
]
|
| 160/4 |
2026/08/17 21:16 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 37851
output: 111
thoughts: 38
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Refactoring Reminder: Don't Forget the Callers!**
Okay, I've got this `ttusb_dec.c` change nailed down, but wait a second... there's that `ttusb_dec_send_command` function. I'm modifying its internals, meaning I absolutely *must* track down *every single* place that calls it. This isn't just a minor tweak; a change here ripples outward. I need to ensure the calling contexts are updated to reflect whatever interface modifications I'm introducing. Right, let's get those cross-references sorted immediately. Time to update those callers and ensure everything still functions as expected. No assumptions, full code review, make sure everything still passes the tests. Gotta be thorough.
|
| 161/4 |
2026/08/17 21:16 |
tool |
codeeditor |
0m
Args: map[CurrentCode: result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL); NewCode: result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL, 0); SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 162/4 |
2026/08/17 21:16 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 38184
output: 111
thoughts: 3
Thoughts: Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and delivered in the first person:
**Next Caller - Immediate Assessment & Tactical Considerations**
Alright, new caller, let's see what we've got. The immediate focus is on rapid assessment. My brain is already running through a mental checklist: what's the typical range of issues in this queue? What are the key indicators I'll be listening for in the initial greeting and problem description? I'm anticipating the potential areas they might be struggling in, based on the historical data of the type of customers I usually get. My mind will be ready to quickly assess the caller's level of technical understanding, their emotional state, and the potential severity of the issue. Pre-programmed in my mind are the troubleshooting steps that I can use to narrow the field. From there I'll have the tactical considerations: how to explain this in the clearest terms for the caller? What’s the most efficient path to resolution, balancing speed with thoroughness to prevent repeat calls? My experience will tell me whether this call will need to escalate to a specialist, or whether I can quickly resolve this call.
|
| 163/4 |
2026/08/17 21:16 |
tool |
codeeditor |
0m
Args: map[CurrentCode: result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL); NewCode: result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL, 0); SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 164/4 |
2026/08/17 21:16 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 38550
output: 114
thoughts: 3
Thoughts: Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and delivered in the first person:
**Next Caller - Immediate Assessment & Tactical Considerations**
Alright, new caller, let's see what we've got. The immediate focus is on rapid assessment. My brain is already running through a mental checklist: what's the typical range of issues in this queue? What are the key indicators I'll be listening for in the initial greeting and problem description? I'm anticipating the potential areas they might be struggling in, based on the historical data of the type of customers I usually get. My mind will be ready to quickly assess the caller's level of technical understanding, their emotional state, and the potential severity of the issue. Pre-programmed in my mind are the troubleshooting steps that I can use to narrow the field. From there I'll have the tactical considerations: how to explain this in the clearest terms for the caller? What’s the most efficient path to resolution, balancing speed with thoroughness to prevent repeat calls? My experience will tell me whether this call will need to escalate to a specialist, or whether I can quickly resolve this call.
|
| 165/4 |
2026/08/17 21:16 |
tool |
codeeditor |
0m
Args: map[CurrentCode: result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c); NewCode: result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c,
sizeof(c)); SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 166/4 |
2026/08/17 21:16 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 38919
output: 135
thoughts: 3
Thoughts: Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and delivered in the first person:
**Next Caller - Immediate Assessment & Tactical Considerations**
Alright, new caller, let's see what we've got. The immediate focus is on rapid assessment. My brain is already running through a mental checklist: what's the typical range of issues in this queue? What are the key indicators I'll be listening for in the initial greeting and problem description? I'm anticipating the potential areas they might be struggling in, based on the historical data of the type of customers I usually get. My mind will be ready to quickly assess the caller's level of technical understanding, their emotional state, and the potential severity of the issue. Pre-programmed in my mind are the troubleshooting steps that I can use to narrow the field. From there I'll have the tactical considerations: how to explain this in the clearest terms for the caller? What’s the most efficient path to resolution, balancing speed with thoroughness to prevent repeat calls? My experience will tell me whether this call will need to escalate to a specialist, or whether I can quickly resolve this call.
|
| 167/4 |
2026/08/17 21:16 |
tool |
codeeditor |
0m
Args: map[CurrentCode: case TTUSB_DEC_INTERFACE_IN:
result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
b, NULL, NULL); NewCode: case TTUSB_DEC_INTERFACE_IN:
result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
b, NULL, NULL, 0); SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 168/4 |
2026/08/17 21:16 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 39309
output: 103
thoughts: 3
Thoughts: Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and delivered in the first person:
**Next Caller - Immediate Assessment & Tactical Considerations**
Alright, new caller, let's see what we've got. The immediate focus is on rapid assessment. My brain is already running through a mental checklist: what's the typical range of issues in this queue? What are the key indicators I'll be listening for in the initial greeting and problem description? I'm anticipating the potential areas they might be struggling in, based on the historical data of the type of customers I usually get. My mind will be ready to quickly assess the caller's level of technical understanding, their emotional state, and the potential severity of the issue. Pre-programmed in my mind are the troubleshooting steps that I can use to narrow the field. From there I'll have the tactical considerations: how to explain this in the clearest terms for the caller? What’s the most efficient path to resolution, balancing speed with thoroughness to prevent repeat calls? My experience will tell me whether this call will need to escalate to a specialist, or whether I can quickly resolve this call.
|
| 169/4 |
2026/08/17 21:16 |
tool |
codeeditor |
0m
Args: map[CurrentCode: ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL); NewCode: ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL, 0); SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 170/4 |
2026/08/17 21:16 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 39667
output: 122
thoughts: 3
Thoughts: Okay, I'm ready. Let's get this done.
***
**Processing the Next Inquiry**
Alright, new caller coming up. Time to switch gears, assess the situation, and be ready to provide a solid, informed response. I need to be quick, efficient, and address their specific needs. No room for hesitation, I need to listen carefully to the caller's concerns and be prepared to use the right technical jargon to communicate my point effectively. Let's get down to business.
|
| 171/4 |
2026/08/17 21:16 |
tool |
codeeditor |
0m
Args: map[CurrentCode: result = ttusb_dec_send_command(dec, 0x60, sizeof(b0), b0,
&c_length, c); NewCode: result = ttusb_dec_send_command(dec, 0x60, sizeof(b0), b0,
&c_length, c, sizeof(c)); SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 172/4 |
2026/08/17 21:16 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 39904
output: 111
thoughts: 3
Thoughts: Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and delivered in the first person:
**Next Caller - Immediate Assessment & Tactical Considerations**
Alright, new caller, let's see what we've got. The immediate focus is on rapid assessment. My brain is already running through a mental checklist: what's the typical range of issues in this queue? What are the key indicators I'll be listening for in the initial greeting and problem description? I'm anticipating the potential areas they might be struggling in, based on the historical data of the type of customers I usually get. My mind will be ready to quickly assess the caller's level of technical understanding, their emotional state, and the potential severity of the issue. Pre-programmed in my mind are the troubleshooting steps that I can use to narrow the field. From there I'll have the tactical considerations: how to explain this in the clearest terms for the caller? What’s the most efficient path to resolution, balancing speed with thoroughness to prevent repeat calls? My experience will tell me whether this call will need to escalate to a specialist, or whether I can quickly resolve this call.
|
| 173/4 |
2026/08/17 21:16 |
tool |
codeeditor |
0m
Args: map[CurrentCode: result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL); NewCode: result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL, 0); SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 174/4 |
2026/08/17 21:16 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 40270
output: 107
thoughts: 3
Thoughts: Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and delivered in the first person:
**Next Caller - Immediate Assessment & Tactical Considerations**
Alright, new caller, let's see what we've got. The immediate focus is on rapid assessment. My brain is already running through a mental checklist: what's the typical range of issues in this queue? What are the key indicators I'll be listening for in the initial greeting and problem description? I'm anticipating the potential areas they might be struggling in, based on the historical data of the type of customers I usually get. My mind will be ready to quickly assess the caller's level of technical understanding, their emotional state, and the potential severity of the issue. Pre-programmed in my mind are the troubleshooting steps that I can use to narrow the field. From there I'll have the tactical considerations: how to explain this in the clearest terms for the caller? What’s the most efficient path to resolution, balancing speed with thoroughness to prevent repeat calls? My experience will tell me whether this call will need to escalate to a specialist, or whether I can quickly resolve this call.
|
| 175/4 |
2026/08/17 21:17 |
tool |
codeeditor |
0m
Args: map[CurrentCode: ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL); NewCode: ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL, 0); SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 176/4 |
2026/08/17 21:17 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 40632
output: 107
thoughts: 3
Thoughts: Okay, I'm ready. Let's get this done.
***
**Processing the Next Inquiry**
Alright, new caller coming up. Time to switch gears, assess the situation, and be ready to provide a solid, informed response. I need to be quick, efficient, and address their specific needs. No room for hesitation, I need to listen carefully to the caller's concerns and be prepared to use the right technical jargon to communicate my point effectively. Let's get down to business.
|
| 177/4 |
2026/08/17 21:17 |
tool |
codeeditor |
0m
Args: map[CurrentCode: ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL); NewCode: ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL, 0); SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 178/4 |
2026/08/17 21:17 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 40854
output: 98
thoughts: 3
Thoughts: Okay, I'm ready. Let's get this done.
***
**Processing the Next Inquiry**
Alright, new caller coming up. Time to switch gears, assess the situation, and be ready to provide a solid, informed response. I need to be quick, efficient, and address their specific needs. No room for hesitation, I need to listen carefully to the caller's concerns and be prepared to use the right technical jargon to communicate my point effectively. Let's get down to business.
|
| 179/4 |
2026/08/17 21:17 |
tool |
codeeditor |
0m
Args: map[CurrentCode: ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL); NewCode: ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL,0); SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 180/4 |
2026/08/17 21:17 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 41067
output: 15
thoughts: 11
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Revisiting the Diff**
Alright, time to circle back and give that `patch-diff` another look. There's a nagging feeling that something might be missed, some subtle interaction I'd like to confirm, or perhaps a potential edge case that wasn't immediately apparent. I need to make sure I've accounted for all the nuances, especially given the complexity of the current codebase. Always wise to double-check these things, particularly with changes this intricate. Let's see if a fresh set of eyes reveals anything new. It’s better to be thorough now than to chase down a silent bug later.
|
| 181/4 |
2026/08/17 21:17 |
tool |
patch-diff |
0m
Args:
Results: map[Output:diff --git a/drivers/media/usb/ttusb-dec/ttusb_dec.c b/drivers/media/usb/ttusb-dec/ttusb_dec.c
index 825a38759..4aa26e08d 100644
--- a/drivers/media/usb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/usb/ttusb-dec/ttusb_dec.c
@@ -307,107 +307,124 @@ static u16 crc16(u16 crc, const u8 *buf, size_t len)
crc ^= *buf++;
crc ^= (u8)crc >> 4;
tmp = (u8)crc;
crc ^= (tmp ^ (tmp << 1)) << 4;
}
return crc;
}
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
int result, actual_len;
u8 *b;
dprintk("%s\n", __func__);
b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
if (!b)
return -ENOMEM;
result = mutex_lock_interruptible(&dec->usb_mutex);
if (result) {
printk("%s: Failed to lock usb mutex.\n", __func__);
goto err_free;
}
b[0] = 0xaa;
b[1] = ++dec->trans_count;
b[2] = command;
b[3] = param_length;
if (params)
memcpy(&b[4], params, param_length);
if (debug) {
printk(KERN_DEBUG "%s: command: %*ph\n",
__func__, param_length, b);
}
result = usb_bulk_msg(dec->udev, dec->command_pipe, b,
COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
if (result) {
printk("%s: command bulk message failed: error %d\n",
__func__, result);
goto err_mutex_unlock;
}
result = usb_bulk_msg(dec->udev, dec->result_pipe, b,
COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
if (result) {
printk("%s: result bulk message failed: error %d\n",
__func__, result);
goto err_mutex_unlock;
} else {
if (debug) {
printk(KERN_DEBUG "%s: result: %*ph\n",
__func__, actual_len, b);
}
+ if (actual_len < 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
+ if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
if (result_length)
*result_length = b[3];
- if (cmd_result && b[3] > 0)
+ if (cmd_result && b[3] > 0) {
+ if (b[3] > cmd_result_len) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
memcpy(cmd_result, &b[4], b[3]);
+ }
}
err_mutex_unlock:
mutex_unlock(&dec->usb_mutex);
err_free:
kfree(b);
return result;
}
static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
unsigned int *model, unsigned int *version)
{
u8 c[COMMAND_PACKET_SIZE];
int c_length;
int result;
__be32 tmp;
dprintk("%s\n", __func__);
- result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
+ result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c,
+ sizeof(c));
if (result)
return result;
if (c_length >= 0x0c) {
if (mode != NULL) {
memcpy(&tmp, c, 4);
*mode = ntohl(tmp);
}
if (model != NULL) {
memcpy(&tmp, &c[4], 4);
*model = ntohl(tmp);
}
if (version != NULL) {
memcpy(&tmp, &c[8], 4);
*version = ntohl(tmp);
}
return 0;
} else {
return -ENOENT;
}
}
@@ -435,27 +452,27 @@ static int ttusb_dec_video_pes2ts_cb(void *priv, unsigned char *data)
static void ttusb_dec_set_pids(struct ttusb_dec *dec)
{
u8 b[] = { 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff };
__be16 pcr = htons(dec->pid[DMX_PES_PCR]);
__be16 audio = htons(dec->pid[DMX_PES_AUDIO]);
__be16 video = htons(dec->pid[DMX_PES_VIDEO]);
dprintk("%s\n", __func__);
memcpy(&b[0], &pcr, 2);
memcpy(&b[2], &audio, 2);
memcpy(&b[4], &video, 2);
- ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL, 0);
dvb_filter_pes2ts_init(&dec->a_pes2ts, dec->pid[DMX_PES_AUDIO],
ttusb_dec_audio_pes2ts_cb, dec);
dvb_filter_pes2ts_init(&dec->v_pes2ts, dec->pid[DMX_PES_VIDEO],
ttusb_dec_video_pes2ts_cb, dec);
dec->v_pes_length = 0;
dec->v_pes_postbytes = 0;
}
static void ttusb_dec_process_pva(struct ttusb_dec *dec, u8 *pva, int length)
@@ -888,35 +905,35 @@ static void ttusb_dec_stop_iso_xfer(struct ttusb_dec *dec)
/* Setting the interface of the DEC tends to take down the USB communications
* for a short period, so it's important not to call this function just before
* trying to talk to it.
*/
static int ttusb_dec_set_interface(struct ttusb_dec *dec,
enum ttusb_dec_interface interface)
{
int result = 0;
u8 b[] = { 0x05 };
if (interface != dec->interface) {
switch (interface) {
case TTUSB_DEC_INTERFACE_INITIAL:
result = usb_set_interface(dec->udev, 0, 0);
break;
- case TTUSB_DEC_INTERFACE_IN:
- result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
- b, NULL, NULL);
+ case TTUSB_DEC_INTERFACE_IN:
+ result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
+ b, NULL, NULL, 0);
if (result)
return result;
result = usb_set_interface(dec->udev, 0, 8);
break;
case TTUSB_DEC_INTERFACE_OUT:
result = usb_set_interface(dec->udev, 0, 1);
break;
}
if (result)
return result;
dec->interface = interface;
}
return 0;
}
@@ -964,121 +981,121 @@ static int ttusb_dec_start_iso_xfer(struct ttusb_dec *dec)
static int ttusb_dec_start_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
{
struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
struct ttusb_dec *dec = dvbdmx->priv;
u8 b0[] = { 0x05 };
int result = 0;
dprintk("%s\n", __func__);
dprintk(" ts_type:");
if (dvbdmxfeed->ts_type & TS_DECODER)
dprintk(" TS_DECODER");
if (dvbdmxfeed->ts_type & TS_PACKET)
dprintk(" TS_PACKET");
if (dvbdmxfeed->ts_type & TS_PAYLOAD_ONLY)
dprintk(" TS_PAYLOAD_ONLY");
dprintk("\n");
switch (dvbdmxfeed->pes_type) {
case DMX_PES_VIDEO:
dprintk(" pes_type: DMX_PES_VIDEO\n");
dec->pid[DMX_PES_PCR] = dvbdmxfeed->pid;
dec->pid[DMX_PES_VIDEO] = dvbdmxfeed->pid;
dec->video_filter = dvbdmxfeed->filter;
ttusb_dec_set_pids(dec);
break;
case DMX_PES_AUDIO:
dprintk(" pes_type: DMX_PES_AUDIO\n");
dec->pid[DMX_PES_AUDIO] = dvbdmxfeed->pid;
dec->audio_filter = dvbdmxfeed->filter;
ttusb_dec_set_pids(dec);
break;
case DMX_PES_TELETEXT:
dec->pid[DMX_PES_TELETEXT] = dvbdmxfeed->pid;
dprintk(" pes_type: DMX_PES_TELETEXT(not supported)\n");
return -ENOSYS;
case DMX_PES_PCR:
dprintk(" pes_type: DMX_PES_PCR\n");
dec->pid[DMX_PES_PCR] = dvbdmxfeed->pid;
ttusb_dec_set_pids(dec);
break;
case DMX_PES_OTHER:
dprintk(" pes_type: DMX_PES_OTHER(not supported)\n");
return -ENOSYS;
default:
dprintk(" pes_type: unknown (%d)\n", dvbdmxfeed->pes_type);
return -EINVAL;
}
- result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL, 0);
if (result)
return result;
dec->pva_stream_count++;
return ttusb_dec_start_iso_xfer(dec);
}
static int ttusb_dec_start_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
{
struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
u8 b0[] = { 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0xff, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00 };
__be16 pid;
u8 c[COMMAND_PACKET_SIZE];
int c_length;
int result;
struct filter_info *finfo;
unsigned long flags;
u8 x = 1;
dprintk("%s\n", __func__);
pid = htons(dvbdmxfeed->pid);
memcpy(&b0[0], &pid, 2);
memcpy(&b0[4], &x, 1);
memcpy(&b0[5], &dvbdmxfeed->filter->filter.filter_value[0], 1);
result = ttusb_dec_send_command(dec, 0x60, sizeof(b0), b0,
- &c_length, c);
+ &c_length, c, sizeof(c));
if (!result) {
if (c_length == 2) {
if (!(finfo = kmalloc_obj(struct filter_info, GFP_ATOMIC)))
return -ENOMEM;
finfo->stream_id = c[1];
finfo->filter = dvbdmxfeed->filter;
spin_lock_irqsave(&dec->filter_info_list_lock, flags);
list_add_tail(&finfo->filter_info_list,
&dec->filter_info_list);
spin_unlock_irqrestore(&dec->filter_info_list_lock,
flags);
dvbdmxfeed->priv = finfo;
dec->filter_stream_count++;
return ttusb_dec_start_iso_xfer(dec);
}
return -EAGAIN;
} else
return result;
}
@@ -1107,42 +1124,42 @@ static int ttusb_dec_start_feed(struct dvb_demux_feed *dvbdmxfeed)
return -EINVAL;
}
}
static int ttusb_dec_stop_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
{
struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
u8 b0[] = { 0x00 };
- ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL, 0);
dec->pva_stream_count--;
ttusb_dec_stop_iso_xfer(dec);
return 0;
}
static int ttusb_dec_stop_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
{
struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
u8 b0[] = { 0x00, 0x00 };
struct filter_info *finfo = dvbdmxfeed->priv;
unsigned long flags;
b0[1] = finfo->stream_id;
spin_lock_irqsave(&dec->filter_info_list_lock, flags);
list_del(&finfo->filter_info_list);
spin_unlock_irqrestore(&dec->filter_info_list_lock, flags);
kfree(finfo);
- ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL, 0);
dec->filter_stream_count--;
ttusb_dec_stop_iso_xfer(dec);
return 0;
}
static int ttusb_dec_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
{
@@ -1207,45 +1224,45 @@ static void ttusb_dec_init_bh_work(struct ttusb_dec *dec)
static int ttusb_init_rc( struct ttusb_dec *dec)
{
struct input_dev *input_dev;
u8 b[] = { 0x00, 0x01 };
int i;
int err;
usb_make_path(dec->udev, dec->rc_phys, sizeof(dec->rc_phys));
strlcat(dec->rc_phys, "/input0", sizeof(dec->rc_phys));
input_dev = input_allocate_device();
if (!input_dev)
return -ENOMEM;
input_dev->name = "ttusb_dec remote control";
input_dev->phys = dec->rc_phys;
input_dev->evbit[0] = BIT_MASK(EV_KEY);
input_dev->keycodesize = sizeof(u16);
input_dev->keycodemax = 0x1a;
input_dev->keycode = rc_keys;
for (i = 0; i < ARRAY_SIZE(rc_keys); i++)
set_bit(rc_keys[i], input_dev->keybit);
err = input_register_device(input_dev);
if (err) {
input_free_device(input_dev);
return err;
}
dec->rc_input_dev = input_dev;
if (usb_submit_urb(dec->irq_urb, GFP_KERNEL))
printk("%s: usb_submit_urb failed\n",__func__);
/* enable irq pipe */
- ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
+ ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL,0);
return 0;
}
static void ttusb_dec_init_v_pes(struct ttusb_dec *dec)
{
dprintk("%s\n", __func__);
dec->v_pes[0] = 0x00;
dec->v_pes[1] = 0x00;
@@ -1298,111 +1315,111 @@ static int ttusb_dec_init_usb(struct ttusb_dec *dec)
static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
{
int i, j, actual_len, result, size, trans_count;
u8 b0[] = { 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x61, 0x00 };
u8 b1[] = { 0x61 };
u8 *b;
char idstring[21];
const u8 *firmware = NULL;
size_t firmware_size = 0;
u16 firmware_csum = 0;
__be16 firmware_csum_ns;
__be32 firmware_size_nl;
u32 crc32_csum, crc32_check;
__be32 tmp;
const struct firmware *fw_entry = NULL;
dprintk("%s\n", __func__);
result = request_firmware(&fw_entry, dec->firmware_name, &dec->udev->dev);
if (result) {
printk(KERN_ERR "%s: Firmware (%s) unavailable.\n",
__func__, dec->firmware_name);
return result;
}
firmware = fw_entry->data;
firmware_size = fw_entry->size;
if (firmware_size < 60) {
printk("%s: firmware size too small for DSP code (%zu < 60).\n",
__func__, firmware_size);
release_firmware(fw_entry);
return -ENOENT;
}
/* a 32 bit checksum over the first 56 bytes of the DSP Code is stored
at offset 56 of file, so use it to check if the firmware file is
valid. */
crc32_csum = crc32(~0L, firmware, 56) ^ ~0L;
memcpy(&tmp, &firmware[56], 4);
crc32_check = ntohl(tmp);
if (crc32_csum != crc32_check) {
printk("%s: crc32 check of DSP code failed (calculated 0x%08x != 0x%08x in file), file invalid.\n",
__func__, crc32_csum, crc32_check);
release_firmware(fw_entry);
return -ENOENT;
}
memcpy(idstring, &firmware[36], 20);
idstring[20] = '\0';
printk(KERN_INFO "ttusb_dec: found DSP code \"%s\".\n", idstring);
firmware_size_nl = htonl(firmware_size);
memcpy(b0, &firmware_size_nl, 4);
firmware_csum = crc16(~0, firmware, firmware_size) ^ ~0;
firmware_csum_ns = htons(firmware_csum);
memcpy(&b0[6], &firmware_csum_ns, 2);
- result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL, 0);
if (result) {
release_firmware(fw_entry);
return result;
}
trans_count = 0;
j = 0;
b = kmalloc(ARM_PACKET_SIZE, GFP_KERNEL);
if (b == NULL) {
release_firmware(fw_entry);
return -ENOMEM;
}
for (i = 0; i < firmware_size; i += COMMAND_PACKET_SIZE) {
size = firmware_size - i;
if (size > COMMAND_PACKET_SIZE)
size = COMMAND_PACKET_SIZE;
b[j + 0] = 0xaa;
b[j + 1] = trans_count++;
b[j + 2] = 0xf0;
b[j + 3] = size;
memcpy(&b[j + 4], &firmware[i], size);
j += COMMAND_PACKET_SIZE + 4;
if (j >= ARM_PACKET_SIZE) {
result = usb_bulk_msg(dec->udev, dec->command_pipe, b,
ARM_PACKET_SIZE, &actual_len,
100);
j = 0;
} else if (size < COMMAND_PACKET_SIZE) {
result = usb_bulk_msg(dec->udev, dec->command_pipe, b,
j - COMMAND_PACKET_SIZE + size,
&actual_len, 100);
}
}
- result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL, 0);
release_firmware(fw_entry);
kfree(b);
return result;
}
static int ttusb_dec_init_stb(struct ttusb_dec *dec)
{
int result;
@@ -1614,24 +1631,25 @@ static void ttusb_dec_exit_filters(struct ttusb_dec *dec)
while ((item = dec->filter_info_list.next) != &dec->filter_info_list) {
finfo = list_entry(item, struct filter_info, filter_info_list);
list_del(&finfo->filter_info_list);
kfree(finfo);
}
}
static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
struct ttusb_dec* dec = fe->dvb->priv;
- return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
+ return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result, cmd_result_len);
}
static const struct ttusbdecfe_config fe_config = {
.send_command = fe_send_command
};
static int ttusb_dec_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
struct usb_device *udev;
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.c b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
index 215221370..0bd80ade4 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.c
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
@@ -36,39 +36,40 @@ static int ttusbdecfe_dvbs_read_status(struct dvb_frontend *fe,
static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
enum fe_status *status)
{
struct ttusbdecfe_state* state = fe->demodulator_priv;
u8 b[] = { 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
u8 result[4];
int len, ret;
*status=0;
- ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
+ ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result,
+ sizeof(result));
if(ret)
return ret;
if(len != 4) {
printk(KERN_ERR "%s: unexpected reply\n", __func__);
return -EIO;
}
switch(result[3]) {
case 1: /* not tuned yet */
case 2: /* no signal/no lock*/
break;
case 3: /* signal found and locked*/
*status = FE_HAS_SIGNAL | FE_HAS_VITERBI |
FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK;
break;
case 4:
*status = FE_TIMEDOUT;
break;
default:
pr_info("%s: returned unknown value: %d\n",
__func__, result[3]);
return -EIO;
}
return 0;
}
@@ -76,23 +77,23 @@ static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend *fe)
{
struct dtv_frontend_properties *p = &fe->dtv_property_cache;
struct ttusbdecfe_state *state = fe->demodulator_priv;
u8 b[] = { 0x00, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0xff,
0x00, 0x00, 0x00, 0xff };
__be32 freq = htonl(p->frequency / 1000);
memcpy(&b[4], &freq, sizeof (u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
static int ttusbdecfe_dvbt_get_tune_settings(struct dvb_frontend* fe,
struct dvb_frontend_tune_settings* fesettings)
{
fesettings->min_delay_ms = 1500;
/* Drift compensation makes no sense for DVB-T */
fesettings->step_size = 0;
@@ -103,60 +104,60 @@ static int ttusbdecfe_dvbt_get_tune_settings(struct dvb_frontend* fe,
static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend *fe)
{
struct dtv_frontend_properties *p = &fe->dtv_property_cache;
struct ttusbdecfe_state *state = fe->demodulator_priv;
u8 b[] = { 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
__be32 freq;
__be32 sym_rate;
__be32 band;
__be32 lnb_voltage;
freq = htonl(p->frequency +
(state->hi_band ? LOF_HI : LOF_LO));
memcpy(&b[4], &freq, sizeof(u32));
sym_rate = htonl(p->symbol_rate);
memcpy(&b[12], &sym_rate, sizeof(u32));
band = htonl(state->hi_band ? LOF_HI : LOF_LO);
memcpy(&b[24], &band, sizeof(u32));
lnb_voltage = htonl(state->voltage);
memcpy(&b[28], &lnb_voltage, sizeof(u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *cmd)
{
struct ttusbdecfe_state *state = fe->demodulator_priv;
u8 b[] = { 0x00, 0xff, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00 };
if (cmd->msg_len > sizeof(b) - 4)
return -EINVAL;
memcpy(&b[4], cmd->msg, cmd->msg_len);
state->config->send_command(fe, 0x72,
sizeof(b) - (6 - cmd->msg_len), b,
- NULL, NULL);
+ NULL, NULL, 0);
return 0;
}
static int ttusbdecfe_dvbs_set_tone(struct dvb_frontend *fe,
enum fe_sec_tone_mode tone)
{
struct ttusbdecfe_state *state = fe->demodulator_priv;
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.h b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
index 73828bb22..96600ad4c 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.h
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
@@ -7,18 +7,19 @@
#ifndef TTUSBDECFE_H
#define TTUSBDECFE_H
#include <linux/dvb/frontend.h>
struct ttusbdecfe_config
{
int (*send_command)(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[]);
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len);
};
extern struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config);
extern struct dvb_frontend* ttusbdecfe_dvbt_attach(const struct ttusbdecfe_config* config);
#endif // TTUSBDECFE_H
]
|
| 182/4 |
2026/08/17 21:17 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 50592
output: 64
thoughts: 849
Thoughts: **My Analysis of the `ttusb_dec_send_command` Patch**
Okay, so I've just updated `ttusb_dec_send_command` and its callers to handle the `cmd_result_len` correctly, ensuring we have bounds checks against both `actual_len` and the caller's buffer. I thought I'd better give the logic in `ttusb_dec_send_command` another look.
The code itself seems sound on the surface. We have these checks within the function:
```c
if (actual_len < 4) {
result = -EIO;
goto err_mutex_unlock;
}
if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
result = -EIO;
goto err_mutex_unlock;
}
if (result_length)
*result_length = b[3];
if (cmd_result && b[3] > 0) {
if (b[3] > cmd_result_len) {
result = -EIO;
goto err_mutex_unlock;
}
memcpy(cmd_result, &b[4], b[3]);
}
```
`b[3]` represents the length of the data we're going to read into `cmd_result`. It's an 8-bit unsigned value, meaning it can be from 0 to 255. `COMMAND_PACKET_SIZE` is defined as 60 (0x3c). `actual_len` is the received length.
The checks are as expected:
1. We ensure we received at least 4 bytes.
2. `b[3]` must be less than or equal to both `COMMAND_PACKET_SIZE` (the maximum payload size for a command) and `actual_len - 4` (the remaining length of the received data after the 4-byte header).
3. We check for buffer overflows when copying the data to `cmd_result`.
I did a quick mental check to make sure that the `actual_len - 4` subtraction wouldn't cause an underflow in the case of `b[3]` being a large value and `actual_len` being a small value. We know that the code already checks to ensure that `actual_len` is always >= 4, which means there is no underflow condition.
I need to make sure I've covered all the bases. I've used `codesearch-find-references` to identify all the callers of `ttusb_dec_send_command`. I found 11 direct calls:
1. `fe_send_command`
2. `ttusb_dec_boot_dsp` (2 calls)
3. `ttusb_dec_get_stb_state`
4. `ttusb_dec_set_interface`
5. `ttusb_dec_set_pids`
6. `ttusb_dec_start_sec_feed`
7. `ttusb_dec_start_ts_feed`
8. `ttusb_dec_stop_sec_feed`
9. `ttusb_dec_stop_ts_feed`
10. `ttusb_init_rc`
And looking at the callers within `ttusbdecfe.c`, I see these calls to `send_command`:
1. `ttusbdecfe_dvbt_read_status`
2. `ttusbdecfe_dvbt_set_frontend`
3. `ttusbdecfe_dvbs_set_frontend`
4. `ttusbdecfe_dvbs_diseqc_send_master_cmd`
I'm confident I've caught all the places this change could affect. I think this patch is now ready to go.
|
| 183/4 |
2026/08/17 21:17 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c IncludeSnippetLines:0 Name:ttusbdecfe_config::send_command SourceTreePrefix:]
Results: map[References:[map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:ttusbdecfe_dvbs_diseqc_send_master_cmd SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c SourceLine:150] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:ttusbdecfe_dvbs_set_frontend SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c SourceLine:133] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:ttusbdecfe_dvbt_read_status SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c SourceLine:47] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:ttusbdecfe_dvbt_set_frontend SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c SourceLine:88]] TruncatedOutput:false]
|
| 184/4 |
2026/08/17 21:17 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 52664
output: 60
thoughts: 27
Thoughts: Here's my take on the thought process:
**Internal Audit - Low Caller Count**
Okay, four callers. That's a surprisingly low number for a function like `ttusbdecfe_config`. I would expect this to be used in more places, especially given its name. It's time to dig deeper. I need to make sure I haven't missed something crucial here. Let's start with a thorough check to confirm that no other implementations of `ttusbdecfe_config` exist within this code base, or any related modules. We can't afford to miss even a single instance.
|
| 185/4 |
2026/08/17 21:17 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c IncludeSnippetLines:0 Name:ttusbdecfe_config SourceTreePrefix:]
Results: map[References:[map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:ttusbdecfe_dvbs_attach SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c SourceLine:216] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:ttusbdecfe_dvbt_attach SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c SourceLine:196] map[ReferenceKind:uses ReferencingEntityKind:global_variable ReferencingEntityName:fe_config SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c SourceLine:1630]] TruncatedOutput:false]
|
| 186/4 |
2026/08/17 21:17 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 53086
output: 292
thoughts: 897
Thoughts: **Analyzing Potential Buffer Overflows in `ttusb_dec_send_command`**
Okay, so I'm focusing on the `ttusb_dec.c` file, specifically the `ttusb_dec_send_command` function. My initial thought is to review the changes made to that function, particularly how the `b` buffer is handled. I need to make sure that the length checks are sufficient to prevent any potential buffer overflows.
I've got the code in front of me:
```c
if (actual_len < 4) {
result = -EIO;
goto err_mutex_unlock;
}
if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
result = -EIO;
goto err_mutex_unlock;
}
if (result_length)
*result_length = b[3];
if (cmd_result && b[3] > 0) {
if (b[3] > cmd_result_len) {
result = -EIO;
goto err_mutex_unlock;
}
memcpy(cmd_result, &b[4], b[3]);
}
```
I'm looking for where `b` is accessed beyond those checks, and I see where it's initialized:
```c
b[0] = 0xaa;
b[1] = ++dec->trans_count;
b[2] = command;
b[3] = param_length;
if (params)
memcpy(&b[4], params, param_length);
```
Ah, right. The potentially problematic part is that `memcpy(&b[4], params, param_length)`. `param_length` is a variable that determines how much data is copied into the `b` buffer. The `b` buffer is allocated as `COMMAND_PACKET_SIZE + 4` (that's 64 bytes). If `param_length` is greater than 60, I'd have a buffer overflow. But, is `param_length` checked elsewhere?
The `param_length` variable is also passed to `ttusb_dec_send_command`. So, I need to trace back to where this `param_length` is set to check what the maximum value is. I need to find the callers of `ttusb_dec_send_command`.
Looking at the code, these functions call `ttusb_dec_send_command`, along with the size of the buffer:
1. `fe_send_command`: `param_length` comes from `ttusbdecfe.c`.
* `ttusbdecfe_dvbt_read_status`: `sizeof(b)` which is 8.
* `ttusbdecfe_dvbt_set_frontend`: `sizeof(b)` which is 20.
* `ttusbdecfe_dvbs_set_frontend`: `sizeof(b)` which is 40.
* `ttusbdecfe_dvbs_diseqc_send_master_cmd`: `sizeof(b) - (6 - cmd->msg_len)`. `sizeof(b)` is 10. `cmd->msg_len` is checked against `sizeof(b) - 4` (which is 6). So `param_length` is at most 10.
2. `ttusb_dec_boot_dsp`: `sizeof(b0)` (10) and `sizeof(b1)` (1).
3. `ttusb_dec_get_stb_state`: 0.
4. `ttusb_dec_set_interface`: `sizeof(b)` (1).
5. `ttusb_dec_set_pids`: `sizeof(b)` (12).
6. `ttusb_dec_start_sec_feed`: `sizeof(b0)` (29).
7. `ttusb_dec_start_ts_feed`: `sizeof(b0)` (1).
8. `ttusb_dec_stop_sec_feed`: `sizeof(b0)` (2).
9. `ttusb_dec_stop_ts_feed`: `sizeof(b0)` (1).
10. `ttusb_init_rc`: `sizeof(b)` (2).
Okay, after examining all the callers, the maximum value that `param_length` can take is 40 which is far less than 6
|
| 187/4 |
2026/08/17 21:17 |
tool |
codeeditor |
0m
Args: map[CurrentCode:static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len)
{
int result, actual_len;
u8 *b;
dprintk("%s\n", __func__);
b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL); NewCode:static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len)
{
int result, actual_len;
u8 *b;
dprintk("%s\n", __func__);
if (param_length > COMMAND_PACKET_SIZE)
return -EINVAL;
b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL); SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 188/4 |
2026/08/17 21:17 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 55307
output: 15
thoughts: 11
Thoughts: Okay, here's my attempt at summarizing that thought process, keeping in mind I'm speaking to a fellow expert and adopting a first-person perspective:
**Checking That Diff Again...**
Alright, time to revisit that `patch-diff`. I remember going over it, but there's a nagging feeling, a little doubt whispering in the back of my mind. It's that subtle sense you get when you've reviewed something, but you haven't quite *felt* it sink in completely. I need to make absolutely sure everything there aligns with my understanding and the overall architecture we're working with. This project's intricacies demand that level of rigor. Let's make sure there aren't any potential edge cases that I missed on the first pass. No point in pushing something upstream without having absolute confidence. Deep breath, and let's dive back in.
|
| 189/4 |
2026/08/17 21:17 |
tool |
patch-diff |
0m
Args:
Results: map[Output:diff --git a/drivers/media/usb/ttusb-dec/ttusb_dec.c b/drivers/media/usb/ttusb-dec/ttusb_dec.c
index 825a38759..a8e7b5b28 100644
--- a/drivers/media/usb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/usb/ttusb-dec/ttusb_dec.c
@@ -307,107 +307,127 @@ static u16 crc16(u16 crc, const u8 *buf, size_t len)
crc ^= *buf++;
crc ^= (u8)crc >> 4;
tmp = (u8)crc;
crc ^= (tmp ^ (tmp << 1)) << 4;
}
return crc;
}
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
int result, actual_len;
u8 *b;
dprintk("%s\n", __func__);
+ if (param_length > COMMAND_PACKET_SIZE)
+ return -EINVAL;
+
b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
if (!b)
return -ENOMEM;
result = mutex_lock_interruptible(&dec->usb_mutex);
if (result) {
printk("%s: Failed to lock usb mutex.\n", __func__);
goto err_free;
}
b[0] = 0xaa;
b[1] = ++dec->trans_count;
b[2] = command;
b[3] = param_length;
if (params)
memcpy(&b[4], params, param_length);
if (debug) {
printk(KERN_DEBUG "%s: command: %*ph\n",
__func__, param_length, b);
}
result = usb_bulk_msg(dec->udev, dec->command_pipe, b,
COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
if (result) {
printk("%s: command bulk message failed: error %d\n",
__func__, result);
goto err_mutex_unlock;
}
result = usb_bulk_msg(dec->udev, dec->result_pipe, b,
COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
if (result) {
printk("%s: result bulk message failed: error %d\n",
__func__, result);
goto err_mutex_unlock;
} else {
if (debug) {
printk(KERN_DEBUG "%s: result: %*ph\n",
__func__, actual_len, b);
}
+ if (actual_len < 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
+ if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
if (result_length)
*result_length = b[3];
- if (cmd_result && b[3] > 0)
+ if (cmd_result && b[3] > 0) {
+ if (b[3] > cmd_result_len) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
memcpy(cmd_result, &b[4], b[3]);
+ }
}
err_mutex_unlock:
mutex_unlock(&dec->usb_mutex);
err_free:
kfree(b);
return result;
}
static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
unsigned int *model, unsigned int *version)
{
u8 c[COMMAND_PACKET_SIZE];
int c_length;
int result;
__be32 tmp;
dprintk("%s\n", __func__);
- result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
+ result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c,
+ sizeof(c));
if (result)
return result;
if (c_length >= 0x0c) {
if (mode != NULL) {
memcpy(&tmp, c, 4);
*mode = ntohl(tmp);
}
if (model != NULL) {
memcpy(&tmp, &c[4], 4);
*model = ntohl(tmp);
}
if (version != NULL) {
memcpy(&tmp, &c[8], 4);
*version = ntohl(tmp);
}
return 0;
} else {
return -ENOENT;
}
}
@@ -435,27 +455,27 @@ static int ttusb_dec_video_pes2ts_cb(void *priv, unsigned char *data)
static void ttusb_dec_set_pids(struct ttusb_dec *dec)
{
u8 b[] = { 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff };
__be16 pcr = htons(dec->pid[DMX_PES_PCR]);
__be16 audio = htons(dec->pid[DMX_PES_AUDIO]);
__be16 video = htons(dec->pid[DMX_PES_VIDEO]);
dprintk("%s\n", __func__);
memcpy(&b[0], &pcr, 2);
memcpy(&b[2], &audio, 2);
memcpy(&b[4], &video, 2);
- ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL, 0);
dvb_filter_pes2ts_init(&dec->a_pes2ts, dec->pid[DMX_PES_AUDIO],
ttusb_dec_audio_pes2ts_cb, dec);
dvb_filter_pes2ts_init(&dec->v_pes2ts, dec->pid[DMX_PES_VIDEO],
ttusb_dec_video_pes2ts_cb, dec);
dec->v_pes_length = 0;
dec->v_pes_postbytes = 0;
}
static void ttusb_dec_process_pva(struct ttusb_dec *dec, u8 *pva, int length)
@@ -888,35 +908,35 @@ static void ttusb_dec_stop_iso_xfer(struct ttusb_dec *dec)
/* Setting the interface of the DEC tends to take down the USB communications
* for a short period, so it's important not to call this function just before
* trying to talk to it.
*/
static int ttusb_dec_set_interface(struct ttusb_dec *dec,
enum ttusb_dec_interface interface)
{
int result = 0;
u8 b[] = { 0x05 };
if (interface != dec->interface) {
switch (interface) {
case TTUSB_DEC_INTERFACE_INITIAL:
result = usb_set_interface(dec->udev, 0, 0);
break;
- case TTUSB_DEC_INTERFACE_IN:
- result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
- b, NULL, NULL);
+ case TTUSB_DEC_INTERFACE_IN:
+ result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
+ b, NULL, NULL, 0);
if (result)
return result;
result = usb_set_interface(dec->udev, 0, 8);
break;
case TTUSB_DEC_INTERFACE_OUT:
result = usb_set_interface(dec->udev, 0, 1);
break;
}
if (result)
return result;
dec->interface = interface;
}
return 0;
}
@@ -964,121 +984,121 @@ static int ttusb_dec_start_iso_xfer(struct ttusb_dec *dec)
static int ttusb_dec_start_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
{
struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
struct ttusb_dec *dec = dvbdmx->priv;
u8 b0[] = { 0x05 };
int result = 0;
dprintk("%s\n", __func__);
dprintk(" ts_type:");
if (dvbdmxfeed->ts_type & TS_DECODER)
dprintk(" TS_DECODER");
if (dvbdmxfeed->ts_type & TS_PACKET)
dprintk(" TS_PACKET");
if (dvbdmxfeed->ts_type & TS_PAYLOAD_ONLY)
dprintk(" TS_PAYLOAD_ONLY");
dprintk("\n");
switch (dvbdmxfeed->pes_type) {
case DMX_PES_VIDEO:
dprintk(" pes_type: DMX_PES_VIDEO\n");
dec->pid[DMX_PES_PCR] = dvbdmxfeed->pid;
dec->pid[DMX_PES_VIDEO] = dvbdmxfeed->pid;
dec->video_filter = dvbdmxfeed->filter;
ttusb_dec_set_pids(dec);
break;
case DMX_PES_AUDIO:
dprintk(" pes_type: DMX_PES_AUDIO\n");
dec->pid[DMX_PES_AUDIO] = dvbdmxfeed->pid;
dec->audio_filter = dvbdmxfeed->filter;
ttusb_dec_set_pids(dec);
break;
case DMX_PES_TELETEXT:
dec->pid[DMX_PES_TELETEXT] = dvbdmxfeed->pid;
dprintk(" pes_type: DMX_PES_TELETEXT(not supported)\n");
return -ENOSYS;
case DMX_PES_PCR:
dprintk(" pes_type: DMX_PES_PCR\n");
dec->pid[DMX_PES_PCR] = dvbdmxfeed->pid;
ttusb_dec_set_pids(dec);
break;
case DMX_PES_OTHER:
dprintk(" pes_type: DMX_PES_OTHER(not supported)\n");
return -ENOSYS;
default:
dprintk(" pes_type: unknown (%d)\n", dvbdmxfeed->pes_type);
return -EINVAL;
}
- result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL, 0);
if (result)
return result;
dec->pva_stream_count++;
return ttusb_dec_start_iso_xfer(dec);
}
static int ttusb_dec_start_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
{
struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
u8 b0[] = { 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0xff, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00 };
__be16 pid;
u8 c[COMMAND_PACKET_SIZE];
int c_length;
int result;
struct filter_info *finfo;
unsigned long flags;
u8 x = 1;
dprintk("%s\n", __func__);
pid = htons(dvbdmxfeed->pid);
memcpy(&b0[0], &pid, 2);
memcpy(&b0[4], &x, 1);
memcpy(&b0[5], &dvbdmxfeed->filter->filter.filter_value[0], 1);
result = ttusb_dec_send_command(dec, 0x60, sizeof(b0), b0,
- &c_length, c);
+ &c_length, c, sizeof(c));
if (!result) {
if (c_length == 2) {
if (!(finfo = kmalloc_obj(struct filter_info, GFP_ATOMIC)))
return -ENOMEM;
finfo->stream_id = c[1];
finfo->filter = dvbdmxfeed->filter;
spin_lock_irqsave(&dec->filter_info_list_lock, flags);
list_add_tail(&finfo->filter_info_list,
&dec->filter_info_list);
spin_unlock_irqrestore(&dec->filter_info_list_lock,
flags);
dvbdmxfeed->priv = finfo;
dec->filter_stream_count++;
return ttusb_dec_start_iso_xfer(dec);
}
return -EAGAIN;
} else
return result;
}
@@ -1107,42 +1127,42 @@ static int ttusb_dec_start_feed(struct dvb_demux_feed *dvbdmxfeed)
return -EINVAL;
}
}
static int ttusb_dec_stop_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
{
struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
u8 b0[] = { 0x00 };
- ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL, 0);
dec->pva_stream_count--;
ttusb_dec_stop_iso_xfer(dec);
return 0;
}
static int ttusb_dec_stop_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
{
struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
u8 b0[] = { 0x00, 0x00 };
struct filter_info *finfo = dvbdmxfeed->priv;
unsigned long flags;
b0[1] = finfo->stream_id;
spin_lock_irqsave(&dec->filter_info_list_lock, flags);
list_del(&finfo->filter_info_list);
spin_unlock_irqrestore(&dec->filter_info_list_lock, flags);
kfree(finfo);
- ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL, 0);
dec->filter_stream_count--;
ttusb_dec_stop_iso_xfer(dec);
return 0;
}
static int ttusb_dec_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
{
@@ -1207,45 +1227,45 @@ static void ttusb_dec_init_bh_work(struct ttusb_dec *dec)
static int ttusb_init_rc( struct ttusb_dec *dec)
{
struct input_dev *input_dev;
u8 b[] = { 0x00, 0x01 };
int i;
int err;
usb_make_path(dec->udev, dec->rc_phys, sizeof(dec->rc_phys));
strlcat(dec->rc_phys, "/input0", sizeof(dec->rc_phys));
input_dev = input_allocate_device();
if (!input_dev)
return -ENOMEM;
input_dev->name = "ttusb_dec remote control";
input_dev->phys = dec->rc_phys;
input_dev->evbit[0] = BIT_MASK(EV_KEY);
input_dev->keycodesize = sizeof(u16);
input_dev->keycodemax = 0x1a;
input_dev->keycode = rc_keys;
for (i = 0; i < ARRAY_SIZE(rc_keys); i++)
set_bit(rc_keys[i], input_dev->keybit);
err = input_register_device(input_dev);
if (err) {
input_free_device(input_dev);
return err;
}
dec->rc_input_dev = input_dev;
if (usb_submit_urb(dec->irq_urb, GFP_KERNEL))
printk("%s: usb_submit_urb failed\n",__func__);
/* enable irq pipe */
- ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
+ ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL,0);
return 0;
}
static void ttusb_dec_init_v_pes(struct ttusb_dec *dec)
{
dprintk("%s\n", __func__);
dec->v_pes[0] = 0x00;
dec->v_pes[1] = 0x00;
@@ -1298,111 +1318,111 @@ static int ttusb_dec_init_usb(struct ttusb_dec *dec)
static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
{
int i, j, actual_len, result, size, trans_count;
u8 b0[] = { 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x61, 0x00 };
u8 b1[] = { 0x61 };
u8 *b;
char idstring[21];
const u8 *firmware = NULL;
size_t firmware_size = 0;
u16 firmware_csum = 0;
__be16 firmware_csum_ns;
__be32 firmware_size_nl;
u32 crc32_csum, crc32_check;
__be32 tmp;
const struct firmware *fw_entry = NULL;
dprintk("%s\n", __func__);
result = request_firmware(&fw_entry, dec->firmware_name, &dec->udev->dev);
if (result) {
printk(KERN_ERR "%s: Firmware (%s) unavailable.\n",
__func__, dec->firmware_name);
return result;
}
firmware = fw_entry->data;
firmware_size = fw_entry->size;
if (firmware_size < 60) {
printk("%s: firmware size too small for DSP code (%zu < 60).\n",
__func__, firmware_size);
release_firmware(fw_entry);
return -ENOENT;
}
/* a 32 bit checksum over the first 56 bytes of the DSP Code is stored
at offset 56 of file, so use it to check if the firmware file is
valid. */
crc32_csum = crc32(~0L, firmware, 56) ^ ~0L;
memcpy(&tmp, &firmware[56], 4);
crc32_check = ntohl(tmp);
if (crc32_csum != crc32_check) {
printk("%s: crc32 check of DSP code failed (calculated 0x%08x != 0x%08x in file), file invalid.\n",
__func__, crc32_csum, crc32_check);
release_firmware(fw_entry);
return -ENOENT;
}
memcpy(idstring, &firmware[36], 20);
idstring[20] = '\0';
printk(KERN_INFO "ttusb_dec: found DSP code \"%s\".\n", idstring);
firmware_size_nl = htonl(firmware_size);
memcpy(b0, &firmware_size_nl, 4);
firmware_csum = crc16(~0, firmware, firmware_size) ^ ~0;
firmware_csum_ns = htons(firmware_csum);
memcpy(&b0[6], &firmware_csum_ns, 2);
- result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL, 0);
if (result) {
release_firmware(fw_entry);
return result;
}
trans_count = 0;
j = 0;
b = kmalloc(ARM_PACKET_SIZE, GFP_KERNEL);
if (b == NULL) {
release_firmware(fw_entry);
return -ENOMEM;
}
for (i = 0; i < firmware_size; i += COMMAND_PACKET_SIZE) {
size = firmware_size - i;
if (size > COMMAND_PACKET_SIZE)
size = COMMAND_PACKET_SIZE;
b[j + 0] = 0xaa;
b[j + 1] = trans_count++;
b[j + 2] = 0xf0;
b[j + 3] = size;
memcpy(&b[j + 4], &firmware[i], size);
j += COMMAND_PACKET_SIZE + 4;
if (j >= ARM_PACKET_SIZE) {
result = usb_bulk_msg(dec->udev, dec->command_pipe, b,
ARM_PACKET_SIZE, &actual_len,
100);
j = 0;
} else if (size < COMMAND_PACKET_SIZE) {
result = usb_bulk_msg(dec->udev, dec->command_pipe, b,
j - COMMAND_PACKET_SIZE + size,
&actual_len, 100);
}
}
- result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL, 0);
release_firmware(fw_entry);
kfree(b);
return result;
}
static int ttusb_dec_init_stb(struct ttusb_dec *dec)
{
int result;
@@ -1614,24 +1634,25 @@ static void ttusb_dec_exit_filters(struct ttusb_dec *dec)
while ((item = dec->filter_info_list.next) != &dec->filter_info_list) {
finfo = list_entry(item, struct filter_info, filter_info_list);
list_del(&finfo->filter_info_list);
kfree(finfo);
}
}
static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
struct ttusb_dec* dec = fe->dvb->priv;
- return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
+ return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result, cmd_result_len);
}
static const struct ttusbdecfe_config fe_config = {
.send_command = fe_send_command
};
static int ttusb_dec_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
struct usb_device *udev;
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.c b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
index 215221370..0bd80ade4 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.c
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
@@ -36,39 +36,40 @@ static int ttusbdecfe_dvbs_read_status(struct dvb_frontend *fe,
static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
enum fe_status *status)
{
struct ttusbdecfe_state* state = fe->demodulator_priv;
u8 b[] = { 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
u8 result[4];
int len, ret;
*status=0;
- ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
+ ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result,
+ sizeof(result));
if(ret)
return ret;
if(len != 4) {
printk(KERN_ERR "%s: unexpected reply\n", __func__);
return -EIO;
}
switch(result[3]) {
case 1: /* not tuned yet */
case 2: /* no signal/no lock*/
break;
case 3: /* signal found and locked*/
*status = FE_HAS_SIGNAL | FE_HAS_VITERBI |
FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK;
break;
case 4:
*status = FE_TIMEDOUT;
break;
default:
pr_info("%s: returned unknown value: %d\n",
__func__, result[3]);
return -EIO;
}
return 0;
}
@@ -76,23 +77,23 @@ static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend *fe)
{
struct dtv_frontend_properties *p = &fe->dtv_property_cache;
struct ttusbdecfe_state *state = fe->demodulator_priv;
u8 b[] = { 0x00, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0xff,
0x00, 0x00, 0x00, 0xff };
__be32 freq = htonl(p->frequency / 1000);
memcpy(&b[4], &freq, sizeof (u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
static int ttusbdecfe_dvbt_get_tune_settings(struct dvb_frontend* fe,
struct dvb_frontend_tune_settings* fesettings)
{
fesettings->min_delay_ms = 1500;
/* Drift compensation makes no sense for DVB-T */
fesettings->step_size = 0;
@@ -103,60 +104,60 @@ static int ttusbdecfe_dvbt_get_tune_settings(struct dvb_frontend* fe,
static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend *fe)
{
struct dtv_frontend_properties *p = &fe->dtv_property_cache;
struct ttusbdecfe_state *state = fe->demodulator_priv;
u8 b[] = { 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
__be32 freq;
__be32 sym_rate;
__be32 band;
__be32 lnb_voltage;
freq = htonl(p->frequency +
(state->hi_band ? LOF_HI : LOF_LO));
memcpy(&b[4], &freq, sizeof(u32));
sym_rate = htonl(p->symbol_rate);
memcpy(&b[12], &sym_rate, sizeof(u32));
band = htonl(state->hi_band ? LOF_HI : LOF_LO);
memcpy(&b[24], &band, sizeof(u32));
lnb_voltage = htonl(state->voltage);
memcpy(&b[28], &lnb_voltage, sizeof(u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *cmd)
{
struct ttusbdecfe_state *state = fe->demodulator_priv;
u8 b[] = { 0x00, 0xff, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00 };
if (cmd->msg_len > sizeof(b) - 4)
return -EINVAL;
memcpy(&b[4], cmd->msg, cmd->msg_len);
state->config->send_command(fe, 0x72,
sizeof(b) - (6 - cmd->msg_len), b,
- NULL, NULL);
+ NULL, NULL, 0);
return 0;
}
static int ttusbdecfe_dvbs_set_tone(struct dvb_frontend *fe,
enum fe_sec_tone_mode tone)
{
struct ttusbdecfe_state *state = fe->demodulator_priv;
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.h b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
index 73828bb22..96600ad4c 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.h
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
@@ -7,18 +7,19 @@
#ifndef TTUSBDECFE_H
#define TTUSBDECFE_H
#include <linux/dvb/frontend.h>
struct ttusbdecfe_config
{
int (*send_command)(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[]);
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len);
};
extern struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config);
extern struct dvb_frontend* ttusbdecfe_dvbt_attach(const struct ttusbdecfe_config* config);
#endif // TTUSBDECFE_H
]
|
| 190/4 |
2026/08/17 21:17 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 64894
output: 479
thoughts: 860
Thoughts: **Code Review and Safety Checks**
Okay, so I've finalized this patch and the initial assessment is positive – everything appears complete and correct. I've gone ahead and updated `ttusbdecfe_config` to include `cmd_result_len`, and, critically, I've updated `ttusb_dec_send_command` to properly incorporate `cmd_result_len` and implemented some crucial bounds checking on the parameters: `param_length`, `actual_len`, and `b[3]`. Plus, I made sure all the calling functions were passing the appropriate length arguments.
Now, let's dissect the safety considerations I've meticulously worked through. I had a quick moment of concern – `b[3]` is `u8`, unsigned, while `actual_len` is an `int`. If `actual_len` is less than 4, we're returning `-EIO`, so the expression `actual_len - 4` will always be non-negative. Therefore, `b[3] > actual_len - 4` is safe. The check against `cmd_result_len` is also safe because `cmd_result_len` is `int` and we only check it if `cmd_result` is not NULL, even though I will need to be extremely vigilant as to the value passed in. Returning `-EIO` is desired if `cmd_result_len` is smaller than `b[3]`.
To cement my confidence, I needed to re-examine the key call sites. In `ttusb_dec_get_stb_state`, the `cmd_result_len` is `sizeof(c)` (which is 60). If `b[3]` is greater than 60, `ttusb_dec_send_command` will correctly return `-EIO` due to the earlier check in the function. I confirmed this is the correct flow and that this check is in the right place.
Then, I turned my attention to `ttusbdecfe_dvbt_read_status`. Here, the `cmd_result_len` is 4. If `b[3]` is greater than 4, `-EIO` will be returned. Again, the logic checks out.
Finally, I checked `ttusb_dec_start_sec_feed`. Same deal - it uses 60 and the existing checks ensure the safety of the operation.
I also double-checked the `param_length` check – making sure `param_length` is not larger than `COMMAND_PACKET_SIZE` and am confident that this fix is sound. Okay, I've run through everything. Now I am satisfied. Time to submit this.
|
| 191/3 |
2026/08/17 21:17 |
action |
test-patch |
25m
Results: map[PatchDiff:diff --git a/drivers/media/usb/ttusb-dec/ttusb_dec.c b/drivers/media/usb/ttusb-dec/ttusb_dec.c
index 825a38759..a8e7b5b28 100644
--- a/drivers/media/usb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/usb/ttusb-dec/ttusb_dec.c
@@ -314,13 +314,17 @@ static u16 crc16(u16 crc, const u8 *buf, size_t len)
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
int result, actual_len;
u8 *b;
dprintk("%s\n", __func__);
+ if (param_length > COMMAND_PACKET_SIZE)
+ return -EINVAL;
+
b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
if (!b)
return -ENOMEM;
@@ -366,10 +370,25 @@ static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
__func__, actual_len, b);
}
+ if (actual_len < 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
+ if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
if (result_length)
*result_length = b[3];
- if (cmd_result && b[3] > 0)
+ if (cmd_result && b[3] > 0) {
+ if (b[3] > cmd_result_len) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
memcpy(cmd_result, &b[4], b[3]);
+ }
}
err_mutex_unlock:
@@ -389,7 +408,8 @@ static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
dprintk("%s\n", __func__);
- result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
+ result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c,
+ sizeof(c));
if (result)
return result;
@@ -448,7 +468,7 @@ static void ttusb_dec_set_pids(struct ttusb_dec *dec)
memcpy(&b[2], &audio, 2);
memcpy(&b[4], &video, 2);
- ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL, 0);
dvb_filter_pes2ts_init(&dec->a_pes2ts, dec->pid[DMX_PES_AUDIO],
ttusb_dec_audio_pes2ts_cb, dec);
@@ -900,9 +920,9 @@ static int ttusb_dec_set_interface(struct ttusb_dec *dec,
case TTUSB_DEC_INTERFACE_INITIAL:
result = usb_set_interface(dec->udev, 0, 0);
break;
- case TTUSB_DEC_INTERFACE_IN:
- result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
- b, NULL, NULL);
+ case TTUSB_DEC_INTERFACE_IN:
+ result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
+ b, NULL, NULL, 0);
if (result)
return result;
result = usb_set_interface(dec->udev, 0, 8);
@@ -1021,7 +1041,7 @@ static int ttusb_dec_start_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
}
- result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL, 0);
if (result)
return result;
@@ -1056,7 +1076,7 @@ static int ttusb_dec_start_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
memcpy(&b0[5], &dvbdmxfeed->filter->filter.filter_value[0], 1);
result = ttusb_dec_send_command(dec, 0x60, sizeof(b0), b0,
- &c_length, c);
+ &c_length, c, sizeof(c));
if (!result) {
if (c_length == 2) {
@@ -1114,7 +1134,7 @@ static int ttusb_dec_stop_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
u8 b0[] = { 0x00 };
- ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL, 0);
dec->pva_stream_count--;
@@ -1135,7 +1155,7 @@ static int ttusb_dec_stop_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
list_del(&finfo->filter_info_list);
spin_unlock_irqrestore(&dec->filter_info_list_lock, flags);
kfree(finfo);
- ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL, 0);
dec->filter_stream_count--;
@@ -1238,7 +1258,7 @@ static int ttusb_init_rc( struct ttusb_dec *dec)
if (usb_submit_urb(dec->irq_urb, GFP_KERNEL))
printk("%s: usb_submit_urb failed\n",__func__);
/* enable irq pipe */
- ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
+ ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL,0);
return 0;
}
@@ -1354,7 +1374,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
firmware_csum_ns = htons(firmware_csum);
memcpy(&b0[6], &firmware_csum_ns, 2);
- result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL, 0);
if (result) {
release_firmware(fw_entry);
@@ -1395,7 +1415,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
}
}
- result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL, 0);
release_firmware(fw_entry);
kfree(b);
@@ -1621,10 +1641,11 @@ static void ttusb_dec_exit_filters(struct ttusb_dec *dec)
static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
struct ttusb_dec* dec = fe->dvb->priv;
- return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
+ return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result, cmd_result_len);
}
static const struct ttusbdecfe_config fe_config = {
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.c b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
index 215221370..0bd80ade4 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.c
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
@@ -44,7 +44,8 @@ static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
*status=0;
- ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
+ ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result,
+ sizeof(result));
if(ret)
return ret;
@@ -85,7 +86,7 @@ static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend *fe)
__be32 freq = htonl(p->frequency / 1000);
memcpy(&b[4], &freq, sizeof (u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
@@ -130,7 +131,7 @@ static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend *fe)
lnb_voltage = htonl(state->voltage);
memcpy(&b[28], &lnb_voltage, sizeof(u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
@@ -149,7 +150,7 @@ static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struc
state->config->send_command(fe, 0x72,
sizeof(b) - (6 - cmd->msg_len), b,
- NULL, NULL);
+ NULL, NULL, 0);
return 0;
}
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.h b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
index 73828bb22..96600ad4c 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.h
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
@@ -14,7 +14,8 @@ struct ttusbdecfe_config
{
int (*send_command)(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[]);
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len);
};
extern struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config);
TestError:]
|
| 192/1 |
2026/08/17 21:43 |
action |
apply-patch |
0m
Results:
|
| 193/1 |
2026/08/17 21:43 |
action |
init-style-items |
0m
Results:
|
| 194/1 |
2026/08/17 21:43 |
loop |
|
15m
|
| 195/2 |
2026/08/17 21:43 |
iteration |
0 |
15m
|
| 196/3 |
2026/08/17 21:43 |
agent |
patch-formatter |
1m
Model:
Instruction:
You are an expert Linux kernel developer tasked with formatting a kernel patch.
Your objective is purely formatting: you must ensure the patch complies with the kernel's coding style,
conforms to the surrounding code rules, and passes checkpatch.pl, while preserving the code logic exactly as it is.
You should stop once the requested formatting changes are done and checkpatch.pl is happy.
Do not question the requested changes unless they are obviously wrong.
If the code already conforms to the requested changes, surrounding code rules,
and checkpatch.pl is happy, you should just finish your task.
WARNING: The clang-format tool may break the formatting of the surrounding code (like manual alignment).
Use it with caution. We want to make the change fit into the existing formatting as much as possible.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The current patch diff is:
diff --git a/drivers/media/usb/ttusb-dec/ttusb_dec.c b/drivers/media/usb/ttusb-dec/ttusb_dec.c
index 825a38759..a8e7b5b28 100644
--- a/drivers/media/usb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/usb/ttusb-dec/ttusb_dec.c
@@ -314,13 +314,17 @@ static u16 crc16(u16 crc, const u8 *buf, size_t len)
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
int result, actual_len;
u8 *b;
dprintk("%s\n", __func__);
+ if (param_length > COMMAND_PACKET_SIZE)
+ return -EINVAL;
+
b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
if (!b)
return -ENOMEM;
@@ -366,10 +370,25 @@ static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
__func__, actual_len, b);
}
+ if (actual_len < 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
+ if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
if (result_length)
*result_length = b[3];
- if (cmd_result && b[3] > 0)
+ if (cmd_result && b[3] > 0) {
+ if (b[3] > cmd_result_len) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
memcpy(cmd_result, &b[4], b[3]);
+ }
}
err_mutex_unlock:
@@ -389,7 +408,8 @@ static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
dprintk("%s\n", __func__);
- result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
+ result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c,
+ sizeof(c));
if (result)
return result;
@@ -448,7 +468,7 @@ static void ttusb_dec_set_pids(struct ttusb_dec *dec)
memcpy(&b[2], &audio, 2);
memcpy(&b[4], &video, 2);
- ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL, 0);
dvb_filter_pes2ts_init(&dec->a_pes2ts, dec->pid[DMX_PES_AUDIO],
ttusb_dec_audio_pes2ts_cb, dec);
@@ -900,9 +920,9 @@ static int ttusb_dec_set_interface(struct ttusb_dec *dec,
case TTUSB_DEC_INTERFACE_INITIAL:
result = usb_set_interface(dec->udev, 0, 0);
break;
- case TTUSB_DEC_INTERFACE_IN:
- result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
- b, NULL, NULL);
+ case TTUSB_DEC_INTERFACE_IN:
+ result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
+ b, NULL, NULL, 0);
if (result)
return result;
result = usb_set_interface(dec->udev, 0, 8);
@@ -1021,7 +1041,7 @@ static int ttusb_dec_start_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
}
- result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL, 0);
if (result)
return result;
@@ -1056,7 +1076,7 @@ static int ttusb_dec_start_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
memcpy(&b0[5], &dvbdmxfeed->filter->filter.filter_value[0], 1);
result = ttusb_dec_send_command(dec, 0x60, sizeof(b0), b0,
- &c_length, c);
+ &c_length, c, sizeof(c));
if (!result) {
if (c_length == 2) {
@@ -1114,7 +1134,7 @@ static int ttusb_dec_stop_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
u8 b0[] = { 0x00 };
- ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL, 0);
dec->pva_stream_count--;
@@ -1135,7 +1155,7 @@ static int ttusb_dec_stop_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
list_del(&finfo->filter_info_list);
spin_unlock_irqrestore(&dec->filter_info_list_lock, flags);
kfree(finfo);
- ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL, 0);
dec->filter_stream_count--;
@@ -1238,7 +1258,7 @@ static int ttusb_init_rc( struct ttusb_dec *dec)
if (usb_submit_urb(dec->irq_urb, GFP_KERNEL))
printk("%s: usb_submit_urb failed\n",__func__);
/* enable irq pipe */
- ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
+ ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL,0);
return 0;
}
@@ -1354,7 +1374,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
firmware_csum_ns = htons(firmware_csum);
memcpy(&b0[6], &firmware_csum_ns, 2);
- result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL, 0);
if (result) {
release_firmware(fw_entry);
@@ -1395,7 +1415,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
}
}
- result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL, 0);
release_firmware(fw_entry);
kfree(b);
@@ -1621,10 +1641,11 @@ static void ttusb_dec_exit_filters(struct ttusb_dec *dec)
static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
struct ttusb_dec* dec = fe->dvb->priv;
- return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
+ return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result, cmd_result_len);
}
static const struct ttusbdecfe_config fe_config = {
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.c b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
index 215221370..0bd80ade4 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.c
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
@@ -44,7 +44,8 @@ static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
*status=0;
- ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
+ ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result,
+ sizeof(result));
if(ret)
return ret;
@@ -85,7 +86,7 @@ static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend *fe)
__be32 freq = htonl(p->frequency / 1000);
memcpy(&b[4], &freq, sizeof (u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
@@ -130,7 +131,7 @@ static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend *fe)
lnb_voltage = htonl(state->voltage);
memcpy(&b[28], &lnb_voltage, sizeof(u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
@@ -149,7 +150,7 @@ static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struc
state->config->send_command(fe, 0x72,
sizeof(b) - (6 - cmd->msg_len), b,
- NULL, NULL);
+ NULL, NULL, 0);
return 0;
}
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.h b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
index 73828bb22..96600ad4c 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.h
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
@@ -14,7 +14,8 @@ struct ttusbdecfe_config
{
int (*send_command)(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[]);
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len);
};
extern struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config);
Use the provided tools to format the patch.
Reply: I have formatted the patch according to Linux kernel coding style guidelines and fixed all checkpatch.pl issues:
1. Fixed accidental indentation change in `ttusb_dec_set_interface()` switch statement for `case TTUSB_DEC_INTERFACE_IN:`.
2. Added missing spaces after commas in `ttusb_dec_send_command()` call in `ttusb_init_rc()`.
3. Wrapped long function call line in `fe_send_command()` to stay within line length limits.
4. Added required spaces around operator `=` in `ttusbdecfe_dvbt_read_status()`.
The modified patch now passes `checkpatch.pl` with zero errors and zero warnings.
|
| 197/4 |
2026/08/17 21:43 |
llm |
patch-formatter |
0m
Model:
Tokens:
input: 7779
output: 9
thoughts: 29
Thoughts: Here's your summary:
**Initial Patch Inspection**
Okay, before I even start digging into the meat of this patch, let's establish a baseline. The first thing I'm going to do is run `checkpatch`. I know it's not perfect, but it's a quick and dirty way to identify any obvious style violations or formatting inconsistencies. This command is pretty simple to call, so that's the first step.
|
| 198/4 |
2026/08/17 21:43 |
tool |
checkpatch |
0m
Results: map[Output:ERROR: space required after that ',' (ctx:VxV)
#124: FILE: drivers/media/usb/ttusb-dec/ttusb_dec.c:1261:
+ ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL,0);
^
ERROR: space required after that ',' (ctx:VxV)
#124: FILE: drivers/media/usb/ttusb-dec/ttusb_dec.c:1261:
+ ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL,0);
^
ERROR: space required after that ',' (ctx:VxV)
#124: FILE: drivers/media/usb/ttusb-dec/ttusb_dec.c:1261:
+ ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL,0);
^
ERROR: space required after that ',' (ctx:VxV)
#124: FILE: drivers/media/usb/ttusb-dec/ttusb_dec.c:1261:
+ ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL,0);
^
ERROR: space required after that ',' (ctx:VxV)
#124: FILE: drivers/media/usb/ttusb-dec/ttusb_dec.c:1261:
+ ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL,0);
^
ERROR: space required after that ',' (ctx:VxV)
#124: FILE: drivers/media/usb/ttusb-dec/ttusb_dec.c:1261:
+ ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL,0);
^
WARNING: line length of 117 exceeds 100 columns
#156: FILE: drivers/media/usb/ttusb-dec/ttusb_dec.c:1648:
+ return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result, cmd_result_len);
ERROR: spaces required around that '=' (ctx:VxV)
#169: FILE: drivers/media/usb/ttusb-dec/ttusbdecfe.c:47:
+ ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result,
^
total: 7 errors, 1 warnings, 184 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
Your patch has style problems, please review.
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
]
|
| 199/4 |
2026/08/17 21:43 |
llm |
patch-formatter |
0m
Model:
Tokens:
input: 8661
output: 182
thoughts: 382
Thoughts: **Analyzing a Potential Indentation Issue**
Okay, let's dive into these `checkpatch` results and see what we've got. The plan is to scrutinize all errors and warnings, and also to take a closer look at the surrounding code for style violations, formatting inconsistencies, or anything that doesn't quite jibe with kernel coding standards. We'll start by reading the patch diff carefully and inspecting the relevant source files.
Right, here we are in `drivers/media/usb/ttusb-dec/ttusb_dec.c`. Looking specifically at lines 900-910, I see a diff:
```diff
- case TTUSB_DEC_INTERFACE_IN:
- result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
- b, NULL, NULL);
+ case TTUSB_DEC_INTERFACE_IN:
+ result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
+ b, NULL, NULL, 0);
```
Wait a second... hold on. My eyes are drawn to the indentation of that `case TTUSB_DEC_INTERFACE_IN:` line. Let's compare to the context:
```c
case TTUSB_DEC_INTERFACE_INITIAL:
result = usb_set_interface(dec->udev, 0, 0);
break;
case TTUSB_DEC_INTERFACE_IN:
result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
b, NULL, NULL);
```
Bingo! It looks like an extra tab was introduced on `case TTUSB_DEC_INTERFACE_IN:`. The patch has made that line *more* indented than `case TTUSB_DEC_INTERFACE_INITIAL:`, which is definitely not the correct indentation for a `case` within a `switch` statement! That's a clear violation of our kernel coding style rules. We need to address this.
Let me now use my usual tools to quickly check surrounding code; either `read-file` or `codesearch-definition-source` should give me the relevant context around line 900 in `ttusb_dec.c`.
|
| 200/4 |
2026/08/17 21:43 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusb_dec.c FirstLine:310 LineCount:80]
Results: map[Contents: 310: crc ^= (tmp ^ (tmp << 1)) << 4;
311: }
312: return crc;
313: }
314:
315: static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
316: int param_length, const u8 params[],
317: int *result_length, u8 cmd_result[])
318: {
319: int result, actual_len;
320: u8 *b;
321:
322: dprintk("%s\n", __func__);
323:
324: b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
325: if (!b)
326: return -ENOMEM;
327:
328: result = mutex_lock_interruptible(&dec->usb_mutex);
329: if (result) {
330: printk("%s: Failed to lock usb mutex.\n", __func__);
331: goto err_free;
332: }
333:
334: b[0] = 0xaa;
335: b[1] = ++dec->trans_count;
336: b[2] = command;
337: b[3] = param_length;
338:
339: if (params)
340: memcpy(&b[4], params, param_length);
341:
342: if (debug) {
343: printk(KERN_DEBUG "%s: command: %*ph\n",
344: __func__, param_length, b);
345: }
346:
347: result = usb_bulk_msg(dec->udev, dec->command_pipe, b,
348: COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
349:
350: if (result) {
351: printk("%s: command bulk message failed: error %d\n",
352: __func__, result);
353: goto err_mutex_unlock;
354: }
355:
356: result = usb_bulk_msg(dec->udev, dec->result_pipe, b,
357: COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
358:
359: if (result) {
360: printk("%s: result bulk message failed: error %d\n",
361: __func__, result);
362: goto err_mutex_unlock;
363: } else {
364: if (debug) {
365: printk(KERN_DEBUG "%s: result: %*ph\n",
366: __func__, actual_len, b);
367: }
368:
369: if (result_length)
370: *result_length = b[3];
371: if (cmd_result && b[3] > 0)
372: memcpy(cmd_result, &b[4], b[3]);
373: }
374:
375: err_mutex_unlock:
376: mutex_unlock(&dec->usb_mutex);
377: err_free:
378: kfree(b);
379: return result;
380: }
381:
382: static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
383: unsigned int *model, unsigned int *version)
384: {
385: u8 c[COMMAND_PACKET_SIZE];
386: int c_length;
387: int result;
388: __be32 tmp;
389:
]
|
| 201/4 |
2026/08/17 21:43 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusb_dec.c FirstLine:900 LineCount:30]
Results: map[Contents: 900: case TTUSB_DEC_INTERFACE_INITIAL:
901: result = usb_set_interface(dec->udev, 0, 0);
902: break;
903: case TTUSB_DEC_INTERFACE_IN:
904: result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
905: b, NULL, NULL);
906: if (result)
907: return result;
908: result = usb_set_interface(dec->udev, 0, 8);
909: break;
910: case TTUSB_DEC_INTERFACE_OUT:
911: result = usb_set_interface(dec->udev, 0, 1);
912: break;
913: }
914:
915: if (result)
916: return result;
917:
918: dec->interface = interface;
919: }
920:
921: return 0;
922: }
923:
924: static int ttusb_dec_start_iso_xfer(struct ttusb_dec *dec)
925: {
926: int i, result;
927:
928: dprintk("%s\n", __func__);
929:
]
|
| 202/4 |
2026/08/17 21:43 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusb_dec.c FirstLine:1230 LineCount:30]
Results: map[Contents:1230:
1231: err = input_register_device(input_dev);
1232: if (err) {
1233: input_free_device(input_dev);
1234: return err;
1235: }
1236:
1237: dec->rc_input_dev = input_dev;
1238: if (usb_submit_urb(dec->irq_urb, GFP_KERNEL))
1239: printk("%s: usb_submit_urb failed\n",__func__);
1240: /* enable irq pipe */
1241: ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
1242:
1243: return 0;
1244: }
1245:
1246: static void ttusb_dec_init_v_pes(struct ttusb_dec *dec)
1247: {
1248: dprintk("%s\n", __func__);
1249:
1250: dec->v_pes[0] = 0x00;
1251: dec->v_pes[1] = 0x00;
1252: dec->v_pes[2] = 0x01;
1253: dec->v_pes[3] = 0xe0;
1254: }
1255:
1256: static int ttusb_dec_init_usb(struct ttusb_dec *dec)
1257: {
1258: int result;
1259:
]
|
| 203/4 |
2026/08/17 21:43 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusb_dec.c FirstLine:1630 LineCount:30]
Results: map[Contents:1630: static const struct ttusbdecfe_config fe_config = {
1631: .send_command = fe_send_command
1632: };
1633:
1634: static int ttusb_dec_probe(struct usb_interface *intf,
1635: const struct usb_device_id *id)
1636: {
1637: struct usb_device *udev;
1638: struct ttusb_dec *dec;
1639: int result;
1640:
1641: dprintk("%s\n", __func__);
1642:
1643: udev = interface_to_usbdev(intf);
1644:
1645: if (!(dec = kzalloc_obj(struct ttusb_dec))) {
1646: printk("%s: couldn't allocate memory.\n", __func__);
1647: return -ENOMEM;
1648: }
1649:
1650: usb_set_intfdata(intf, (void *)dec);
1651:
1652: switch (id->idProduct) {
1653: case 0x1006:
1654: ttusb_dec_set_model(dec, TTUSB_DEC3000S);
1655: break;
1656:
1657: case 0x1008:
1658: ttusb_dec_set_model(dec, TTUSB_DEC2000T);
1659: break;
]
|
| 204/4 |
2026/08/17 21:43 |
llm |
patch-formatter |
0m
Model:
Tokens:
input: 12164
output: 46
thoughts: 31
Thoughts: Okay, let's dive into this. Here's how I'd approach that:
**Investigating `fe_send_command` in `ttusb_dec.c`**
Alright, I need to get to the heart of what's going on with this `fe_send_command` function. Let's start by zeroing in on where it's defined within the `ttusb_dec.c` file. I'm going to jump to that area, specifically around line 1620. That seems like a reasonable place to start, given its prominence and likely role in this process. Time to start digging!
|
| 205/4 |
2026/08/17 21:43 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusb_dec.c FirstLine:1610 LineCount:25]
Results: map[Contents:1610: static void ttusb_dec_exit_filters(struct ttusb_dec *dec)
1611: {
1612: struct list_head *item;
1613: struct filter_info *finfo;
1614:
1615: while ((item = dec->filter_info_list.next) != &dec->filter_info_list) {
1616: finfo = list_entry(item, struct filter_info, filter_info_list);
1617: list_del(&finfo->filter_info_list);
1618: kfree(finfo);
1619: }
1620: }
1621:
1622: static int fe_send_command(struct dvb_frontend* fe, const u8 command,
1623: int param_length, const u8 params[],
1624: int *result_length, u8 cmd_result[])
1625: {
1626: struct ttusb_dec* dec = fe->dvb->priv;
1627: return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
1628: }
1629:
1630: static const struct ttusbdecfe_config fe_config = {
1631: .send_command = fe_send_command
1632: };
1633:
1634: static int ttusb_dec_probe(struct usb_interface *intf,
]
|
| 206/4 |
2026/08/17 21:43 |
llm |
patch-formatter |
0m
Model:
Tokens:
input: 12799
output: 45
thoughts: 47
Thoughts: Okay, let's dive into this.
**Examining the ttusbdecfe.c Source**
Right, so to get a handle on this, I need to check `ttusbdecfe.c` thoroughly. I'm going to start by focusing on lines 30 through 160 within the `drivers/media/usb/ttusb-dec/` directory. That section should give me a good baseline to work from and hopefully outline the core functionality that's happening there. I'm especially looking for any initializations, register accesses, or data structure definitions in that range. This should help me to understand how the driver interfaces with the hardware and how its configured. Let's see what we can find.
|
| 207/4 |
2026/08/17 21:43 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusbdecfe.c FirstLine:30 LineCount:130]
Results: map[Contents: 30: *status = FE_HAS_SIGNAL | FE_HAS_VITERBI |
31: FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK;
32: return 0;
33: }
34:
35:
36: static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
37: enum fe_status *status)
38: {
39: struct ttusbdecfe_state* state = fe->demodulator_priv;
40: u8 b[] = { 0x00, 0x00, 0x00, 0x00,
41: 0x00, 0x00, 0x00, 0x00 };
42: u8 result[4];
43: int len, ret;
44:
45: *status=0;
46:
47: ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
48: if(ret)
49: return ret;
50:
51: if(len != 4) {
52: printk(KERN_ERR "%s: unexpected reply\n", __func__);
53: return -EIO;
54: }
55:
56: switch(result[3]) {
57: case 1: /* not tuned yet */
58: case 2: /* no signal/no lock*/
59: break;
60: case 3: /* signal found and locked*/
61: *status = FE_HAS_SIGNAL | FE_HAS_VITERBI |
62: FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK;
63: break;
64: case 4:
65: *status = FE_TIMEDOUT;
66: break;
67: default:
68: pr_info("%s: returned unknown value: %d\n",
69: __func__, result[3]);
70: return -EIO;
71: }
72:
73: return 0;
74: }
75:
76: static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend *fe)
77: {
78: struct dtv_frontend_properties *p = &fe->dtv_property_cache;
79: struct ttusbdecfe_state *state = fe->demodulator_priv;
80: u8 b[] = { 0x00, 0x00, 0x00, 0x03,
81: 0x00, 0x00, 0x00, 0x00,
82: 0x00, 0x00, 0x00, 0x01,
83: 0x00, 0x00, 0x00, 0xff,
84: 0x00, 0x00, 0x00, 0xff };
85:
86: __be32 freq = htonl(p->frequency / 1000);
87: memcpy(&b[4], &freq, sizeof (u32));
88: state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
89:
90: return 0;
91: }
92:
93: static int ttusbdecfe_dvbt_get_tune_settings(struct dvb_frontend* fe,
94: struct dvb_frontend_tune_settings* fesettings)
95: {
96: fesettings->min_delay_ms = 1500;
97: /* Drift compensation makes no sense for DVB-T */
98: fesettings->step_size = 0;
99: fesettings->max_drift = 0;
100: return 0;
101: }
102:
103: static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend *fe)
104: {
105: struct dtv_frontend_properties *p = &fe->dtv_property_cache;
106: struct ttusbdecfe_state *state = fe->demodulator_priv;
107:
108: u8 b[] = { 0x00, 0x00, 0x00, 0x01,
109: 0x00, 0x00, 0x00, 0x00,
110: 0x00, 0x00, 0x00, 0x01,
111: 0x00, 0x00, 0x00, 0x00,
112: 0x00, 0x00, 0x00, 0x00,
113: 0x00, 0x00, 0x00, 0x00,
114: 0x00, 0x00, 0x00, 0x00,
115: 0x00, 0x00, 0x00, 0x00,
116: 0x00, 0x00, 0x00, 0x00,
117: 0x00, 0x00, 0x00, 0x00 };
118: __be32 freq;
119: __be32 sym_rate;
120: __be32 band;
121: __be32 lnb_voltage;
122:
123: freq = htonl(p->frequency +
124: (state->hi_band ? LOF_HI : LOF_LO));
125: memcpy(&b[4], &freq, sizeof(u32));
126: sym_rate = htonl(p->symbol_rate);
127: memcpy(&b[12], &sym_rate, sizeof(u32));
128: band = htonl(state->hi_band ? LOF_HI : LOF_LO);
129: memcpy(&b[24], &band, sizeof(u32));
]
|
| 208/4 |
2026/08/17 21:43 |
llm |
patch-formatter |
0m
Model:
Tokens:
input: 14824
output: 46
thoughts: 2013
Thoughts: **Patch Analysis and Code Review**
Okay, let's break down this patch methodically. First, I need to verify all the changes are sound and adhere to kernel coding standards. It's a bit like detective work, but I'm looking for any potential problems before they hit the mainline.
**Issue 1: Commas and Spacing** The first issue flagged concerns line 1261 in `ttusb_dec.c`. The original code `ttusb_dec_send_command(dec, 0xb0, sizeof(b), b, NULL, NULL);` has been modified to `ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL,0);`. The `checkpatch` tool is correct. A space is definitely required after each comma for readability. So I'll amend that line to: `ttusb_dec_send_command(dec, 0xb0, sizeof(b), b, NULL, NULL, 0);`. That's a simple fix.
**Issue 2: Line Length in `ttusb_dec.c`** This one is a line length issue in `ttusb_dec.c`, line 1648. The proposed fix, which is definitely the right approach, is to break the excessively long `ttusb_dec_send_command` call into multiple lines to keep it within the 80/100 column limit. I'd go with the second version, as it is clearer to read. So, it's now:
```c
return ttusb_dec_send_command(dec, command, param_length, params,
result_length, cmd_result,
cmd_result_len);
```
**Issue 3: Spacing Around `=` in `ttusbdecfe.c`** This is about spacing around the assignment operator `=` on line 47 in `ttusbdecfe.c`. The original code `ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);` has been modified to `ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result,`. The added `sizeof(result));` triggers the error. Adding spaces to the `ret=` assignment to make it `ret =` fixes it, as does adding the `sizeof(result));`. Now the line looks like:
```c
ret = state->config->send_command(fe, 0x73, sizeof(b), b, &len, result,
sizeof(result));
```
I also need to check the alignment of the `sizeof(result));` function call with the other arguments. The current patch is fine.
**Indentation and Alignment Check** The code adds a tab to the beginning of the `case TTUSB_DEC_INTERFACE_IN:` block. I need to correct this. This added indentation makes the code harder to read. The fixed version should be:
```c
case TTUSB_DEC_INTERFACE_IN:
result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
b, NULL, NULL, 0);
if (result)
return result;
```
This aligns with the existing indentation style of the surrounding `case` statements.
**Thorough Review of Code Changes** Now, I need to examine the new `ttusb_dec.c` file from the beginning and review all changes. I need to ensure the added function `ttusb_dec_send_command` matches the coding style of the other functions. I also need to make sure `kzalloc` is used correctly.
I need to examine the function signature and the arguments. The alignment looks good:
```c
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len)
```
The logic within the `ttusb_dec_send_command` function regarding error handling looks standard. I'll read and check the code.
That's the process I'd follow. Now I need to check all changes within `ttusbdecfe.c` and `ttusbdecfe.h`, thoroughly. This includes all changes to ensure they are correct, consistent, and do not introduce any regressions. It's a comprehensive review to maintain code quality.
|
| 209/4 |
2026/08/17 21:44 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusb_dec.c FirstLine:314 LineCount:100]
Results: map[Contents: 314:
315: static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
316: int param_length, const u8 params[],
317: int *result_length, u8 cmd_result[])
318: {
319: int result, actual_len;
320: u8 *b;
321:
322: dprintk("%s\n", __func__);
323:
324: b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
325: if (!b)
326: return -ENOMEM;
327:
328: result = mutex_lock_interruptible(&dec->usb_mutex);
329: if (result) {
330: printk("%s: Failed to lock usb mutex.\n", __func__);
331: goto err_free;
332: }
333:
334: b[0] = 0xaa;
335: b[1] = ++dec->trans_count;
336: b[2] = command;
337: b[3] = param_length;
338:
339: if (params)
340: memcpy(&b[4], params, param_length);
341:
342: if (debug) {
343: printk(KERN_DEBUG "%s: command: %*ph\n",
344: __func__, param_length, b);
345: }
346:
347: result = usb_bulk_msg(dec->udev, dec->command_pipe, b,
348: COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
349:
350: if (result) {
351: printk("%s: command bulk message failed: error %d\n",
352: __func__, result);
353: goto err_mutex_unlock;
354: }
355:
356: result = usb_bulk_msg(dec->udev, dec->result_pipe, b,
357: COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
358:
359: if (result) {
360: printk("%s: result bulk message failed: error %d\n",
361: __func__, result);
362: goto err_mutex_unlock;
363: } else {
364: if (debug) {
365: printk(KERN_DEBUG "%s: result: %*ph\n",
366: __func__, actual_len, b);
367: }
368:
369: if (result_length)
370: *result_length = b[3];
371: if (cmd_result && b[3] > 0)
372: memcpy(cmd_result, &b[4], b[3]);
373: }
374:
375: err_mutex_unlock:
376: mutex_unlock(&dec->usb_mutex);
377: err_free:
378: kfree(b);
379: return result;
380: }
381:
382: static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
383: unsigned int *model, unsigned int *version)
384: {
385: u8 c[COMMAND_PACKET_SIZE];
386: int c_length;
387: int result;
388: __be32 tmp;
389:
390: dprintk("%s\n", __func__);
391:
392: result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
393: if (result)
394: return result;
395:
396: if (c_length >= 0x0c) {
397: if (mode != NULL) {
398: memcpy(&tmp, c, 4);
399: *mode = ntohl(tmp);
400: }
401: if (model != NULL) {
402: memcpy(&tmp, &c[4], 4);
403: *model = ntohl(tmp);
404: }
405: if (version != NULL) {
406: memcpy(&tmp, &c[8], 4);
407: *version = ntohl(tmp);
408: }
409: return 0;
410: } else {
411: return -ENOENT;
412: }
413: }
]
|
| 210/4 |
2026/08/17 21:44 |
llm |
patch-formatter |
0m
Model:
Tokens:
input: 19309
output: 137
thoughts: 2839
Thoughts: **Code Review and Patch Analysis: `ttusb_dec_send_command`**
Alright, let's break this down. The objective here is clear: meticulously review all call sites of `ttusb_dec_send_command` across the `ttusb_dec.c` file and any related files, especially the `ttusbdecfe.c` file, as the patch seems to add a new parameter to this function. This is critical for ensuring the changes are correctly propagated and no regressions are introduced.
First, I'm noting the initial checks within `ttusb_dec.c`: I'm focusing on the alignment of the new `sizeof()` arguments and the overall formatting. I'm carefully examining indentation levels, which are critical in the Linux kernel style for function calls. I'm mentally calculating column positions to ensure tabs and spaces are used correctly for wrapping and alignment with the opening parenthesis of a multi-line function call. I also make a quick mental note about the correct spacing around the `=` operator (spaces required around the `=`).
The diffs in `ttusb_dec.c` reveal several modifications: lines 382, 468, 900, 1021, 1056, 1114, 1135, 1238, 1354, and 1395 are all adding a new final argument. I'm verifying that the added `sizeof()` arguments are correct and consistent across all usages. I immediately spot the lack of spaces around the commas in the original code on line 1238, and I know this needs to be fixed to satisfy the checkpatch tooling.
The most important point here is the change in the `fe_send_command` function (line 1621). This is where the function signature is being changed to accept the added argument, `cmd_result_len`. This is the core modification. I'm now satisfied that the modifications to `ttusb_dec_send_command` are correct: new arguments are added correctly and with proper alignment and spacing. I verify this visually by checking the alignment.
Moving on to `ttusbdecfe.c`, I carefully analyze the `send_command` calls that use the `ttusbdecfe_config` structure. Lines 44, 85, 130 and 149 of the file are impacted by this change. I'm again verifying the alignment using manual tab calculations, accounting for the indentation depth and the opening parenthesis of the function call. In particular, I will need to ensure that the added arguments are properly aligned and that any existing code alignment rules are respected.
Finally, I move to `ttusbdecfe.h` to confirm the function signature change in the `struct ttusbdecfe_config`, specifically adding the `cmd_result_len` parameter to the `send_command` function pointer. This is crucial for the header files to agree with the .c files.
In short: I've verified the changes, ensuring consistency, proper alignment, and correct argument passing throughout both source files.
|
| 211/4 |
2026/08/17 21:44 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusb_dec.c FirstLine:900 LineCount:15]
Results: map[Contents: 900: case TTUSB_DEC_INTERFACE_INITIAL:
901: result = usb_set_interface(dec->udev, 0, 0);
902: break;
903: case TTUSB_DEC_INTERFACE_IN:
904: result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
905: b, NULL, NULL);
906: if (result)
907: return result;
908: result = usb_set_interface(dec->udev, 0, 8);
909: break;
910: case TTUSB_DEC_INTERFACE_OUT:
911: result = usb_set_interface(dec->udev, 0, 1);
912: break;
913: }
914:
]
|
| 212/4 |
2026/08/17 21:44 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusb_dec.c FirstLine:1235 LineCount:12]
Results: map[Contents:1235: }
1236:
1237: dec->rc_input_dev = input_dev;
1238: if (usb_submit_urb(dec->irq_urb, GFP_KERNEL))
1239: printk("%s: usb_submit_urb failed\n",__func__);
1240: /* enable irq pipe */
1241: ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
1242:
1243: return 0;
1244: }
1245:
1246: static void ttusb_dec_init_v_pes(struct ttusb_dec *dec)
]
|
| 213/4 |
2026/08/17 21:44 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusb_dec.c FirstLine:1620 LineCount:12]
Results: map[Contents:1620: }
1621:
1622: static int fe_send_command(struct dvb_frontend* fe, const u8 command,
1623: int param_length, const u8 params[],
1624: int *result_length, u8 cmd_result[])
1625: {
1626: struct ttusb_dec* dec = fe->dvb->priv;
1627: return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
1628: }
1629:
1630: static const struct ttusbdecfe_config fe_config = {
1631: .send_command = fe_send_command
]
|
| 214/4 |
2026/08/17 21:44 |
llm |
patch-formatter |
0m
Model:
Tokens:
input: 23605
output: 10
thoughts: 58
Thoughts: **Checking the Current State of `ttusb_dec.c`**
Okay, let's just make absolutely sure I'm clear on the `ttusb_dec.c` situation. Need to re-examine the current patch diff against the repo version. No sense going further without that clear picture. Wait a minute! The `patch-diff` tool, that's it! It'll show me *precisely* what edits have been applied to `ttusb_dec.c` so far. Right, time to call `patch-diff`. Let's get this done.
|
| 215/4 |
2026/08/17 21:44 |
tool |
patch-diff |
0m
Error:
|
| 216/4 |
2026/08/17 21:44 |
llm |
patch-formatter |
0m
Model:
Tokens:
input: 23816
output: 15
thoughts: 14
Thoughts: Here's my summary, as though I'm thinking through this process:
**Analyzing the `patch-diff` Call**
Okay, so I need to examine this proposed action: Let's call `patch-diff` with `File=""`. Immediately, my expert brain kicks in, parsing this directive. A call to `patch-diff` suggests we're dealing with version control or file modifications. The fact that the `File` argument is set to an empty string... that's the interesting bit. This could indicate a few things, each requiring further investigation.
My initial thoughts are:
* **Global Patch Application:** Could this mean we're intending to apply a patch across *all* files, or to a "null" file, perhaps affecting the root of the file system's perceived state? This is potentially dangerous and I need to consider the context of the environment this command is being run in very carefully. It implies a global operation. This would need absolute precision, as even the slightest error could be catastrophic.
* **Initialization/Default Behavior:** Maybe `patch-diff` is designed to initialize a patch repository or configure the tool. An empty `File` argument could trigger a default behavior, like creating a new patch file. I need to check the documentation to confirm this, but it seems unlikely.
* **Debugging/Testing:** Is this call intended for testing the `patch-diff` utility itself? An empty string might be used to force a specific code path within the application, perhaps triggering a default, zero-input, or "no-file" scenario for debugging purposes. If it's for testing, what are the expected results? I need to understand that.
* **Incorrect Usage:** It's also possible this is simply a syntax error or a misinterpretation of how `patch-diff` works. I need to consider whether the command is being correctly used, or if this is user error or an incomplete command. Are there other flags or arguments that are missing?
I need to quickly determine the true intention. I'd start by:
1. **Consulting Documentation:** I should immediately check the documentation for `patch-diff`. What is its intended use? How does it handle an empty `File` argument?
2. **Examining the Context:** What is the surrounding code or script? What is the overall workflow this is part of? This will provide critical clues.
3. **Considering the Environment:** Where is this command being executed? What is the current working directory? Is there a version control system in use? Are there potential consequences to running this command in the current environment?
4. **Confirming Expected Behavior:** Do I know what will be returned or changed by such a command?
Ultimately, this `File=""` situation demands immediate scrutiny. Ignoring it could have severe unintended consequences. I need to be sure I understand the intent *before* proceeding any further.
|
| 217/4 |
2026/08/17 21:44 |
tool |
patch-diff |
0m
Args:
Results: map[Output:diff --git a/drivers/media/usb/ttusb-dec/ttusb_dec.c b/drivers/media/usb/ttusb-dec/ttusb_dec.c
index 825a38759..a8e7b5b28 100644
--- a/drivers/media/usb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/usb/ttusb-dec/ttusb_dec.c
@@ -307,107 +307,127 @@ static u16 crc16(u16 crc, const u8 *buf, size_t len)
crc ^= *buf++;
crc ^= (u8)crc >> 4;
tmp = (u8)crc;
crc ^= (tmp ^ (tmp << 1)) << 4;
}
return crc;
}
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
int result, actual_len;
u8 *b;
dprintk("%s\n", __func__);
+ if (param_length > COMMAND_PACKET_SIZE)
+ return -EINVAL;
+
b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
if (!b)
return -ENOMEM;
result = mutex_lock_interruptible(&dec->usb_mutex);
if (result) {
printk("%s: Failed to lock usb mutex.\n", __func__);
goto err_free;
}
b[0] = 0xaa;
b[1] = ++dec->trans_count;
b[2] = command;
b[3] = param_length;
if (params)
memcpy(&b[4], params, param_length);
if (debug) {
printk(KERN_DEBUG "%s: command: %*ph\n",
__func__, param_length, b);
}
result = usb_bulk_msg(dec->udev, dec->command_pipe, b,
COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
if (result) {
printk("%s: command bulk message failed: error %d\n",
__func__, result);
goto err_mutex_unlock;
}
result = usb_bulk_msg(dec->udev, dec->result_pipe, b,
COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
if (result) {
printk("%s: result bulk message failed: error %d\n",
__func__, result);
goto err_mutex_unlock;
} else {
if (debug) {
printk(KERN_DEBUG "%s: result: %*ph\n",
__func__, actual_len, b);
}
+ if (actual_len < 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
+ if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
if (result_length)
*result_length = b[3];
- if (cmd_result && b[3] > 0)
+ if (cmd_result && b[3] > 0) {
+ if (b[3] > cmd_result_len) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
memcpy(cmd_result, &b[4], b[3]);
+ }
}
err_mutex_unlock:
mutex_unlock(&dec->usb_mutex);
err_free:
kfree(b);
return result;
}
static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
unsigned int *model, unsigned int *version)
{
u8 c[COMMAND_PACKET_SIZE];
int c_length;
int result;
__be32 tmp;
dprintk("%s\n", __func__);
- result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
+ result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c,
+ sizeof(c));
if (result)
return result;
if (c_length >= 0x0c) {
if (mode != NULL) {
memcpy(&tmp, c, 4);
*mode = ntohl(tmp);
}
if (model != NULL) {
memcpy(&tmp, &c[4], 4);
*model = ntohl(tmp);
}
if (version != NULL) {
memcpy(&tmp, &c[8], 4);
*version = ntohl(tmp);
}
return 0;
} else {
return -ENOENT;
}
}
@@ -435,27 +455,27 @@ static int ttusb_dec_video_pes2ts_cb(void *priv, unsigned char *data)
static void ttusb_dec_set_pids(struct ttusb_dec *dec)
{
u8 b[] = { 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff };
__be16 pcr = htons(dec->pid[DMX_PES_PCR]);
__be16 audio = htons(dec->pid[DMX_PES_AUDIO]);
__be16 video = htons(dec->pid[DMX_PES_VIDEO]);
dprintk("%s\n", __func__);
memcpy(&b[0], &pcr, 2);
memcpy(&b[2], &audio, 2);
memcpy(&b[4], &video, 2);
- ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL, 0);
dvb_filter_pes2ts_init(&dec->a_pes2ts, dec->pid[DMX_PES_AUDIO],
ttusb_dec_audio_pes2ts_cb, dec);
dvb_filter_pes2ts_init(&dec->v_pes2ts, dec->pid[DMX_PES_VIDEO],
ttusb_dec_video_pes2ts_cb, dec);
dec->v_pes_length = 0;
dec->v_pes_postbytes = 0;
}
static void ttusb_dec_process_pva(struct ttusb_dec *dec, u8 *pva, int length)
@@ -888,35 +908,35 @@ static void ttusb_dec_stop_iso_xfer(struct ttusb_dec *dec)
/* Setting the interface of the DEC tends to take down the USB communications
* for a short period, so it's important not to call this function just before
* trying to talk to it.
*/
static int ttusb_dec_set_interface(struct ttusb_dec *dec,
enum ttusb_dec_interface interface)
{
int result = 0;
u8 b[] = { 0x05 };
if (interface != dec->interface) {
switch (interface) {
case TTUSB_DEC_INTERFACE_INITIAL:
result = usb_set_interface(dec->udev, 0, 0);
break;
- case TTUSB_DEC_INTERFACE_IN:
- result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
- b, NULL, NULL);
+ case TTUSB_DEC_INTERFACE_IN:
+ result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
+ b, NULL, NULL, 0);
if (result)
return result;
result = usb_set_interface(dec->udev, 0, 8);
break;
case TTUSB_DEC_INTERFACE_OUT:
result = usb_set_interface(dec->udev, 0, 1);
break;
}
if (result)
return result;
dec->interface = interface;
}
return 0;
}
@@ -964,121 +984,121 @@ static int ttusb_dec_start_iso_xfer(struct ttusb_dec *dec)
static int ttusb_dec_start_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
{
struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
struct ttusb_dec *dec = dvbdmx->priv;
u8 b0[] = { 0x05 };
int result = 0;
dprintk("%s\n", __func__);
dprintk(" ts_type:");
if (dvbdmxfeed->ts_type & TS_DECODER)
dprintk(" TS_DECODER");
if (dvbdmxfeed->ts_type & TS_PACKET)
dprintk(" TS_PACKET");
if (dvbdmxfeed->ts_type & TS_PAYLOAD_ONLY)
dprintk(" TS_PAYLOAD_ONLY");
dprintk("\n");
switch (dvbdmxfeed->pes_type) {
case DMX_PES_VIDEO:
dprintk(" pes_type: DMX_PES_VIDEO\n");
dec->pid[DMX_PES_PCR] = dvbdmxfeed->pid;
dec->pid[DMX_PES_VIDEO] = dvbdmxfeed->pid;
dec->video_filter = dvbdmxfeed->filter;
ttusb_dec_set_pids(dec);
break;
case DMX_PES_AUDIO:
dprintk(" pes_type: DMX_PES_AUDIO\n");
dec->pid[DMX_PES_AUDIO] = dvbdmxfeed->pid;
dec->audio_filter = dvbdmxfeed->filter;
ttusb_dec_set_pids(dec);
break;
case DMX_PES_TELETEXT:
dec->pid[DMX_PES_TELETEXT] = dvbdmxfeed->pid;
dprintk(" pes_type: DMX_PES_TELETEXT(not supported)\n");
return -ENOSYS;
case DMX_PES_PCR:
dprintk(" pes_type: DMX_PES_PCR\n");
dec->pid[DMX_PES_PCR] = dvbdmxfeed->pid;
ttusb_dec_set_pids(dec);
break;
case DMX_PES_OTHER:
dprintk(" pes_type: DMX_PES_OTHER(not supported)\n");
return -ENOSYS;
default:
dprintk(" pes_type: unknown (%d)\n", dvbdmxfeed->pes_type);
return -EINVAL;
}
- result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL, 0);
if (result)
return result;
dec->pva_stream_count++;
return ttusb_dec_start_iso_xfer(dec);
}
static int ttusb_dec_start_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
{
struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
u8 b0[] = { 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0xff, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00 };
__be16 pid;
u8 c[COMMAND_PACKET_SIZE];
int c_length;
int result;
struct filter_info *finfo;
unsigned long flags;
u8 x = 1;
dprintk("%s\n", __func__);
pid = htons(dvbdmxfeed->pid);
memcpy(&b0[0], &pid, 2);
memcpy(&b0[4], &x, 1);
memcpy(&b0[5], &dvbdmxfeed->filter->filter.filter_value[0], 1);
result = ttusb_dec_send_command(dec, 0x60, sizeof(b0), b0,
- &c_length, c);
+ &c_length, c, sizeof(c));
if (!result) {
if (c_length == 2) {
if (!(finfo = kmalloc_obj(struct filter_info, GFP_ATOMIC)))
return -ENOMEM;
finfo->stream_id = c[1];
finfo->filter = dvbdmxfeed->filter;
spin_lock_irqsave(&dec->filter_info_list_lock, flags);
list_add_tail(&finfo->filter_info_list,
&dec->filter_info_list);
spin_unlock_irqrestore(&dec->filter_info_list_lock,
flags);
dvbdmxfeed->priv = finfo;
dec->filter_stream_count++;
return ttusb_dec_start_iso_xfer(dec);
}
return -EAGAIN;
} else
return result;
}
@@ -1107,42 +1127,42 @@ static int ttusb_dec_start_feed(struct dvb_demux_feed *dvbdmxfeed)
return -EINVAL;
}
}
static int ttusb_dec_stop_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
{
struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
u8 b0[] = { 0x00 };
- ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL, 0);
dec->pva_stream_count--;
ttusb_dec_stop_iso_xfer(dec);
return 0;
}
static int ttusb_dec_stop_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
{
struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
u8 b0[] = { 0x00, 0x00 };
struct filter_info *finfo = dvbdmxfeed->priv;
unsigned long flags;
b0[1] = finfo->stream_id;
spin_lock_irqsave(&dec->filter_info_list_lock, flags);
list_del(&finfo->filter_info_list);
spin_unlock_irqrestore(&dec->filter_info_list_lock, flags);
kfree(finfo);
- ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL, 0);
dec->filter_stream_count--;
ttusb_dec_stop_iso_xfer(dec);
return 0;
}
static int ttusb_dec_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
{
@@ -1207,45 +1227,45 @@ static void ttusb_dec_init_bh_work(struct ttusb_dec *dec)
static int ttusb_init_rc( struct ttusb_dec *dec)
{
struct input_dev *input_dev;
u8 b[] = { 0x00, 0x01 };
int i;
int err;
usb_make_path(dec->udev, dec->rc_phys, sizeof(dec->rc_phys));
strlcat(dec->rc_phys, "/input0", sizeof(dec->rc_phys));
input_dev = input_allocate_device();
if (!input_dev)
return -ENOMEM;
input_dev->name = "ttusb_dec remote control";
input_dev->phys = dec->rc_phys;
input_dev->evbit[0] = BIT_MASK(EV_KEY);
input_dev->keycodesize = sizeof(u16);
input_dev->keycodemax = 0x1a;
input_dev->keycode = rc_keys;
for (i = 0; i < ARRAY_SIZE(rc_keys); i++)
set_bit(rc_keys[i], input_dev->keybit);
err = input_register_device(input_dev);
if (err) {
input_free_device(input_dev);
return err;
}
dec->rc_input_dev = input_dev;
if (usb_submit_urb(dec->irq_urb, GFP_KERNEL))
printk("%s: usb_submit_urb failed\n",__func__);
/* enable irq pipe */
- ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
+ ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL,0);
return 0;
}
static void ttusb_dec_init_v_pes(struct ttusb_dec *dec)
{
dprintk("%s\n", __func__);
dec->v_pes[0] = 0x00;
dec->v_pes[1] = 0x00;
@@ -1298,111 +1318,111 @@ static int ttusb_dec_init_usb(struct ttusb_dec *dec)
static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
{
int i, j, actual_len, result, size, trans_count;
u8 b0[] = { 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x61, 0x00 };
u8 b1[] = { 0x61 };
u8 *b;
char idstring[21];
const u8 *firmware = NULL;
size_t firmware_size = 0;
u16 firmware_csum = 0;
__be16 firmware_csum_ns;
__be32 firmware_size_nl;
u32 crc32_csum, crc32_check;
__be32 tmp;
const struct firmware *fw_entry = NULL;
dprintk("%s\n", __func__);
result = request_firmware(&fw_entry, dec->firmware_name, &dec->udev->dev);
if (result) {
printk(KERN_ERR "%s: Firmware (%s) unavailable.\n",
__func__, dec->firmware_name);
return result;
}
firmware = fw_entry->data;
firmware_size = fw_entry->size;
if (firmware_size < 60) {
printk("%s: firmware size too small for DSP code (%zu < 60).\n",
__func__, firmware_size);
release_firmware(fw_entry);
return -ENOENT;
}
/* a 32 bit checksum over the first 56 bytes of the DSP Code is stored
at offset 56 of file, so use it to check if the firmware file is
valid. */
crc32_csum = crc32(~0L, firmware, 56) ^ ~0L;
memcpy(&tmp, &firmware[56], 4);
crc32_check = ntohl(tmp);
if (crc32_csum != crc32_check) {
printk("%s: crc32 check of DSP code failed (calculated 0x%08x != 0x%08x in file), file invalid.\n",
__func__, crc32_csum, crc32_check);
release_firmware(fw_entry);
return -ENOENT;
}
memcpy(idstring, &firmware[36], 20);
idstring[20] = '\0';
printk(KERN_INFO "ttusb_dec: found DSP code \"%s\".\n", idstring);
firmware_size_nl = htonl(firmware_size);
memcpy(b0, &firmware_size_nl, 4);
firmware_csum = crc16(~0, firmware, firmware_size) ^ ~0;
firmware_csum_ns = htons(firmware_csum);
memcpy(&b0[6], &firmware_csum_ns, 2);
- result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL, 0);
if (result) {
release_firmware(fw_entry);
return result;
}
trans_count = 0;
j = 0;
b = kmalloc(ARM_PACKET_SIZE, GFP_KERNEL);
if (b == NULL) {
release_firmware(fw_entry);
return -ENOMEM;
}
for (i = 0; i < firmware_size; i += COMMAND_PACKET_SIZE) {
size = firmware_size - i;
if (size > COMMAND_PACKET_SIZE)
size = COMMAND_PACKET_SIZE;
b[j + 0] = 0xaa;
b[j + 1] = trans_count++;
b[j + 2] = 0xf0;
b[j + 3] = size;
memcpy(&b[j + 4], &firmware[i], size);
j += COMMAND_PACKET_SIZE + 4;
if (j >= ARM_PACKET_SIZE) {
result = usb_bulk_msg(dec->udev, dec->command_pipe, b,
ARM_PACKET_SIZE, &actual_len,
100);
j = 0;
} else if (size < COMMAND_PACKET_SIZE) {
result = usb_bulk_msg(dec->udev, dec->command_pipe, b,
j - COMMAND_PACKET_SIZE + size,
&actual_len, 100);
}
}
- result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL, 0);
release_firmware(fw_entry);
kfree(b);
return result;
}
static int ttusb_dec_init_stb(struct ttusb_dec *dec)
{
int result;
@@ -1614,24 +1634,25 @@ static void ttusb_dec_exit_filters(struct ttusb_dec *dec)
while ((item = dec->filter_info_list.next) != &dec->filter_info_list) {
finfo = list_entry(item, struct filter_info, filter_info_list);
list_del(&finfo->filter_info_list);
kfree(finfo);
}
}
static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
struct ttusb_dec* dec = fe->dvb->priv;
- return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
+ return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result, cmd_result_len);
}
static const struct ttusbdecfe_config fe_config = {
.send_command = fe_send_command
};
static int ttusb_dec_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
struct usb_device *udev;
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.c b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
index 215221370..0bd80ade4 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.c
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
@@ -36,39 +36,40 @@ static int ttusbdecfe_dvbs_read_status(struct dvb_frontend *fe,
static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
enum fe_status *status)
{
struct ttusbdecfe_state* state = fe->demodulator_priv;
u8 b[] = { 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
u8 result[4];
int len, ret;
*status=0;
- ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
+ ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result,
+ sizeof(result));
if(ret)
return ret;
if(len != 4) {
printk(KERN_ERR "%s: unexpected reply\n", __func__);
return -EIO;
}
switch(result[3]) {
case 1: /* not tuned yet */
case 2: /* no signal/no lock*/
break;
case 3: /* signal found and locked*/
*status = FE_HAS_SIGNAL | FE_HAS_VITERBI |
FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK;
break;
case 4:
*status = FE_TIMEDOUT;
break;
default:
pr_info("%s: returned unknown value: %d\n",
__func__, result[3]);
return -EIO;
}
return 0;
}
@@ -76,23 +77,23 @@ static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend *fe)
{
struct dtv_frontend_properties *p = &fe->dtv_property_cache;
struct ttusbdecfe_state *state = fe->demodulator_priv;
u8 b[] = { 0x00, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0xff,
0x00, 0x00, 0x00, 0xff };
__be32 freq = htonl(p->frequency / 1000);
memcpy(&b[4], &freq, sizeof (u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
static int ttusbdecfe_dvbt_get_tune_settings(struct dvb_frontend* fe,
struct dvb_frontend_tune_settings* fesettings)
{
fesettings->min_delay_ms = 1500;
/* Drift compensation makes no sense for DVB-T */
fesettings->step_size = 0;
@@ -103,60 +104,60 @@ static int ttusbdecfe_dvbt_get_tune_settings(struct dvb_frontend* fe,
static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend *fe)
{
struct dtv_frontend_properties *p = &fe->dtv_property_cache;
struct ttusbdecfe_state *state = fe->demodulator_priv;
u8 b[] = { 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
__be32 freq;
__be32 sym_rate;
__be32 band;
__be32 lnb_voltage;
freq = htonl(p->frequency +
(state->hi_band ? LOF_HI : LOF_LO));
memcpy(&b[4], &freq, sizeof(u32));
sym_rate = htonl(p->symbol_rate);
memcpy(&b[12], &sym_rate, sizeof(u32));
band = htonl(state->hi_band ? LOF_HI : LOF_LO);
memcpy(&b[24], &band, sizeof(u32));
lnb_voltage = htonl(state->voltage);
memcpy(&b[28], &lnb_voltage, sizeof(u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *cmd)
{
struct ttusbdecfe_state *state = fe->demodulator_priv;
u8 b[] = { 0x00, 0xff, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00 };
if (cmd->msg_len > sizeof(b) - 4)
return -EINVAL;
memcpy(&b[4], cmd->msg, cmd->msg_len);
state->config->send_command(fe, 0x72,
sizeof(b) - (6 - cmd->msg_len), b,
- NULL, NULL);
+ NULL, NULL, 0);
return 0;
}
static int ttusbdecfe_dvbs_set_tone(struct dvb_frontend *fe,
enum fe_sec_tone_mode tone)
{
struct ttusbdecfe_state *state = fe->demodulator_priv;
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.h b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
index 73828bb22..96600ad4c 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.h
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
@@ -7,18 +7,19 @@
#ifndef TTUSBDECFE_H
#define TTUSBDECFE_H
#include <linux/dvb/frontend.h>
struct ttusbdecfe_config
{
int (*send_command)(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[]);
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len);
};
extern struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config);
extern struct dvb_frontend* ttusbdecfe_dvbt_attach(const struct ttusbdecfe_config* config);
#endif // TTUSBDECFE_H
]
|
| 218/4 |
2026/08/17 21:44 |
llm |
patch-formatter |
0m
Model:
Tokens:
input: 33836
output: 138
thoughts: 415
Thoughts: **My Immediate Assessment and Corrective Action Plan**
Alright, I've got a clear understanding of the situation now. Time to roll up my sleeves and address these issues head-on, using `codeeditor`, of course. This looks like straightforward cleanup. Let's start with the first file, `drivers/media/usb/ttusb-dec/ttusb_dec.c`.
First on the list: an indentation problem in `ttusb_dec_set_interface`. It's a simple fix, just needs the case statement properly indented. Easy peasy, should take seconds to rectify.
Then, there's a cosmetic spacing issue on line 1241. A missing space; `ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL,0);` needs to become `ttusb_dec_send_command(dec, 0xb0, sizeof(b), b, NULL, NULL, 0);`. Again, trivial.
Finally, the function call spanning lines 1622-1628 is a bit unwieldy. We need to wrap that call for improved readability and maintainability. `return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result, cmd_result_len);` to be reformatted as:
```c
return ttusb_dec_send_command(dec, command, param_length, params,
result_length, cmd_result,
cmd_result_len);
```
Let's get this `codeeditor` fired up and make these changes. Starting with `ttusb_dec.c` and addressing the case indentation issue.
|
| 219/4 |
2026/08/17 21:44 |
tool |
codeeditor |
0m
Args: map[CurrentCode: case TTUSB_DEC_INTERFACE_IN:
result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
b, NULL, NULL, 0); NewCode: case TTUSB_DEC_INTERFACE_IN:
result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
b, NULL, NULL, 0); SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 220/4 |
2026/08/17 21:44 |
llm |
patch-formatter |
0m
Model:
Tokens:
input: 34773
output: 118
thoughts: 21
Thoughts: Here's my summary, as though I'm thinking it:
**Minor Code Clean-up in `ttusb_dec.c`**
Right, quick note to self: line 1241 in `ttusb_dec.c`. The code's solid, functionality's fine, but I'm just spotting a small, nitpicky style issue. I need to add a space after the comma on that line. That's all. Keep the code consistent. Done. Next!
|
| 221/4 |
2026/08/17 21:44 |
tool |
codeeditor |
0m
Args: map[CurrentCode: /* enable irq pipe */
ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL,0); NewCode: /* enable irq pipe */
ttusb_dec_send_command(dec, 0xb0, sizeof(b), b, NULL, NULL, 0); SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 222/4 |
2026/08/17 21:44 |
llm |
patch-formatter |
0m
Model:
Tokens:
input: 35027
output: 282
thoughts: 26
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm deep in the weeds of `ttusb_dec.c` and a total expert:
**Reflecting on the `fe_send_command` Modification**
Alright, so the next thing on my plate is in `ttusb_dec.c`, line 1627. Looks like I need to revisit the wrapping of the `fe_send_command` function. I'm probably thinking about some potential edge case I missed, a race condition, or perhaps a buffer overflow scenario. I'm likely concerned with the robustness of the error handling around that command. Was there a specific issue reported? Did a recent test highlight a problem? Or am I proactively addressing a potential vulnerability I spotted during a code review or a refactoring effort? Knowing this area of the code so well, the specifics of the wrap are probably top of mind - is it a mutex protection, a timeout, or maybe some form of error checking after the call? I'll need to carefully consider how this change will impact the overall flow of the decoding process and its interaction with the frontend. Let's dig in.
|
| 223/4 |
2026/08/17 21:44 |
tool |
codeeditor |
0m
Args: map[CurrentCode:static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len)
{
struct ttusb_dec* dec = fe->dvb->priv;
return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result, cmd_result_len);
} NewCode:static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len)
{
struct ttusb_dec* dec = fe->dvb->priv;
return ttusb_dec_send_command(dec, command, param_length, params,
result_length, cmd_result,
cmd_result_len);
} SourceFile:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results:
|
| 224/4 |
2026/08/17 21:44 |
llm |
patch-formatter |
0m
Model:
Tokens:
input: 35585
output: 44
thoughts: 112
Thoughts: **Analyzing the TTUSB-DEC Driver**
Okay, let's dive into this `ttusbdecfe.c` file, specifically within the `drivers/media/usb/ttusb-dec` directory. I'm seeing this `send_command` call and I need to understand it better:
`ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result, sizeof(result));`
I'm zeroing in on this function call, figuring it's the heart of the communication with the front-end device. Looking at lines 40-52 of the code file. I need to refresh the function call parameters as a reminder:
* `fe`: I assume this is a pointer to the front-end device structure.
* `0x73`: This looks like a command code. I'll need to figure out what that specific code does.
* `sizeof(b)` and `b`: These likely relate to the outgoing command data. `b` is probably a buffer.
* `&len` and `result`: Here, I see the expected length of the result (likely an output parameter) and the actual result buffer.
* `sizeof(result)`: And, of course, the size of the result buffer.
Now, I'll review lines 40-52 to get a better handle on the context of this function call. I need to understand the data structures and how this command is being used within the larger scope of the driver. I need to understand how the command is being used.
|
| 225/4 |
2026/08/17 21:44 |
tool |
read-file |
0m
Args: map[File:drivers/media/usb/ttusb-dec/ttusbdecfe.c FirstLine:40 LineCount:15]
Results: map[Contents: 40: u8 b[] = { 0x00, 0x00, 0x00, 0x00,
41: 0x00, 0x00, 0x00, 0x00 };
42: u8 result[4];
43: int len, ret;
44:
45: *status=0;
46:
47: ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
48: if(ret)
49: return ret;
50:
51: if(len != 4) {
52: printk(KERN_ERR "%s: unexpected reply\n", __func__);
53: return -EIO;
54: }
]
|
| 226/4 |
2026/08/17 21:44 |
llm |
patch-formatter |
0m
Model:
Tokens:
input: 36327
output: 117
thoughts: 838
Thoughts: **Analyzing and Refining Code Alignment in `ttusbdecfe.c`**
Okay, let's dive into this snippet of `ttusbdecfe.c`. I need to ensure the alignment is consistent and conforms to the Linux kernel coding style. Specifically, I'm focusing on line 47, which calls `state->config->send_command()`. I see that the original line is:
` ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result,`
` sizeof(result));`
First, I need to make a minor edit for formatting:
`ret = state->config->send_command(fe, 0x73, sizeof(b), b, &len, result,`
` sizeof(result));`
Now, for the alignment! I need to nail down whether it's tabs, spaces, or a combination. The key is adhering to the kernel's coding standards. I quickly check lines 45-48. This confirms the context.
I need to calculate the alignment precisely. The length of `"ret = state->config->send_command("` is 33 characters, after the tab. After one tab (8 spaces), that puts me at column 41. I need to get the `sizeof(result));` under the parenthesis. The line `\tret = state->config->send_command(` is 41 characters. To align it, it would be 5 tabs + 1 space from the beginning of the line. Also, I could use 4 tabs and 9 spaces (32 + 9 = 41).
I recall the kernel coding style; it's quite specific about this. Outside of comments, spaces are *never* used for indentation and when wrapping function calls. We should use tabs up to the tab stop before the parenthesis, then spaces.
So, I need to calculate: Starting with a tab (8 spaces). Then 33 characters. That's a total of 41 spaces. Let's see... 41 / 8 is 5 tabs with a remainder of 1. So, it should be: `\t\t\t\t\t`. Then after the fifth tab, it's 1 space. No, this can't be correct, let's see what `checkpatch` thinks!
I'll check both methods and verify the result using `checkpatch`! Finally, I'll apply the edit to `ttusbdecfe.c`.
|
| 227/4 |
2026/08/17 21:44 |
tool |
codeeditor |
0m
Args: map[CurrentCode: ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result,
sizeof(result)); NewCode: ret = state->config->send_command(fe, 0x73, sizeof(b), b, &len, result,
sizeof(result)); SourceFile:drivers/media/usb/ttusb-dec/ttusbdecfe.c]
Results:
|
| 228/4 |
2026/08/17 21:44 |
llm |
patch-formatter |
0m
Model:
Tokens:
input: 37843
output: 9
thoughts: 20
Thoughts: Okay, let's see. I've been working diligently on this, but before I consider it truly done, I need to make absolutely sure everything is up to snuff. Let's fire up `checkpatch`. That's the go-to tool for finding those subtle, but potentially critical, coding style issues, remnants of debugging statements, or any other overlooked imperfections that might have slipped through the cracks. It's time to run it and ensure I've dotted all the i's and crossed all the t's before submitting this. I want this to be as flawless as possible.
|
| 229/4 |
2026/08/17 21:44 |
tool |
checkpatch |
0m
Results: map[Output:total: 0 errors, 0 warnings, 182 lines checked
Your patch has no obvious style problems and is ready for submission.
]
|
| 230/4 |
2026/08/17 21:44 |
llm |
patch-formatter |
0m
Model:
Tokens:
input: 38039
output: 15
thoughts: 72
Thoughts: **Patch Review Confirmed – Ready for Deep Dive**
Okay, so `checkpatch` is giving me the green light – no errors, no warnings, a clean bill of health across 182 lines. That's a great start, and I'm not surprised. I'm usually pretty meticulous about these things. The "ready for submission" message is promising, but I'm not going to get complacent. This is where the real work begins.
Now, let's pull up that `patch-diff`. I need to verify that this entire change is clean, that every line is precisely what it needs to be. I want to be *absolutely* certain that the code logic remains not just intact, but also that it’s demonstrably improved, optimized where applicable, and certainly doesn't introduce any regressions or subtle bugs. And, of course, the code needs to *look* great. Readability and maintainability are paramount. I need to give this change a thorough inspection.
|
| 231/4 |
2026/08/17 21:44 |
tool |
patch-diff |
0m
Args:
Results: map[Output:diff --git a/drivers/media/usb/ttusb-dec/ttusb_dec.c b/drivers/media/usb/ttusb-dec/ttusb_dec.c
index 825a38759..b54b7b4bb 100644
--- a/drivers/media/usb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/usb/ttusb-dec/ttusb_dec.c
@@ -307,107 +307,127 @@ static u16 crc16(u16 crc, const u8 *buf, size_t len)
crc ^= *buf++;
crc ^= (u8)crc >> 4;
tmp = (u8)crc;
crc ^= (tmp ^ (tmp << 1)) << 4;
}
return crc;
}
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
int result, actual_len;
u8 *b;
dprintk("%s\n", __func__);
+ if (param_length > COMMAND_PACKET_SIZE)
+ return -EINVAL;
+
b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
if (!b)
return -ENOMEM;
result = mutex_lock_interruptible(&dec->usb_mutex);
if (result) {
printk("%s: Failed to lock usb mutex.\n", __func__);
goto err_free;
}
b[0] = 0xaa;
b[1] = ++dec->trans_count;
b[2] = command;
b[3] = param_length;
if (params)
memcpy(&b[4], params, param_length);
if (debug) {
printk(KERN_DEBUG "%s: command: %*ph\n",
__func__, param_length, b);
}
result = usb_bulk_msg(dec->udev, dec->command_pipe, b,
COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
if (result) {
printk("%s: command bulk message failed: error %d\n",
__func__, result);
goto err_mutex_unlock;
}
result = usb_bulk_msg(dec->udev, dec->result_pipe, b,
COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
if (result) {
printk("%s: result bulk message failed: error %d\n",
__func__, result);
goto err_mutex_unlock;
} else {
if (debug) {
printk(KERN_DEBUG "%s: result: %*ph\n",
__func__, actual_len, b);
}
+ if (actual_len < 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
+ if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
if (result_length)
*result_length = b[3];
- if (cmd_result && b[3] > 0)
+ if (cmd_result && b[3] > 0) {
+ if (b[3] > cmd_result_len) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
memcpy(cmd_result, &b[4], b[3]);
+ }
}
err_mutex_unlock:
mutex_unlock(&dec->usb_mutex);
err_free:
kfree(b);
return result;
}
static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
unsigned int *model, unsigned int *version)
{
u8 c[COMMAND_PACKET_SIZE];
int c_length;
int result;
__be32 tmp;
dprintk("%s\n", __func__);
- result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
+ result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c,
+ sizeof(c));
if (result)
return result;
if (c_length >= 0x0c) {
if (mode != NULL) {
memcpy(&tmp, c, 4);
*mode = ntohl(tmp);
}
if (model != NULL) {
memcpy(&tmp, &c[4], 4);
*model = ntohl(tmp);
}
if (version != NULL) {
memcpy(&tmp, &c[8], 4);
*version = ntohl(tmp);
}
return 0;
} else {
return -ENOENT;
}
}
@@ -435,27 +455,27 @@ static int ttusb_dec_video_pes2ts_cb(void *priv, unsigned char *data)
static void ttusb_dec_set_pids(struct ttusb_dec *dec)
{
u8 b[] = { 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff };
__be16 pcr = htons(dec->pid[DMX_PES_PCR]);
__be16 audio = htons(dec->pid[DMX_PES_AUDIO]);
__be16 video = htons(dec->pid[DMX_PES_VIDEO]);
dprintk("%s\n", __func__);
memcpy(&b[0], &pcr, 2);
memcpy(&b[2], &audio, 2);
memcpy(&b[4], &video, 2);
- ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL, 0);
dvb_filter_pes2ts_init(&dec->a_pes2ts, dec->pid[DMX_PES_AUDIO],
ttusb_dec_audio_pes2ts_cb, dec);
dvb_filter_pes2ts_init(&dec->v_pes2ts, dec->pid[DMX_PES_VIDEO],
ttusb_dec_video_pes2ts_cb, dec);
dec->v_pes_length = 0;
dec->v_pes_postbytes = 0;
}
static void ttusb_dec_process_pva(struct ttusb_dec *dec, u8 *pva, int length)
@@ -888,35 +908,35 @@ static void ttusb_dec_stop_iso_xfer(struct ttusb_dec *dec)
/* Setting the interface of the DEC tends to take down the USB communications
* for a short period, so it's important not to call this function just before
* trying to talk to it.
*/
static int ttusb_dec_set_interface(struct ttusb_dec *dec,
enum ttusb_dec_interface interface)
{
int result = 0;
u8 b[] = { 0x05 };
if (interface != dec->interface) {
switch (interface) {
case TTUSB_DEC_INTERFACE_INITIAL:
result = usb_set_interface(dec->udev, 0, 0);
break;
case TTUSB_DEC_INTERFACE_IN:
result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
- b, NULL, NULL);
+ b, NULL, NULL, 0);
if (result)
return result;
result = usb_set_interface(dec->udev, 0, 8);
break;
case TTUSB_DEC_INTERFACE_OUT:
result = usb_set_interface(dec->udev, 0, 1);
break;
}
if (result)
return result;
dec->interface = interface;
}
return 0;
}
@@ -964,121 +984,121 @@ static int ttusb_dec_start_iso_xfer(struct ttusb_dec *dec)
static int ttusb_dec_start_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
{
struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
struct ttusb_dec *dec = dvbdmx->priv;
u8 b0[] = { 0x05 };
int result = 0;
dprintk("%s\n", __func__);
dprintk(" ts_type:");
if (dvbdmxfeed->ts_type & TS_DECODER)
dprintk(" TS_DECODER");
if (dvbdmxfeed->ts_type & TS_PACKET)
dprintk(" TS_PACKET");
if (dvbdmxfeed->ts_type & TS_PAYLOAD_ONLY)
dprintk(" TS_PAYLOAD_ONLY");
dprintk("\n");
switch (dvbdmxfeed->pes_type) {
case DMX_PES_VIDEO:
dprintk(" pes_type: DMX_PES_VIDEO\n");
dec->pid[DMX_PES_PCR] = dvbdmxfeed->pid;
dec->pid[DMX_PES_VIDEO] = dvbdmxfeed->pid;
dec->video_filter = dvbdmxfeed->filter;
ttusb_dec_set_pids(dec);
break;
case DMX_PES_AUDIO:
dprintk(" pes_type: DMX_PES_AUDIO\n");
dec->pid[DMX_PES_AUDIO] = dvbdmxfeed->pid;
dec->audio_filter = dvbdmxfeed->filter;
ttusb_dec_set_pids(dec);
break;
case DMX_PES_TELETEXT:
dec->pid[DMX_PES_TELETEXT] = dvbdmxfeed->pid;
dprintk(" pes_type: DMX_PES_TELETEXT(not supported)\n");
return -ENOSYS;
case DMX_PES_PCR:
dprintk(" pes_type: DMX_PES_PCR\n");
dec->pid[DMX_PES_PCR] = dvbdmxfeed->pid;
ttusb_dec_set_pids(dec);
break;
case DMX_PES_OTHER:
dprintk(" pes_type: DMX_PES_OTHER(not supported)\n");
return -ENOSYS;
default:
dprintk(" pes_type: unknown (%d)\n", dvbdmxfeed->pes_type);
return -EINVAL;
}
- result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL, 0);
if (result)
return result;
dec->pva_stream_count++;
return ttusb_dec_start_iso_xfer(dec);
}
static int ttusb_dec_start_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
{
struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
u8 b0[] = { 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0xff, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00 };
__be16 pid;
u8 c[COMMAND_PACKET_SIZE];
int c_length;
int result;
struct filter_info *finfo;
unsigned long flags;
u8 x = 1;
dprintk("%s\n", __func__);
pid = htons(dvbdmxfeed->pid);
memcpy(&b0[0], &pid, 2);
memcpy(&b0[4], &x, 1);
memcpy(&b0[5], &dvbdmxfeed->filter->filter.filter_value[0], 1);
result = ttusb_dec_send_command(dec, 0x60, sizeof(b0), b0,
- &c_length, c);
+ &c_length, c, sizeof(c));
if (!result) {
if (c_length == 2) {
if (!(finfo = kmalloc_obj(struct filter_info, GFP_ATOMIC)))
return -ENOMEM;
finfo->stream_id = c[1];
finfo->filter = dvbdmxfeed->filter;
spin_lock_irqsave(&dec->filter_info_list_lock, flags);
list_add_tail(&finfo->filter_info_list,
&dec->filter_info_list);
spin_unlock_irqrestore(&dec->filter_info_list_lock,
flags);
dvbdmxfeed->priv = finfo;
dec->filter_stream_count++;
return ttusb_dec_start_iso_xfer(dec);
}
return -EAGAIN;
} else
return result;
}
@@ -1107,42 +1127,42 @@ static int ttusb_dec_start_feed(struct dvb_demux_feed *dvbdmxfeed)
return -EINVAL;
}
}
static int ttusb_dec_stop_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
{
struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
u8 b0[] = { 0x00 };
- ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL, 0);
dec->pva_stream_count--;
ttusb_dec_stop_iso_xfer(dec);
return 0;
}
static int ttusb_dec_stop_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
{
struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
u8 b0[] = { 0x00, 0x00 };
struct filter_info *finfo = dvbdmxfeed->priv;
unsigned long flags;
b0[1] = finfo->stream_id;
spin_lock_irqsave(&dec->filter_info_list_lock, flags);
list_del(&finfo->filter_info_list);
spin_unlock_irqrestore(&dec->filter_info_list_lock, flags);
kfree(finfo);
- ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL, 0);
dec->filter_stream_count--;
ttusb_dec_stop_iso_xfer(dec);
return 0;
}
static int ttusb_dec_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
{
@@ -1207,45 +1227,45 @@ static void ttusb_dec_init_bh_work(struct ttusb_dec *dec)
static int ttusb_init_rc( struct ttusb_dec *dec)
{
struct input_dev *input_dev;
u8 b[] = { 0x00, 0x01 };
int i;
int err;
usb_make_path(dec->udev, dec->rc_phys, sizeof(dec->rc_phys));
strlcat(dec->rc_phys, "/input0", sizeof(dec->rc_phys));
input_dev = input_allocate_device();
if (!input_dev)
return -ENOMEM;
input_dev->name = "ttusb_dec remote control";
input_dev->phys = dec->rc_phys;
input_dev->evbit[0] = BIT_MASK(EV_KEY);
input_dev->keycodesize = sizeof(u16);
input_dev->keycodemax = 0x1a;
input_dev->keycode = rc_keys;
for (i = 0; i < ARRAY_SIZE(rc_keys); i++)
set_bit(rc_keys[i], input_dev->keybit);
err = input_register_device(input_dev);
if (err) {
input_free_device(input_dev);
return err;
}
dec->rc_input_dev = input_dev;
if (usb_submit_urb(dec->irq_urb, GFP_KERNEL))
printk("%s: usb_submit_urb failed\n",__func__);
/* enable irq pipe */
- ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
+ ttusb_dec_send_command(dec, 0xb0, sizeof(b), b, NULL, NULL, 0);
return 0;
}
static void ttusb_dec_init_v_pes(struct ttusb_dec *dec)
{
dprintk("%s\n", __func__);
dec->v_pes[0] = 0x00;
dec->v_pes[1] = 0x00;
@@ -1298,111 +1318,111 @@ static int ttusb_dec_init_usb(struct ttusb_dec *dec)
static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
{
int i, j, actual_len, result, size, trans_count;
u8 b0[] = { 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x61, 0x00 };
u8 b1[] = { 0x61 };
u8 *b;
char idstring[21];
const u8 *firmware = NULL;
size_t firmware_size = 0;
u16 firmware_csum = 0;
__be16 firmware_csum_ns;
__be32 firmware_size_nl;
u32 crc32_csum, crc32_check;
__be32 tmp;
const struct firmware *fw_entry = NULL;
dprintk("%s\n", __func__);
result = request_firmware(&fw_entry, dec->firmware_name, &dec->udev->dev);
if (result) {
printk(KERN_ERR "%s: Firmware (%s) unavailable.\n",
__func__, dec->firmware_name);
return result;
}
firmware = fw_entry->data;
firmware_size = fw_entry->size;
if (firmware_size < 60) {
printk("%s: firmware size too small for DSP code (%zu < 60).\n",
__func__, firmware_size);
release_firmware(fw_entry);
return -ENOENT;
}
/* a 32 bit checksum over the first 56 bytes of the DSP Code is stored
at offset 56 of file, so use it to check if the firmware file is
valid. */
crc32_csum = crc32(~0L, firmware, 56) ^ ~0L;
memcpy(&tmp, &firmware[56], 4);
crc32_check = ntohl(tmp);
if (crc32_csum != crc32_check) {
printk("%s: crc32 check of DSP code failed (calculated 0x%08x != 0x%08x in file), file invalid.\n",
__func__, crc32_csum, crc32_check);
release_firmware(fw_entry);
return -ENOENT;
}
memcpy(idstring, &firmware[36], 20);
idstring[20] = '\0';
printk(KERN_INFO "ttusb_dec: found DSP code \"%s\".\n", idstring);
firmware_size_nl = htonl(firmware_size);
memcpy(b0, &firmware_size_nl, 4);
firmware_csum = crc16(~0, firmware, firmware_size) ^ ~0;
firmware_csum_ns = htons(firmware_csum);
memcpy(&b0[6], &firmware_csum_ns, 2);
- result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL, 0);
if (result) {
release_firmware(fw_entry);
return result;
}
trans_count = 0;
j = 0;
b = kmalloc(ARM_PACKET_SIZE, GFP_KERNEL);
if (b == NULL) {
release_firmware(fw_entry);
return -ENOMEM;
}
for (i = 0; i < firmware_size; i += COMMAND_PACKET_SIZE) {
size = firmware_size - i;
if (size > COMMAND_PACKET_SIZE)
size = COMMAND_PACKET_SIZE;
b[j + 0] = 0xaa;
b[j + 1] = trans_count++;
b[j + 2] = 0xf0;
b[j + 3] = size;
memcpy(&b[j + 4], &firmware[i], size);
j += COMMAND_PACKET_SIZE + 4;
if (j >= ARM_PACKET_SIZE) {
result = usb_bulk_msg(dec->udev, dec->command_pipe, b,
ARM_PACKET_SIZE, &actual_len,
100);
j = 0;
} else if (size < COMMAND_PACKET_SIZE) {
result = usb_bulk_msg(dec->udev, dec->command_pipe, b,
j - COMMAND_PACKET_SIZE + size,
&actual_len, 100);
}
}
- result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL, 0);
release_firmware(fw_entry);
kfree(b);
return result;
}
static int ttusb_dec_init_stb(struct ttusb_dec *dec)
{
int result;
@@ -1614,24 +1634,27 @@ static void ttusb_dec_exit_filters(struct ttusb_dec *dec)
while ((item = dec->filter_info_list.next) != &dec->filter_info_list) {
finfo = list_entry(item, struct filter_info, filter_info_list);
list_del(&finfo->filter_info_list);
kfree(finfo);
}
}
static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
struct ttusb_dec* dec = fe->dvb->priv;
- return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
+ return ttusb_dec_send_command(dec, command, param_length, params,
+ result_length, cmd_result,
+ cmd_result_len);
}
static const struct ttusbdecfe_config fe_config = {
.send_command = fe_send_command
};
static int ttusb_dec_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
struct usb_device *udev;
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.c b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
index 215221370..b013d6dfc 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.c
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
@@ -36,39 +36,40 @@ static int ttusbdecfe_dvbs_read_status(struct dvb_frontend *fe,
static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
enum fe_status *status)
{
struct ttusbdecfe_state* state = fe->demodulator_priv;
u8 b[] = { 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
u8 result[4];
int len, ret;
*status=0;
- ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
+ ret = state->config->send_command(fe, 0x73, sizeof(b), b, &len, result,
+ sizeof(result));
if(ret)
return ret;
if(len != 4) {
printk(KERN_ERR "%s: unexpected reply\n", __func__);
return -EIO;
}
switch(result[3]) {
case 1: /* not tuned yet */
case 2: /* no signal/no lock*/
break;
case 3: /* signal found and locked*/
*status = FE_HAS_SIGNAL | FE_HAS_VITERBI |
FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK;
break;
case 4:
*status = FE_TIMEDOUT;
break;
default:
pr_info("%s: returned unknown value: %d\n",
__func__, result[3]);
return -EIO;
}
return 0;
}
@@ -76,23 +77,23 @@ static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend *fe)
{
struct dtv_frontend_properties *p = &fe->dtv_property_cache;
struct ttusbdecfe_state *state = fe->demodulator_priv;
u8 b[] = { 0x00, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0xff,
0x00, 0x00, 0x00, 0xff };
__be32 freq = htonl(p->frequency / 1000);
memcpy(&b[4], &freq, sizeof (u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
static int ttusbdecfe_dvbt_get_tune_settings(struct dvb_frontend* fe,
struct dvb_frontend_tune_settings* fesettings)
{
fesettings->min_delay_ms = 1500;
/* Drift compensation makes no sense for DVB-T */
fesettings->step_size = 0;
@@ -103,60 +104,60 @@ static int ttusbdecfe_dvbt_get_tune_settings(struct dvb_frontend* fe,
static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend *fe)
{
struct dtv_frontend_properties *p = &fe->dtv_property_cache;
struct ttusbdecfe_state *state = fe->demodulator_priv;
u8 b[] = { 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 };
__be32 freq;
__be32 sym_rate;
__be32 band;
__be32 lnb_voltage;
freq = htonl(p->frequency +
(state->hi_band ? LOF_HI : LOF_LO));
memcpy(&b[4], &freq, sizeof(u32));
sym_rate = htonl(p->symbol_rate);
memcpy(&b[12], &sym_rate, sizeof(u32));
band = htonl(state->hi_band ? LOF_HI : LOF_LO);
memcpy(&b[24], &band, sizeof(u32));
lnb_voltage = htonl(state->voltage);
memcpy(&b[28], &lnb_voltage, sizeof(u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *cmd)
{
struct ttusbdecfe_state *state = fe->demodulator_priv;
u8 b[] = { 0x00, 0xff, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00 };
if (cmd->msg_len > sizeof(b) - 4)
return -EINVAL;
memcpy(&b[4], cmd->msg, cmd->msg_len);
state->config->send_command(fe, 0x72,
sizeof(b) - (6 - cmd->msg_len), b,
- NULL, NULL);
+ NULL, NULL, 0);
return 0;
}
static int ttusbdecfe_dvbs_set_tone(struct dvb_frontend *fe,
enum fe_sec_tone_mode tone)
{
struct ttusbdecfe_state *state = fe->demodulator_priv;
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.h b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
index 73828bb22..96600ad4c 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.h
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
@@ -7,18 +7,19 @@
#ifndef TTUSBDECFE_H
#define TTUSBDECFE_H
#include <linux/dvb/frontend.h>
struct ttusbdecfe_config
{
int (*send_command)(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[]);
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len);
};
extern struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config);
extern struct dvb_frontend* ttusbdecfe_dvbt_attach(const struct ttusbdecfe_config* config);
#endif // TTUSBDECFE_H
]
|
| 232/4 |
2026/08/17 21:44 |
llm |
patch-formatter |
0m
Model:
Tokens:
input: 47685
output: 150
thoughts: 35
Thoughts: Here's my take on the situation:
**Ready to Present**
Okay, so I've meticulously examined the patch diff – everything's looking pristine. It's clean, the changes are well-defined. I've run `checkpatch`, and the output is flawless; no errors, no warnings, which is exactly what I was hoping for. Most importantly, I've confirmed that the logic remains intact, precisely as intended. With all of that confirmed, I'm confident in presenting this result now. We're good to go.
|
| 233/3 |
2026/08/17 21:44 |
action |
test-patch-inplace |
13m
Results: map[PatchDiff:diff --git a/drivers/media/usb/ttusb-dec/ttusb_dec.c b/drivers/media/usb/ttusb-dec/ttusb_dec.c
index 825a38759..b54b7b4bb 100644
--- a/drivers/media/usb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/usb/ttusb-dec/ttusb_dec.c
@@ -314,13 +314,17 @@ static u16 crc16(u16 crc, const u8 *buf, size_t len)
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
int result, actual_len;
u8 *b;
dprintk("%s\n", __func__);
+ if (param_length > COMMAND_PACKET_SIZE)
+ return -EINVAL;
+
b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
if (!b)
return -ENOMEM;
@@ -366,10 +370,25 @@ static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
__func__, actual_len, b);
}
+ if (actual_len < 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
+ if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
if (result_length)
*result_length = b[3];
- if (cmd_result && b[3] > 0)
+ if (cmd_result && b[3] > 0) {
+ if (b[3] > cmd_result_len) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
memcpy(cmd_result, &b[4], b[3]);
+ }
}
err_mutex_unlock:
@@ -389,7 +408,8 @@ static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
dprintk("%s\n", __func__);
- result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
+ result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c,
+ sizeof(c));
if (result)
return result;
@@ -448,7 +468,7 @@ static void ttusb_dec_set_pids(struct ttusb_dec *dec)
memcpy(&b[2], &audio, 2);
memcpy(&b[4], &video, 2);
- ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL, 0);
dvb_filter_pes2ts_init(&dec->a_pes2ts, dec->pid[DMX_PES_AUDIO],
ttusb_dec_audio_pes2ts_cb, dec);
@@ -902,7 +922,7 @@ static int ttusb_dec_set_interface(struct ttusb_dec *dec,
break;
case TTUSB_DEC_INTERFACE_IN:
result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
- b, NULL, NULL);
+ b, NULL, NULL, 0);
if (result)
return result;
result = usb_set_interface(dec->udev, 0, 8);
@@ -1021,7 +1041,7 @@ static int ttusb_dec_start_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
}
- result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL, 0);
if (result)
return result;
@@ -1056,7 +1076,7 @@ static int ttusb_dec_start_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
memcpy(&b0[5], &dvbdmxfeed->filter->filter.filter_value[0], 1);
result = ttusb_dec_send_command(dec, 0x60, sizeof(b0), b0,
- &c_length, c);
+ &c_length, c, sizeof(c));
if (!result) {
if (c_length == 2) {
@@ -1114,7 +1134,7 @@ static int ttusb_dec_stop_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
u8 b0[] = { 0x00 };
- ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL, 0);
dec->pva_stream_count--;
@@ -1135,7 +1155,7 @@ static int ttusb_dec_stop_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
list_del(&finfo->filter_info_list);
spin_unlock_irqrestore(&dec->filter_info_list_lock, flags);
kfree(finfo);
- ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL, 0);
dec->filter_stream_count--;
@@ -1238,7 +1258,7 @@ static int ttusb_init_rc( struct ttusb_dec *dec)
if (usb_submit_urb(dec->irq_urb, GFP_KERNEL))
printk("%s: usb_submit_urb failed\n",__func__);
/* enable irq pipe */
- ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
+ ttusb_dec_send_command(dec, 0xb0, sizeof(b), b, NULL, NULL, 0);
return 0;
}
@@ -1354,7 +1374,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
firmware_csum_ns = htons(firmware_csum);
memcpy(&b0[6], &firmware_csum_ns, 2);
- result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL, 0);
if (result) {
release_firmware(fw_entry);
@@ -1395,7 +1415,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
}
}
- result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL, 0);
release_firmware(fw_entry);
kfree(b);
@@ -1621,10 +1641,13 @@ static void ttusb_dec_exit_filters(struct ttusb_dec *dec)
static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
struct ttusb_dec* dec = fe->dvb->priv;
- return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
+ return ttusb_dec_send_command(dec, command, param_length, params,
+ result_length, cmd_result,
+ cmd_result_len);
}
static const struct ttusbdecfe_config fe_config = {
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.c b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
index 215221370..b013d6dfc 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.c
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
@@ -44,7 +44,8 @@ static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
*status=0;
- ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
+ ret = state->config->send_command(fe, 0x73, sizeof(b), b, &len, result,
+ sizeof(result));
if(ret)
return ret;
@@ -85,7 +86,7 @@ static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend *fe)
__be32 freq = htonl(p->frequency / 1000);
memcpy(&b[4], &freq, sizeof (u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
@@ -130,7 +131,7 @@ static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend *fe)
lnb_voltage = htonl(state->voltage);
memcpy(&b[28], &lnb_voltage, sizeof(u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
@@ -149,7 +150,7 @@ static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struc
state->config->send_command(fe, 0x72,
sizeof(b) - (6 - cmd->msg_len), b,
- NULL, NULL);
+ NULL, NULL, 0);
return 0;
}
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.h b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
index 73828bb22..96600ad4c 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.h
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
@@ -14,7 +14,8 @@ struct ttusbdecfe_config
{
int (*send_command)(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[]);
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len);
};
extern struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config);
TestError:]
|
| 234/3 |
2026/08/17 21:58 |
action |
run-checkpatch |
0m
Results: map[CheckpatchOutput:total: 0 errors, 0 warnings, 182 lines checked
Your patch has no obvious style problems and is ready for submission.
NeedRefinement:false]
|
| 235/1 |
2026/08/17 21:58 |
agent |
fixes-finder |
11m
Model:
Results: map[FixesHash:1da177e4c3f41524e886b7f1b8a0c1fc7321cac2]
Instruction:
You are an experienced Linux kernel developer tasked with identifying the commit
that introduced the bug being fixed. Identifying the correct buggy commit is crucial
for proper kernel maintenance (backporting to stable trees, etc.).
Your investigation strategy:
1. Examine the patch that fixes the bug. Use git tools (like git-log or git-blame)
to trace the history of the lines or functions modified by the patch.
2. Analyze the stack trace in the crash report. Identify the key files and functions
involved in the crash and investigate their history to see when the problematic
logic was introduced.
3. Compare the bug explanation with the commit history to find the point where
the described logic error first appeared.
A bug is typically introduced when a piece of code is first written, or when
a refactoring changed its logic in a way that introduced the bug.
Trace the history of relevant symbols or find when specific code patterns were introduced/removed.
You must provide exactly one bug-introducing commit hash.
If you are unable to confidently determine the bug-introducing commit after investigation,
return an empty string rather than guessing.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The crash is:
usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
------------[ cut here ]------------
memcpy: detected buffer overflow: 75 byte read of buffer size 60
WARNING: lib/string_helpers.c:1037 at __fortify_report+0xa0/0xb8 lib/string_helpers.c:1036, CPU#0: kworker/0:4/4798
Modules linked in:
CPU: 0 UID: 0 PID: 4798 Comm: kworker/0:4 Not tainted syzkaller #1 PREEMPT
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/07/2026
Workqueue: usb_hub_wq hub_event
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : __fortify_report+0xa0/0xb8 lib/string_helpers.c:1036
lr : __fortify_report+0xa0/0xb8 lib/string_helpers.c:1036
sp : ffff800098516d20
x29: ffff800098516d20 x28: dfff800000000000 x27: ffff7000130a2db0
x26: 0000000000000000 x25: ffff0000d1862683 x24: ffff800098516ea0
x23: 000000000000004b x22: ffff800086d0a338 x21: 0000000000000000
x20: 000000000000004b x19: 000000000000003c x18: 1fffe00035ba8028
x17: 0000000000000003 x16: ffff800088ba7000 x15: ffff8000824ea6c8
x14: 0000000000000000 x13: 0000000000000001 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000002 x9 : 653dfa0a2f6c5200
x8 : 653dfa0a2f6c5200 x7 : ffff80008048e0c4 x6 : 0000000000000000
x5 : 0000000000000000 x4 : 0000000000000000 x3 : ffff8000802f8054
x2 : 0000000100000000 x1 : ffff0000c57d1d40 x0 : 0000000000000000
Call trace:
__fortify_report+0xa0/0xb8 lib/string_helpers.c:1036 (P)
__fortify_panic+0x10/0x14 lib/string_helpers.c:1043
fortify_memcpy_chk include/linux/fortify-string.h:549 [inline]
ttusb_dec_start_feed+0x0/0x10ac drivers/media/usb/ttusb-dec/ttusb_dec.c:372
ttusb_dec_get_stb_state drivers/media/usb/ttusb-dec/ttusb_dec.c:392 [inline]
ttusb_dec_init_stb drivers/media/usb/ttusb-dec/ttusb_dec.c:1413 [inline]
ttusb_dec_probe+0x724/0x1aa0 drivers/media/usb/ttusb-dec/ttusb_dec.c:1671
usb_probe_interface+0x308/0x788 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_set_configuration+0x1184/0x158c drivers/usb/core/message.c:2268
usb_generic_driver_probe+0x8c/0x148 drivers/usb/core/generic.c:250
usb_probe_device+0x114/0x2b0 drivers/usb/core/driver.c:291
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_new_device+0x9c4/0x11f8 drivers/usb/core/hub.c:2703
hub_port_connect drivers/usb/core/hub.c:5575 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5715 [inline]
port_event drivers/usb/core/hub.c:5879 [inline]
hub_event+0x1ef0/0x39fc drivers/usb/core/hub.c:5961
process_one_work kernel/workqueue.c:3322 [inline]
process_scheduled_works+0x788/0x10b8 kernel/workqueue.c:3405
worker_thread+0x798/0xbd0 kernel/workqueue.c:3486
kthread+0x304/0x3d4 kernel/kthread.c:436
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:842
irq event stamp: 16196
hardirqs last enabled at (16195): [<ffff8000868fc7b4>] irqentry_exit_to_kernel_mode_after_preempt include/linux/irq-entry-common.h:507 [inline]
hardirqs last enabled at (16195): [<ffff8000868fc7b4>] arm64_exit_to_kernel_mode+0x80/0x94 arch/arm64/kernel/entry-common.c:62
hardirqs last disabled at (16196): [<ffff8000868f86e0>] el1_brk64+0x20/0x54 arch/arm64/kernel/entry-common.c:425
softirqs last enabled at (16128): [<ffff80008030ff18>] softirq_handle_end kernel/softirq.c:468 [inline]
softirqs last enabled at (16128): [<ffff80008030ff18>] handle_softirqs+0xc28/0xd98 kernel/softirq.c:650
softirqs last disabled at (16119): [<ffff8000800204b0>] __do_softirq+0x14/0x20 kernel/softirq.c:656
---[ end trace 0000000000000000 ]---
------------[ cut here ]------------
kernel BUG at lib/string_helpers.c:1044!
Internal error: Oops - BUG: 00000000f2000800 [#1] SMP
Modules linked in:
CPU: 0 UID: 0 PID: 4798 Comm: kworker/0:4 Tainted: G W syzkaller #1 PREEMPT
Tainted: [W]=WARN
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/07/2026
Workqueue: usb_hub_wq hub_event
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : __fortify_panic+0x10/0x14 lib/string_helpers.c:1043
lr : __fortify_panic+0x10/0x14 lib/string_helpers.c:1043
sp : ffff800098516d50
x29: ffff800098516d50 x28: dfff800000000000 x27: ffff7000130a2db0
x26: 0000000000000000 x25: ffff0000d1862683 x24: ffff800098516ea0
x23: 000000000000004b x22: 000000000000004b x21: ffff0000d1862680
x20: 1fffe0001a30c4d0 x19: ffff0000c3014000 x18: 1fffe00035ba8028
x17: 0000000000000003 x16: ffff800088ba7000 x15: ffff8000824ea6c8
x14: 0000000000000000 x13: 0000000000000001 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000002 x9 : 653dfa0a2f6c5200
x8 : 653dfa0a2f6c5200 x7 : ffff80008048e0c4 x6 : 0000000000000000
x5 : 0000000000000000 x4 : 0000000000000000 x3 : ffff8000802f8054
x2 : 0000000100000000 x1 : ffff0000c57d1d40 x0 : 0000000000000000
Call trace:
__fortify_panic+0x10/0x14 lib/string_helpers.c:1043 (P)
fortify_memcpy_chk include/linux/fortify-string.h:549 [inline]
ttusb_dec_start_feed+0x0/0x10ac drivers/media/usb/ttusb-dec/ttusb_dec.c:372
ttusb_dec_get_stb_state drivers/media/usb/ttusb-dec/ttusb_dec.c:392 [inline]
ttusb_dec_init_stb drivers/media/usb/ttusb-dec/ttusb_dec.c:1413 [inline]
ttusb_dec_probe+0x724/0x1aa0 drivers/media/usb/ttusb-dec/ttusb_dec.c:1671
usb_probe_interface+0x308/0x788 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_set_configuration+0x1184/0x158c drivers/usb/core/message.c:2268
usb_generic_driver_probe+0x8c/0x148 drivers/usb/core/generic.c:250
usb_probe_device+0x114/0x2b0 drivers/usb/core/driver.c:291
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_new_device+0x9c4/0x11f8 drivers/usb/core/hub.c:2703
hub_port_connect drivers/usb/core/hub.c:5575 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5715 [inline]
port_event drivers/usb/core/hub.c:5879 [inline]
hub_event+0x1ef0/0x39fc drivers/usb/core/hub.c:5961
process_one_work kernel/workqueue.c:3322 [inline]
process_scheduled_works+0x788/0x10b8 kernel/workqueue.c:3405
worker_thread+0x798/0xbd0 kernel/workqueue.c:3486
kthread+0x304/0x3d4 kernel/kthread.c:436
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:842
Code: d503233f a9bf7bfd 910003fd 94619ee8 (d4210000)
---[ end trace 0000000000000000 ]---
The explanation of the root cause is:
The crash is caused by a buffer overflow (both an out-of-bounds read and an out-of-bounds write) in the `ttusb_dec_send_command()` function, triggered by a malicious or malfunctioning USB device returning an unexpectedly large payload length.
### Detailed Analysis
In `drivers/media/usb/ttusb-dec/ttusb_dec.c`, the `ttusb_dec_send_command()` function allocates a buffer `b` to send a command and receive the response via `usb_bulk_msg()`:
```c
b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
```
Here, `COMMAND_PACKET_SIZE` is defined as `0x3c` (60), so the allocated buffer `b` is exactly 64 bytes.
After receiving the response from the USB device, the driver reads the payload length directly from `b[3]` (which is fully controlled by the USB device) and copies the payload into the caller-provided `cmd_result` buffer:
```c
if (result_length)
*result_length = b[3];
if (cmd_result && b[3] > 0)
memcpy(cmd_result, &b[4], b[3]);
```
There are two major flaws in this logic:
1. **No bounds check against the received data or the allocated buffer `b`**: `b[3]` is an 8-bit value and can be up to 255. If the device returns a value greater than `COMMAND_PACKET_SIZE` (60), the `memcpy()` will read past the end of the 64-byte buffer `b`. In the syzkaller crash, `b[3]` was `75`, leading to a 75-byte read from `&b[4]` (which only has 60 bytes allocated). This triggers the `fortify_memcpy_chk` panic (`75 byte read of buffer size 60`).
2. **No bounds check against the destination buffer `cmd_result`**: The size of `cmd_result` is never passed to `ttusb_dec_send_command()`. While callers like `ttusb_dec_get_stb_state()` pass a 60-byte buffer (`u8 c[COMMAND_PACKET_SIZE]`), other callers like `ttusbdecfe_dvbt_read_status()` in `ttusbdecfe.c` pass a much smaller buffer (`u8 result[4]`). If the device returns `b[3] = 60` for the latter, it will result in a severe stack buffer overflow.
### Proposed Fix
To fix this comprehensively, the API needs to be updated to pass the size of the destination buffer, and `ttusb_dec_send_command()` must validate `b[3]` against the received length, the maximum packet size, and the destination buffer size.
**1. Update `ttusbdecfe_config` in `drivers/media/usb/ttusb-dec/ttusbdecfe.h`:**
Add `cmd_result_len` to the `send_command` callback signature.
```c
struct ttusbdecfe_config
{
int (*send_command)(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len);
};
```
**2. Update `ttusb_dec_send_command()` in `ttusb_dec.c`:**
Add `cmd_result_len` to the signature and implement the necessary bounds checks.
```c
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len)
{
// ...
result = usb_bulk_msg(dec->udev, dec->result_pipe, b,
COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
if (result) {
printk("%s: result bulk message failed: error %d\n",
__func__, result);
goto err_mutex_unlock;
} else {
if (debug) {
printk(KERN_DEBUG "%s: result: %*ph\n",
__func__, actual_len, b);
}
/* Ensure we received at least the 4-byte header */
if (actual_len < 4) {
result = -EIO;
goto err_mutex_unlock;
}
/* Ensure the device isn't claiming more data than it sent or than fits in b */
if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
result = -EIO;
goto err_mutex_unlock;
}
if (result_length)
*result_length = b[3];
if (cmd_result && b[3] > 0) {
/* Ensure we don't overflow the caller's buffer */
if (b[3] > cmd_result_len) {
result = -EIO;
goto err_mutex_unlock;
}
memcpy(cmd_result, &b[4], b[3]);
}
}
// ...
```
**3. Update all callers:**
You will need to update all callers of `ttusb_dec_send_command()` in `ttusb_dec.c` and `state->config->send_command()` in `ttusbdecfe.c` to pass the correct buffer size.
For example:
- In `ttusb_dec_get_stb_state()`: pass `sizeof(c)` instead of just `c`.
- In `ttusbdecfe_dvbt_read_status()`: pass `sizeof(result)` instead of just `result`.
- For calls where `cmd_result` is `NULL`, simply pass `0` as the length.
The patch that fixes the bug is:
diff --git a/drivers/media/usb/ttusb-dec/ttusb_dec.c b/drivers/media/usb/ttusb-dec/ttusb_dec.c
index 825a38759..b54b7b4bb 100644
--- a/drivers/media/usb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/usb/ttusb-dec/ttusb_dec.c
@@ -314,13 +314,17 @@ static u16 crc16(u16 crc, const u8 *buf, size_t len)
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
int result, actual_len;
u8 *b;
dprintk("%s\n", __func__);
+ if (param_length > COMMAND_PACKET_SIZE)
+ return -EINVAL;
+
b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
if (!b)
return -ENOMEM;
@@ -366,10 +370,25 @@ static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
__func__, actual_len, b);
}
+ if (actual_len < 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
+ if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
if (result_length)
*result_length = b[3];
- if (cmd_result && b[3] > 0)
+ if (cmd_result && b[3] > 0) {
+ if (b[3] > cmd_result_len) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
memcpy(cmd_result, &b[4], b[3]);
+ }
}
err_mutex_unlock:
@@ -389,7 +408,8 @@ static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
dprintk("%s\n", __func__);
- result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
+ result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c,
+ sizeof(c));
if (result)
return result;
@@ -448,7 +468,7 @@ static void ttusb_dec_set_pids(struct ttusb_dec *dec)
memcpy(&b[2], &audio, 2);
memcpy(&b[4], &video, 2);
- ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL, 0);
dvb_filter_pes2ts_init(&dec->a_pes2ts, dec->pid[DMX_PES_AUDIO],
ttusb_dec_audio_pes2ts_cb, dec);
@@ -902,7 +922,7 @@ static int ttusb_dec_set_interface(struct ttusb_dec *dec,
break;
case TTUSB_DEC_INTERFACE_IN:
result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
- b, NULL, NULL);
+ b, NULL, NULL, 0);
if (result)
return result;
result = usb_set_interface(dec->udev, 0, 8);
@@ -1021,7 +1041,7 @@ static int ttusb_dec_start_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
}
- result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL, 0);
if (result)
return result;
@@ -1056,7 +1076,7 @@ static int ttusb_dec_start_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
memcpy(&b0[5], &dvbdmxfeed->filter->filter.filter_value[0], 1);
result = ttusb_dec_send_command(dec, 0x60, sizeof(b0), b0,
- &c_length, c);
+ &c_length, c, sizeof(c));
if (!result) {
if (c_length == 2) {
@@ -1114,7 +1134,7 @@ static int ttusb_dec_stop_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
u8 b0[] = { 0x00 };
- ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL, 0);
dec->pva_stream_count--;
@@ -1135,7 +1155,7 @@ static int ttusb_dec_stop_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
list_del(&finfo->filter_info_list);
spin_unlock_irqrestore(&dec->filter_info_list_lock, flags);
kfree(finfo);
- ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL, 0);
dec->filter_stream_count--;
@@ -1238,7 +1258,7 @@ static int ttusb_init_rc( struct ttusb_dec *dec)
if (usb_submit_urb(dec->irq_urb, GFP_KERNEL))
printk("%s: usb_submit_urb failed\n",__func__);
/* enable irq pipe */
- ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
+ ttusb_dec_send_command(dec, 0xb0, sizeof(b), b, NULL, NULL, 0);
return 0;
}
@@ -1354,7 +1374,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
firmware_csum_ns = htons(firmware_csum);
memcpy(&b0[6], &firmware_csum_ns, 2);
- result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL, 0);
if (result) {
release_firmware(fw_entry);
@@ -1395,7 +1415,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
}
}
- result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL, 0);
release_firmware(fw_entry);
kfree(b);
@@ -1621,10 +1641,13 @@ static void ttusb_dec_exit_filters(struct ttusb_dec *dec)
static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
struct ttusb_dec* dec = fe->dvb->priv;
- return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
+ return ttusb_dec_send_command(dec, command, param_length, params,
+ result_length, cmd_result,
+ cmd_result_len);
}
static const struct ttusbdecfe_config fe_config = {
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.c b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
index 215221370..b013d6dfc 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.c
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
@@ -44,7 +44,8 @@ static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
*status=0;
- ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
+ ret = state->config->send_command(fe, 0x73, sizeof(b), b, &len, result,
+ sizeof(result));
if(ret)
return ret;
@@ -85,7 +86,7 @@ static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend *fe)
__be32 freq = htonl(p->frequency / 1000);
memcpy(&b[4], &freq, sizeof (u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
@@ -130,7 +131,7 @@ static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend *fe)
lnb_voltage = htonl(state->voltage);
memcpy(&b[28], &lnb_voltage, sizeof(u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
@@ -149,7 +150,7 @@ static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struc
state->config->send_command(fe, 0x72,
sizeof(b) - (6 - cmd->msg_len), b,
- NULL, NULL);
+ NULL, NULL, 0);
return 0;
}
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.h b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
index 73828bb22..96600ad4c 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.h
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
@@ -14,7 +14,8 @@ struct ttusbdecfe_config
{
int (*send_command)(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[]);
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len);
};
extern struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config);
Search for the commit(s) that introduced this bug.
|
| 236/2 |
2026/08/17 21:58 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 13280
output: 57
thoughts: 232
Thoughts: **Pinpointing the Bug's Genesis**
Okay, so we've got a patch that fixes an out-of-bounds read/write in `ttusb_dec_send_command` within the `ttusb_dec.c` driver. The issue, as I understand it, stems from a vulnerability. We're using `b[3]` as the length for a `memcpy`, which is a classic recipe for disaster, and it's not being properly checked against either the allocated buffer size or the intended destination size. The provided patch adds `cmd_result_len` and properly bounds-checks the incoming value in multiple cases, addressing `b[3] > COMMAND_PACKET_SIZE`, `b[3] > actual_len - 4`, and `b[3] > cmd_result_len`.
My next step is clear: I need to pinpoint the exact commit that introduced this flaw. My approach? A good old `git log` dive. I'll trace the history of `ttusb_dec_send_command` in `drivers/media/usb/ttusb-dec/ttusb_dec.c`, zeroing in on either when the function itself was first added or, more likely, when the vulnerable `memcpy` logic was introduced. This will allow me to narrow down the possible commits that are responsible for the bug. From there, I can begin my deep dive of the likely culprits.
|
| 237/2 |
2026/08/17 21:58 |
tool |
git-log |
0m
Args: map[CodeRegexp:memcpy\(cmd_result, &b\[4\], b\[3\]\) PathPrefix:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results: map[Output:786baecfe78f [media] dvb-usb: move it to drivers/media/usb/dvb-usb
]
|
| 238/2 |
2026/08/17 21:59 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 13914
output: 47
thoughts: 54
Thoughts: **Investigating Potential File Relocation**
Okay, hold on a minute. My initial instinct is telling me that `drivers/media/usb/ttusb-dec/ttusb_dec.c` may have undergone a move, a refactoring, or some other organizational change within the codebase. The location feels... *off*. To be absolutely sure, and before I start hunting down potentially missing functions, the first thing I need to do is verify the history of `ttusb_dec_send_command`. I'll use `git log` with the symbol name search parameter to trace its lineage. This will definitively tell me if the relevant file was moved, renamed, or if it has been touched recently, and might point me to its new home or any related changesets that are relevant to this function. This is a crucial first step before wasting time chasing phantoms. I'm going to get this clarified ASAP.
|
| 239/2 |
2026/08/17 21:59 |
tool |
git-log |
0m
Args: map[SourcePath:drivers/media/usb/ttusb-dec/ttusb_dec.c SymbolName:ttusb_dec_send_command]
Results: map[Output:36b9d695aa6f media: ttusb-dec: avoid release of non-acquired mutex
dba328bab4c6 media: ttusb-dec: cleanup an error handling logic
a10feaf8c464 media: ttusb-dec: Fix info-leak in ttusb_dec_send_command()
61fc87498bc6 [media] ttusb_dec: use KERNEL_CONT where needed
e9815ceea973 V4L/DVB (7517): media/dvb/ttusb-dec replace remaining __FUNCTION__ occurrences
3593cab5d62c V4L/DVB (3318b): sem2mutex: drivers/media/, #2
1da177e4c3f4 Linux-2.6.12-rc2
]
|
| 240/2 |
2026/08/17 21:59 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 14419
output: 45
thoughts: 43
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm deep in the weeds of debugging and familiar with the Linux kernel:
**Root Cause Analysis Begins: Backtracking to 2.6.12-rc2**
Alright, so we've got a bug to hunt down. My immediate instinct is to start rewinding the clock, seeing where this thing *first* reared its ugly head. The commit ID `1da177e4c3f4` is jumping out at me as a likely starting point – that's the Linux-2.6.12-rc2 tag, if my memory serves. Given the age, I'm betting that the bug might have been there from the start. Let's fire up the git log and get a diff, and check, because if it was introduced later it would save some time.
|
| 241/2 |
2026/08/17 21:59 |
tool |
git-show |
0m
Args: map[Commit:1da177e4c3f4:drivers/media/dvb/ttusb-dec/ttusb_dec.c]
Results: map[Output:
Full output is too long, showing 1000 out of 1744 lines.
[/*
* TTUSB DEC Driver
*
* Copyright (C) 2003-2004 Alex Woods <linux-dvb@giblets.org>
* IR support by Peter Beutner <p.beutner@gmx.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <asm/semaphore.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/usb.h>
#include <linux/version.h>
#include <linux/interrupt.h>
#include <linux/firmware.h>
#include <linux/crc32.h>
#include <linux/init.h>
#include <linux/input.h>
#include "dmxdev.h"
#include "dvb_demux.h"
#include "dvb_filter.h"
#include "dvb_frontend.h"
#include "dvb_net.h"
#include "ttusbdecfe.h"
static int debug;
static int output_pva;
static int enable_rc;
module_param(debug, int, 0644);
MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
module_param(output_pva, int, 0444);
MODULE_PARM_DESC(output_pva, "Output PVA from dvr device (default:off)");
module_param(enable_rc, int, 0644);
MODULE_PARM_DESC(enable_rc, "Turn on/off IR remote control(default: off)");
#define dprintk if (debug) printk
#define DRIVER_NAME "TechnoTrend/Hauppauge DEC USB"
#define COMMAND_PIPE 0x03
#define RESULT_PIPE 0x04
#define IN_PIPE 0x08
#define OUT_PIPE 0x07
#define IRQ_PIPE 0x0A
#define COMMAND_PACKET_SIZE 0x3c
#define ARM_PACKET_SIZE 0x1000
#define IRQ_PACKET_SIZE 0x8
#define ISO_BUF_COUNT 0x04
#define FRAMES_PER_ISO_BUF 0x04
#define ISO_FRAME_SIZE 0x0380
#define MAX_PVA_LENGTH 6144
enum ttusb_dec_model {
TTUSB_DEC2000T,
TTUSB_DEC2540T,
TTUSB_DEC3000S
};
enum ttusb_dec_packet_type {
TTUSB_DEC_PACKET_PVA,
TTUSB_DEC_PACKET_SECTION,
TTUSB_DEC_PACKET_EMPTY
};
enum ttusb_dec_interface {
TTUSB_DEC_INTERFACE_INITIAL,
TTUSB_DEC_INTERFACE_IN,
TTUSB_DEC_INTERFACE_OUT
};
struct ttusb_dec {
enum ttusb_dec_model model;
char *model_name;
char *firmware_name;
int can_playback;
/* DVB bits */
struct dvb_adapter *adapter;
struct dmxdev dmxdev;
struct dvb_demux demux;
struct dmx_frontend frontend;
struct dvb_net dvb_net;
struct dvb_frontend* fe;
u16 pid[DMX_PES_OTHER];
/* USB bits */
struct usb_device *udev;
u8 trans_count;
unsigned int command_pipe;
unsigned int result_pipe;
unsigned int in_pipe;
unsigned int out_pipe;
unsigned int irq_pipe;
enum ttusb_dec_interface interface;
struct semaphore usb_sem;
void *irq_buffer;
struct urb *irq_urb;
dma_addr_t irq_dma_handle;
void *iso_buffer;
dma_addr_t iso_dma_handle;
struct urb *iso_urb[ISO_BUF_COUNT];
int iso_stream_count;
struct semaphore iso_sem;
u8 packet[MAX_PVA_LENGTH + 4];
enum ttusb_dec_packet_type packet_type;
int packet_state;
int packet_length;
int packet_payload_length;
u16 next_packet_id;
int pva_stream_count;
int filter_stream_count;
struct dvb_filter_pes2ts a_pes2ts;
struct dvb_filter_pes2ts v_pes2ts;
u8 v_pes[16 + MAX_PVA_LENGTH];
int v_pes_length;
int v_pes_postbytes;
struct list_head urb_frame_list;
struct tasklet_struct urb_tasklet;
spinlock_t urb_frame_list_lock;
struct dvb_demux_filter *audio_filter;
struct dvb_demux_filter *video_filter;
struct list_head filter_info_list;
spinlock_t filter_info_list_lock;
struct input_dev rc_input_dev;
int active; /* Loaded successfully */
};
struct urb_frame {
u8 data[ISO_FRAME_SIZE];
int length;
struct list_head urb_frame_list;
};
struct filter_info {
u8 stream_id;
struct dvb_demux_filter *filter;
struct list_head filter_info_list;
};
static u16 rc_keys[] = {
KEY_POWER,
KEY_MUTE,
KEY_1,
KEY_2,
KEY_3,
KEY_4,
KEY_5,
KEY_6,
KEY_7,
KEY_8,
KEY_9,
KEY_0,
KEY_CHANNELUP,
KEY_VOLUMEDOWN,
KEY_OK,
KEY_VOLUMEUP,
KEY_CHANNELDOWN,
KEY_PREVIOUS,
KEY_ESC,
KEY_RED,
KEY_GREEN,
KEY_YELLOW,
KEY_BLUE,
KEY_OPTION,
KEY_M,
KEY_RADIO
};
static void ttusb_dec_set_model(struct ttusb_dec *dec,
enum ttusb_dec_model model);
static void ttusb_dec_handle_irq( struct urb *urb, struct pt_regs *regs)
{
struct ttusb_dec * dec = urb->context;
char *buffer = dec->irq_buffer;
int retval;
switch(urb->status) {
case 0: /*success*/
break;
case -ECONNRESET:
case -ENOENT:
case -ESHUTDOWN:
case -ETIMEDOUT:
/* this urb is dead, cleanup */
dprintk("%s:urb shutting down with status: %d\n",
__FUNCTION__, urb->status);
return;
default:
dprintk("%s:nonzero status received: %d\n",
__FUNCTION__,urb->status);
goto exit;
}
if( (buffer[0] == 0x1) && (buffer[2] == 0x15) ) {
/* IR - Event */
/* this is an fact a bit too simple implementation;
* the box also reports a keyrepeat signal
* (with buffer[3] == 0x40) in an intervall of ~100ms.
* But to handle this correctly we had to imlemenent some
* kind of timer which signals a 'key up' event if no
* keyrepeat signal is recieved for lets say 200ms.
* this should/could be added later ...
* for now lets report each signal as a key down and up*/
dprintk("%s:rc signal:%d\n", __FUNCTION__, buffer[4]);
input_report_key(&dec->rc_input_dev,rc_keys[buffer[4]-1],1);
input_report_key(&dec->rc_input_dev,rc_keys[buffer[4]-1],0);
input_sync(&dec->rc_input_dev);
}
exit: retval = usb_submit_urb(urb, GFP_ATOMIC);
if(retval)
printk("%s - usb_commit_urb failed with result: %d\n",
__FUNCTION__, retval);
}
static u16 crc16(u16 crc, const u8 *buf, size_t len)
{
u16 tmp;
while (len--) {
crc ^= *buf++;
crc ^= (u8)crc >> 4;
tmp = (u8)crc;
crc ^= (tmp ^ (tmp << 1)) << 4;
}
return crc;
}
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[])
{
int result, actual_len, i;
u8 *b;
dprintk("%s\n", __FUNCTION__);
b = kmalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
if (!b)
return -ENOMEM;
if ((result = down_interruptible(&dec->usb_sem))) {
kfree(b);
printk("%s: Failed to down usb semaphore.\n", __FUNCTION__);
return result;
}
b[0] = 0xaa;
b[1] = ++dec->trans_count;
b[2] = command;
b[3] = param_length;
if (params)
memcpy(&b[4], params, param_length);
if (debug) {
printk("%s: command: ", __FUNCTION__);
for (i = 0; i < param_length + 4; i++)
printk("0x%02X ", b[i]);
printk("\n");
}
result = usb_bulk_msg(dec->udev, dec->command_pipe, b,
COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
if (result) {
printk("%s: command bulk message failed: error %d\n",
__FUNCTION__, result);
up(&dec->usb_sem);
kfree(b);
return result;
}
result = usb_bulk_msg(dec->udev, dec->result_pipe, b,
COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
if (result) {
printk("%s: result bulk message failed: error %d\n",
__FUNCTION__, result);
up(&dec->usb_sem);
kfree(b);
return result;
} else {
if (debug) {
printk("%s: result: ", __FUNCTION__);
for (i = 0; i < actual_len; i++)
printk("0x%02X ", b[i]);
printk("\n");
}
if (result_length)
*result_length = b[3];
if (cmd_result && b[3] > 0)
memcpy(cmd_result, &b[4], b[3]);
up(&dec->usb_sem);
kfree(b);
return 0;
}
}
static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
unsigned int *model, unsigned int *version)
{
u8 c[COMMAND_PACKET_SIZE];
int c_length;
int result;
unsigned int tmp;
dprintk("%s\n", __FUNCTION__);
result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
if (result)
return result;
if (c_length >= 0x0c) {
if (mode != NULL) {
memcpy(&tmp, c, 4);
*mode = ntohl(tmp);
}
if (model != NULL) {
memcpy(&tmp, &c[4], 4);
*model = ntohl(tmp);
}
if (version != NULL) {
memcpy(&tmp, &c[8], 4);
*version = ntohl(tmp);
}
return 0;
} else {
return -1;
}
}
static int ttusb_dec_audio_pes2ts_cb(void *priv, unsigned char *data)
{
struct ttusb_dec *dec = (struct ttusb_dec *)priv;
dec->audio_filter->feed->cb.ts(data, 188, NULL, 0,
&dec->audio_filter->feed->feed.ts,
DMX_OK);
return 0;
}
static int ttusb_dec_video_pes2ts_cb(void *priv, unsigned char *data)
{
struct ttusb_dec *dec = (struct ttusb_dec *)priv;
dec->video_filter->feed->cb.ts(data, 188, NULL, 0,
&dec->video_filter->feed->feed.ts,
DMX_OK);
return 0;
}
static void ttusb_dec_set_pids(struct ttusb_dec *dec)
{
u8 b[] = { 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff };
u16 pcr = htons(dec->pid[DMX_PES_PCR]);
u16 audio = htons(dec->pid[DMX_PES_AUDIO]);
u16 video = htons(dec->pid[DMX_PES_VIDEO]);
dprintk("%s\n", __FUNCTION__);
memcpy(&b[0], &pcr, 2);
memcpy(&b[2], &audio, 2);
memcpy(&b[4], &video, 2);
ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL);
dvb_filter_pes2ts_init(&dec->a_pes2ts, dec->pid[DMX_PES_AUDIO],
ttusb_dec_audio_pes2ts_cb, dec);
dvb_filter_pes2ts_init(&dec->v_pes2ts, dec->pid[DMX_PES_VIDEO],
ttusb_dec_video_pes2ts_cb, dec);
dec->v_pes_length = 0;
dec->v_pes_postbytes = 0;
}
static void ttusb_dec_process_pva(struct ttusb_dec *dec, u8 *pva, int length)
{
if (length < 8) {
printk("%s: packet too short - discarding\n", __FUNCTION__);
return;
}
if (length > 8 + MAX_PVA_LENGTH) {
printk("%s: packet too long - discarding\n", __FUNCTION__);
return;
}
switch (pva[2]) {
case 0x01: { /* VideoStream */
int prebytes = pva[5] & 0x03;
int postbytes = (pva[5] & 0x0c) >> 2;
u16 v_pes_payload_length;
if (output_pva) {
dec->video_filter->feed->cb.ts(pva, length, NULL, 0,
&dec->video_filter->feed->feed.ts, DMX_OK);
return;
}
if (dec->v_pes_postbytes > 0 &&
dec->v_pes_postbytes == prebytes) {
memcpy(&dec->v_pes[dec->v_pes_length],
&pva[12], prebytes);
dvb_filter_pes2ts(&dec->v_pes2ts, dec->v_pes,
dec->v_pes_length + prebytes, 1);
}
if (pva[5] & 0x10) {
dec->v_pes[7] = 0x80;
dec->v_pes[8] = 0x05;
dec->v_pes[9] = 0x21 | ((pva[8] & 0xc0) >> 5);
dec->v_pes[10] = ((pva[8] & 0x3f) << 2) |
((pva[9] & 0xc0) >> 6);
dec->v_pes[11] = 0x01 |
((pva[9] & 0x3f) << 2) |
((pva[10] & 0x80) >> 6);
dec->v_pes[12] = ((pva[10] & 0x7f) << 1) |
((pva[11] & 0xc0) >> 7);
dec->v_pes[13] = 0x01 | ((pva[11] & 0x7f) << 1);
memcpy(&dec->v_pes[14], &pva[12 + prebytes],
length - 12 - prebytes);
dec->v_pes_length = 14 + length - 12 - prebytes;
} else {
dec->v_pes[7] = 0x00;
dec->v_pes[8] = 0x00;
memcpy(&dec->v_pes[9], &pva[8], length - 8);
dec->v_pes_length = 9 + length - 8;
}
dec->v_pes_postbytes = postbytes;
if (dec->v_pes[9 + dec->v_pes[8]] == 0x00 &&
dec->v_pes[10 + dec->v_pes[8]] == 0x00 &&
dec->v_pes[11 + dec->v_pes[8]] == 0x01)
dec->v_pes[6] = 0x84;
else
dec->v_pes[6] = 0x80;
v_pes_payload_length = htons(dec->v_pes_length - 6 +
postbytes);
memcpy(&dec->v_pes[4], &v_pes_payload_length, 2);
if (postbytes == 0)
dvb_filter_pes2ts(&dec->v_pes2ts, dec->v_pes,
dec->v_pes_length, 1);
break;
}
case 0x02: /* MainAudioStream */
if (output_pva) {
dec->audio_filter->feed->cb.ts(pva, length, NULL, 0,
&dec->audio_filter->feed->feed.ts, DMX_OK);
return;
}
dvb_filter_pes2ts(&dec->a_pes2ts, &pva[8], length - 8,
pva[5] & 0x10);
break;
default:
printk("%s: unknown PVA type: %02x.\n", __FUNCTION__,
pva[2]);
break;
}
}
static void ttusb_dec_process_filter(struct ttusb_dec *dec, u8 *packet,
int length)
{
struct list_head *item;
struct filter_info *finfo;
struct dvb_demux_filter *filter = NULL;
unsigned long flags;
u8 sid;
sid = packet[1];
spin_lock_irqsave(&dec->filter_info_list_lock, flags);
for (item = dec->filter_info_list.next; item != &dec->filter_info_list;
item = item->next) {
finfo = list_entry(item, struct filter_info, filter_info_list);
if (finfo->stream_id == sid) {
filter = finfo->filter;
break;
}
}
spin_unlock_irqrestore(&dec->filter_info_list_lock, flags);
if (filter)
filter->feed->cb.sec(&packet[2], length - 2, NULL, 0,
&filter->filter, DMX_OK);
}
static void ttusb_dec_process_packet(struct ttusb_dec *dec)
{
int i;
u16 csum = 0;
u16 packet_id;
if (dec->packet_length % 2) {
printk("%s: odd sized packet - discarding\n", __FUNCTION__);
return;
}
for (i = 0; i < dec->packet_length; i += 2)
csum ^= ((dec->packet[i] << 8) + dec->packet[i + 1]);
if (csum) {
printk("%s: checksum failed - discarding\n", __FUNCTION__);
return;
}
packet_id = dec->packet[dec->packet_length - 4] << 8;
packet_id += dec->packet[dec->packet_length - 3];
if ((packet_id != dec->next_packet_id) && dec->next_packet_id) {
printk("%s: warning: lost packets between %u and %u\n",
__FUNCTION__, dec->next_packet_id - 1, packet_id);
}
if (packet_id == 0xffff)
dec->next_packet_id = 0x8000;
else
dec->next_packet_id = packet_id + 1;
switch (dec->packet_type) {
case TTUSB_DEC_PACKET_PVA:
if (dec->pva_stream_count)
ttusb_dec_process_pva(dec, dec->packet,
dec->packet_payload_length);
break;
case TTUSB_DEC_PACKET_SECTION:
if (dec->filter_stream_count)
ttusb_dec_process_filter(dec, dec->packet,
dec->packet_payload_length);
break;
case TTUSB_DEC_PACKET_EMPTY:
break;
}
}
static void swap_bytes(u8 *b, int length)
{
u8 c;
length -= length % 2;
for (; length; b += 2, length -= 2) {
c = *b;
*b = *(b + 1);
*(b + 1) = c;
}
}
static void ttusb_dec_process_urb_frame(struct ttusb_dec *dec, u8 *b,
int length)
{
swap_bytes(b, length);
while (length) {
switch (dec->packet_state) {
case 0:
case 1:
case 2:
if (*b++ == 0xaa)
dec->packet_state++;
else
dec->packet_state = 0;
length--;
break;
case 3:
if (*b == 0x00) {
dec->packet_state++;
dec->packet_length = 0;
} else if (*b != 0xaa) {
dec->packet_state = 0;
}
b++;
length--;
break;
case 4:
dec->packet[dec->packet_length++] = *b++;
if (dec->packet_length == 2) {
if (dec->packet[0] == 'A' &&
dec->packet[1] == 'V') {
dec->packet_type =
TTUSB_DEC_PACKET_PVA;
dec->packet_state++;
} else if (dec->packet[0] == 'S') {
dec->packet_type =
TTUSB_DEC_PACKET_SECTION;
dec->packet_state++;
} else if (dec->packet[0] == 0x00) {
dec->packet_type =
TTUSB_DEC_PACKET_EMPTY;
dec->packet_payload_length = 2;
dec->packet_state = 7;
} else {
printk("%s: unknown packet type: "
"%02x%02x\n", __FUNCTION__,
dec->packet[0], dec->packet[1]);
dec->packet_state = 0;
}
}
length--;
break;
case 5:
dec->packet[dec->packet_length++] = *b++;
if (dec->packet_type == TTUSB_DEC_PACKET_PVA &&
dec->packet_length == 8) {
dec->packet_state++;
dec->packet_payload_length = 8 +
(dec->packet[6] << 8) +
dec->packet[7];
} else if (dec->packet_type ==
TTUSB_DEC_PACKET_SECTION &&
dec->packet_length == 5) {
dec->packet_state++;
dec->packet_payload_length = 5 +
((dec->packet[3] & 0x0f) << 8) +
dec->packet[4];
}
length--;
break;
case 6: {
int remainder = dec->packet_payload_length -
dec->packet_length;
if (length >= remainder) {
memcpy(dec->packet + dec->packet_length,
b, remainder);
dec->packet_length += remainder;
b += remainder;
length -= remainder;
dec->packet_state++;
} else {
memcpy(&dec->packet[dec->packet_length],
b, length);
dec->packet_length += length;
length = 0;
}
break;
}
case 7: {
int tail = 4;
dec->packet[dec->packet_length++] = *b++;
if (dec->packet_type == TTUSB_DEC_PACKET_SECTION &&
dec->packet_payload_length % 2)
tail++;
if (dec->packet_length ==
dec->packet_payload_length + tail) {
ttusb_dec_process_packet(dec);
dec->packet_state = 0;
}
length--;
break;
}
default:
printk("%s: illegal packet state encountered.\n",
__FUNCTION__);
dec->packet_state = 0;
}
}
}
static void ttusb_dec_process_urb_frame_list(unsigned long data)
{
struct ttusb_dec *dec = (struct ttusb_dec *)data;
struct list_head *item;
struct urb_frame *frame;
unsigned long flags;
while (1) {
spin_lock_irqsave(&dec->urb_frame_list_lock, flags);
if ((item = dec->urb_frame_list.next) != &dec->urb_frame_list) {
frame = list_entry(item, struct urb_frame,
urb_frame_list);
list_del(&frame->urb_frame_list);
} else {
spin_unlock_irqrestore(&dec->urb_frame_list_lock,
flags);
return;
}
spin_unlock_irqrestore(&dec->urb_frame_list_lock, flags);
ttusb_dec_process_urb_frame(dec, frame->data, frame->length);
kfree(frame);
}
}
static void ttusb_dec_process_urb(struct urb *urb, struct pt_regs *ptregs)
{
struct ttusb_dec *dec = urb->context;
if (!urb->status) {
int i;
for (i = 0; i < FRAMES_PER_ISO_BUF; i++) {
struct usb_iso_packet_descriptor *d;
u8 *b;
int length;
struct urb_frame *frame;
d = &urb->iso_frame_desc[i];
b = urb->transfer_buffer + d->offset;
length = d->actual_length;
if ((frame = kmalloc(sizeof(struct urb_frame),
GFP_ATOMIC))) {
unsigned long flags;
memcpy(frame->data, b, length);
frame->length = length;
spin_lock_irqsave(&dec->urb_frame_list_lock,
flags);
list_add_tail(&frame->urb_frame_list,
&dec->urb_frame_list);
spin_unlock_irqrestore(&dec->urb_frame_list_lock,
flags);
tasklet_schedule(&dec->urb_tasklet);
}
}
} else {
/* -ENOENT is expected when unlinking urbs */
if (urb->status != -ENOENT)
dprintk("%s: urb error: %d\n", __FUNCTION__,
urb->status);
}
if (dec->iso_stream_count)
usb_submit_urb(urb, GFP_ATOMIC);
}
static void ttusb_dec_setup_urbs(struct ttusb_dec *dec)
{
int i, j, buffer_offset = 0;
dprintk("%s\n", __FUNCTION__);
for (i = 0; i < ISO_BUF_COUNT; i++) {
int frame_offset = 0;
struct urb *urb = dec->iso_urb[i];
urb->dev = dec->udev;
urb->context = dec;
urb->complete = ttusb_dec_process_urb;
urb->pipe = dec->in_pipe;
urb->transfer_flags = URB_ISO_ASAP;
urb->interval = 1;
urb->number_of_packets = FRAMES_PER_ISO_BUF;
urb->transfer_buffer_length = ISO_FRAME_SIZE *
FRAMES_PER_ISO_BUF;
urb->transfer_buffer = dec->iso_buffer + buffer_offset;
buffer_offset += ISO_FRAME_SIZE * FRAMES_PER_ISO_BUF;
for (j = 0; j < FRAMES_PER_ISO_BUF; j++) {
urb->iso_frame_desc[j].offset = frame_offset;
urb->iso_frame_desc[j].length = ISO_FRAME_SIZE;
frame_offset += ISO_FRAME_SIZE;
}
}
}
static void ttusb_dec_stop_iso_xfer(struct ttusb_dec *dec)
{
int i;
dprintk("%s\n", __FUNCTION__);
if (down_interruptible(&dec->iso_sem))
return;
dec->iso_stream_count--;
if (!dec->iso_stream_count) {
for (i = 0; i < ISO_BUF_COUNT; i++)
usb_kill_urb(dec->iso_urb[i]);
}
up(&dec->iso_sem);
}
/* Setting the interface of the DEC tends to take down the USB communications
* for a short period, so it's important not to call this function just before
* trying to talk to it.
*/
static int ttusb_dec_set_interface(struct ttusb_dec *dec,
enum ttusb_dec_interface interface)
{
int result = 0;
u8 b[] = { 0x05 };
if (interface != dec->interface) {
switch (interface) {
case TTUSB_DEC_INTERFACE_INITIAL:
result = usb_set_interface(dec->udev, 0, 0);
break;
case TTUSB_DEC_INTERFACE_IN:
result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
b, NULL, NULL);
if (result)
return result;
result = usb_set_interface(dec->udev, 0, 8);
break;
case TTUSB_DEC_INTERFACE_OUT:
result = usb_set_interface(dec->udev, 0, 1);
break;
}
if (result)
return result;
dec->interface = interface;
}
return 0;
}
static int ttusb_dec_start_iso_xfer(struct ttusb_dec *dec)
{
int i, result;
dprintk("%s\n", __FUNCTION__);
if (down_interruptible(&dec->iso_sem))
return -EAGAIN;
if (!dec->iso_stream_count) {
ttusb_dec_setup_urbs(dec);
dec->packet_state = 0;
dec->v_pes_postbytes = 0;
dec->next_packet_id = 0;
for (i = 0; i < ISO_BUF_COUNT; i++) {
if ((result = usb_submit_urb(dec->iso_urb[i],
GFP_ATOMIC))) {
printk("%s: failed urb submission %d: "
"error %d\n", __FUNCTION__, i, result);
while (i) {
usb_kill_urb(dec->iso_urb[i - 1]);
i--;
}
up(&dec->iso_sem);
return result;
}
}
}
dec->iso_stream_count++;
up(&dec->iso_sem);
return 0;
}
static int ttusb_dec_start_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
{
struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
struct ttusb_dec *dec = dvbdmx->priv;
u8 b0[] = { 0x05 };
int result = 0;
dprintk("%s\n", __FUNCTION__);
dprintk(" ts_type:");
if (dvbdmxfeed->ts_type & TS_DECODER)
dprintk(" TS_DECODER");
if (dvbdmxfeed->ts_type & TS_PACKET)
dprintk(" TS_PACKET");
if (dvbdmxfeed->ts_type & TS_PAYLOAD_ONLY)
dprintk(" TS_PAYLOAD_ONLY");
dprintk("\n");
switch (dvbdmxfeed->pes_type) {
case DMX_TS_PES_VIDEO:
dprintk(" pes_type: DMX_TS_PES_VIDEO\n");
dec->pid[DMX_PES_PCR] = dvbdmxfeed->pid;
dec->pid[DMX_PES_VIDEO] = dvbdmxfeed->pid;
dec->video_filter = dvbdmxfeed->filter;
ttusb_dec_set_pids(dec);
break;
case DMX_TS_PES_AUDIO:
dprintk(" pes_type: DMX_TS_PES_AUDIO\n");
dec->pid[DMX_PES_AUDIO] = dvbdmxfeed->pid;
dec->audio_filter = dvbdmxfeed->filter;
ttusb_dec_set_pids(dec);
break;
case DMX_TS_PES_TELETEXT:
dec->pid[DMX_PES_TELETEXT] = dvbdmxfeed->pid;
dprintk(" pes_type: DMX_TS_PES_TELETEXT\n");
break;
case DMX_TS_PES_PCR:
dprintk(" pes_type: DMX_TS_PES_PCR\n");
dec->pid[DMX_PES_PCR] = dvbdmxfeed->pid;
ttusb_dec_set_pids(dec);
break;
case DMX_TS_PES_OTHER:
dprintk(" pes_type: DMX_TS_PES_OTHER\n");
break;
default:
dprintk(" pes_type: unknown (%d)\n", dvbdmxfeed->pes_type);
return -EINVAL;
}
result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL);
if (result)
return result;
dec->pva_stream_count++;
return ttusb_dec_start_iso_xfer(dec);
}
static int ttusb_dec_start_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
{
struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
u8 b0[] = { 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
]
]
|
| 242/2 |
2026/08/17 21:59 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 25238
output: 52
thoughts: 923
Thoughts: **Bug Analysis: ttusb_dec_send_command - Initial Commit Vulnerability**
Okay, so I'm digging into this `ttusb_dec_send_command` function, and it looks like it's been around since the very beginning – the initial Linux kernel commit, `1da177e4c3f4`. My initial thought was to see if the buggy `memcpy` had been introduced later, perhaps as part of a refactoring, but no such luck. It's right there, in the original implementation. I confirmed this with a quick check: the `memcpy(cmd_result, &b[4], b[3]);` is indeed present from the very start.
Now, let's nail down *why* this is a problem. The crash report specifically mentions a `memcpy` buffer overflow: "75 byte read of buffer size 60". Aha! So, `b[3]` is being used as the length for the `memcpy` without any bounds checking. This is the root cause. This is a classic vulnerability, easily spotted.
`b` is allocated with a size of `COMMAND_PACKET_SIZE + 4` (64 bytes). The `crash report` is saying that `memcpy` tries to read 75 bytes, an out-of-bounds read of `b`. The key is that `b[3]` represents the length of the data to be copied. The vulnerability lies in the fact that `b[3]` isn't validated to ensure it's within the allocated buffer size. This allows a malicious value in `b[3]` to cause an out-of-bounds read. In addition, the size of the destination buffer `cmd_result` is not checked either, which can lead to a buffer overflow.
I'm pretty confident that the bug-introducing commit is indeed `1da177e4c3f412243cecb1a8220a65ce01ed66d0`. It's that initial commit, and the flawed `memcpy` has been there since day one.
So, I'll return `1da177e4c3f412243cecb1a8220a65ce01ed66d0` as the culprit. I am, however, keeping an eye out for any further related commits, just in case.
|
| 243/2 |
2026/08/17 21:59 |
tool |
set-results |
0m
Error:
Args: map[FixesHash:1da177e4c3f412243cecb1a8220a65ce01ed66d0]
Results: map[FixesHash:1da177e4c3f412243cecb1a8220a65ce01ed66d0]
|
| 244/2 |
2026/08/17 21:59 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 26789
output: 37
thoughts: 55
Thoughts: **Investigating a Missing Commit**
Okay, hold on a second. Something's not right. The system is telling me that `1da177e4c3f412243cecb1a8220a65ce01ed66d0` can't be found. That's strange, that commit should definitely exist. It's a fundamental reference point. I'm going to have to double-check the exact hash of the *very* first commit to make sure I haven't got a typo somewhere in my command or script. There's no way that base is missing, not in a correctly managed repository. Something is awry and I need to identify it.
|
| 245/2 |
2026/08/17 21:59 |
tool |
git-log |
0m
Args: map[Count:1 PathPrefix:drivers/media/usb/ttusb-dec/ttusb_dec.c]
Results: map[Output:bf4afc53b77a Convert 'alloc_obj' family to use the new default GFP_KERNEL argument
]
|
| 246/2 |
2026/08/17 21:59 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 27076
output: 39
thoughts: 68
Thoughts: **Investigating the `ttusb_dec.c` History**
Okay, so I was just looking at the `git-log` output for `drivers/media/usb/ttusb-dec/ttusb_dec.c`, and I saw that commit `bf4afc53b77a` popped up. Now, that's interesting. I need to make sure I understand the full context here. Time to double-check that file's commit history to make sure there are no other unexpected changes. I'll take a closer look and make sure I haven't missed anything significant.
|
| 247/2 |
2026/08/17 21:59 |
tool |
git-log |
10m
Error:
Args: map[CodeRegexp:memcpy\(cmd_result, &b\[4\], b\[3\]\) Count:10]
Results:
|
| 248/2 |
2026/08/17 22:09 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 27347
output: 52
thoughts: 22
Thoughts: Here's my thought process, summarized as you requested:
**Finding the Origin of `ttusb_dec_send_command`**
Okay, so I need to track down the exact commit where the `ttusb_dec_send_command` function was first introduced. This is a common and necessary task, especially when dealing with legacy codebases. Understanding the provenance of a function, particularly a potentially sensitive one, is crucial for debugging, understanding its intended behavior, and assessing its potential impact on the system. I’ll need to use my expertise in version control, most likely Git, to pinpoint this specific commit. Knowing the commit hash is essential for cross-referencing this information with related documentation, bug reports, and code reviews, providing a solid foundation for analysis. This hash is the breadcrumb trail I need to follow.
|
| 249/2 |
2026/08/17 22:09 |
tool |
git-log |
0m
Error:
Args: map[Count:10 PathPrefix:drivers/media/usb/ttusb-dec/ttusb_dec.c SymbolName:ttusb_dec_send_command]
Results:
|
| 250/2 |
2026/08/17 22:09 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 27615
output: 52
thoughts: 14
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Leveraging SourcePath with SymbolName for Optimal Results**
Okay, so I'm processing this data, and it's hitting me: the optimal approach here is to couple `SourcePath` with `SymbolName`. It's pretty obvious in retrospect, but it just clicked. I was probably trying to use them separately initially, which, depending on the context, might *sometimes* work. But for *this specific task* I'm working on, the inherent correlation between the two is where the power lies. That combination unlocks a more precise and efficient solution. Using `SourcePath` alone, I'd probably be missing valuable context, or, I'd have to perform more operations to achieve the same result. The same goes for `SymbolName`. It would have required additional work to identify the information or context I need. This combined approach is going to streamline everything significantly. Yeah, that's definitely the route to go.
|
| 251/2 |
2026/08/17 22:09 |
tool |
git-log |
0m
Args: map[Count:10 SourcePath:drivers/media/usb/ttusb-dec/ttusb_dec.c SymbolName:ttusb_dec_send_command]
Results: map[Output:36b9d695aa6f media: ttusb-dec: avoid release of non-acquired mutex
dba328bab4c6 media: ttusb-dec: cleanup an error handling logic
a10feaf8c464 media: ttusb-dec: Fix info-leak in ttusb_dec_send_command()
61fc87498bc6 [media] ttusb_dec: use KERNEL_CONT where needed
e9815ceea973 V4L/DVB (7517): media/dvb/ttusb-dec replace remaining __FUNCTION__ occurrences
3593cab5d62c V4L/DVB (3318b): sem2mutex: drivers/media/, #2
1da177e4c3f4 Linux-2.6.12-rc2
]
|
| 252/2 |
2026/08/17 22:09 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 28107
output: 26
thoughts: 58
Thoughts: Okay, here's my interpretation of that.
**Analyzing the Hash Integrity**
Alright, so the input hash I'm given, `1da177e4c3f4`, is apparently supposed to be a truncated version of the full hash `1da177e4c3f41524e886b7f1b8a0c1fc7321cac2`. The immediate question is, does that truncated form actually *represent* the full hash as intended? I need to verify that the prefix match is valid. While I wouldn't expect a collision on such a short prefix with a decent hashing algorithm, it's always worth confirming, especially when dealing with data integrity. I'll need to double check the generation process for this hash to make sure that the full hash is correctly derived from the source, and that the shorter value is actually a valid abbreviated representation. I'm going to have to dive into the specifics of *how* this hash was generated and what it's intended to represent to ensure there are no issues.
|
| 253/2 |
2026/08/17 22:09 |
tool |
git-show |
0m
Args:
Results: map[Output:
Full output is too long, showing 1000 out of 6822520 lines.
[commit 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2
Author: Linus Torvalds <torvalds@ppc970.osdl.org>
Date: Sat Apr 16 15:20:36 2005 -0700
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
diff --git a/COPYING b/COPYING
new file mode 100644
index 000000000000..2a7e338ec2fc
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,356 @@
+
+ NOTE! This copyright does *not* cover user programs that use kernel
+ services by normal system calls - this is merely considered normal use
+ of the kernel, and does *not* fall under the heading of "derived work".
+ Also note that the GPL below is copyrighted by the Free Software
+ Foundation, but the instance of code that it refers to (the Linux
+ kernel) is copyrighted by me and others who actually wrote it.
+
+ Also note that the only valid version of the GPL as far as the kernel
+ is concerned is _this_ particular version of the license (ie v2, not
+ v2.2 or v3.x or whatever), unless explicitly otherwise stated.
+
+ Linus Torvalds
+
+----------------------------------------
+
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/CREDITS b/CREDITS
new file mode 100644
index 000000000000..671e9c2d31fe
--- /dev/null
+++ b/CREDITS
@@ -0,0 +1,3743 @@
+ This is at least a partial credits-file of people that have
+ contributed to the Linux project. It is sorted by name and
+ formatted to allow easy grepping and beautification by
+ scripts. The fields are: name (N), email (E), web-address
+ (W), PGP key ID and fingerprint (P), description (D), and
+ snail-mail address (S).
+ Thanks,
+
+ Linus
+----------
+
+N: Matti Aarnio
+E: mea@nic.funet.fi
+D: Alpha systems hacking, IPv6 and other network related stuff
+D: One of assisting postmasters for vger.kernel.org's lists
+S: (ask for current address)
+S: Finland
+
+N: Dragos Acostachioaie
+E: dragos@iname.com
+W: http://www.arbornet.org/~dragos
+D: /proc/sysvipc
+S: C. Negri 6, bl. D3
+S: Iasi 6600
+S: Romania
+
+N: Monalisa Agrawal
+E: magrawal@nortelnetworks.com
+D: Basic Interphase 5575 driver with UBR and ABR support.
+S: 75 Donald St, Apt 42
+S: Weymouth, MA 02188
+
+N: Dave Airlie
+E: airlied@linux.ie
+W: http://www.csn.ul.ie/~airlied
+D: NFS over TCP patches
+D: in-kernel DRM Maintainer
+S: Longford, Ireland
+S: Sydney, Australia
+
+N: Tigran A. Aivazian
+E: tigran@veritas.com
+W: http://www.moses.uklinux.net/patches
+D: BFS filesystem
+D: Intel IA32 CPU microcode update support
+D: Various kernel patches
+S: United Kingdom
+
+N: Werner Almesberger
+E: werner@almesberger.net
+W: http://www.almesberger.net/
+D: dosfs, LILO, some fd features, ATM, various other hacks here and there
+S: Buenos Aires
+S: Argentina
+
+N: Tim Alpaerts
+E: tim_alpaerts@toyota-motor-europe.com
+D: 802.2 class II logical link control layer,
+D: the humble start of an opening towards the IBM SNA protocols
+S: Klaproosstraat 72 c 10
+S: B-2610 Wilrijk-Antwerpen
+S: Belgium
+
+N: Anton Altaparmakov
+E: aia21@cantab.net
+W: http://www-stu.christs.cam.ac.uk/~aia21/
+D: Author of new NTFS driver, various other kernel hacks.
+S: Christ's College
+S: Cambridge CB2 3BU
+S: United Kingdom
+
+N: C. Scott Ananian
+E: cananian@alumni.princeton.edu
+W: http://www.pdos.lcs.mit.edu/~cananian
+P: 1024/85AD9EED AD C0 49 08 91 67 DF D7 FA 04 1A EE 09 E8 44 B0
+D: Unix98 pty support.
+D: APM update to 1.2 spec.
+D: /devfs hacking.
+S: 7 Kiwi Loop
+S: Howell, NJ 07731
+S: USA
+
+N: Erik Andersen
+E: andersen@codepoet.org
+W: http://www.codepoet.org/
+P: 1024D/30D39057 1BC4 2742 E885 E4DE 9301 0C82 5F9B 643E 30D3 9057
+D: Maintainer of ide-cd and Uniform CD-ROM driver,
+D: ATAPI CD-Changer support, Major 2.1.x CD-ROM update.
+S: 352 North 525 East
+S: Springville, Utah 84663
+S: USA
+
+N: Michael Ang
+E: mang@subcarrier.org
+W: http://www.subcarrier.org/mang
+D: Linux/PA-RISC hacker
+S: 85 Frank St.
+S: Ottawa, Ontario
+S: Canada K2P 0X3
+
+N: H. Peter Anvin
+E: hpa@zytor.com
+W: http://www.zytor.com/~hpa/
+P: 2047/2A960705 BA 03 D3 2C 14 A8 A8 BD 1E DF FE 69 EE 35 BD 74
+D: Author of the SYSLINUX boot loader, maintainer of the linux.* news
+D: hierarchy and the Linux Device List; various kernel hacks
+S: 4390 Albany Drive #46
+S: San Jose, California 95129
+S: USA
+
+N: Andrea Arcangeli
+E: andrea@suse.de
+W: http://www.kernel.org/pub/linux/kernel/people/andrea/
+P: 1024D/68B9CB43 13D9 8355 295F 4823 7C49 C012 DFA1 686E 68B9 CB43
+P: 1024R/CB4660B9 CC A0 71 81 F4 A0 63 AC C0 4B 81 1D 8C 15 C8 E5
+D: Parport hacker
+D: Implemented a workaround for some interrupt buggy printers
+D: Author of pscan that helps to fix lp/parport bugs
+D: Author of lil (Linux Interrupt Latency benchmark)
+D: Fixed the shm swap deallocation at swapoff time (try_to_unuse message)
+D: VM hacker
+D: Various other kernel hacks
+S: Via Cicalini 26
+S: Imola 40026
+S: Italy
+
+N: Derek Atkins
+E: warlord@MIT.EDU
+D: Linux-AFS Port, random kernel hacker,
+D: VFS fixes (new notify_change in particular)
+D: Moving all VFS access checks into the file systems
+S: MIT Room E15-341
+S: 20 Ames Street
+S: Cambridge, Massachusetts 02139
+S: USA
+
+N: Michel Aubry
+E: giovanni <giovanni@sudfr.com>
+D: Aladdin 1533/1543(C) chipset IDE
+D: VIA MVP-3/TX Pro III chipset IDE
+
+N: Jens Axboe
+E: axboe@suse.de
+D: Linux CD-ROM maintainer, DVD support
+D: elevator + block layer rewrites
+D: highmem I/O support
+D: misc hacking on IDE, SCSI, block drivers, etc
+S: Peter Bangs Vej 258, 2TH
+S: 2500 Valby
+S: Denmark
+
+N: John Aycock
+E: aycock@cpsc.ucalgary.ca
+D: Adaptec 274x driver
+S: Department of Computer Science
+S: University of Calgary
+S: Calgary, Alberta
+S: Canada
+
+N: Miles Bader
+E: miles@gnu.org
+D: v850 port (uClinux)
+S: NEC Corporation
+S: 1753 Shimonumabe, Nakahara-ku
+S: Kawasaki 211-8666
+S: Japan
+
+N: Ralf Baechle
+E: ralf@gnu.org
+P: 1024/AF7B30C1 CF 97 C2 CC 6D AE A7 FE C8 BA 9C FC 88 DE 32 C3
+D: Linux/MIPS port
+D: Linux/68k hacker
+S: Hauptstrasse 19
+S: 79837 St. Blasien
+S: Germany
+
+N: Krishna Balasubramanian
+E: balasub@cis.ohio-state.edu
+D: Wrote SYS V IPC (part of standard kernel since 0.99.10)
+
+N: Dario Ballabio
+E: ballabio_dario@emc.com
+E: dario.ballabio@tiscalinet.it
+E: dario.ballabio@inwind.it
+D: Author and maintainer of the Ultrastor 14F/34F SCSI driver
+D: Author and maintainer of the EATA ISA/EISA/PCI SCSI driver
+S: EMC Corporation
+S: Milano
+S: Italy
+
+N: Paul Bame
+E: bame@debian.org
+E: bame@puffin.external.hp.com
+E: paul_bame@hp.com
+W: http://www.parisc-linux.org
+D: PA-RISC 32 and 64-bit early boot, firmware interface, interrupts, misc
+S: MS42
+S: Hewlett-Packard
+S: 3404 E Harmony Rd
+S: Fort Collins, CO 80525
+
+N: Arindam Banerji
+E: axb@cse.nd.edu
+D: Contributed ESDI driver routines needed to port LINUX to the PS/2 MCA.
+S: Department of Computer Science & Eng.
+S: University of Notre Dame
+S: Notre Dame, Indiana
+S: USA
+
+N: Greg Banks
+E: gnb@alphalink.com.au
+D: IDT77105 ATM network driver
+D: some SuperH port work
+D: some trivial futzing with kconfig
+
+N: James Banks
+E: james@sovereign.org
+D: TLAN network driver
+D: Logitech Busmouse driver
+
+N: Krzysztof G. Baranowski
+E: kgb@manjak.knm.org.pl
+P: 1024/FA6F16D1 96 D1 1A CF 5F CA 69 EC F9 4F 36 1F 6D 60 7B DA
+D: Maintainer of the System V file system.
+D: System V fs update for 2.1.x dcache.
+D: Forward ported a couple of SCSI drivers.
+D: Various bugfixes.
+S: ul. Koscielna 12a
+S: 62-300 Wrzesnia
+S: Poland
+
+N: Fred Barnes
+E: frmb2@ukc.ac.uk
+D: Various parport/ppdev hacks and fixes
+S: Computing Lab, The University
+S: Canterbury, KENT
+S: CT2 7NF
+S: England
+
+N: Paul Barton-Davis
+E: pbd@op.net
+D: Driver for WaveFront soundcards (Turtle Beach Maui, Tropez, Tropez+)
+D: Various bugfixes and changes to sound drivers
+S: USA
+
+N: Carlos Henrique Bauer
+E: chbauer@acm.org
+E: bauer@atlas.unisinos.br
+D: Some new sysctl entries for the parport driver.
+D: New sysctl function for handling unsigned longs
+S: Universidade do Vale do Rio dos Sinos - UNISINOS
+S: DSI/IDASI
+S: Av. Unisinos, 950
+S: 93022000 Sao Leopoldo RS
+S: Brazil
+
+N: Peter Bauer
+E: 100136.3530@compuserve.com
+D: Driver for depca-ethernet-board
+S: 69259 Wilhemsfeld
+S: Rainweg 15
+S: Germany
+
+N: Fred Baumgarten
+E: dc6iq@insl1.etec.uni-karlsruhe.de
+E: dc6iq@adacom.org
+E: dc6iq@db0ais.#hes.deu.eu (packet radio)
+D: NET-2 & netstat(8)
+S: Soevener Strasse 11
+S: 53773 Hennef
+S: Germany
+
+N: Donald Becker
+E: becker@cesdis.gsfc.nasa.gov
+D: General low-level networking hacker
+D: Most of the ethercard drivers
+D: Original author of the NFS server
+S: USRA Center of Excellence in Space Data and Information Sciences
+S: Code 930.5, Goddard Space Flight Center
+S: Greenbelt, Maryland 20771
+S: USA
+
+N: Adam Belay
+E: ambx1@neo.rr.com
+D: Linux Plug and Play Support
+S: USA
+
+N: Daniele Bellucci
+E: bellucda@tiscali.it
+D: Various Janitor work.
+W: http://web.tiscali.it/bellucda
+S: Via Delle Palme, 9
+S: Terni 05100
+S: Italy
+
+N: Krzysztof Benedyczak
+E: golbi@mat.uni.torun.pl
+W: http://www.mat.uni.torun.pl/~golbi
+D: POSIX message queues fs (with M. Wronski)
+S: ul. Podmiejska 52
+S: Radunica
+S: 83-000 Pruszcz Gdanski
+S: Poland
+
+N: Randolph Bentson
+E: bentson@grieg.seaslug.org
+W: http://www.aa.net/~bentson/
+P: 1024/39ED5729 5C A8 7A F4 B2 7A D1 3E B5 3B 81 CF 47 30 11 71
+D: Author of driver for Cyclom-Y and Cyclades-Z async mux
+S: 2322 37th Ave SW
+S: Seattle, Washington 98126-2010
+S: USA
+
+N: Stephen R. van den Berg (AKA BuGless)
+E: berg@pool.informatik.rwth-aachen.de
+D: General kernel, gcc, and libc hacker
+D: Specialisation: tweaking, ensuring portability, tweaking, cleaning,
+D: tweaking and occasionally debugging :-)
+S: Bouwensstraat 22
+S: 6369 BG Simpelveld
+S: The Netherlands
+
+N: Peter Berger
+E: pberger@brimson.com
+W: http://www.brimson.com
+D: Author/maintainer of Digi AccelePort USB driver
+S: 1549 Hiironen Rd.
+S: Brimson, MN 55602
+S: USA
+
+N: Hennus Bergman
+P: 1024/77D50909 76 99 FD 31 91 E1 96 1C 90 BB 22 80 62 F6 BD 63
+D: Author and maintainer of the QIC-02 tape driver
+S: The Netherlands
+
+N: Tomas Berndtsson
+E: tomas@nocrew.org
+W: http://tomas.nocrew.org/
+D: dsp56k device driver
+
+N: Ross Biro
+E: bir7@leland.Stanford.Edu
+D: Original author of the Linux networking code
+
+N: Anton Blanchard
+E: anton@samba.org
+W: http://samba.org/~anton/
+P: 1024/8462A731 4C 55 86 34 44 59 A7 99 2B 97 88 4A 88 9A 0D 97
+D: sun4 port, Sparc hacker
+
+N: Hugh Blemings
+E: hugh@misc.nu
+W: http://misc.nu/hugh/
+D: Author and maintainer of the Keyspan USB to Serial drivers
+S: Po Box 234
+S: Belconnen ACT 2616
+S: Australia
+
+N: Philip Blundell
+E: philb@gnu.org
+D: Linux/ARM hacker
+D: Device driver hacker (eexpress, 3c505, c-qcam, ...)
+D: m68k port to HP9000/300
+D: AUN network protocols
+D: Co-architect of the parallel port sharing system
+D: IPv6 netfilter
+S: FutureTV Labs Ltd
+S: Brunswick House, 61-69 Newmarket Rd, Cambridge CB5 8EG
+S: United Kingdom
+
+N: Thomas Bogend�rfer
+E: tsbogend@alpha.franken.de
+D: PCnet32 driver, SONIC driver, JAZZ_ESP driver
+D: newport abscon driver, g364 framebuffer driver
+D: strace for Linux/Alpha
+D: Linux/MIPS hacker
+S: Schafhofstr. 40
+S: 90556 Cadolzburg
+S: Germany
+
+N: Bill Bogstad
+E: bogstad@pobox.com
+D: wrote /proc/self hack, minor samba & dosemu patches
+
+N: Axel Boldt
+E: axel@uni-paderborn.de
+W: http://math-www.uni-paderborn.de/~axel/
+D: Configuration help text support
+D: Linux CD and Support Giveaway List
+
+N: Erik Inge Bols�
+E: knan@mo.himolde.no
+D: Misc kernel hacks
+
+N: Andreas E. Bombe
+E: andreas.bombe@munich.netsurf.de
+W: http://home.pages.de/~andreas.bombe/
+P: 1024/04880A44 72E5 7031 4414 2EB6 F6B4 4CBD 1181 7032 0488 0A44
+D: IEEE 1394 subsystem rewrite and maintainer
+D: Texas Instruments PCILynx IEEE 1394 driver
+
+N: Al Borchers
+E: alborchers@steinerpoint.com
+D: Author/maintainer of Digi AccelePort USB driver
+D: work on usbserial and keyspan_pda drivers
+S: 4912 Zenith Ave. S.
+S: Minneapolis, MN 55410
+S: USA
+
+N: Marc Boucher
+E: marc@mbsi.ca
+P: CA 67 A5 1A 38 CE B6 F2 D5 83 51 03 D2 9C 30 9E CE D2 DD 65
+D: Netfilter core
+D: IP policy routing by mark
+D: Various fixes (mostly networking)
+S: Montreal, Quebec
+S: Canada
+
+N: Zolt�n B�sz�rm�nyi
+E: zboszor@mail.externet.hu
+D: MTRR emulation with Cyrix style ARR registers, Athlon MTRR support
+
+N: John Boyd
+E: boyd@cis.ohio-state.edu
+D: Co-author of wd7000 SCSI driver
+S: 101 Curl Drive #591
+S: Columbus, Ohio 43210
+S: USA
+
+N: Peter Braam
+E: braam@clusterfs.com
+W: http://www.clusterfs.com/
+D: Coda & InterMezzo filesystems
+S: 181 McNeil
+S: Canmore, AB
+S: Canada, T1W 2R9
+
+N: Ryan Bradetich
+E: rbradetich@uswest.net
+D: Linux/PA-RISC hacker
+S: 1200 Goldenrod Dr.
+S: Nampa, Idaho 83686
+
+N: Derrick J. Brashear
+E: shadow@dementia.org
+W: http://www.dementia.org/~shadow
+P: 512/71EC9367 C5 29 0F BC 83 51 B9 F0 BC 05 89 A0 4F 1F 30 05
+D: Author of Sparc CS4231 audio driver, random Sparc work
+S: 403 Gilmore Avenue
+S: Trafford, Pennsylvania 15085
+S: USA
+
+N: Dag Brattli
+E: dagb@cs.uit.no
+W: http://www.cs.uit.no/~dagb
+D: IrDA Subsystem
+S: 19. Wellington Road
+S: Lancaster, LA1 4DN
+S: UK, England
+
+N: Lars Brinkhoff
+E: lars@nocrew.org
+W: http://lars.nocrew.org/
+D: dsp56k device driver
+D: ptrace proxy in user mode kernel port
+S: Kopmansg 2
+S: 411 13 Goteborg
+S: Sweden
+
+N: Dominik Brodowski
+E: linux@brodo.de
+W: http://www.brodo.de/
+P: 1024D/725B37C6 190F 3E77 9C89 3B6D BECD 46EE 67C3 0308 725B 37C6
+D: parts of CPUFreq code, ACPI bugfixes
+S: Tuebingen, Germany
+
+N: Andries Brouwer
+E: aeb@cwi.nl
+D: random Linux hacker
+S: Bessemerstraat 21
+S: Amsterdam
+S: The Netherlands
+
+N: Zach Brown
+E: zab@zabbo.net
+D: maestro pci sound
+
+N: Gary Brubaker
+E: xavyer@ix.netcom.com
+D: USB Serial Empeg Empeg-car Mark I/II Driver
+
+N: Matthias Bruestle
+E: m@mbsks.franken.de
+D: REINER SCT cyberJack pinpad/e-com USB chipcard reader driver
+S: Germany
+
+N: Adrian Bunk
+E: bunk@stusta.de
+P: 1024D/4F12B400 B29C E71E FE19 6755 5C8A 84D4 99FC EA98 4F12 B400
+D: misc kernel hacking and testing
+S: Grasmeierstrasse 11
+S: 80805 Muenchen
+S: Germany
+
+N: Ray Burr
+E: ryb@nightmare.com
+D: Original author of Amiga FFS filesystem
+S: Orlando, Florida
+S: USA
+
+N: Lennert Buytenhek
+E: buytenh@gnu.org
+D: Rewrite of the ethernet bridging code
+S: Ravenhorst 58B
+S: 2317 AK Leiden
+S: The Netherlands
+
+N: Michael Callahan
+E: callahan@maths.ox.ac.uk
+D: PPP for Linux
+S: The Mathematical Institute
+S: 25-29 St Giles
+S: Oxford
+S: United Kingdom
+
+N: Luiz Fernando N. Capitulino
+E: lcapitulino@terra.com.br
+E: lcapitulino@prefeitura.sp.gov.br
+W: http://www.telecentros.sp.gov.br
+D: Little fixes and a lot of janitorial work
+S: E-GOV Telecentros SP
+S: Brazil
+
+N: Remy Card
+E: Remy.Card@masi.ibp.fr
+E: Remy.Card@linux.org
+D: Extended file system [defunct] designer and developer
+D: Second extended file system designer and developer
+S: Institut Blaise Pascal
+S: 4 Place Jussieu
+S: 75252 Paris Cedex 05
+S: France
+
+N: Ulf Carlsson
+D: SGI Indy audio (HAL2) drivers
+E: ulfc@bun.falkenberg.se
+
+N: Ed Carp
+E: ecarp@netcom.com
+D: uucp, elm, pine, pico port
+D: cron, at(1) developer
+S: 48287 Sawleaf
+S: Fremont, California 94539
+S: USA
+
+N: Florent Chabaud
+E: florent.chabaud@polytechnique.org
+D: software suspend
+S: SGDN/DCSSI/SDS/LTI
+S: 58, Bd Latour-Maubourg
+S: 75700 Paris 07 SP
+S: France
+
+N: Gordon Chaffee
+E: chaffee@cs.berkeley.edu
+W: http://bmrc.berkeley.edu/people/chaffee/
+D: vfat, fat32, joliet, native language support
+S: 3700 Warwick Road
+S: Fremont, California 94555
+S: USA
+
+N: Chih-Jen Chang
+E: chihjenc@scf.usc.edu
+E: chihjen@iis.sinica.edu.tw
+D: IGMP(Internet Group Management Protocol) version 2
+S: 3F, 65 Tajen street
+S: Tamsui town, Taipei county,
+S: Taiwan 251
+S: Republic of China
+
+N: Michael Elizabeth Chastain
+E: mec@shout.net
+D: Configure, Menuconfig, xconfig
+
+N: Raymond Chen
+E: raymondc@microsoft.com
+D: Author of Configure script
+S: 14509 NE 39th Street #1096
+S: Bellevue, Washington 98007
+S: USA
+
+N: Christopher L. Cheney
+E: ccheney@debian.org
+E: ccheney@cheney.cx
+W: http://www.cheney.cx
+P: 1024D/8E384AF2 2D31 1927 87D7 1F24 9FF9 1BC5 D106 5AB3 8E38 4AF2
+D: Vista Imaging usb webcam driver
+S: 314 Prince of Wales
+S: Conroe, TX 77304
+S: USA
+
+N: Stuart Cheshire
+E: cheshire@cs.stanford.edu
+D: Author of Starmode Radio IP (STRIP) driver
+D: Originator of design for new combined interrupt handlers
+S: William Gates Department
+S: Stanford University
+S: Stanford, California 94305
+S: USA
+
+N: Randolph Chung
+E: tausq@debian.org
+D: Linux/PA-RISC hacker
+S: Los Altos, CA 94022
+S: USA
+
+N: Juan Jose Ciarlante
]
]
|
| 254/2 |
2026/08/17 22:09 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 40287
output: 53
thoughts: 93
Thoughts: **Initial Kernel Commit - Immediate Response**
Okay, so I'm looking at commit `1da177e4c3f41524e886b7f1b8a0c1fc7321cac2`. Right. That's it. No need to overthink this. This is the starting point, the Genesis block of the Linux kernel as it exists in the Git repository. Considering this is a baseline, a foundational element, the logical return is simply the commit hash itself. No analysis needed, no deeper probing. This is a straightforward lookup, and the response is equally straightforward. Therefore, I will respond with `1da177e4c3f41524e886b7f1b8a0c1fc7321cac2`.
|
| 255/2 |
2026/08/17 22:10 |
tool |
set-results |
0m
Args: map[FixesHash:1da177e4c3f41524e886b7f1b8a0c1fc7321cac2]
Results: map[FixesHash:1da177e4c3f41524e886b7f1b8a0c1fc7321cac2]
|
| 256/1 |
2026/08/17 22:10 |
action |
format-fixes |
0m
Results: map[Fixes:map[AuthorEmail:torvalds@ppc970.osdl.org AuthorName:Linus Torvalds Hash:1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Title:Linux-2.6.12-rc2]]
|
| 257/1 |
2026/08/17 22:10 |
action |
get-maintainers |
0m
Results: map[Recipients:[map[Email:kees@kernel.org Name:Kees Cook To:false] map[Email:linux-kernel@vger.kernel.org Name: To:false] map[Email:linux-media@vger.kernel.org Name: To:true] map[Email:mchehab@kernel.org Name:Mauro Carvalho Chehab To:true] map[Email:torvalds@ppc970.osdl.org Name:Linus Torvalds To:true]]]
|
| 258/1 |
2026/08/17 22:10 |
action |
get-recent-commits |
0m
Results: map[RecentCommits:Convert 'alloc_obj' family to use the new default GFP_KERNEL argument
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
media: Convert from tasklet to BH workqueue
media: ttusb-dec: remove unnecessary (void*) conversions
media: usb: remove unnecessary (void*) conversions
media: ttusb-dec: fix memory leak in ttusb_dec_exit_dvb()
media: ttusb-dec: avoid release of non-acquired mutex
media: ttusb-dec: cleanup an error handling logic
media: media/usb:Remove superfluous "breaks" in the ttusb_dec.c
media: ttusb-dec: convert tasklets to use new tasklet_setup() API
media: usb: ttusb-dec: reduce the number of memory reads in ttusb_dec_handle_irq()
media: ttusb-dec: Fix info-leak in ttusb_dec_send_command()
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157
media: usb: fix several typos
media: dvb: represent min/max/step/tolerance freqs in Hz
media: dvb: update buffer mmaped flags and frame counter
media: ttusb-dec: Remove pci_zalloc_coherent() abuse
media: move dvb kAPI headers to include/media
media: usb: constify usb_device_id
[media] media: Drop FSF's postal address from the source code files
]
|
| 259/1 |
2026/08/17 22:10 |
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.
The one-line summary should describe the change being made, rather than mention the tool that
detected the bug.
The description must not contain lines starting with '#' because they will dropped by git as comments.
The description must not contain lines starting with '--' or '---' (including inline code diffs)
because they may confuse git/patch utilities.
Your final reply should contain only the text of the commit description.
The one-line summary must be not longer than 72 characters.
IMPORTANT: Do not wrap lines manually (e.g., at 80 characters); we will reformat the text
automatically, so keep paragraphs as single lines without newlines.
Generally try to phrase the description without mentioning syzkaller
(avoid phrases like "the bug was triggered by syzkaller" or "the bug was triggered by fuzzer", etc).
How the bug was triggered is generally an irrelevant detail.
Any bug triggered by a fuzzer can also be triggered by a malicious user, or a buggy program.
If the crash is reported by a sanitizer (e.g., KASAN, KMSAN, lockdep), include the relevant
parts of the sanitizer output to illustrate the problem. Exclude less relevant sections,
as the stack trace can be very long. Describe the execution path that leads to the manifestation
of the kernel bug.
If the patch removes the WARN_ON macro, refer to the fact that WARN_ON
must not be used for conditions that can legitimately happen, and that pr_err
should be used instead if necessary.
Don't assume that panic_on_warn is set, and that WARNINGs are fatal.
While panic_on_warn may be set when the bug was reproduced, it's generally not set on production systems.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash that corresponds to the bug is:
usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
------------[ cut here ]------------
memcpy: detected buffer overflow: 75 byte read of buffer size 60
WARNING: lib/string_helpers.c:1037 at __fortify_report+0xa0/0xb8 lib/string_helpers.c:1036, CPU#0: kworker/0:4/4798
Modules linked in:
CPU: 0 UID: 0 PID: 4798 Comm: kworker/0:4 Not tainted syzkaller #1 PREEMPT
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/07/2026
Workqueue: usb_hub_wq hub_event
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : __fortify_report+0xa0/0xb8 lib/string_helpers.c:1036
lr : __fortify_report+0xa0/0xb8 lib/string_helpers.c:1036
sp : ffff800098516d20
x29: ffff800098516d20 x28: dfff800000000000 x27: ffff7000130a2db0
x26: 0000000000000000 x25: ffff0000d1862683 x24: ffff800098516ea0
x23: 000000000000004b x22: ffff800086d0a338 x21: 0000000000000000
x20: 000000000000004b x19: 000000000000003c x18: 1fffe00035ba8028
x17: 0000000000000003 x16: ffff800088ba7000 x15: ffff8000824ea6c8
x14: 0000000000000000 x13: 0000000000000001 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000002 x9 : 653dfa0a2f6c5200
x8 : 653dfa0a2f6c5200 x7 : ffff80008048e0c4 x6 : 0000000000000000
x5 : 0000000000000000 x4 : 0000000000000000 x3 : ffff8000802f8054
x2 : 0000000100000000 x1 : ffff0000c57d1d40 x0 : 0000000000000000
Call trace:
__fortify_report+0xa0/0xb8 lib/string_helpers.c:1036 (P)
__fortify_panic+0x10/0x14 lib/string_helpers.c:1043
fortify_memcpy_chk include/linux/fortify-string.h:549 [inline]
ttusb_dec_start_feed+0x0/0x10ac drivers/media/usb/ttusb-dec/ttusb_dec.c:372
ttusb_dec_get_stb_state drivers/media/usb/ttusb-dec/ttusb_dec.c:392 [inline]
ttusb_dec_init_stb drivers/media/usb/ttusb-dec/ttusb_dec.c:1413 [inline]
ttusb_dec_probe+0x724/0x1aa0 drivers/media/usb/ttusb-dec/ttusb_dec.c:1671
usb_probe_interface+0x308/0x788 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_set_configuration+0x1184/0x158c drivers/usb/core/message.c:2268
usb_generic_driver_probe+0x8c/0x148 drivers/usb/core/generic.c:250
usb_probe_device+0x114/0x2b0 drivers/usb/core/driver.c:291
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_new_device+0x9c4/0x11f8 drivers/usb/core/hub.c:2703
hub_port_connect drivers/usb/core/hub.c:5575 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5715 [inline]
port_event drivers/usb/core/hub.c:5879 [inline]
hub_event+0x1ef0/0x39fc drivers/usb/core/hub.c:5961
process_one_work kernel/workqueue.c:3322 [inline]
process_scheduled_works+0x788/0x10b8 kernel/workqueue.c:3405
worker_thread+0x798/0xbd0 kernel/workqueue.c:3486
kthread+0x304/0x3d4 kernel/kthread.c:436
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:842
irq event stamp: 16196
hardirqs last enabled at (16195): [<ffff8000868fc7b4>] irqentry_exit_to_kernel_mode_after_preempt include/linux/irq-entry-common.h:507 [inline]
hardirqs last enabled at (16195): [<ffff8000868fc7b4>] arm64_exit_to_kernel_mode+0x80/0x94 arch/arm64/kernel/entry-common.c:62
hardirqs last disabled at (16196): [<ffff8000868f86e0>] el1_brk64+0x20/0x54 arch/arm64/kernel/entry-common.c:425
softirqs last enabled at (16128): [<ffff80008030ff18>] softirq_handle_end kernel/softirq.c:468 [inline]
softirqs last enabled at (16128): [<ffff80008030ff18>] handle_softirqs+0xc28/0xd98 kernel/softirq.c:650
softirqs last disabled at (16119): [<ffff8000800204b0>] __do_softirq+0x14/0x20 kernel/softirq.c:656
---[ end trace 0000000000000000 ]---
------------[ cut here ]------------
kernel BUG at lib/string_helpers.c:1044!
Internal error: Oops - BUG: 00000000f2000800 [#1] SMP
Modules linked in:
CPU: 0 UID: 0 PID: 4798 Comm: kworker/0:4 Tainted: G W syzkaller #1 PREEMPT
Tainted: [W]=WARN
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/07/2026
Workqueue: usb_hub_wq hub_event
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : __fortify_panic+0x10/0x14 lib/string_helpers.c:1043
lr : __fortify_panic+0x10/0x14 lib/string_helpers.c:1043
sp : ffff800098516d50
x29: ffff800098516d50 x28: dfff800000000000 x27: ffff7000130a2db0
x26: 0000000000000000 x25: ffff0000d1862683 x24: ffff800098516ea0
x23: 000000000000004b x22: 000000000000004b x21: ffff0000d1862680
x20: 1fffe0001a30c4d0 x19: ffff0000c3014000 x18: 1fffe00035ba8028
x17: 0000000000000003 x16: ffff800088ba7000 x15: ffff8000824ea6c8
x14: 0000000000000000 x13: 0000000000000001 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000002 x9 : 653dfa0a2f6c5200
x8 : 653dfa0a2f6c5200 x7 : ffff80008048e0c4 x6 : 0000000000000000
x5 : 0000000000000000 x4 : 0000000000000000 x3 : ffff8000802f8054
x2 : 0000000100000000 x1 : ffff0000c57d1d40 x0 : 0000000000000000
Call trace:
__fortify_panic+0x10/0x14 lib/string_helpers.c:1043 (P)
fortify_memcpy_chk include/linux/fortify-string.h:549 [inline]
ttusb_dec_start_feed+0x0/0x10ac drivers/media/usb/ttusb-dec/ttusb_dec.c:372
ttusb_dec_get_stb_state drivers/media/usb/ttusb-dec/ttusb_dec.c:392 [inline]
ttusb_dec_init_stb drivers/media/usb/ttusb-dec/ttusb_dec.c:1413 [inline]
ttusb_dec_probe+0x724/0x1aa0 drivers/media/usb/ttusb-dec/ttusb_dec.c:1671
usb_probe_interface+0x308/0x788 drivers/usb/core/driver.c:396
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_set_configuration+0x1184/0x158c drivers/usb/core/message.c:2268
usb_generic_driver_probe+0x8c/0x148 drivers/usb/core/generic.c:250
usb_probe_device+0x114/0x2b0 drivers/usb/core/driver.c:291
call_driver_probe drivers/base/dd.c:-1 [inline]
really_probe+0x29c/0x800 drivers/base/dd.c:706
__driver_probe_device+0x1e0/0x350 drivers/base/dd.c:868
driver_probe_device+0x6c/0x19c drivers/base/dd.c:898
__device_attach_driver+0x198/0x2f8 drivers/base/dd.c:1026
bus_for_each_drv+0x144/0x1dc drivers/base/bus.c:500
__device_attach+0x248/0x390 drivers/base/dd.c:1098
device_initial_probe+0x90/0xc8 drivers/base/dd.c:1153
bus_probe_device+0x58/0x120 drivers/base/bus.c:620
device_add+0x6cc/0x9e0 drivers/base/core.c:3772
usb_new_device+0x9c4/0x11f8 drivers/usb/core/hub.c:2703
hub_port_connect drivers/usb/core/hub.c:5575 [inline]
hub_port_connect_change drivers/usb/core/hub.c:5715 [inline]
port_event drivers/usb/core/hub.c:5879 [inline]
hub_event+0x1ef0/0x39fc drivers/usb/core/hub.c:5961
process_one_work kernel/workqueue.c:3322 [inline]
process_scheduled_works+0x788/0x10b8 kernel/workqueue.c:3405
worker_thread+0x798/0xbd0 kernel/workqueue.c:3486
kthread+0x304/0x3d4 kernel/kthread.c:436
ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:842
Code: d503233f a9bf7bfd 910003fd 94619ee8 (d4210000)
---[ end trace 0000000000000000 ]---
The explanation of the root cause of the bug is:
The crash is caused by a buffer overflow (both an out-of-bounds read and an out-of-bounds write) in the `ttusb_dec_send_command()` function, triggered by a malicious or malfunctioning USB device returning an unexpectedly large payload length.
### Detailed Analysis
In `drivers/media/usb/ttusb-dec/ttusb_dec.c`, the `ttusb_dec_send_command()` function allocates a buffer `b` to send a command and receive the response via `usb_bulk_msg()`:
```c
b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
```
Here, `COMMAND_PACKET_SIZE` is defined as `0x3c` (60), so the allocated buffer `b` is exactly 64 bytes.
After receiving the response from the USB device, the driver reads the payload length directly from `b[3]` (which is fully controlled by the USB device) and copies the payload into the caller-provided `cmd_result` buffer:
```c
if (result_length)
*result_length = b[3];
if (cmd_result && b[3] > 0)
memcpy(cmd_result, &b[4], b[3]);
```
There are two major flaws in this logic:
1. **No bounds check against the received data or the allocated buffer `b`**: `b[3]` is an 8-bit value and can be up to 255. If the device returns a value greater than `COMMAND_PACKET_SIZE` (60), the `memcpy()` will read past the end of the 64-byte buffer `b`. In the syzkaller crash, `b[3]` was `75`, leading to a 75-byte read from `&b[4]` (which only has 60 bytes allocated). This triggers the `fortify_memcpy_chk` panic (`75 byte read of buffer size 60`).
2. **No bounds check against the destination buffer `cmd_result`**: The size of `cmd_result` is never passed to `ttusb_dec_send_command()`. While callers like `ttusb_dec_get_stb_state()` pass a 60-byte buffer (`u8 c[COMMAND_PACKET_SIZE]`), other callers like `ttusbdecfe_dvbt_read_status()` in `ttusbdecfe.c` pass a much smaller buffer (`u8 result[4]`). If the device returns `b[3] = 60` for the latter, it will result in a severe stack buffer overflow.
### Proposed Fix
To fix this comprehensively, the API needs to be updated to pass the size of the destination buffer, and `ttusb_dec_send_command()` must validate `b[3]` against the received length, the maximum packet size, and the destination buffer size.
**1. Update `ttusbdecfe_config` in `drivers/media/usb/ttusb-dec/ttusbdecfe.h`:**
Add `cmd_result_len` to the `send_command` callback signature.
```c
struct ttusbdecfe_config
{
int (*send_command)(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len);
};
```
**2. Update `ttusb_dec_send_command()` in `ttusb_dec.c`:**
Add `cmd_result_len` to the signature and implement the necessary bounds checks.
```c
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
int *result_length, u8 cmd_result[],
int cmd_result_len)
{
// ...
result = usb_bulk_msg(dec->udev, dec->result_pipe, b,
COMMAND_PACKET_SIZE + 4, &actual_len, 1000);
if (result) {
printk("%s: result bulk message failed: error %d\n",
__func__, result);
goto err_mutex_unlock;
} else {
if (debug) {
printk(KERN_DEBUG "%s: result: %*ph\n",
__func__, actual_len, b);
}
/* Ensure we received at least the 4-byte header */
if (actual_len < 4) {
result = -EIO;
goto err_mutex_unlock;
}
/* Ensure the device isn't claiming more data than it sent or than fits in b */
if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
result = -EIO;
goto err_mutex_unlock;
}
if (result_length)
*result_length = b[3];
if (cmd_result && b[3] > 0) {
/* Ensure we don't overflow the caller's buffer */
if (b[3] > cmd_result_len) {
result = -EIO;
goto err_mutex_unlock;
}
memcpy(cmd_result, &b[4], b[3]);
}
}
// ...
```
**3. Update all callers:**
You will need to update all callers of `ttusb_dec_send_command()` in `ttusb_dec.c` and `state->config->send_command()` in `ttusbdecfe.c` to pass the correct buffer size.
For example:
- In `ttusb_dec_get_stb_state()`: pass `sizeof(c)` instead of just `c`.
- In `ttusbdecfe_dvbt_read_status()`: pass `sizeof(result)` instead of just `result`.
- For calls where `cmd_result` is `NULL`, simply pass `0` as the length.
The diff of the bug fix is:
diff --git a/drivers/media/usb/ttusb-dec/ttusb_dec.c b/drivers/media/usb/ttusb-dec/ttusb_dec.c
index 825a38759..b54b7b4bb 100644
--- a/drivers/media/usb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/usb/ttusb-dec/ttusb_dec.c
@@ -314,13 +314,17 @@ static u16 crc16(u16 crc, const u8 *buf, size_t len)
static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
int result, actual_len;
u8 *b;
dprintk("%s\n", __func__);
+ if (param_length > COMMAND_PACKET_SIZE)
+ return -EINVAL;
+
b = kzalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
if (!b)
return -ENOMEM;
@@ -366,10 +370,25 @@ static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
__func__, actual_len, b);
}
+ if (actual_len < 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
+ if (b[3] > COMMAND_PACKET_SIZE || b[3] > actual_len - 4) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
+
if (result_length)
*result_length = b[3];
- if (cmd_result && b[3] > 0)
+ if (cmd_result && b[3] > 0) {
+ if (b[3] > cmd_result_len) {
+ result = -EIO;
+ goto err_mutex_unlock;
+ }
memcpy(cmd_result, &b[4], b[3]);
+ }
}
err_mutex_unlock:
@@ -389,7 +408,8 @@ static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
dprintk("%s\n", __func__);
- result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
+ result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c,
+ sizeof(c));
if (result)
return result;
@@ -448,7 +468,7 @@ static void ttusb_dec_set_pids(struct ttusb_dec *dec)
memcpy(&b[2], &audio, 2);
memcpy(&b[4], &video, 2);
- ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x50, sizeof(b), b, NULL, NULL, 0);
dvb_filter_pes2ts_init(&dec->a_pes2ts, dec->pid[DMX_PES_AUDIO],
ttusb_dec_audio_pes2ts_cb, dec);
@@ -902,7 +922,7 @@ static int ttusb_dec_set_interface(struct ttusb_dec *dec,
break;
case TTUSB_DEC_INTERFACE_IN:
result = ttusb_dec_send_command(dec, 0x80, sizeof(b),
- b, NULL, NULL);
+ b, NULL, NULL, 0);
if (result)
return result;
result = usb_set_interface(dec->udev, 0, 8);
@@ -1021,7 +1041,7 @@ static int ttusb_dec_start_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
}
- result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x80, sizeof(b0), b0, NULL, NULL, 0);
if (result)
return result;
@@ -1056,7 +1076,7 @@ static int ttusb_dec_start_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
memcpy(&b0[5], &dvbdmxfeed->filter->filter.filter_value[0], 1);
result = ttusb_dec_send_command(dec, 0x60, sizeof(b0), b0,
- &c_length, c);
+ &c_length, c, sizeof(c));
if (!result) {
if (c_length == 2) {
@@ -1114,7 +1134,7 @@ static int ttusb_dec_stop_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
struct ttusb_dec *dec = dvbdmxfeed->demux->priv;
u8 b0[] = { 0x00 };
- ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x81, sizeof(b0), b0, NULL, NULL, 0);
dec->pva_stream_count--;
@@ -1135,7 +1155,7 @@ static int ttusb_dec_stop_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
list_del(&finfo->filter_info_list);
spin_unlock_irqrestore(&dec->filter_info_list_lock, flags);
kfree(finfo);
- ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL);
+ ttusb_dec_send_command(dec, 0x62, sizeof(b0), b0, NULL, NULL, 0);
dec->filter_stream_count--;
@@ -1238,7 +1258,7 @@ static int ttusb_init_rc( struct ttusb_dec *dec)
if (usb_submit_urb(dec->irq_urb, GFP_KERNEL))
printk("%s: usb_submit_urb failed\n",__func__);
/* enable irq pipe */
- ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
+ ttusb_dec_send_command(dec, 0xb0, sizeof(b), b, NULL, NULL, 0);
return 0;
}
@@ -1354,7 +1374,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
firmware_csum_ns = htons(firmware_csum);
memcpy(&b0[6], &firmware_csum_ns, 2);
- result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x41, sizeof(b0), b0, NULL, NULL, 0);
if (result) {
release_firmware(fw_entry);
@@ -1395,7 +1415,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
}
}
- result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL);
+ result = ttusb_dec_send_command(dec, 0x43, sizeof(b1), b1, NULL, NULL, 0);
release_firmware(fw_entry);
kfree(b);
@@ -1621,10 +1641,13 @@ static void ttusb_dec_exit_filters(struct ttusb_dec *dec)
static int fe_send_command(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[])
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len)
{
struct ttusb_dec* dec = fe->dvb->priv;
- return ttusb_dec_send_command(dec, command, param_length, params, result_length, cmd_result);
+ return ttusb_dec_send_command(dec, command, param_length, params,
+ result_length, cmd_result,
+ cmd_result_len);
}
static const struct ttusbdecfe_config fe_config = {
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.c b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
index 215221370..b013d6dfc 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.c
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
@@ -44,7 +44,8 @@ static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
*status=0;
- ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
+ ret = state->config->send_command(fe, 0x73, sizeof(b), b, &len, result,
+ sizeof(result));
if(ret)
return ret;
@@ -85,7 +86,7 @@ static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend *fe)
__be32 freq = htonl(p->frequency / 1000);
memcpy(&b[4], &freq, sizeof (u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
@@ -130,7 +131,7 @@ static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend *fe)
lnb_voltage = htonl(state->voltage);
memcpy(&b[28], &lnb_voltage, sizeof(u32));
- state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
+ state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL, 0);
return 0;
}
@@ -149,7 +150,7 @@ static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struc
state->config->send_command(fe, 0x72,
sizeof(b) - (6 - cmd->msg_len), b,
- NULL, NULL);
+ NULL, NULL, 0);
return 0;
}
diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.h b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
index 73828bb22..96600ad4c 100644
--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.h
+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.h
@@ -14,7 +14,8 @@ struct ttusbdecfe_config
{
int (*send_command)(struct dvb_frontend* fe, const u8 command,
int param_length, const u8 params[],
- int *result_length, u8 cmd_result[]);
+ int *result_length, u8 cmd_result[],
+ int cmd_result_len);
};
extern struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config);
Additional description of the patch:
I have analyzed the root cause and implemented the fix as proposed, with an additional safeguard.
### Changes made:
1. **Updated `ttusbdecfe_config`**: Added `cmd_result_len` to the `send_command` callback signature in `drivers/media/usb/ttusb-dec/ttusbdecfe.h`.
2. **Updated `ttusb_dec_send_command`**:
- Added `cmd_result_len` to the function signature.
- Added a check to ensure `param_length` does not exceed `COMMAND_PACKET_SIZE` before allocating and copying into the buffer `b`. This prevents a potential out-of-bounds write when copying `params` into `b`.
- Added bounds checks to ensure the received payload length (`b[3]`) does not exceed `COMMAND_PACKET_SIZE`, the actual received data length (`actual_len - 4`), or the caller-provided buffer size (`cmd_result_len`).
- Added a check to ensure `actual_len` is at least 4 bytes to safely read the header.
3. **Updated all callers**: Updated all invocations of `ttusb_dec_send_command` in `ttusb_dec.c` and `state->config->send_command` in `ttusbdecfe.c` to pass the correct destination buffer size (using `sizeof()`) or `0` when `cmd_result` is `NULL`.
### Why these changes were made:
The primary issue was trusting the device-provided length field (`b[3]`) without validating it against the bounds of the allocated buffer or the caller's destination buffer. By passing the destination buffer size down the call stack and validating `b[3]` against both the source (actual received data) and destination (caller's buffer size) boundaries, we ensure that malicious or malfunctioning USB devices cannot trigger out-of-bounds reads or writes.
Additionally, I added a check for `param_length > COMMAND_PACKET_SIZE` at the beginning of `ttusb_dec_send_command`. While current callers pass safe values, this prevents future callers from accidentally overflowing the allocated command buffer `b` when copying `params`.
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.
Convert 'alloc_obj' family to use the new default GFP_KERNEL argument
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
media: Convert from tasklet to BH workqueue
media: ttusb-dec: remove unnecessary (void*) conversions
media: usb: remove unnecessary (void*) conversions
media: ttusb-dec: fix memory leak in ttusb_dec_exit_dvb()
media: ttusb-dec: avoid release of non-acquired mutex
media: ttusb-dec: cleanup an error handling logic
media: media/usb:Remove superfluous "breaks" in the ttusb_dec.c
media: ttusb-dec: convert tasklets to use new tasklet_setup() API
media: usb: ttusb-dec: reduce the number of memory reads in ttusb_dec_handle_irq()
media: ttusb-dec: Fix info-leak in ttusb_dec_send_command()
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157
media: usb: fix several typos
media: dvb: represent min/max/step/tolerance freqs in Hz
media: dvb: update buffer mmaped flags and frame counter
media: ttusb-dec: Remove pci_zalloc_coherent() abuse
media: move dvb kAPI headers to include/media
media: usb: constify usb_device_id
[media] media: Drop FSF's postal address from the source code files
Reply: media: ttusb-dec: fix buffer overflow in ttusb_dec_send_command()
The ttusb_dec_send_command() function allocates a 64-byte buffer
(COMMAND_PACKET_SIZE + 4) for USB communication. After receiving a
response, it reads the payload length from b[3] (which is fully controlled
by the USB device) and copies the payload into the caller-provided
cmd_result buffer. There are two missing bounds checks. First, b[3] can be
up to 255, exceeding the 60-byte payload capacity of the allocated buffer,
leading to an out-of-bounds read. Second, the size of cmd_result is not
passed to the function, so a large b[3] can cause a buffer overflow in the
destination buffer (e.g., a 4-byte buffer in
ttusbdecfe_dvbt_read_status()).
This can result in a fortify panic:
memcpy: detected buffer overflow: 75 byte read of buffer size 60
WARNING: lib/string_helpers.c:1037 at __fortify_report+0xa0/0xb8
lib/string_helpers.c:1036
...
Call trace:
__fortify_report+0xa0/0xb8 lib/string_helpers.c:1036 (P)
__fortify_panic+0x10/0x14 lib/string_helpers.c:1043
fortify_memcpy_chk include/linux/fortify-string.h:549 [inline]
ttusb_dec_start_feed+0x0/0x10ac
drivers/media/usb/ttusb-dec/ttusb_dec.c:372
ttusb_dec_get_stb_state drivers/media/usb/ttusb-dec/ttusb_dec.c:392
[inline]
ttusb_dec_init_stb drivers/media/usb/ttusb-dec/ttusb_dec.c:1413 [inline]
ttusb_dec_probe+0x724/0x1aa0 drivers/media/usb/ttusb-dec/ttusb_dec.c:1671
Fix this by adding a cmd_result_len parameter to ttusb_dec_send_command()
and the send_command callback in ttusbdecfe_config. Update all callers to
pass the correct buffer size. Inside ttusb_dec_send_command(), validate
param_length, ensure actual_len is at least 4 bytes, and check that b[3]
does not exceed COMMAND_PACKET_SIZE, actual_len - 4, or cmd_result_len.
|
| 260/2 |
2026/08/17 22:10 |
llm |
description-generator |
0m
Model:
Tokens:
input: 14190
output: 606
thoughts: 2137
Thoughts: **My Analysis of the Linux Kernel Bug Fix**
Okay, so I'm looking at a buffer overflow in `ttusb_dec_send_command` within the `ttusb-dec` driver. The immediate issue is that the driver trusts the payload length reported by the USB device without validating it. Specifically, `b[3]` is read from the USB device, but there's no check to ensure it doesn't exceed either the allocated buffer size or, crucially, the size of the buffer the caller provides. This is a classic vulnerability. I see a function, `ttusb_dec_send_command()`, that allocates a 64-byte buffer (plus four bytes) for USB communication, and then pulls the payload length from `b[3]`. This payload is then copied into a buffer provided by the calling function. There are two glaring oversights here that need fixing. First, `b[3]` can contain a value up to 255 which goes way over the internal buffer, causing an out-of-bounds read. Second, and perhaps more significantly, the size of the destination buffer (`cmd_result`) is not passed to `ttusb_dec_send_command()`. This allows a malicious USB device to potentially trigger a buffer overflow in the calling code, such as in `ttusbdecfe_dvbt_read_status()`, where it appears the buffer could be as small as 4 bytes. I have KASAN/fortify output to highlight this as well.
The sanitizer output clearly points this out: `memcpy: detected buffer overflow: 75 byte read of buffer size 60`. It goes on to report the call trace as well, which includes the offending `ttusb_dec_send_command()` function. The error shows up through a chain of calls including `ttusb_dec_start_feed`, `ttusb_dec_get_stb_state`, `ttusb_dec_init_stb`, and finally `ttusb_dec_probe`.
To fix this, I have to add a `cmd_result_len` parameter to `ttusb_dec_send_command()` and also to the `send_command` callback within `ttusbdecfe_config`. I'll then add validations within `ttusb_dec_send_command()` itself. The fix involves validating that `param_length` is not larger than `COMMAND_PACKET_SIZE` and that `actual_len` is at least four bytes, the minimum for the response. Crucially, I need to check `b[3]` against `COMMAND_PACKET_SIZE`, `actual_len - 4` and now the newly added `cmd_result_len`. Finally, I'll need to update all the callers to now pass the correct buffer size.
|