Skip to content
/ linux Public

Commit 35854ed

Browse files
haruki3hhhSasha Levin
authored andcommitted
net: usb: pegasus: enable basic endpoint checking
[ Upstream commit 3d7e6ce ] pegasus_probe() fills URBs with hardcoded endpoint pipes without verifying the endpoint descriptors: - usb_rcvbulkpipe(dev, 1) for RX data - usb_sndbulkpipe(dev, 2) for TX data - usb_rcvintpipe(dev, 3) for status interrupts A malformed USB device can present these endpoints with transfer types that differ from what the driver assumes. Add a pegasus_usb_ep enum for endpoint numbers, replacing magic constants throughout. Add usb_check_bulk_endpoints() and usb_check_int_endpoints() calls before any resource allocation to verify endpoint types before use, rejecting devices with mismatched descriptors at probe time, and avoid triggering assertion. Similar fix to - commit 90b7f29 ("net: usb: rtl8150: enable basic endpoint checking") - commit 9e7021d ("net: usb: catc: enable basic endpoint checking") Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Ziyi Guo <n7l8m4@u.northwestern.edu> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/20260222050633.410165-1-n7l8m4@u.northwestern.edu Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent df001db commit 35854ed

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

drivers/net/usb/pegasus.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ static const char driver_name[] = "pegasus";
3131
BMSR_100FULL | BMSR_ANEGCAPABLE)
3232
#define CARRIER_CHECK_DELAY (2 * HZ)
3333

34+
/*
35+
* USB endpoints.
36+
*/
37+
38+
enum pegasus_usb_ep {
39+
PEGASUS_USB_EP_CONTROL = 0,
40+
PEGASUS_USB_EP_BULK_IN = 1,
41+
PEGASUS_USB_EP_BULK_OUT = 2,
42+
PEGASUS_USB_EP_INT_IN = 3,
43+
};
44+
3445
static bool loopback;
3546
static bool mii_mode;
3647
static char *devid;
@@ -545,7 +556,7 @@ static void read_bulk_callback(struct urb *urb)
545556
goto tl_sched;
546557
goon:
547558
usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
548-
usb_rcvbulkpipe(pegasus->usb, 1),
559+
usb_rcvbulkpipe(pegasus->usb, PEGASUS_USB_EP_BULK_IN),
549560
pegasus->rx_skb->data, PEGASUS_MTU,
550561
read_bulk_callback, pegasus);
551562
rx_status = usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC);
@@ -585,7 +596,7 @@ static void rx_fixup(struct tasklet_struct *t)
585596
return;
586597
}
587598
usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
588-
usb_rcvbulkpipe(pegasus->usb, 1),
599+
usb_rcvbulkpipe(pegasus->usb, PEGASUS_USB_EP_BULK_IN),
589600
pegasus->rx_skb->data, PEGASUS_MTU,
590601
read_bulk_callback, pegasus);
591602
try_again:
@@ -713,7 +724,7 @@ static netdev_tx_t pegasus_start_xmit(struct sk_buff *skb,
713724
((__le16 *) pegasus->tx_buff)[0] = cpu_to_le16(l16);
714725
skb_copy_from_linear_data(skb, pegasus->tx_buff + 2, skb->len);
715726
usb_fill_bulk_urb(pegasus->tx_urb, pegasus->usb,
716-
usb_sndbulkpipe(pegasus->usb, 2),
727+
usb_sndbulkpipe(pegasus->usb, PEGASUS_USB_EP_BULK_OUT),
717728
pegasus->tx_buff, count,
718729
write_bulk_callback, pegasus);
719730
if ((res = usb_submit_urb(pegasus->tx_urb, GFP_ATOMIC))) {
@@ -840,7 +851,7 @@ static int pegasus_open(struct net_device *net)
840851
set_registers(pegasus, EthID, 6, net->dev_addr);
841852

842853
usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
843-
usb_rcvbulkpipe(pegasus->usb, 1),
854+
usb_rcvbulkpipe(pegasus->usb, PEGASUS_USB_EP_BULK_IN),
844855
pegasus->rx_skb->data, PEGASUS_MTU,
845856
read_bulk_callback, pegasus);
846857
if ((res = usb_submit_urb(pegasus->rx_urb, GFP_KERNEL))) {
@@ -851,7 +862,7 @@ static int pegasus_open(struct net_device *net)
851862
}
852863

853864
usb_fill_int_urb(pegasus->intr_urb, pegasus->usb,
854-
usb_rcvintpipe(pegasus->usb, 3),
865+
usb_rcvintpipe(pegasus->usb, PEGASUS_USB_EP_INT_IN),
855866
pegasus->intr_buff, sizeof(pegasus->intr_buff),
856867
intr_callback, pegasus, pegasus->intr_interval);
857868
if ((res = usb_submit_urb(pegasus->intr_urb, GFP_KERNEL))) {
@@ -1136,10 +1147,24 @@ static int pegasus_probe(struct usb_interface *intf,
11361147
pegasus_t *pegasus;
11371148
int dev_index = id - pegasus_ids;
11381149
int res = -ENOMEM;
1150+
static const u8 bulk_ep_addr[] = {
1151+
PEGASUS_USB_EP_BULK_IN | USB_DIR_IN,
1152+
PEGASUS_USB_EP_BULK_OUT | USB_DIR_OUT,
1153+
0};
1154+
static const u8 int_ep_addr[] = {
1155+
PEGASUS_USB_EP_INT_IN | USB_DIR_IN,
1156+
0};
11391157

11401158
if (pegasus_blacklisted(dev))
11411159
return -ENODEV;
11421160

1161+
/* Verify that all required endpoints are present */
1162+
if (!usb_check_bulk_endpoints(intf, bulk_ep_addr) ||
1163+
!usb_check_int_endpoints(intf, int_ep_addr)) {
1164+
dev_err(&intf->dev, "Missing or invalid endpoints\n");
1165+
return -ENODEV;
1166+
}
1167+
11431168
net = alloc_etherdev(sizeof(struct pegasus));
11441169
if (!net)
11451170
goto out;

0 commit comments

Comments
 (0)