From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 C639426B098; Thu, 13 Feb 2025 15:30:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739460635; cv=none; b=XPmFMkrJi23EVF2Iby93mJuDvy4wYim1NapNusOynUjnmIm5nxWr0Rb3ergvD19vMBvLFOKH7gzcw3Ks6iaV6MreH+rekjeAilK+5AnSy+WM5dP32zoQ4V0JsRcOI4+fvQAdvZEYhl4Z2DzLfMd5LxcRkvr1wQd2OQTiigIeoUo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739460635; c=relaxed/simple; bh=DFQZee2GFTLI2PwqB94O8IzZ22YxD3NH/jRJcaQ6hG8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ngUc5tOimPzQzJV6GhYscv5jMT/fDgRIzEdHEa6B2BP3BaF1Ss14Sidgkp2WW7O41nTjCJcPbKvOGZo9xyYQ71sQ+6G1mOLKYoYywtVOn/i4XL0PdNeK0FWAhEs8Omk1DRjEIgr0TLmv0HyvQkf6NzItDiOhhccxkoBEnH0Zsq0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Nj/SUGXn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Nj/SUGXn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31F7FC4CED1; Thu, 13 Feb 2025 15:30:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1739460635; bh=DFQZee2GFTLI2PwqB94O8IzZ22YxD3NH/jRJcaQ6hG8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nj/SUGXn2+RB5LhenDmn477T5ZDleUp88cNtGYsnPSlSflDD2XVbxqiSrEW8+XPIJ Zs0WCWSV5EcID1sL89w9ADuUiU2H/ay3Tz81RebFVmLm4VZKeWxPcllFoVxEjSZXxq OozY/q9wYzNkYhb8ABFSxjMDMcGdn1mendUFH6mo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Foster Snowhill , Jakub Kicinski , Paolo Abeni Subject: [PATCH 6.6 137/273] usbnet: ipheth: use static NDP16 location in URB Date: Thu, 13 Feb 2025 15:28:29 +0100 Message-ID: <20250213142412.751761985@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250213142407.354217048@linuxfoundation.org> References: <20250213142407.354217048@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Foster Snowhill commit 86586dcb75cb8fd062a518aca8ee667938b91efb upstream. 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") Cc: stable@vger.kernel.org Signed-off-by: Foster Snowhill Reviewed-by: Jakub Kicinski Signed-off-by: Paolo Abeni Signed-off-by: Greg Kroah-Hartman --- 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 1ff5f7076ad5..c385623596d2 100644 --- a/drivers/net/usb/ipheth.c +++ b/drivers/net/usb/ipheth.c @@ -226,15 +226,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; } -- 2.48.1