From nobody Thu Apr 2 22:27:32 2026 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7F8026FA77 for ; Fri, 13 Feb 2026 20:39:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771015179; cv=none; b=LRH+eRh2fiL80875E/J+8WhszbQad7Rh+xjSJXzof+CZx4093cfJVYx4Hi67MyrXmFhmEuXx9Ei2nviNqYbv9w9LMwT7+L4BI9QoUcoSsTjc6E43DikBVh2cK1xs3yXqvpwjt4d7JAO3n/9LIBmJBQuqWrml8rrNDKiLDFvTTgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771015179; c=relaxed/simple; bh=PkCx504WUQw3zV2bV77aZM7bv/Fx1mHfx9GsW15YaFg=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=XUjX809hz0+D1Q/otFX2PFviqb2SThVo2D7DuanoQMwMbkSf3FAkbmtc/MsH9S+d6XXxjvFSaU917yeDq1qwvsCCGhrRAbrO4pJGjmNBg4iqRQlsnMA5q1h/PQUrD8op9CzZQeN2gQ5hcmB2XAXeaWaf0dbVl4VAwIE3SPdeBpw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=u.northwestern.edu; spf=pass smtp.mailfrom=u.northwestern.edu; dkim=pass (2048-bit key) header.d=u-northwestern-edu.20230601.gappssmtp.com header.i=@u-northwestern-edu.20230601.gappssmtp.com header.b=Vg9ZQaqc; arc=none smtp.client-ip=209.85.160.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=u.northwestern.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=u.northwestern.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=u-northwestern-edu.20230601.gappssmtp.com header.i=@u-northwestern-edu.20230601.gappssmtp.com header.b="Vg9ZQaqc" Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-502a789834fso12085041cf.2 for ; Fri, 13 Feb 2026 12:39:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=u-northwestern-edu.20230601.gappssmtp.com; s=20230601; t=1771015177; x=1771619977; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=u96JUABPipojjrofMBVXV/+R1lFeYvvLF1yUQTLyLHo=; b=Vg9ZQaqchubYEEW4d5i/EQ6jvyVq0ugWGEasE4Hd3AmAt7Wgt2/9ohFzXiLcE6LBQf zYSK+rQrcnJ7MJqGkXYiJe5ksdbMijmxDVG2AOKlhcW24dTEk853p0x3w4OIj3v2CPBq 4HB22pXoqfD6CO8FZK2uz1IKq96+nzTStcMEw3PEm8O/PSZjX7sfZN+sRD/bYA6fcdIl 19t9HluxeSBcOsWBx5ywEDGgw0a2qLK3BZORZNqFnoeHScMiqh5z6YX3WIdoEltFj8+/ 2mq9AAyOcBQYsADLz/98roJ1FTpDmr+q9IGM/pFQN5uNTyXrwxcDxuNstNF0um51hztv Xd6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771015177; x=1771619977; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=u96JUABPipojjrofMBVXV/+R1lFeYvvLF1yUQTLyLHo=; b=VtZjdpUUxMdqN+T43nHyRj4YGWSvsi+5mQ0A5qSZ1ICz6xLQiWtWlguLrVcmgMSys+ 1YmvxrZtz/RwFly2TDe/rlAq1akJDEVnc6vBKMHnP1D/t0ne3R8uPcavUEcbxAgEw/GM zwpHXWXOmDqVDvsOJPmn5EyAS8rK5Mgdu3zRHYbigB9ajaQbDaM4dm7/E14YjbS+KWpV Z/fQLt//2tfb7EoALWqhuRvmO8SKdwberua/XOsBTmB0Yx2urCCkVO190Aw8IaNzfFHR GEIIn+sIKMbV3FBZJOpomGH3t+169/PySQoxMO0QIKw0iHEN63POLAw6BSy80i9CJjUO 1vqQ== X-Forwarded-Encrypted: i=1; AJvYcCWv+pBc1+VPi6T+Gh1zIR69THCndTMu4rou2TrHMk3tlKciiq4PU15VXu6lThznFHApl/AzoLMe5aie+ec=@vger.kernel.org X-Gm-Message-State: AOJu0YxSvAstrDN6AOYMcIv20h9byjW5UlzhVJq0bwpB+B4E6mMBWp99 oemLa1HTgNbobNlBv/l09VhFUY6728yGo7OyVewZv/4tmH+tvaWGdwfaC7dN5av84Ks= X-Gm-Gg: AZuq6aLPgabIU8dEE6VzO9+ne7PfNhBs+igZRY1rvIq5xBlY0cUg/tSfpvIprljPxsh XqdSEXR3fFYABxCnTZWJSGNx8k7CfQHiEM9WEXGUhjIGMNZZZ8GTeCfLeKp43t6jJqhChdROHCg B9Uiy/sorlf+tHf/Yhqv8MeEKJBhZHjKVvXFPr/n7kkED+Sb0NWNnGf1J3EvbI+DduUYK2A/E80 GKZ3ll3Tb5cNPGozHEurOTXj0uI5PLPBr40iYpOfRrxvEqS9bImnt+vMPAe25vTomPkeBDps8Q7 eaXGcuo1WM1JXTWi+uM9QgYw5E1iy1cp2ywwCPDdGf0AAK81a8/3Czu9alCE8NAHvQ8NIN2NCPa JA6SXnCnj3kzHU14QKta2/vGGgs7geF4GY47viSsXnhm4uYN1Jh1nWooHhSW/4Bjo2CWqqb/YVG dMiF4irRXhz/nn5qlZECLEXimy57GPagHH2aqL3/gKTumkYt5UGWmG21KF43cbhvcms66flUaGE 3ABd13n78PJKe9QgqvGaAXL9tUbpZq7QFdGc8A++hQ= X-Received: by 2002:a05:622a:1356:b0:4e8:b446:c023 with SMTP id d75a77b69052e-506a6aefc75mr45267961cf.49.1771015176679; Fri, 13 Feb 2026 12:39:36 -0800 (PST) Received: from security.cs.northwestern.edu (security.cs.northwestern.edu. [165.124.184.136]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-50684bb9251sm69846281cf.30.2026.02.13.12.39.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Feb 2026 12:39:36 -0800 (PST) From: Ziyi Guo To: Vincent Mailhol , Frank Jungclaus , Marc Kleine-Budde Cc: socketcan@esd.eu, "David S . Miller" , Wolfgang Grandegger , linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, Ziyi Guo Subject: [PATCH v2] can: esd_usb: add endpoint type validation Date: Fri, 13 Feb 2026 20:39:27 +0000 Message-Id: <20260213203927.599163-1-n7l8m4@u.northwestern.edu> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" esd_usb_probe() constructs bulk pipes for two endpoints without verifying their transfer types: - usb_rcvbulkpipe(dev->udev, 1) for RX (version reply, async RX data) - usb_sndbulkpipe(dev->udev, 2) for TX (version query, CAN frames) A malformed USB device can present these endpoints with transfer types that differ from what the driver assumes, triggering the WARNING in usb_submit_urb(). Use usb_find_common_endpoints() to discover and validate the first bulk IN and bulk OUT endpoints at probe time, before any allocation. Found pipes are saved to struct esd_usb and code uses them directly instead of making pipes in place. Similar to - commit 136bed0bfd3b ("can: mcba_usb: properly check endpoint type") which established the usb_find_common_endpoints() + stored pipes pattern for CAN USB drivers. Fixes: 96d8e90382dc ("can: Add driver for esd CAN-USB/2 device") Suggested-by: Vincent Mailhol Signed-off-by: Ziyi Guo Reviewed-by: Vincent Mailhol --- v2: - Use usb_find_common_endpoints() to discover and validate.=20 drivers/net/can/usb/esd_usb.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c index 8cc924c47042..c1da0f3acf89 100644 --- a/drivers/net/can/usb/esd_usb.c +++ b/drivers/net/can/usb/esd_usb.c @@ -272,6 +272,9 @@ struct esd_usb { =20 struct usb_anchor rx_submitted; =20 + unsigned int rx_pipe; + unsigned int tx_pipe; + int net_count; u32 version; int rxinitdone; @@ -537,7 +540,7 @@ static void esd_usb_read_bulk_callback(struct urb *urb) } =20 resubmit_urb: - usb_fill_bulk_urb(urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1), + usb_fill_bulk_urb(urb, dev->udev, dev->rx_pipe, urb->transfer_buffer, ESD_USB_RX_BUFFER_SIZE, esd_usb_read_bulk_callback, dev); =20 @@ -626,9 +629,7 @@ static int esd_usb_send_msg(struct esd_usb *dev, union = esd_usb_msg *msg) { int actual_length; =20 - return usb_bulk_msg(dev->udev, - usb_sndbulkpipe(dev->udev, 2), - msg, + return usb_bulk_msg(dev->udev, dev->tx_pipe, msg, msg->hdr.len * sizeof(u32), /* convert to # of bytes */ &actual_length, 1000); @@ -639,12 +640,8 @@ static int esd_usb_wait_msg(struct esd_usb *dev, { int actual_length; =20 - return usb_bulk_msg(dev->udev, - usb_rcvbulkpipe(dev->udev, 1), - msg, - sizeof(*msg), - &actual_length, - 1000); + return usb_bulk_msg(dev->udev, dev->rx_pipe, msg, + sizeof(*msg), &actual_length, 1000); } =20 static int esd_usb_setup_rx_urbs(struct esd_usb *dev) @@ -677,8 +674,7 @@ static int esd_usb_setup_rx_urbs(struct esd_usb *dev) =20 urb->transfer_dma =3D buf_dma; =20 - usb_fill_bulk_urb(urb, dev->udev, - usb_rcvbulkpipe(dev->udev, 1), + usb_fill_bulk_urb(urb, dev->udev, dev->rx_pipe, buf, ESD_USB_RX_BUFFER_SIZE, esd_usb_read_bulk_callback, dev); urb->transfer_flags |=3D URB_NO_TRANSFER_DMA_MAP; @@ -903,7 +899,7 @@ static netdev_tx_t esd_usb_start_xmit(struct sk_buff *s= kb, /* hnd must not be 0 - MSB is stripped in txdone handling */ msg->tx.hnd =3D BIT(31) | i; /* returned in TX done message */ =20 - usb_fill_bulk_urb(urb, dev->udev, usb_sndbulkpipe(dev->udev, 2), buf, + usb_fill_bulk_urb(urb, dev->udev, dev->tx_pipe, buf, msg->hdr.len * sizeof(u32), /* convert to # of bytes */ esd_usb_write_bulk_callback, context); =20 @@ -1298,10 +1294,16 @@ static int esd_usb_probe_one_net(struct usb_interfa= ce *intf, int index) static int esd_usb_probe(struct usb_interface *intf, const struct usb_device_id *id) { + struct usb_endpoint_descriptor *ep_in, *ep_out; struct esd_usb *dev; union esd_usb_msg *msg; int i, err; =20 + err =3D usb_find_common_endpoints(intf->cur_altsetting, &ep_in, &ep_out, + NULL, NULL); + if (err) + return err; + dev =3D kzalloc(sizeof(*dev), GFP_KERNEL); if (!dev) { err =3D -ENOMEM; @@ -1309,6 +1311,8 @@ static int esd_usb_probe(struct usb_interface *intf, } =20 dev->udev =3D interface_to_usbdev(intf); + dev->rx_pipe =3D usb_rcvbulkpipe(dev->udev, ep_in->bEndpointAddress); + dev->tx_pipe =3D usb_sndbulkpipe(dev->udev, ep_out->bEndpointAddress); =20 init_usb_anchor(&dev->rx_submitted); =20 --=20 2.34.1