Skip to content
/ linux Public

Commit ac7739b

Browse files
haruki3hhhSasha Levin
authored andcommitted
net: usb: catc: enable basic endpoint checking
[ Upstream commit 9e7021d ] catc_probe() fills three URBs with hardcoded endpoint pipes without verifying the endpoint descriptors: - usb_sndbulkpipe(usbdev, 1) and usb_rcvbulkpipe(usbdev, 1) for TX/RX - usb_rcvintpipe(usbdev, 2) for interrupt status A malformed USB device can present these endpoints with transfer types that differ from what the driver assumes. Add a catc_usb_ep enum for endpoint numbers, replacing magic constants throughout. Add usb_check_bulk_endpoints() and usb_check_int_endpoints() calls after usb_set_interface() to verify endpoint types before use, rejecting devices with mismatched descriptors at probe time. Similar to - commit 90b7f29 ("net: usb: rtl8150: enable basic endpoint checking") which fixed the issue in rtl8150. Fixes: 1da177e ("Linux-2.6.12-rc2") Suggested-by: Simon Horman <horms@kernel.org> Signed-off-by: Ziyi Guo <n7l8m4@u.northwestern.edu> Link: https://patch.msgid.link/20260212214154.3609844-1-n7l8m4@u.northwestern.edu Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 4296a07 commit ac7739b

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

drivers/net/usb/catc.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ static const char driver_name[] = "catc";
6464
#define CTRL_QUEUE 16 /* Max control requests in flight (power of two) */
6565
#define RX_PKT_SZ 1600 /* Max size of receive packet for F5U011 */
6666

67+
/*
68+
* USB endpoints.
69+
*/
70+
71+
enum catc_usb_ep {
72+
CATC_USB_EP_CONTROL = 0,
73+
CATC_USB_EP_BULK = 1,
74+
CATC_USB_EP_INT_IN = 2,
75+
};
76+
6777
/*
6878
* Control requests.
6979
*/
@@ -772,6 +782,13 @@ static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id
772782
u8 broadcast[ETH_ALEN];
773783
u8 *macbuf;
774784
int pktsz, ret = -ENOMEM;
785+
static const u8 bulk_ep_addr[] = {
786+
CATC_USB_EP_BULK | USB_DIR_OUT,
787+
CATC_USB_EP_BULK | USB_DIR_IN,
788+
0};
789+
static const u8 int_ep_addr[] = {
790+
CATC_USB_EP_INT_IN | USB_DIR_IN,
791+
0};
775792

776793
macbuf = kmalloc(ETH_ALEN, GFP_KERNEL);
777794
if (!macbuf)
@@ -784,6 +801,14 @@ static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id
784801
goto fail_mem;
785802
}
786803

804+
/* Verify that all required endpoints are present */
805+
if (!usb_check_bulk_endpoints(intf, bulk_ep_addr) ||
806+
!usb_check_int_endpoints(intf, int_ep_addr)) {
807+
dev_err(dev, "Missing or invalid endpoints\n");
808+
ret = -ENODEV;
809+
goto fail_mem;
810+
}
811+
787812
netdev = alloc_etherdev(sizeof(struct catc));
788813
if (!netdev)
789814
goto fail_mem;
@@ -828,14 +853,14 @@ static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id
828853
usb_fill_control_urb(catc->ctrl_urb, usbdev, usb_sndctrlpipe(usbdev, 0),
829854
NULL, NULL, 0, catc_ctrl_done, catc);
830855

831-
usb_fill_bulk_urb(catc->tx_urb, usbdev, usb_sndbulkpipe(usbdev, 1),
832-
NULL, 0, catc_tx_done, catc);
856+
usb_fill_bulk_urb(catc->tx_urb, usbdev, usb_sndbulkpipe(usbdev, CATC_USB_EP_BULK),
857+
NULL, 0, catc_tx_done, catc);
833858

834-
usb_fill_bulk_urb(catc->rx_urb, usbdev, usb_rcvbulkpipe(usbdev, 1),
835-
catc->rx_buf, pktsz, catc_rx_done, catc);
859+
usb_fill_bulk_urb(catc->rx_urb, usbdev, usb_rcvbulkpipe(usbdev, CATC_USB_EP_BULK),
860+
catc->rx_buf, pktsz, catc_rx_done, catc);
836861

837-
usb_fill_int_urb(catc->irq_urb, usbdev, usb_rcvintpipe(usbdev, 2),
838-
catc->irq_buf, 2, catc_irq_done, catc, 1);
862+
usb_fill_int_urb(catc->irq_urb, usbdev, usb_rcvintpipe(usbdev, CATC_USB_EP_INT_IN),
863+
catc->irq_buf, 2, catc_irq_done, catc, 1);
839864

840865
if (!catc->is_f5u011) {
841866
u32 *buf;

0 commit comments

Comments
 (0)