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 A228B13CA81; Thu, 12 Dec 2024 17:28:10 +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=1734024490; cv=none; b=lWWddIHv+nW+g5D8wCQ7ppML79lWLXMGbMdvXKqwTUHuKglqFiwZia0KvNYrjIS/r8TmQYyW81M527LZOMKczmHl12uZQu/4Kuc7uDn9BIO/xKF4yOL3SdvWhWlLS0ynBR5sEmcZhjcao8G8ZXIwUMVHjh5t1WTxXBEg7fJpWm4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734024490; c=relaxed/simple; bh=G+d5wiZNPz1AO7i/3vfLj0SCLfKpbvvPI5prO8EVXVA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ojxlY6ClrCiohfqYx25xfiieRajfqdju6ifLB4JsD/02o2gRA6MkkCvhLxKgF751D5ndA9+yFY0b+JUIPHivzq3hLjpkh8LSa9m7weEvEe0KszC2SJ6KJvQtDwWw10fq96HZ8phjvr63t80PYhMd2ZJHZDvX6Ab9ZCE0wOyxbcY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Pn0+Y2sJ; 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="Pn0+Y2sJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23928C4CED0; Thu, 12 Dec 2024 17:28:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1734024490; bh=G+d5wiZNPz1AO7i/3vfLj0SCLfKpbvvPI5prO8EVXVA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pn0+Y2sJu2+XZ0MrxTeMulg2ImZIhmeaJNJcGPi1CNHdOiZEv81TeL94EquPo/clq 2otcDtPWqW67mN0e6yZLRlBAv/P+268Hq58i2WjQPr7nlOCvCPxLbfhGFtHEdHjk7G tBUjsC5zJMuo5UUJ+aocVJEzVHe5KLf1+YvvO13o= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Thinh Nguyen Subject: [PATCH 5.10 283/459] usb: dwc3: gadget: Fix looping of queued SG entries Date: Thu, 12 Dec 2024 16:00:21 +0100 Message-ID: <20241212144304.812221979@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241212144253.511169641@linuxfoundation.org> References: <20241212144253.511169641@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-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thinh Nguyen commit b7fc65f5141c24785dc8c19249ca4efcf71b3524 upstream. The dwc3_request->num_queued_sgs is decremented on completion. If a partially completed request is handled, then the dwc3_request->num_queued_sgs no longer reflects the total number of num_queued_sgs (it would be cleared). Correctly check the number of request SG entries remained to be prepare and queued. Failure to do this may cause null pointer dereference when accessing non-existent SG entry. Cc: stable@vger.kernel.org Fixes: c96e6725db9d ("usb: dwc3: gadget: Correct the logic for queuing sgs") Signed-off-by: Thinh Nguyen Link: https://lore.kernel.org/r/d07a7c4aa0fcf746cdca0515150dbe5c52000af7.1731545781.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/gadget.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1188,8 +1188,8 @@ static int dwc3_prepare_trbs_sg(struct d struct scatterlist *s; int i; unsigned int length = req->request.length; - unsigned int remaining = req->request.num_mapped_sgs - - req->num_queued_sgs; + unsigned int remaining = req->num_pending_sgs; + unsigned int num_queued_sgs = req->request.num_mapped_sgs - remaining; unsigned int num_trbs = req->num_trbs; bool needs_extra_trb = dwc3_needs_extra_trb(dep, req); @@ -1197,7 +1197,7 @@ static int dwc3_prepare_trbs_sg(struct d * If we resume preparing the request, then get the remaining length of * the request and resume where we left off. */ - for_each_sg(req->request.sg, s, req->num_queued_sgs, i) + for_each_sg(req->request.sg, s, num_queued_sgs, i) length -= sg_dma_len(s); for_each_sg(sg, s, remaining, i) {