linux/drivers/media/usb
Zheng Yejian 2052138b7d 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: 4d43e13f72 ("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>
2024-05-31 14:20:40 +02:00
..
airspy media: usb: airspy: Stop direct calls to queue num_buffers field 2023-11-23 12:35:58 +01:00
as102 media: as102: avoid GFP_ATOMIC 2024-04-29 12:07:00 +01:00
au0828 media: au0828: Use umin macro 2024-05-03 11:13:02 +01:00
b2c2 media: flexcop-usb: Use min macro 2024-05-03 11:13:24 +01:00
cx231xx i2c: mux: Remove class argument from i2c_mux_add_adapter() 2024-05-13 16:13:19 +02:00
dvb-usb media: dvb-usb: Fix unexpected infinite loop in dvb_usb_read_remote_control() 2024-05-31 14:20:40 +02:00
dvb-usb-v2 media: IR remote control for AVerMedia TD310 2024-04-29 14:53:50 +01:00
em28xx media: em28xx: annotate unchecked call to media_device_register() 2024-02-05 12:57:44 +01:00
go7007 media: go7007: Refactor Adlink PCI-MPG24 i2c mutex 2024-05-31 13:51:16 +02:00
gspca media: gspca: cpia1: Use min macro 2024-05-03 11:13:45 +01:00
hackrf media: usb: hackrf: Stop direct calls to queue num_buffers field 2023-11-23 12:36:42 +01:00
hdpvr media: hdpvr: fix error value returns in hdpvr_read 2022-06-27 09:02:50 +01:00
msi2500 media: usb/msi2500: Follow renaming of SPI "master" to "controller" 2024-02-08 11:54:41 +00:00
pvrusb2 media: pvrusb2: remove unused struct 'debugifc_mask_item' 2024-05-31 13:51:16 +02:00
pwc media: usb: pwc-uncompress: Use flex array destination for memcpy() 2022-12-07 17:58:46 +01:00
s2255 media: s2255: Use refcount_t instead of atomic_t for num_channels 2024-05-03 11:10:58 +01:00
siano media: usb: siano: Fix allocation of urbs 2024-04-16 00:02:53 +02:00
stk1160 media: stk1160: Use min macro 2024-05-03 11:14:15 +01:00
ttusb-budget media: dvb-ttusb-budget: cleanup printk logic 2020-09-03 11:15:47 +02:00
ttusb-dec media: ttusb-dec: remove unnecessary (void*) conversions 2023-07-19 12:57:47 +02:00
usbtv media: usbtv: Remove useless locks in usbtv_video_free() 2024-03-04 12:58:38 +01:00
uvc media: uvcvideo: Refactor iterators 2024-05-04 10:19:59 +02:00
Kconfig media: tm6000: deprecate this driver 2022-08-29 16:43:00 +02:00
Makefile media: tm6000: deprecate this driver 2022-08-29 16:43:00 +02:00