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 AF5202EAE5; Thu, 11 Apr 2024 10:01:42 +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=1712829702; cv=none; b=cjtsX4+jLTH9PYYoUnSyD3Ue9vbipXwnOjGNH9NOIzG7YpdFGcyMhv0uxpblq25m2ojWdiMapfoU8G68QuVp12ehgenOJ182b3s4A+CyNO4w2On7c7UWz6v3Zbn1cWbtePgnJCmUU4p/+bMNISjbrdx345j2+OFPOtWrI6hLluM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712829702; c=relaxed/simple; bh=iHi2LD98F86TTnU9wOg2NksImbNwJmjMENgiv70NkAU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=U92DycJ+lNurkO/ZXVQfhGyp7ou6OZnKcy2CdzzvCjiVDrqRmil0wKQL8Zg8TEIaAiR7Q4Eapm22U5Dww7WKriPa2LvhS5g/IA7+ilfvxyAJzqUY8SmePP0VxFXCpy4REJB1K+jv0WKqMFPs5m2IrBrHfIRnx/5uAlZ9whLvau4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=JGurSLAj; 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="JGurSLAj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34A7CC433F1; Thu, 11 Apr 2024 10:01:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1712829702; bh=iHi2LD98F86TTnU9wOg2NksImbNwJmjMENgiv70NkAU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JGurSLAj0zX+xUOwWDMijEcHXAQnI3gzNFuxL2kxBIL9gGNZ3RO+tb80gazhELjap AJstkmWAKMFH4tUmJEbk/S0bmdWIDt0qu9Z2XZ3v/pcTLsKiwxSk6KsvKiRpBmi82y fodF1OSqDabhw+5aE8hGqUyfWuyOnFmD9lr88ZJo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Krishna Kurapati , =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Subject: [PATCH 4.19 075/175] usb: gadget: ncm: Fix handling of zero block length packets Date: Thu, 11 Apr 2024 11:54:58 +0200 Message-ID: <20240411095421.821348557@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411095419.532012976@linuxfoundation.org> References: <20240411095419.532012976@linuxfoundation.org> User-Agent: quilt/0.67 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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Krishna Kurapati commit f90ce1e04cbcc76639d6cba0fdbd820cd80b3c70 upstream. While connecting to a Linux host with CDC_NCM_NTB_DEF_SIZE_TX set to 65536, it has been observed that we receive short packets, which come at interval of 5-10 seconds sometimes and have block length zero but still contain 1-2 valid datagrams present. According to the NCM spec: "If wBlockLength = 0x0000, the block is terminated by a short packet. In this case, the USB transfer must still be shorter than dwNtbInMaxSize or dwNtbOutMaxSize. If exactly dwNtbInMaxSize or dwNtbOutMaxSize bytes are sent, and the size is a multiple of wMaxPacketSize for the given pipe, then no ZLP shall be sent. wBlockLength= 0x0000 must be used with extreme care, because of the possibility that the host and device may get out of sync, and because of test issues. wBlockLength = 0x0000 allows the sender to reduce latency by starting to send a very large NTB, and then shortening it when the sender discovers that there’s not sufficient data to justify sending a large NTB" However, there is a potential issue with the current implementation, as it checks for the occurrence of multiple NTBs in a single giveback by verifying if the leftover bytes to be processed is zero or not. If the block length reads zero, we would process the same NTB infintely because the leftover bytes is never zero and it leads to a crash. Fix this by bailing out if block length reads zero. Cc: stable@vger.kernel.org Fixes: 427694cfaafa ("usb: gadget: ncm: Handle decoding of multiple NTB's in unwrap call") Signed-off-by: Krishna Kurapati Reviewed-by: Maciej Żenczykowski Link: https://lore.kernel.org/r/20240228115441.2105585-1-quic_kriskura@quicinc.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_ncm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/usb/gadget/function/f_ncm.c +++ b/drivers/usb/gadget/function/f_ncm.c @@ -1357,7 +1357,7 @@ parse_ntb: if (to_process == 1 && (*(unsigned char *)(ntb_ptr + block_len) == 0x00)) { to_process--; - } else if (to_process > 0) { + } else if ((to_process > 0) && (block_len != 0)) { ntb_ptr = (unsigned char *)(ntb_ptr + block_len); goto parse_ntb; }