[PATCH] media: dvb-usb: pctv452e: select the altsetting only once

From: YuanZhe Liu

Date: Sat Dec 05 2026 - 11:57:42 EST


pctv452e_power_ctrl() selects the isochronous alternate setting of
interface 0 and then resets the board. state->initialized is only set
after both reset transfers succeed, so when one of them fails during
probe, the next call to pctv452e_power_ctrl() from the frontend wakeup
path repeats the whole sequence, including usb_set_interface().

By that time tt3650_ci_init() has already started the CI thread, which
polls the CAM over the bulk endpoint of the same interface. Selecting
an alternate setting drops and re-adds every endpoint of the interface
and frees the endpoint rings, so a bulk URB submitted by the CI thread
can reach xhci_queue_bulk_tx() after its ring was freed:

BUG: KASAN: slab-use-after-free in xhci_ring_expansion_needed
Read of size 8 at addr ffff88800cbbbe90 by task kdvb-ca-0:0/1087
...
Freed by task 1126:
xhci_free_endpoint_ring
xhci_check_bandwidth
usb_hcd_alloc_bandwidth
usb_set_interface
pctv452e_power_ctrl
dvb_usb_fe_wakeup

usb_set_interface() requires that no URBs are pending on the interface,
which cannot be guaranteed once the CI and remote-control code are
running. The alternate setting is part of the one-time device setup,
so select it only during probe and let later calls retry just the board
reset.

The issue was found by analysing a crash report from a TT Connect
S2-3650-CI. The change is compile-tested only; I have no such device.

Fixes: 4e2c53fde651 ("[media] dvb: Add support for pctv452e")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: YuanZhe Liu <25031212351@xxxxxxxxxxxxxxxxx>
---
drivers/media/usb/dvb-usb/pctv452e.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/pctv452e.c b/drivers/media/usb/dvb-usb/pctv452e.c
index bc7a224d829e..a00c8e1710f2 100644
--- a/drivers/media/usb/dvb-usb/pctv452e.c
+++ b/drivers/media/usb/dvb-usb/pctv452e.c
@@ -533,11 +533,16 @@ static int pctv452e_power_ctrl(struct dvb_usb_device *d, int i)

rx = b0 + 5;

- /* hmm where should this should go? */
- ret = usb_set_interface(d->udev, 0, ISOC_INTERFACE_ALTERNATIVE);
- if (ret != 0)
- info("%s: Warning set interface returned: %d\n",
- __func__, ret);
+ /*
+ * Only change the altsetting during probe, before any URBs can be
+ * submitted on this interface.
+ */
+ if (d->state == DVB_USB_STATE_INIT) {
+ ret = usb_set_interface(d->udev, 0, ISOC_INTERFACE_ALTERNATIVE);
+ if (ret != 0)
+ info("%s: Warning set interface returned: %d\n",
+ __func__, ret);
+ }

/* this is a one-time initialization, don't know where to put */
b0[0] = 0xaa;
--
2.34.1