From patchwork Sun Jan 5 01:01:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Foster Snowhill X-Patchwork-Id: 13926404 Received: from qs51p00im-qukt01080502.me.com (qs51p00im-qukt01080502.me.com [17.57.155.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59AE81EB2E for ; Sun, 5 Jan 2025 01:02:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.57.155.23 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736038923; cv=none; b=A5GrZockl84F3hwe1HUifgxPD1G9etvOnT8H0DBKgDoExQt/blkZev2vhv2500alESGWIOZ66Kr0I0ffkGN9Qb8WqWayg9aUtx/Dw5rJoHTiNN0Btpdgx6sokI/PDi9bvGW8wgQi52tLNQkAiEa+u6tSGpAp+mgwBPw2c6diNd0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736038923; c=relaxed/simple; bh=GS4W9TFShLkwq5Q22eLZbZcw7ENoNIixuDAsQuWQVss=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fr54e1ju3TRMAxr7BFIVnC5uGhWK2slYV3nuxY2zO/pvexQLpfQeUDN/3eLxsLJ3j8mqhpucotdxkwQ0yIwojFzxNACL4wrXqkBy+LQ3Tg3cHbYTt8Vv3BEyIB4/kmHLVdenB2aIMXpb6PMKG1ve5+pCNp/8/3ERf9CAWYXXejs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pen.gy; spf=pass smtp.mailfrom=pen.gy; dkim=pass (2048-bit key) header.d=pen.gy header.i=@pen.gy header.b=auO+Y1rO; arc=none smtp.client-ip=17.57.155.23 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pen.gy Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pen.gy Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pen.gy header.i=@pen.gy header.b="auO+Y1rO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pen.gy; s=sig1; t=1736038920; bh=9PgIIZNI9c9i2ldCA3Cf/AEZv9ZPkrBocNBdDv800Ps=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=auO+Y1rOkJSk2AP+h+l9+qp5USGhUjaalfdv8/Rj3pLEAWZgQt5eacDACJez0TJyo HyMYlnQAcq8Wk+VjI/vihHA7VKZzS+eT60BLNZUc04oYVDHdfXEEKaTpX8gAz37+X9 3sa1PN9uhcHlyhTx/gp35kDGj9alMUrJPzz3a8tJE6uXcnyvsbxfy1FlSTX2RrZ5A+ SJH86EP+ZmuDwsqUkTQ00RuPFubf0Mfge+KUlkQXu0o2v2OcXxa4f2saqoGbZNFSg3 3NtxoNTEaGAKNA6bk//7BLk3eCeTd6bJ5t5IssILcMo2owQ7RyZl0ROPeQ7EQIePak tLJfnCah06M6A== Received: from fossa.se1.pen.gy (qs51p00im-dlb-asmtp-mailmevip.me.com [17.57.155.28]) by qs51p00im-qukt01080502.me.com (Postfix) with ESMTPSA id 2B30C4E40199; Sun, 5 Jan 2025 01:01:56 +0000 (UTC) From: Foster Snowhill To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Georgi Valkov , Simon Horman , Oliver Neukum , netdev@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH net v4 1/7] usbnet: ipheth: break up NCM header size computation Date: Sun, 5 Jan 2025 02:01:15 +0100 Message-ID: <20250105010121.12546-2-forst@pen.gy> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20250105010121.12546-1-forst@pen.gy> References: <20250105010121.12546-1-forst@pen.gy> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-GUID: tNpCVvBSkQCyAD-R_uiy5B2X-6oAW6vX X-Proofpoint-ORIG-GUID: tNpCVvBSkQCyAD-R_uiy5B2X-6oAW6vX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-02_03,2025-01-02_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 mlxlogscore=522 malwarescore=0 phishscore=0 bulkscore=0 suspectscore=0 mlxscore=0 clxscore=1030 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2501050007 Originally, the total NCM header size was computed as the sum of two vaguely labelled constants. While accurate, it wasn't particularly clear where they were coming from. Use sizes of existing NCM structs where available. Define the total NDP16 size based on the maximum amount of DPEs that can fit into the iOS-specific fixed-size header. This change does not fix any particular issue. Rather, it introduces intermediate constants that will simplify subsequent commits. It should also make it clearer for the reader where the constant values come from. Signed-off-by: Foster Snowhill --- v4: No code changes. Remove "Fixes" from the commit message, and clarify the purpose/scope of the commit. v3: https://lore.kernel.org/netdev/20241123235432.821220-1-forst@pen.gy/ * NDP16 header size is computed from max DPE count constant, not the other way around. * Split out from a monolithic patch in v2. v2: https://lore.kernel.org/netdev/20240912211817.1707844-1-forst@pen.gy/ No code changes. Update commit message to further clarify that `ipheth` is not and does not aim to be a complete or spec-compliant CDC NCM implementation. v1: https://lore.kernel.org/netdev/20240907230108.978355-1-forst@pen.gy/ --- drivers/net/usb/ipheth.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/net/usb/ipheth.c b/drivers/net/usb/ipheth.c index 46afb95ffabe..2084b940b4ea 100644 --- a/drivers/net/usb/ipheth.c +++ b/drivers/net/usb/ipheth.c @@ -61,7 +61,18 @@ #define IPHETH_USBINTF_PROTO 1 #define IPHETH_IP_ALIGN 2 /* padding at front of URB */ -#define IPHETH_NCM_HEADER_SIZE (12 + 96) /* NCMH + NCM0 */ +/* On iOS devices, NCM headers in RX have a fixed size regardless of DPE count: + * - NTH16 (NCMH): 12 bytes, as per CDC NCM 1.0 spec + * - NDP16 (NCM0): 96 bytes, of which + * - NDP16 fixed header: 8 bytes + * - maximum of 22 DPEs (21 datagrams + trailer), 4 bytes each + */ +#define IPHETH_NDP16_MAX_DPE 22 +#define IPHETH_NDP16_HEADER_SIZE (sizeof(struct usb_cdc_ncm_ndp16) + \ + IPHETH_NDP16_MAX_DPE * \ + sizeof(struct usb_cdc_ncm_dpe16)) +#define IPHETH_NCM_HEADER_SIZE (sizeof(struct usb_cdc_ncm_nth16) + \ + IPHETH_NDP16_HEADER_SIZE) #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 From patchwork Sun Jan 5 01:01:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Foster Snowhill X-Patchwork-Id: 13926405 Received: from qs51p00im-qukt01080502.me.com (qs51p00im-qukt01080502.me.com [17.57.155.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E14971EF01 for ; Sun, 5 Jan 2025 01:02:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.57.155.23 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736038926; cv=none; b=itz+c6SYEgIhVI/TdPeKi/rODRsTQiXwi62ToHxKByAaBSHOIZ16+YKnxEgBgkwtNeLZVzumZvWpsoig4KrCgsFgfFYbSatPp7tzY3Jvfy0RYzR2I5DOoYg85l7lAn6D0QNo5u72gN0szsa9OQV8aIpMWtMaGMO5LkbYzO8Shnk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736038926; c=relaxed/simple; bh=v48SwYQToZkEEuFw38f6V78gYlZ0/JB0VB4uCu3g/6g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bdZxO8d5jyINaRAyBwTM5Ba+C6NOzn7z6Xs23gSpKEdGOoS6NWymNOHsQusCpfyZJ6ZBhBOAKCQxfRWFjNRSgZk7EzWel9GPJF1IoGktKlXj8r9+ZVnfNmtgX0HDPUx7eY3UKLqC43ytlIARzL3F1sJ/NrjPmu2G2fIpwWKtzpg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pen.gy; spf=pass smtp.mailfrom=pen.gy; dkim=pass (2048-bit key) header.d=pen.gy header.i=@pen.gy header.b=ev/RzBbr; arc=none smtp.client-ip=17.57.155.23 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pen.gy Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pen.gy Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pen.gy header.i=@pen.gy header.b="ev/RzBbr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pen.gy; s=sig1; t=1736038924; bh=UBQCEhKGnnf26A1CQv5YwjWX3q/4vt5KvKPq9EdLqT4=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=ev/RzBbrm5Qd0/4504Zt1/Bgy2VQdTzJJajWaYf4sSHv51wZt92pc33QFGIayUbe8 fRbiRUU17Wpd7RZgS64gjKtLstS7Im72EizQkxkp1uUBIGfnzdChw22DlEEYb9PrM1 qCR0mNBy5qujDzFjN4nWDuQuP9FNRIu0Kc3dK79//Wbp75P5fcFmAZA1I5PKNVMXp8 CDXfDM/LdCpEcVhT8UsMyQEsLKsAn2m+EL38GvWwOlBmTzk9VGSXCiXO6SSb1OvuWo vtX5l9B+HUqGcFp5C8oyuSUjx7kAwDKTW/djT0qC2LNGYO9XXPTUhemDlwWgaBAgpi WkM5Ie+kLHxIQ== Received: from fossa.se1.pen.gy (qs51p00im-dlb-asmtp-mailmevip.me.com [17.57.155.28]) by qs51p00im-qukt01080502.me.com (Postfix) with ESMTPSA id A9EB94E4030D; Sun, 5 Jan 2025 01:02:00 +0000 (UTC) From: Foster Snowhill To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Georgi Valkov , Simon Horman , Oliver Neukum , netdev@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH net v4 2/7] usbnet: ipheth: fix possible overflow in DPE length check Date: Sun, 5 Jan 2025 02:01:16 +0100 Message-ID: <20250105010121.12546-3-forst@pen.gy> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20250105010121.12546-1-forst@pen.gy> References: <20250105010121.12546-1-forst@pen.gy> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-GUID: gs-J8ilmDYTYXLzeDW4-0ncSSaxOu_Ws X-Proofpoint-ORIG-GUID: gs-J8ilmDYTYXLzeDW4-0ncSSaxOu_Ws X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-02_03,2025-01-02_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 mlxlogscore=661 malwarescore=0 phishscore=0 bulkscore=0 suspectscore=0 mlxscore=0 clxscore=1030 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2501050007 Originally, it was possible for the DPE length check to overflow if wDatagramIndex + wDatagramLength > U16_MAX. This could lead to an OoB read. Move the wDatagramIndex term to the other side of the inequality. An existing condition ensures that wDatagramIndex < urb->actual_length. Fixes: a2d274c62e44 ("usbnet: ipheth: add CDC NCM support") Signed-off-by: Foster Snowhill --- v4: No change since v3. v3: https://lore.kernel.org/netdev/20241123235432.821220-2-forst@pen.gy/ Split out from a monolithic patch in v2 as an atomic change. v2: https://lore.kernel.org/netdev/20240912211817.1707844-1-forst@pen.gy/ No code changes. Update commit message to further clarify that `ipheth` is not and does not aim to be a complete or spec-compliant CDC NCM implementation. v1: https://lore.kernel.org/netdev/20240907230108.978355-1-forst@pen.gy/ --- drivers/net/usb/ipheth.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/usb/ipheth.c b/drivers/net/usb/ipheth.c index 2084b940b4ea..4b590a5269fd 100644 --- a/drivers/net/usb/ipheth.c +++ b/drivers/net/usb/ipheth.c @@ -254,8 +254,8 @@ static int ipheth_rcvbulk_callback_ncm(struct urb *urb) 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) { + le16_to_cpu(dpe->wDatagramLength) > urb->actual_length - + le16_to_cpu(dpe->wDatagramIndex)) { dev->net->stats.rx_length_errors++; return retval; } From patchwork Sun Jan 5 01:01:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Foster Snowhill X-Patchwork-Id: 13926406 Received: from qs51p00im-qukt01080502.me.com (qs51p00im-qukt01080502.me.com [17.57.155.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E9C73596C for ; Sun, 5 Jan 2025 01:02:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.57.155.23 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736038931; cv=none; b=ruAhe1f2usWf29KdsP6tVQjHYIH4TiPwAtDtG0vtPqVG3ObF7Fsx7S7CBGvxpAYH4dGUfgE/e3qTIh4MQvkhBUIXCvE/nONSGpPckdAETg0ZTO1reCkmurhXfD4zGwod4stuDDlwWcjOzB3znq8DbElLO/r7bRGF0Zp85CUT4cg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736038931; c=relaxed/simple; bh=gdr3lIbDeeu3lGJcPUIXZI0GtBHkqV3idA1+n3n94LM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KVqi//A7owZl/QCVI6nGi39u8v6R3Y0XX86R0Z/+zpPGm4C/YjCKyqiRAmFyBl/iuo3OGXH7+LlCqBSHRBdbB6b6wnTa/MbyumeqZT9tEOtyzNahQpa4IHWGAZ2Qrb8jUenTlOyWSXDrzygWlf2F/6n2i1AkxguAYwfO6q4wL9Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pen.gy; spf=pass smtp.mailfrom=pen.gy; dkim=pass (2048-bit key) header.d=pen.gy header.i=@pen.gy header.b=G+bjnCk8; arc=none smtp.client-ip=17.57.155.23 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pen.gy Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pen.gy Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pen.gy header.i=@pen.gy header.b="G+bjnCk8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pen.gy; s=sig1; t=1736038927; bh=Uu90pAf2wJ+haot8QoQIW/G/7kp2o6NfhKfyyk60q8w=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=G+bjnCk83fhhQui33+48toUdg68Q30GYvvuATIbMPsI2lGW2ZNOWq9txzak2FI69G 3Tvjte70F1NRz8c5yBteAcSOP0cWRiF3pBUxTFB5jCNx9qiY5tAYjx7RCbYA2KvW8a 2gPK+h+7ad8ZLZFbl9X+l5WzawG1WxaLmg0t3ZGIIZQ48w0L/XNeuEbof5ddngAJgm 0FCVYEjuCAj+0I1byWiEA4anHON5Wi7FAq/BmMppioOXZfz6utvWXlgyKdC6xcycye cXYw905Rs9D+unc2RbTyGxDVYMyCXrDPFL5gUovF52vbX4T9RPn7b9Iov/8seP5nyh X3Kkvblcsn6lw== Received: from fossa.se1.pen.gy (qs51p00im-dlb-asmtp-mailmevip.me.com [17.57.155.28]) by qs51p00im-qukt01080502.me.com (Postfix) with ESMTPSA id 723D24E4031C; Sun, 5 Jan 2025 01:02:04 +0000 (UTC) From: Foster Snowhill To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Georgi Valkov , Simon Horman , Oliver Neukum , netdev@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH net v4 3/7] usbnet: ipheth: check that DPE points past NCM header Date: Sun, 5 Jan 2025 02:01:17 +0100 Message-ID: <20250105010121.12546-4-forst@pen.gy> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20250105010121.12546-1-forst@pen.gy> References: <20250105010121.12546-1-forst@pen.gy> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-GUID: mziyVBly5qccvB1Ec9ktIaQqUcZFa1xY X-Proofpoint-ORIG-GUID: mziyVBly5qccvB1Ec9ktIaQqUcZFa1xY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-02_03,2025-01-02_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 mlxlogscore=470 malwarescore=0 phishscore=0 bulkscore=0 suspectscore=0 mlxscore=0 clxscore=1030 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2501050007 By definition, a DPE points at the start of a network frame/datagram. Thus it makes no sense for it to point at anything that's part of the NCM header. It is not a security issue, but merely an indication of a malformed DPE. Enforce that all DPEs point at the data portion of the URB, past the NCM header. Fixes: a2d274c62e44 ("usbnet: ipheth: add CDC NCM support") Signed-off-by: Foster Snowhill --- v4: No change since v3. v3: https://lore.kernel.org/netdev/20241123235432.821220-3-forst@pen.gy/ Split out from a monolithic patch in v2 as an atomic change. v2: https://lore.kernel.org/netdev/20240912211817.1707844-1-forst@pen.gy/ No code changes. Update commit message to further clarify that `ipheth` is not and does not aim to be a complete or spec-compliant CDC NCM implementation. v1: https://lore.kernel.org/netdev/20240907230108.978355-1-forst@pen.gy/ --- drivers/net/usb/ipheth.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/usb/ipheth.c b/drivers/net/usb/ipheth.c index 4b590a5269fd..48c79e69bb7b 100644 --- a/drivers/net/usb/ipheth.c +++ b/drivers/net/usb/ipheth.c @@ -253,7 +253,8 @@ static int ipheth_rcvbulk_callback_ncm(struct urb *urb) 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 || + if (le16_to_cpu(dpe->wDatagramIndex) < IPHETH_NCM_HEADER_SIZE || + le16_to_cpu(dpe->wDatagramIndex) >= urb->actual_length || le16_to_cpu(dpe->wDatagramLength) > urb->actual_length - le16_to_cpu(dpe->wDatagramIndex)) { dev->net->stats.rx_length_errors++; From patchwork Sun Jan 5 01:01:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Foster Snowhill X-Patchwork-Id: 13926407 Received: from qs51p00im-qukt01080502.me.com (qs51p00im-qukt01080502.me.com [17.57.155.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2438A920 for ; Sun, 5 Jan 2025 01:02:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.57.155.23 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736038933; cv=none; b=iBxqg9TfxZsUmNhbv1Cl6d8aaHFhrV1jBycsuVfEkiCFuB6A139fgYKtHdafgt748YmGDbxG9GZ1YOOVDiYwTv3EbDXVFwZ21NCWiGYRj2xmXmQnUtZB+dcj3ZgG/0x9FR+FG5w1hfhSN+YoaClPCqavf0F2w5FEi/hsiiNo2kg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736038933; c=relaxed/simple; bh=v08LP/vA38rMGaE48oYXJiKyqTcyaBXnpqHV1cBNF/M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ok7XhaClKp8EDNFcKZqb7V/5ASq2bcVidYbg+WWDH7Qhr84vim+EYK+lv26i3VHdMxtd+jqB/8ArBXjUMcf41JFqRU9OeETqmKef1ICMGpUKJHC7r/K8Kg/CP65eNsUisIERUYiO1957e8VEScWLvHZ/EeBYYhGho48ladQICkk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pen.gy; spf=pass smtp.mailfrom=pen.gy; dkim=pass (2048-bit key) header.d=pen.gy header.i=@pen.gy header.b=fkzeQRYQ; arc=none smtp.client-ip=17.57.155.23 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pen.gy Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pen.gy Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pen.gy header.i=@pen.gy header.b="fkzeQRYQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pen.gy; s=sig1; t=1736038930; bh=jA5Elsv6DJ1PRK/AyDutknBxgJAPX7pUFb8V5z5GRWw=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=fkzeQRYQ/byD/2KFnLzI+zDnZ/HzzutKpSKhtrO8/xoOi+cVk3dB03EWVGxTbgMgQ 2Mn7yA883bzXNd3g/5jlOwfbVOrKSqjvRdhMANzd0henzGSz3dIfb0+y/FUs47bsiW 0UCkpbb3M1I/7AV29Ol164+VKSjUoh9S8IQ8qYqP97AtPlCjbGmhlNIXheIVyOaOGz agNAr4W8Zf9tWTyHHLHHWBf2yIFpJQXi6gdk1mFBE6lqce+FLSfxyVTpG6EVbovUca OItMkgwuQ9g1/8Jn+zyEepxWFQM5gKR+/zm3e8mt1M7+PyQaSOTzZx0sUJvDMmDR6i jvnjThLe7sSzw== Received: from fossa.se1.pen.gy (qs51p00im-dlb-asmtp-mailmevip.me.com [17.57.155.28]) by qs51p00im-qukt01080502.me.com (Postfix) with ESMTPSA id D43B54E40302; Sun, 5 Jan 2025 01:02:07 +0000 (UTC) From: Foster Snowhill To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Georgi Valkov , Simon Horman , Oliver Neukum , netdev@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH net v4 4/7] usbnet: ipheth: use static NDP16 location in URB Date: Sun, 5 Jan 2025 02:01:18 +0100 Message-ID: <20250105010121.12546-5-forst@pen.gy> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20250105010121.12546-1-forst@pen.gy> References: <20250105010121.12546-1-forst@pen.gy> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-GUID: 19I-srsZhN7ftCtPly6qMe1jvkUlC3kC X-Proofpoint-ORIG-GUID: 19I-srsZhN7ftCtPly6qMe1jvkUlC3kC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-02_03,2025-01-02_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 mlxlogscore=578 malwarescore=0 phishscore=0 bulkscore=0 suspectscore=0 mlxscore=0 clxscore=1030 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2501050007 Original code allowed for the start of NDP16 to be anywhere within the URB based on the `wNdpIndex` value in NTH16. Only the start position of NDP16 was checked, so it was possible for even the fixed-length part of NDP16 to extend past the end of URB, leading to an out-of-bounds read. On iOS devices, the NDP16 header always directly follows NTH16. Rely on and check for this specific format. This, along with NCM-specific minimal URB length check that already exists, will ensure that the fixed-length part of NDP16 plus a set amount of DPEs fit within the URB. Note that this commit alone does not fully address the OoB read. The limit on the amount of DPEs needs to be enforced separately. Fixes: a2d274c62e44 ("usbnet: ipheth: add CDC NCM support") Signed-off-by: Foster Snowhill --- v4: Additionally check that ncmh->wNdpIndex points immediately after NTH16. This covers an unexpected on real devices, and highly unlikely otherwise, case where the bytes after NTH16 are set to `USB_CDC_NCM_NDP16_NOCRC_SIGN`, yet aren't the beginning of the NDP16 header. v3: https://lore.kernel.org/netdev/20241123235432.821220-4-forst@pen.gy/ Split out from a monolithic patch in v2 as an atomic change. v2: https://lore.kernel.org/netdev/20240912211817.1707844-1-forst@pen.gy/ No code changes. Update commit message to further clarify that `ipheth` is not and does not aim to be a complete or spec-compliant CDC NCM implementation. v1: https://lore.kernel.org/netdev/20240907230108.978355-1-forst@pen.gy/ --- drivers/net/usb/ipheth.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/net/usb/ipheth.c b/drivers/net/usb/ipheth.c index 48c79e69bb7b..35f507db2c4a 100644 --- a/drivers/net/usb/ipheth.c +++ b/drivers/net/usb/ipheth.c @@ -237,15 +237,14 @@ static int ipheth_rcvbulk_callback_ncm(struct urb *urb) ncmh = urb->transfer_buffer; if (ncmh->dwSignature != cpu_to_le32(USB_CDC_NCM_NTH16_SIGN) || - le16_to_cpu(ncmh->wNdpIndex) >= urb->actual_length) { + /* On iOS, NDP16 directly follows NTH16 */ + ncmh->wNdpIndex != cpu_to_le16(sizeof(struct usb_cdc_ncm_nth16))) { 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) { + ncm0 = urb->transfer_buffer + sizeof(struct usb_cdc_ncm_nth16); + if (ncm0->dwSignature != cpu_to_le32(USB_CDC_NCM_NDP16_NOCRC_SIGN)) { dev->net->stats.rx_errors++; return retval; } From patchwork Sun Jan 5 01:01:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Foster Snowhill X-Patchwork-Id: 13926408 Received: from qs51p00im-qukt01080502.me.com (qs51p00im-qukt01080502.me.com [17.57.155.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14D331DFDE for ; Sun, 5 Jan 2025 01:02:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.57.155.23 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736038937; cv=none; b=oCsZapbVTZRTX99DSq+6kWGHQnqczLK5SO0GqBLd4Z0NZDOD6y6SrEIx5DvhfwMK4/tO8ygpjXHEcK4AqguEWj6JhlXlGXz+adGIBnbQfEpBkpFX9JsJ/ftiRxr78aEv5jzkMpM10Ua0k1QgZNnR/lFTUEBIRL8BPLpiLlGHLJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736038937; c=relaxed/simple; bh=7UK33KbsyogV1PhFZAF0ip1dQdedZRcjLQ/JjRRQ7J0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e8bhPu8nL5EdQEjch379ThyBSEH1uaOGUecv+Cef3NlHpAm5ihZFHpjNqaniNc379bNgWGGWpoNay9V6klfQNJ20o3Mb3LBFUL4LPX/VOUw8Tmjhsgnxs6AM+nYZvAGUtdikz0tzaePyHJ9kmlYAIUiGToOeAK3tDFL2EnNW+NA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pen.gy; spf=pass smtp.mailfrom=pen.gy; dkim=pass (2048-bit key) header.d=pen.gy header.i=@pen.gy header.b=BlOITIZo; arc=none smtp.client-ip=17.57.155.23 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pen.gy Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pen.gy Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pen.gy header.i=@pen.gy header.b="BlOITIZo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pen.gy; s=sig1; t=1736038934; bh=7x+tWKXx3m/5m2X6cl5M0NW7QXghK6MQ/ArleBnvwAw=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=BlOITIZo580/64veO1TBvdEdT4txzU6KAAKBl11CiJ0D+AsfBOT3zrVEo4lgYQGu0 TND4GTHV1baDGDb5yb2djcl2MKEGINOEG7ryiH4f7/bTccn8huuZkxMHE9eFz4HOow 50Wg1DszSu8fDzek9PnzJINV0O3nnjv6YDBhjMNjt0+2s48kyTRZy16jjpoaWCs/y8 KG/8JHw9J9PBpoDe/Xb3RDK3RDEl122UHonnfstOIo/pki63vf5qFeHRqfq+tW8NyB +NuzC4aCvIkIjLyApFMySTlpAcE8rOBnfV00Ma6WZMBG2qDd7dcWgWVIJsrs2411c3 +JgkPRY3b6kLQ== Received: from fossa.se1.pen.gy (qs51p00im-dlb-asmtp-mailmevip.me.com [17.57.155.28]) by qs51p00im-qukt01080502.me.com (Postfix) with ESMTPSA id 470564E401A5; Sun, 5 Jan 2025 01:02:11 +0000 (UTC) From: Foster Snowhill To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Georgi Valkov , Simon Horman , Oliver Neukum , netdev@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH net v4 5/7] usbnet: ipheth: refactor NCM datagram loop Date: Sun, 5 Jan 2025 02:01:19 +0100 Message-ID: <20250105010121.12546-6-forst@pen.gy> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20250105010121.12546-1-forst@pen.gy> References: <20250105010121.12546-1-forst@pen.gy> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-GUID: FsV0s8q3dVdA-Frb-5dkAPXMrwn69fLs X-Proofpoint-ORIG-GUID: FsV0s8q3dVdA-Frb-5dkAPXMrwn69fLs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-02_03,2025-01-02_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 mlxlogscore=713 malwarescore=0 phishscore=0 bulkscore=0 suspectscore=0 mlxscore=0 clxscore=1030 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2501050007 Introduce an rx_error label to reduce repetitions in the header signature checks. Store wDatagramIndex and wDatagramLength after endianness conversion to avoid repeated le16_to_cpu() calls. Rewrite the loop to return on a null trailing DPE, which is required by the CDC NCM spec. In case it is missing, fall through to rx_error. This change does not fix any particular issue. Its purpose is to simplify a subsequent commit that fixes a potential OoB read by limiting the maximum amount of processed DPEs. Fix an out-of-bounds DPE read, limit the number of processed DPEs to the amount that fits into the fixed-size NDP16 header. Signed-off-by: Foster Snowhill --- v4: Split from "usbnet: ipheth: refactor NCM datagram loop, fix DPE OoB read" in v3. This commit is responsible for the code refactor, while keeping the behaviour the same. v3: https://lore.kernel.org/netdev/20241123235432.821220-5-forst@pen.gy/ Split out from a monolithic patch in v2 as an atomic change. v2: https://lore.kernel.org/netdev/20240912211817.1707844-1-forst@pen.gy/ No code changes. Update commit message to further clarify that `ipheth` is not and does not aim to be a complete or spec-compliant CDC NCM implementation. v1: https://lore.kernel.org/netdev/20240907230108.978355-1-forst@pen.gy/ --- drivers/net/usb/ipheth.c | 42 ++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/drivers/net/usb/ipheth.c b/drivers/net/usb/ipheth.c index 35f507db2c4a..03249208612e 100644 --- a/drivers/net/usb/ipheth.c +++ b/drivers/net/usb/ipheth.c @@ -224,9 +224,9 @@ static int ipheth_rcvbulk_callback_ncm(struct urb *urb) struct usb_cdc_ncm_ndp16 *ncm0; struct usb_cdc_ncm_dpe16 *dpe; struct ipheth_device *dev; + u16 dg_idx, dg_len; int retval = -EINVAL; char *buf; - int len; dev = urb->context; @@ -238,39 +238,43 @@ static int ipheth_rcvbulk_callback_ncm(struct urb *urb) ncmh = urb->transfer_buffer; if (ncmh->dwSignature != cpu_to_le32(USB_CDC_NCM_NTH16_SIGN) || /* On iOS, NDP16 directly follows NTH16 */ - ncmh->wNdpIndex != cpu_to_le16(sizeof(struct usb_cdc_ncm_nth16))) { - dev->net->stats.rx_errors++; - return retval; - } + ncmh->wNdpIndex != cpu_to_le16(sizeof(struct usb_cdc_ncm_nth16))) + goto rx_error; ncm0 = urb->transfer_buffer + sizeof(struct usb_cdc_ncm_nth16); - if (ncm0->dwSignature != cpu_to_le32(USB_CDC_NCM_NDP16_NOCRC_SIGN)) { - dev->net->stats.rx_errors++; - return retval; - } + if (ncm0->dwSignature != cpu_to_le32(USB_CDC_NCM_NDP16_NOCRC_SIGN)) + goto rx_error; dpe = ncm0->dpe16; - while (le16_to_cpu(dpe->wDatagramIndex) != 0 && - le16_to_cpu(dpe->wDatagramLength) != 0) { - if (le16_to_cpu(dpe->wDatagramIndex) < IPHETH_NCM_HEADER_SIZE || - le16_to_cpu(dpe->wDatagramIndex) >= urb->actual_length || - le16_to_cpu(dpe->wDatagramLength) > urb->actual_length - - le16_to_cpu(dpe->wDatagramIndex)) { + while (true) { + dg_idx = le16_to_cpu(dpe->wDatagramIndex); + dg_len = le16_to_cpu(dpe->wDatagramLength); + + /* Null DPE must be present after last datagram pointer entry + * (3.3.1 USB CDC NCM spec v1.0) + */ + if (dg_idx == 0 && dg_len == 0) + return 0; + + if (dg_idx < IPHETH_NCM_HEADER_SIZE || + dg_idx >= urb->actual_length || + dg_len > urb->actual_length - dg_idx) { dev->net->stats.rx_length_errors++; return retval; } - buf = urb->transfer_buffer + le16_to_cpu(dpe->wDatagramIndex); - len = le16_to_cpu(dpe->wDatagramLength); + buf = urb->transfer_buffer + dg_idx; - retval = ipheth_consume_skb(buf, len, dev); + retval = ipheth_consume_skb(buf, dg_len, dev); if (retval != 0) return retval; dpe++; } - return 0; +rx_error: + dev->net->stats.rx_errors++; + return retval; } static void ipheth_rcvbulk_callback(struct urb *urb) From patchwork Sun Jan 5 01:01:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Foster Snowhill X-Patchwork-Id: 13926409 Received: from qs51p00im-qukt01080502.me.com (qs51p00im-qukt01080502.me.com [17.57.155.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A81F349625 for ; Sun, 5 Jan 2025 01:02:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.57.155.23 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736038940; cv=none; b=o6dkM4q3gxnPck09sKIUTTInuTb7JTOc0OPIKQnAy17iCTK75xt9etmrSijHpy9x+h9ZutqjsssziFxG9t4TX9IxTTKXIUCdfaB1ZM0qsbpNbax3y70d87qBbDdSvVfFHvG6OEnsoHsBTCXcNHgCFqop3DnT8McTYE7UyQxk1Ag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736038940; c=relaxed/simple; bh=flyKp3RQ53pkfVwzwBlpnTDsA60UWcGD7KZcCgsPMPk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WjPMU9gVw1RDsS9uB5yeRIZzd8qNxogrPBObuFdGYTB1Xqd33cHqihAjM5pMDRDt3ivWoCTKL4sulkykYaBDfnlTOOh7ihmnR3VlsaJSe3OxLmxINg3b5RKVYmM6CBUakAZ+6xZ/MOwFg1u60G3AH0YCleYyZanG+jzrT6C+IOQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pen.gy; spf=pass smtp.mailfrom=pen.gy; dkim=pass (2048-bit key) header.d=pen.gy header.i=@pen.gy header.b=FXf4HhcR; arc=none smtp.client-ip=17.57.155.23 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pen.gy Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pen.gy Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pen.gy header.i=@pen.gy header.b="FXf4HhcR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pen.gy; s=sig1; t=1736038937; bh=oWa6tcfAyF//NHcdPXeZ1i6bnr87+mwpPqXxI3ayEQE=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=FXf4HhcRhg0Ih6rNTEEoxohcs0DaamOa2vXvSuBKVQ7iA1R2iaFb3rGevMPibgGYk kOHKrg1aXHktn0BcMpjjOc3LNiBg4bqoVsA595gsGVfhTzi59iJJukqg6SEL9o92AV oDvKs8XC8pWuHUi+BlekgsruiNV4/cgzXGmpvuSmDHn5eUACCBwmgpcOMzoZ8dU5qP DNKPEhkGowt+AZKWTjlfjq4+4CwesplF+Gl4DsPl+mBzh+/JBs4O4aZ1sGzpqBVkBM nyHwrwA2IaUzs3B9fkURaLXr59DMSTtukpThCLgF+esCJ3DCmFn6MHXq/+tfGWIN2o Hbop086Os0e/g== Received: from fossa.se1.pen.gy (qs51p00im-dlb-asmtp-mailmevip.me.com [17.57.155.28]) by qs51p00im-qukt01080502.me.com (Postfix) with ESMTPSA id B43484E4030F; Sun, 5 Jan 2025 01:02:14 +0000 (UTC) From: Foster Snowhill To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Georgi Valkov , Simon Horman , Oliver Neukum , netdev@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH net v4 6/7] usbnet: ipheth: fix DPE OoB read Date: Sun, 5 Jan 2025 02:01:20 +0100 Message-ID: <20250105010121.12546-7-forst@pen.gy> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20250105010121.12546-1-forst@pen.gy> References: <20250105010121.12546-1-forst@pen.gy> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-GUID: 1wRceMRCbWig1Waecu5rj_D2gdrov75F X-Proofpoint-ORIG-GUID: 1wRceMRCbWig1Waecu5rj_D2gdrov75F X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-02_03,2025-01-02_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 mlxlogscore=738 malwarescore=0 phishscore=0 bulkscore=0 suspectscore=0 mlxscore=0 clxscore=1030 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2501050007 Fix an out-of-bounds DPE read, limit the number of processed DPEs to the amount that fits into the fixed-size NDP16 header. Fixes: a2d274c62e44 ("usbnet: ipheth: add CDC NCM support") Signed-off-by: Foster Snowhill --- v4: Split from "usbnet: ipheth: refactor NCM datagram loop, fix DPE OoB read" in v3. This commit is responsible for addressing the potential OoB read. v3: https://lore.kernel.org/netdev/20241123235432.821220-5-forst@pen.gy/ Split out from a monolithic patch in v2 as an atomic change. v2: https://lore.kernel.org/netdev/20240912211817.1707844-1-forst@pen.gy/ No code changes. Update commit message to further clarify that `ipheth` is not and does not aim to be a complete or spec-compliant CDC NCM implementation. v1: https://lore.kernel.org/netdev/20240907230108.978355-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 03249208612e..5347cd7e295b 100644 --- a/drivers/net/usb/ipheth.c +++ b/drivers/net/usb/ipheth.c @@ -246,7 +246,7 @@ static int ipheth_rcvbulk_callback_ncm(struct urb *urb) goto rx_error; dpe = ncm0->dpe16; - while (true) { + for (int dpe_i = 0; dpe_i < IPHETH_NDP16_MAX_DPE; ++dpe_i, ++dpe) { dg_idx = le16_to_cpu(dpe->wDatagramIndex); dg_len = le16_to_cpu(dpe->wDatagramLength); @@ -268,8 +268,6 @@ static int ipheth_rcvbulk_callback_ncm(struct urb *urb) retval = ipheth_consume_skb(buf, dg_len, dev); if (retval != 0) return retval; - - dpe++; } rx_error: From patchwork Sun Jan 5 01:01:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Foster Snowhill X-Patchwork-Id: 13926410 Received: from qs51p00im-qukt01080502.me.com (qs51p00im-qukt01080502.me.com [17.57.155.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D41CE6F2F2 for ; Sun, 5 Jan 2025 01:02:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.57.155.23 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736038943; cv=none; b=R99xANtWNdtC97pevcsgLFHRJbEBzFCKxoNxNCLLtCQni+UaaYAgngKiC/2bNzBN4hEH8WpvJh28S0JH0kpFeGPR5GUyEx36tU8qjS/VmKizx4hnScaqqIjNNoMGjsMyNrUQO1+rMvR3kGDAlCdgnl0vJFB6FhdJtJyIS8tpXdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736038943; c=relaxed/simple; bh=7be0LKI8J6P79iL2Z6CX4v1J7IZCLTyouES9PtvD490=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PM/DpXxwfGpN/NTfSoZqWgm1+rpp9payEhApfjXTcFz6z0NGAH4E6x2rCcYn3KwmI761q3LpT6DlK/KNBYtr4/saEY9guTaxRJDJn/acyjfJG98PRIRMgGTM7sqQyzQCdDVIkyLxrbtL9fs6zhEuNKSzq3lYttBvWJuQNb9eCWc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pen.gy; spf=pass smtp.mailfrom=pen.gy; dkim=pass (2048-bit key) header.d=pen.gy header.i=@pen.gy header.b=hDmST1Jc; arc=none smtp.client-ip=17.57.155.23 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pen.gy Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pen.gy Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pen.gy header.i=@pen.gy header.b="hDmST1Jc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pen.gy; s=sig1; t=1736038941; bh=zcmrmEqKEMywVUX7+JCLUV11PBm/zi7E6GUyhzlfy34=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=hDmST1JcAOXvECHYQLmgaacormVJqC+5gVephqFyPisinEZYOHGC6KGecbFYJg769 ZPfCqFjoM8UwdILLUR1Pkd4NE4ffecFVHp3LE0AXsLo6lSaTIdnjEPySr8QfTM+vuJ 4XrQ0VqEfcQeSRa8dzkzw7xAynGCX2T2ECpx9M+C4jrIZ0IFbDV0mWm7HOQGnkJ0cZ bvl9L0SCsjclkb/i+tGKrQIhmLx44BSyw2RVa5O88ZJPeK4j0fZ4xU3LdGnMpu+IdM o42dvFYptkH2mNy424k/tGYQmzBbZYgg4RjElmb8XOA9h7/Cn2+k5FrOKlJtncHh0f Gwm/Xm6FdBmMA== Received: from fossa.se1.pen.gy (qs51p00im-dlb-asmtp-mailmevip.me.com [17.57.155.28]) by qs51p00im-qukt01080502.me.com (Postfix) with ESMTPSA id 2AFEB4E40252; Sun, 5 Jan 2025 01:02:17 +0000 (UTC) From: Foster Snowhill To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Georgi Valkov , Simon Horman , Oliver Neukum , netdev@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH net v4 7/7] usbnet: ipheth: document scope of NCM implementation Date: Sun, 5 Jan 2025 02:01:21 +0100 Message-ID: <20250105010121.12546-8-forst@pen.gy> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20250105010121.12546-1-forst@pen.gy> References: <20250105010121.12546-1-forst@pen.gy> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-GUID: YLcBdPzalQ8M7NOmGtUvNfCdHpnFO_R1 X-Proofpoint-ORIG-GUID: YLcBdPzalQ8M7NOmGtUvNfCdHpnFO_R1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-02_03,2025-01-02_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 mlxlogscore=948 malwarescore=0 phishscore=0 bulkscore=0 suspectscore=0 mlxscore=0 clxscore=1030 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2501050007 Clarify that the "NCM" implementation in `ipheth` is very limited, as iOS devices aren't compatible with the CDC NCM specification in regular tethering mode. For a standards-compliant implementation, one shall turn to the `cdc_ncm` module. Signed-off-by: Foster Snowhill --- v4: No changes. v3: https://lore.kernel.org/netdev/20241123235432.821220-6-forst@pen.gy/ This comment was part of the commit message for v2. With v3, given how the patches are split up, it makes more sense to add the comment directly in code. v2: https://lore.kernel.org/netdev/20240912211817.1707844-1-forst@pen.gy/ No code changes. Update commit message to further clarify that `ipheth` is not and does not aim to be a complete or spec-compliant CDC NCM implementation. v1: n/a --- drivers/net/usb/ipheth.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/usb/ipheth.c b/drivers/net/usb/ipheth.c index 5347cd7e295b..a19789b57190 100644 --- a/drivers/net/usb/ipheth.c +++ b/drivers/net/usb/ipheth.c @@ -218,6 +218,14 @@ static int ipheth_rcvbulk_callback_legacy(struct urb *urb) return ipheth_consume_skb(buf, len, dev); } +/* In "NCM mode", the iOS device encapsulates RX (phone->computer) traffic + * in NCM Transfer Blocks (similarly to CDC NCM). However, unlike reverse + * tethering (handled by the `cdc_ncm` driver), regular tethering is not + * compliant with the CDC NCM spec, as the device is missing the necessary + * descriptors, and TX (computer->phone) traffic is not encapsulated + * at all. Thus `ipheth` implements a very limited subset of the spec with + * the sole purpose of parsing RX URBs. + */ static int ipheth_rcvbulk_callback_ncm(struct urb *urb) { struct usb_cdc_ncm_nth16 *ncmh;