From patchwork Wed Jun 7 13:56:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Foster Snowhill X-Patchwork-Id: 13270756 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62B0CC7EE23 for ; Wed, 7 Jun 2023 14:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240759AbjFGOIM (ORCPT ); Wed, 7 Jun 2023 10:08:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240726AbjFGOH6 (ORCPT ); Wed, 7 Jun 2023 10:07:58 -0400 Received: from qs51p00im-qukt01071502.me.com (qs51p00im-qukt01071502.me.com [17.57.155.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 844682695 for ; Wed, 7 Jun 2023 07:07:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pen.gy; s=sig1; t=1686146263; bh=pzOiGFlXxe7wjzq9Fg+hUaE4VwJuvopU7xJEFjn/GtE=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=Ess5UdrSTD0MqGSfHurZPTz//Rqt34b2G1OxfCVLZ6IQSlR/f/b61dAuKilsJu9Zg 4fqTo8mJZtQPDwDaXMyspBRCDAWBG08P0/TB2aDugahJpWcLhVCt6WzMvGQgQb/9cz SNfEwdpku/4fNbKI4CvozQyvM3x0gArQsV4S6PtiJ0qg6C5i9waqC0knlUqIZPTMhf Oc616rEAj3lmVp0CoaQ0XnNUiPNwUVx/0bKLhmJx6KUTAF6sSDmNitvvXEUCE2lpje 8plkSlF0/IyYYW+OF1AzpNUYp1ee8HfP8qT1tZrLhylzohU2j/G/DhHOZu9R9avLFZ iE8Di/KhMlZTA== Received: from fossa.iopsys.eu (qs51p00im-dlb-asmtp-mailmevip.me.com [17.57.155.28]) by qs51p00im-qukt01071502.me.com (Postfix) with ESMTPSA id 1526666802E9; Wed, 7 Jun 2023 13:57:40 +0000 (UTC) From: Foster Snowhill To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Georgi Valkov , Simon Horman , Jan Kiszka , linux-usb@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v4 1/4] usbnet: ipheth: fix risk of NULL pointer deallocation Date: Wed, 7 Jun 2023 15:56:59 +0200 Message-Id: <20230607135702.32679-1-forst@pen.gy> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: FF6KxZYHCoMp_WPLSmy58s38wlihLML9 X-Proofpoint-GUID: FF6KxZYHCoMp_WPLSmy58s38wlihLML9 X-Proofpoint-Virus-Version: =?utf-8?q?vendor=3Dfsecure_engine=3D1=2E1=2E170-?= =?utf-8?q?22c6f66c430a71ce266a39bfe25bc2903e8d5c8f=3A6=2E0=2E138=2C18=2E0?= =?utf-8?q?=2E790=2C17=2E11=2E62=2E513=2E0000000_definitions=3D2022-01-12=5F?= =?utf-8?q?02=3A2020-02-14=5F02=2C2022-01-12=5F02=2C2021-12-02=5F01_signatur?= =?utf-8?q?es=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 spamscore=0 clxscore=1030 suspectscore=0 malwarescore=0 mlxlogscore=350 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2306070117 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Georgi Valkov The cleanup precedure in ipheth_probe will attempt to free a NULL pointer in dev->ctrl_buf if the memory allocation for this buffer is not successful. While kfree ignores NULL pointers, and the existing code is safe, it is a better design to rearrange the goto labels and avoid this. Signed-off-by: Georgi Valkov Signed-off-by: Foster Snowhill --- v4: No change v3: https://lore.kernel.org/netdev/20230527130309.34090-1-forst@pen.gy/ - Reword commit msg to indicate design improvement rather than bugfix - Add missing signoff for Foster Snowhill No code changes v2: https://lore.kernel.org/netdev/20230525194255.4516-1-forst@pen.gy/ - Factor out goto label change from v1 into this separate patch v1: n/a Part of https://lore.kernel.org/netdev/20230516210127.35841-1-forst@pen.gy/ --- drivers/net/usb/ipheth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/usb/ipheth.c b/drivers/net/usb/ipheth.c index 6a769df0b..8875a3d0e 100644 --- a/drivers/net/usb/ipheth.c +++ b/drivers/net/usb/ipheth.c @@ -510,8 +510,8 @@ static int ipheth_probe(struct usb_interface *intf, ipheth_free_urbs(dev); err_alloc_urbs: err_get_macaddr: -err_alloc_ctrl_buf: kfree(dev->ctrl_buf); +err_alloc_ctrl_buf: err_endpoints: free_netdev(netdev); return retval; From patchwork Wed Jun 7 13:57:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Foster Snowhill X-Patchwork-Id: 13270755 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC662C7EE23 for ; Wed, 7 Jun 2023 14:08:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240956AbjFGOIL (ORCPT ); Wed, 7 Jun 2023 10:08:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239372AbjFGOH4 (ORCPT ); Wed, 7 Jun 2023 10:07:56 -0400 X-Greylist: delayed 580 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 07 Jun 2023 07:07:24 PDT Received: from qs51p00im-qukt01071502.me.com (qs51p00im-qukt01071502.me.com [17.57.155.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BE122691 for ; Wed, 7 Jun 2023 07:07:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pen.gy; s=sig1; t=1686146265; bh=RJKOsdchCAYMjlGQ0yDJPhRfsJKL5Y6GSfkOE7ZQozU=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=WKYkfppaIOYfdS9wrdRkh/MSlnJvELEJVhEyX+rQvCNXmX2CFSsaoEg1OYRYZFk+t YdK+8fuwTDDUylmLSlgZWfFE91+kP1qObStP9GtgNJm7hvW+9+vyIj07/Z3AC/CVQw HZqoRvSgIFZ3gzmobEBnuJYoEpovFQULHyV3vBHct1UTaSHlH4eZC2Jth3rQCkh6pA FLI8CVdyIOa6PZqBW2CyiS01pkFRcOWHQa5qUnYCGmhEDd92rK1EccFvlRObT2N8q9 litwpsEHAP0N8wx0csnZiOLcgMR896LE6AHggdnHH7jQegaNheagUZQYl2NhZkAQIs prrwizzchG9vw== Received: from fossa.iopsys.eu (qs51p00im-dlb-asmtp-mailmevip.me.com [17.57.155.28]) by qs51p00im-qukt01071502.me.com (Postfix) with ESMTPSA id CFFBB66803EB; Wed, 7 Jun 2023 13:57:43 +0000 (UTC) From: Foster Snowhill To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Georgi Valkov , Simon Horman , Jan Kiszka , linux-usb@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v4 2/4] usbnet: ipheth: transmit URBs without trailing padding Date: Wed, 7 Jun 2023 15:57:00 +0200 Message-Id: <20230607135702.32679-2-forst@pen.gy> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230607135702.32679-1-forst@pen.gy> References: <20230607135702.32679-1-forst@pen.gy> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: RFdcnoZeOWCl48ZoohQ38dWzXQog5SOo X-Proofpoint-GUID: RFdcnoZeOWCl48ZoohQ38dWzXQog5SOo X-Proofpoint-Virus-Version: =?utf-8?q?vendor=3Dfsecure_engine=3D1=2E1=2E170-?= =?utf-8?q?22c6f66c430a71ce266a39bfe25bc2903e8d5c8f=3A6=2E0=2E138=2C18=2E0?= =?utf-8?q?=2E790=2C17=2E11=2E62=2E513=2E0000000_definitions=3D2022-01-12=5F?= =?utf-8?q?02=3A2020-02-14=5F02=2C2022-01-12=5F02=2C2021-12-02=5F01_signatur?= =?utf-8?q?es=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 spamscore=0 clxscore=1030 suspectscore=0 malwarescore=0 mlxlogscore=592 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2306070117 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The behaviour of the official iOS tethering driver on macOS is to not transmit any trailing padding at the end of URBs. This is applicable to both NCM and legacy modes, including older devices. Adapt the driver to not include trailing padding in TX URBs, matching the behaviour of the official macOS driver. Signed-off-by: Foster Snowhill Tested-by: Georgi Valkov --- Tested by Georgi Valkov on iPhone 3G (iOS 4.2.1), iPhone 4s (iOS 8.4), iPhone 7 Plus (iOS 15.7.6). Tested by Foster Snowhill on iPhone Xs Max (iOS 16.5). Additionally both Georgi and Foster did USB traffic captures with the devices above on macOS 13.4, this confirmed the macOS driver behaviour. v4: No code change. Factored out from "usbnet: ipheth: add CDC NCM support". v3: n/a Part of https://lore.kernel.org/netdev/20230527130309.34090-2-forst@pen.gy/ v2: n/a Part of https://lore.kernel.org/netdev/20230525194255.4516-2-forst@pen.gy/ v1: n/a Part of https://lore.kernel.org/netdev/20230516210127.35841-1-forst@pen.gy/ --- drivers/net/usb/ipheth.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/usb/ipheth.c b/drivers/net/usb/ipheth.c index 8875a3d0e..dd809e247 100644 --- a/drivers/net/usb/ipheth.c +++ b/drivers/net/usb/ipheth.c @@ -373,12 +373,10 @@ static netdev_tx_t ipheth_tx(struct sk_buff *skb, struct net_device *net) } memcpy(dev->tx_buf, skb->data, skb->len); - if (skb->len < IPHETH_BUF_SIZE) - memset(dev->tx_buf + skb->len, 0, IPHETH_BUF_SIZE - skb->len); usb_fill_bulk_urb(dev->tx_urb, udev, usb_sndbulkpipe(udev, dev->bulk_out), - dev->tx_buf, IPHETH_BUF_SIZE, + dev->tx_buf, skb->len, ipheth_sndbulk_callback, dev); dev->tx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; From patchwork Wed Jun 7 13:57:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Foster Snowhill X-Patchwork-Id: 13270757 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB8ACC7EE2F for ; Wed, 7 Jun 2023 14:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241044AbjFGOIP (ORCPT ); Wed, 7 Jun 2023 10:08:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240950AbjFGOH6 (ORCPT ); Wed, 7 Jun 2023 10:07:58 -0400 Received: from qs51p00im-qukt01071502.me.com (qs51p00im-qukt01071502.me.com [17.57.155.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D375F269A for ; Wed, 7 Jun 2023 07:07:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pen.gy; s=sig1; t=1686146268; bh=p3sJVnJHa0UyFmXar8QowIz60JxwrC0mLM1V8ijANqI=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=UvZSeMBlvVn2L56HjQq/0NrN3A6DYsJEk61MOLWf0MZWDxnSE6JTXHVGN4dD3Vf0D CsfkeU90Qx24Gw8EZMNJZKbaghhC0QEuqeEdg7jEVsokce/tfXFV8tMlDmknrzGtRb 9x5AaxmhsW9m66S4WZp6IqaHITw7+VXBzjIoDlAKYi0lbXhFEnv0lY4eosk/6YqUPu SilAPjVME8o8BjjOXW/v9cvVhZXIOVsg7eiq2Dx/MobzaIfjQJbx32rgxLyxste6CG 3RXa5bcNUyJuMg4ReLLHolQqiXpXNSTDiSlu194/MGACOLBDukUqyh10uu2EkVx5FI hvk2H6obXTujw== Received: from fossa.iopsys.eu (qs51p00im-dlb-asmtp-mailmevip.me.com [17.57.155.28]) by qs51p00im-qukt01071502.me.com (Postfix) with ESMTPSA id 5C4DD668040F; Wed, 7 Jun 2023 13:57:46 +0000 (UTC) From: Foster Snowhill To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Georgi Valkov , Simon Horman , Jan Kiszka , linux-usb@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v4 3/4] usbnet: ipheth: add CDC NCM support Date: Wed, 7 Jun 2023 15:57:01 +0200 Message-Id: <20230607135702.32679-3-forst@pen.gy> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230607135702.32679-1-forst@pen.gy> References: <20230607135702.32679-1-forst@pen.gy> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: avpw1YTM4aEym46RHfJZmtckNU-QM56N X-Proofpoint-GUID: avpw1YTM4aEym46RHfJZmtckNU-QM56N X-Proofpoint-Virus-Version: =?utf-8?q?vendor=3Dfsecure_engine=3D1=2E1=2E170-?= =?utf-8?q?22c6f66c430a71ce266a39bfe25bc2903e8d5c8f=3A6=2E0=2E138=2C18=2E0?= =?utf-8?q?=2E790=2C17=2E11=2E62=2E513=2E0000000_definitions=3D2022-01-12=5F?= =?utf-8?q?02=3A2020-02-14=5F02=2C2022-01-12=5F02=2C2021-12-02=5F01_signatur?= =?utf-8?q?es=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 spamscore=0 clxscore=1030 suspectscore=0 malwarescore=0 mlxlogscore=933 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2306070117 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Recent iOS releases support CDC NCM encapsulation on RX. This mode is the default on macOS and Windows. In this mode, an iOS device may include one or more Ethernet frames inside a single URB. Freshly booted iOS devices start in legacy mode, but are put into NCM mode by the official Apple driver. When reconnecting such a device from a macOS/Windows machine to a Linux host, the device stays in NCM mode, making it unusable with the legacy ipheth driver code. To correctly support such a device, the driver has to either support the NCM mode too, or put the device back into legacy mode. To match the behaviour of the macOS/Windows driver, and since there is no documented control command to revert to legacy mode, implement NCM support. The device is attempted to be put into NCM mode by default, and falls back to legacy mode if the attempt fails. Signed-off-by: Foster Snowhill Tested-by: Georgi Valkov --- v4: - Set RX buffer size depending on encapsulation mode (legacy vs NCM) - Drop control frame URBs starting with 0x00 0x01 - Fix bmRequestType for NCM enablement to match macOS driver - Factor out removing TX URB padding into a separate patch v3: https://lore.kernel.org/netdev/20230527130309.34090-2-forst@pen.gy/ No changes v2: https://lore.kernel.org/netdev/20230525194255.4516-2-forst@pen.gy/ - Fix code formatting (RCS, 80 col width, remove redundant type casts) - Drop an unrelated goto label-related hunk from this patch v1: https://lore.kernel.org/netdev/20230516210127.35841-1-forst@pen.gy/ --- drivers/net/usb/ipheth.c | 180 +++++++++++++++++++++++++++++++++------ 1 file changed, 155 insertions(+), 25 deletions(-) diff --git a/drivers/net/usb/ipheth.c b/drivers/net/usb/ipheth.c index dd809e247..687d70cfc 100644 --- a/drivers/net/usb/ipheth.c +++ b/drivers/net/usb/ipheth.c @@ -52,6 +52,7 @@ #include #include #include +#include #define USB_VENDOR_APPLE 0x05ac @@ -59,8 +60,12 @@ #define IPHETH_USBINTF_SUBCLASS 253 #define IPHETH_USBINTF_PROTO 1 -#define IPHETH_BUF_SIZE 1514 #define IPHETH_IP_ALIGN 2 /* padding at front of URB */ +#define IPHETH_NCM_HEADER_SIZE (12 + 96) /* NCMH + NCM0 */ +#define IPHETH_TX_BUF_SIZE ETH_FRAME_LEN +#define IPHETH_RX_BUF_SIZE_LEGACY (IPHETH_IP_ALIGN + ETH_FRAME_LEN) +#define IPHETH_RX_BUF_SIZE_NCM 65536 + #define IPHETH_TX_TIMEOUT (5 * HZ) #define IPHETH_INTFNUM 2 @@ -71,6 +76,7 @@ #define IPHETH_CTRL_TIMEOUT (5 * HZ) #define IPHETH_CMD_GET_MACADDR 0x00 +#define IPHETH_CMD_ENABLE_NCM 0x04 #define IPHETH_CMD_CARRIER_CHECK 0x45 #define IPHETH_CARRIER_CHECK_TIMEOUT round_jiffies_relative(1 * HZ) @@ -97,6 +103,8 @@ struct ipheth_device { u8 bulk_out; struct delayed_work carrier_work; bool confirmed_pairing; + int (*rcvbulk_callback)(struct urb *urb); + size_t rx_buf_len; }; static int ipheth_rx_submit(struct ipheth_device *dev, gfp_t mem_flags); @@ -116,12 +124,12 @@ static int ipheth_alloc_urbs(struct ipheth_device *iphone) if (rx_urb == NULL) goto free_tx_urb; - tx_buf = usb_alloc_coherent(iphone->udev, IPHETH_BUF_SIZE, + tx_buf = usb_alloc_coherent(iphone->udev, IPHETH_TX_BUF_SIZE, GFP_KERNEL, &tx_urb->transfer_dma); if (tx_buf == NULL) goto free_rx_urb; - rx_buf = usb_alloc_coherent(iphone->udev, IPHETH_BUF_SIZE + IPHETH_IP_ALIGN, + rx_buf = usb_alloc_coherent(iphone->udev, iphone->rx_buf_len, GFP_KERNEL, &rx_urb->transfer_dma); if (rx_buf == NULL) goto free_tx_buf; @@ -134,7 +142,7 @@ static int ipheth_alloc_urbs(struct ipheth_device *iphone) return 0; free_tx_buf: - usb_free_coherent(iphone->udev, IPHETH_BUF_SIZE, tx_buf, + usb_free_coherent(iphone->udev, IPHETH_TX_BUF_SIZE, tx_buf, tx_urb->transfer_dma); free_rx_urb: usb_free_urb(rx_urb); @@ -146,9 +154,9 @@ static int ipheth_alloc_urbs(struct ipheth_device *iphone) static void ipheth_free_urbs(struct ipheth_device *iphone) { - usb_free_coherent(iphone->udev, IPHETH_BUF_SIZE + IPHETH_IP_ALIGN, iphone->rx_buf, + usb_free_coherent(iphone->udev, iphone->rx_buf_len, iphone->rx_buf, iphone->rx_urb->transfer_dma); - usb_free_coherent(iphone->udev, IPHETH_BUF_SIZE, iphone->tx_buf, + usb_free_coherent(iphone->udev, IPHETH_TX_BUF_SIZE, iphone->tx_buf, iphone->tx_urb->transfer_dma); usb_free_urb(iphone->rx_urb); usb_free_urb(iphone->tx_urb); @@ -160,14 +168,105 @@ static void ipheth_kill_urbs(struct ipheth_device *dev) usb_kill_urb(dev->rx_urb); } -static void ipheth_rcvbulk_callback(struct urb *urb) +static int ipheth_consume_skb(char *buf, int len, struct ipheth_device *dev) { - struct ipheth_device *dev; struct sk_buff *skb; - int status; + + skb = dev_alloc_skb(len); + if (!skb) { + dev->net->stats.rx_dropped++; + return -ENOMEM; + } + + skb_put_data(skb, buf, len); + skb->dev = dev->net; + skb->protocol = eth_type_trans(skb, dev->net); + + dev->net->stats.rx_packets++; + dev->net->stats.rx_bytes += len; + netif_rx(skb); + + return 0; +} + +static int ipheth_rcvbulk_callback_legacy(struct urb *urb) +{ + struct ipheth_device *dev; char *buf; int len; + dev = urb->context; + + if (urb->actual_length <= IPHETH_IP_ALIGN) { + dev->net->stats.rx_length_errors++; + return -EINVAL; + } + len = urb->actual_length - IPHETH_IP_ALIGN; + buf = urb->transfer_buffer + IPHETH_IP_ALIGN; + + return ipheth_consume_skb(buf, len, dev); +} + +static int ipheth_rcvbulk_callback_ncm(struct urb *urb) +{ + struct usb_cdc_ncm_nth16 *ncmh; + struct usb_cdc_ncm_ndp16 *ncm0; + struct usb_cdc_ncm_dpe16 *dpe; + struct ipheth_device *dev; + int retval = -EINVAL; + char *buf; + int len; + + dev = urb->context; + + if (urb->actual_length < IPHETH_NCM_HEADER_SIZE) { + dev->net->stats.rx_length_errors++; + return retval; + } + + ncmh = urb->transfer_buffer; + if (ncmh->dwSignature != cpu_to_le32(USB_CDC_NCM_NTH16_SIGN) || + le16_to_cpu(ncmh->wNdpIndex) >= urb->actual_length) { + dev->net->stats.rx_errors++; + return retval; + } + + ncm0 = urb->transfer_buffer + le16_to_cpu(ncmh->wNdpIndex); + if (ncm0->dwSignature != cpu_to_le32(USB_CDC_NCM_NDP16_NOCRC_SIGN) || + le16_to_cpu(ncmh->wHeaderLength) + le16_to_cpu(ncm0->wLength) >= + urb->actual_length) { + dev->net->stats.rx_errors++; + return retval; + } + + dpe = ncm0->dpe16; + while (le16_to_cpu(dpe->wDatagramIndex) != 0 && + le16_to_cpu(dpe->wDatagramLength) != 0) { + if (le16_to_cpu(dpe->wDatagramIndex) >= urb->actual_length || + le16_to_cpu(dpe->wDatagramIndex) + + le16_to_cpu(dpe->wDatagramLength) > urb->actual_length) { + dev->net->stats.rx_length_errors++; + return retval; + } + + buf = urb->transfer_buffer + le16_to_cpu(dpe->wDatagramIndex); + len = le16_to_cpu(dpe->wDatagramLength); + + retval = ipheth_consume_skb(buf, len, dev); + if (retval != 0) + return retval; + + dpe++; + } + + return 0; +} + +static void ipheth_rcvbulk_callback(struct urb *urb) +{ + struct ipheth_device *dev; + int retval, status; + dev = urb->context; if (dev == NULL) return; @@ -191,25 +290,27 @@ static void ipheth_rcvbulk_callback(struct urb *urb) dev->net->stats.rx_length_errors++; return; } - len = urb->actual_length - IPHETH_IP_ALIGN; - buf = urb->transfer_buffer + IPHETH_IP_ALIGN; - skb = dev_alloc_skb(len); - if (!skb) { - dev_err(&dev->intf->dev, "%s: dev_alloc_skb: -ENOMEM\n", - __func__); - dev->net->stats.rx_dropped++; + /* RX URBs starting with 0x00 0x01 do not encapsulate Ethernet frames, + * but rather are control frames. Their purpose is not documented, and + * they don't affect driver functionality, okay to drop them. + * There is usually just one 4-byte control frame as the very first + * URB received from the bulk IN endpoint. + */ + if (unlikely + (((char *)urb->transfer_buffer)[0] == 0 && + ((char *)urb->transfer_buffer)[1] == 1)) + goto rx_submit; + + retval = dev->rcvbulk_callback(urb); + if (retval != 0) { + dev_err(&dev->intf->dev, "%s: callback retval: %d\n", + __func__, retval); return; } - skb_put_data(skb, buf, len); - skb->dev = dev->net; - skb->protocol = eth_type_trans(skb, dev->net); - - dev->net->stats.rx_packets++; - dev->net->stats.rx_bytes += len; +rx_submit: dev->confirmed_pairing = true; - netif_rx(skb); ipheth_rx_submit(dev, GFP_ATOMIC); } @@ -310,6 +411,27 @@ static int ipheth_get_macaddr(struct ipheth_device *dev) return retval; } +static int ipheth_enable_ncm(struct ipheth_device *dev) +{ + struct usb_device *udev = dev->udev; + int retval; + + retval = usb_control_msg(udev, + usb_sndctrlpipe(udev, IPHETH_CTRL_ENDP), + IPHETH_CMD_ENABLE_NCM, /* request */ + 0x41, /* request type */ + 0x00, /* value */ + 0x02, /* index */ + NULL, + 0, + IPHETH_CTRL_TIMEOUT); + + dev_info(&dev->intf->dev, "%s: usb_control_msg: %d\n", + __func__, retval); + + return retval; +} + static int ipheth_rx_submit(struct ipheth_device *dev, gfp_t mem_flags) { struct usb_device *udev = dev->udev; @@ -317,7 +439,7 @@ static int ipheth_rx_submit(struct ipheth_device *dev, gfp_t mem_flags) usb_fill_bulk_urb(dev->rx_urb, udev, usb_rcvbulkpipe(udev, dev->bulk_in), - dev->rx_buf, IPHETH_BUF_SIZE + IPHETH_IP_ALIGN, + dev->rx_buf, dev->rx_buf_len, ipheth_rcvbulk_callback, dev); dev->rx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; @@ -365,7 +487,7 @@ static netdev_tx_t ipheth_tx(struct sk_buff *skb, struct net_device *net) int retval; /* Paranoid */ - if (skb->len > IPHETH_BUF_SIZE) { + if (skb->len > IPHETH_TX_BUF_SIZE) { WARN(1, "%s: skb too large: %d bytes\n", __func__, skb->len); dev->net->stats.tx_dropped++; dev_kfree_skb_any(skb); @@ -448,6 +570,8 @@ static int ipheth_probe(struct usb_interface *intf, dev->net = netdev; dev->intf = intf; dev->confirmed_pairing = false; + dev->rx_buf_len = IPHETH_RX_BUF_SIZE_LEGACY; + dev->rcvbulk_callback = ipheth_rcvbulk_callback_legacy; /* Set up endpoints */ hintf = usb_altnum_to_altsetting(intf, IPHETH_ALT_INTFNUM); if (hintf == NULL) { @@ -479,6 +603,12 @@ static int ipheth_probe(struct usb_interface *intf, if (retval) goto err_get_macaddr; + retval = ipheth_enable_ncm(dev); + if (!retval) { + dev->rx_buf_len = IPHETH_RX_BUF_SIZE_NCM; + dev->rcvbulk_callback = ipheth_rcvbulk_callback_ncm; + } + INIT_DELAYED_WORK(&dev->carrier_work, ipheth_carrier_check_work); retval = ipheth_alloc_urbs(dev); From patchwork Wed Jun 7 13:57:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Foster Snowhill X-Patchwork-Id: 13270754 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA252C7EE25 for ; Wed, 7 Jun 2023 14:08:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240869AbjFGOIK (ORCPT ); Wed, 7 Jun 2023 10:08:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235770AbjFGOH4 (ORCPT ); Wed, 7 Jun 2023 10:07:56 -0400 Received: from qs51p00im-qukt01071502.me.com (qs51p00im-qukt01071502.me.com [17.57.155.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BEA42693 for ; Wed, 7 Jun 2023 07:07:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pen.gy; s=sig1; t=1686146271; bh=WH4UOMGuaBmvgJW4vrRLk/Li3o9mJBIOoSyjNRAIx0M=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=H2na3Y8cfOjzYfmG6gcNvLMSrtQHCGdFVX5KVpc+C/sTovwybYiuz63GJAvzphhl2 XT6D2zwoHhyTinJ3Uz3nv3YHHHT426hUuIiYSRm1qTzY0YbzUpWxGLCE4XwLRlsyhz ZXPVBkMxQhS7gSaC7nTvY6vwtRLUNlrwhaYDMabh8tNWjbSGMZFCx7NAEvP6gYvT8g EXu9o5Zie5tBHvnn+G/CRxefN/IA/fov008fRvUR2p1DBcirlYustSh9psHuBvgGO3 9AzbQMRZLBdq1MtWvLKuYZonFtH1HYv4QHtqDAI/mGJGm9NlLM94VLYBaXQFrxj6yG zXBszpCxxIV8A== Received: from fossa.iopsys.eu (qs51p00im-dlb-asmtp-mailmevip.me.com [17.57.155.28]) by qs51p00im-qukt01071502.me.com (Postfix) with ESMTPSA id 1E98B66803F3; Wed, 7 Jun 2023 13:57:48 +0000 (UTC) From: Foster Snowhill To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Georgi Valkov , Simon Horman , Jan Kiszka , linux-usb@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v4 4/4] usbnet: ipheth: update Kconfig description Date: Wed, 7 Jun 2023 15:57:02 +0200 Message-Id: <20230607135702.32679-4-forst@pen.gy> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230607135702.32679-1-forst@pen.gy> References: <20230607135702.32679-1-forst@pen.gy> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: te8fs2XClFkTHjm9KHtE2AbGV3RREIzr X-Proofpoint-GUID: te8fs2XClFkTHjm9KHtE2AbGV3RREIzr X-Proofpoint-Virus-Version: =?utf-8?q?vendor=3Dfsecure_engine=3D1=2E1=2E170-?= =?utf-8?q?22c6f66c430a71ce266a39bfe25bc2903e8d5c8f=3A6=2E0=2E138=2C18=2E0?= =?utf-8?q?=2E790=2C17=2E11=2E62=2E513=2E0000000_definitions=3D2022-01-12=5F?= =?utf-8?q?02=3A2020-02-14=5F02=2C2022-01-12=5F02=2C2021-12-02=5F01_signatur?= =?utf-8?q?es=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=1 adultscore=0 phishscore=0 spamscore=1 clxscore=1030 suspectscore=0 malwarescore=0 mlxlogscore=228 mlxscore=1 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2306070117 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org This module has for a long time not been limited to iPhone <= 3GS. Update description to match the actual state of the driver. Remove dead link from 2010, instead reference an existing userspace iOS device pairing implementation as part of libimobiledevice. Signed-off-by: Foster Snowhill --- v4: Change added in v4. v3: n/a v2: n/a v1: n/a --- drivers/net/usb/Kconfig | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig index 4402eedb3..3fd7dccf0 100644 --- a/drivers/net/usb/Kconfig +++ b/drivers/net/usb/Kconfig @@ -583,12 +583,10 @@ config USB_IPHETH default n help Module used to share Internet connection (tethering) from your - iPhone (Original, 3G and 3GS) to your system. - Note that you need userspace libraries and programs that are needed - to pair your device with your system and that understand the iPhone - protocol. - - For more information: http://giagio.com/wiki/moin.cgi/iPhoneEthernetDriver + iPhone to your system. + Note that you need a corresponding userspace library/program + to pair your device with your system, for example usbmuxd + . config USB_SIERRA_NET tristate "USB-to-WWAN Driver for Sierra Wireless modems"