Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3396885pxf; Mon, 22 Mar 2021 05:37:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyN5fy+wRdJSXxZhBxaXzHPBLdPK5cTqTEY06bUPSPyXtOSQjkqstK1p0N+1neyB0JYLWLW X-Received: by 2002:a17:906:70d:: with SMTP id y13mr18683019ejb.170.1616416630059; Mon, 22 Mar 2021 05:37:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616416630; cv=none; d=google.com; s=arc-20160816; b=eZPhyZ7yzs/8L3n4qOGXv/mNVHlqIhoMkvAEe9JZAlysi1vC9U65e0eivZQ8T1gQks CcgVGCUGB2/VFXAF/xgHxGaM2UU9MmUwIYEoYvSbK3iVRL/Jq93vIuh9cP0zycGIKagu oc5/qCkUx8vI9vcfMj16lIsy/EAR+rRuE6uVemiLzie2/xe/NPHKq/4v+fObIduRtFJz Jc6Bv685ymoPZKyNxCTLm3e0Ewl1qUTJa6cvUaTnyNo9l2VCO6i/TcnS+cQbhMmmkTnB D2T5p/GDXCn053zgBxVs0RMqYx9PI5jitWZdgF1cLoFeleNuIquoU2aCxYBtm4b1un35 W7kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=d+Fbs5NkHDh03KkBsZ+iE6ix1AetpgVf5RNeuHbhBS0=; b=SD/SeGe0dpas7NfvyG2jUYxE6PXZDrYSpMB1Kg7+q8lbxZ1pEX7j3Pw32hex38vIh4 bdjdP+1rgM4xfrHbf2yS6c6ltwio2tEa+iIK05YyeTbEZauvclSXpojgbEEiYbN61ODs sZdxHOwqWkb27GoTmG8wUHY7n7YIvEohrd+ZV4EnmcEhtCOwGz/hM4CFwF8QDZHpJ5dv 531G5vtVEGdESve94S3T39F2N8wo7UsjtN4QQWVNjBgbH87WM5h3zRgtEf3Ne3iidXIM 5ewbX9Z/CZi2RDbDw14nKDK/qp43ZcA+gPaGV+9K41E2S2gQ20tyPWOZu2c+n5pIGott qfmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GEq87SSR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x11si11125195edd.260.2021.03.22.05.36.47; Mon, 22 Mar 2021 05:37:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GEq87SSR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231229AbhCVMfx (ORCPT + 99 others); Mon, 22 Mar 2021 08:35:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:55660 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230525AbhCVMc5 (ORCPT ); Mon, 22 Mar 2021 08:32:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D84BF619A6; Mon, 22 Mar 2021 12:32:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1616416377; bh=EFDnB3WoNVk9gyb2gRnm2fXLjPkIU6fjClEcWeY1Y+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GEq87SSRhSqnOTJ7exfzN6+wYmYR6T1YCy1XXoXNIrc/yTdl8EDvYOkFTQQAOUcEQ XCXP28uecoImc4udBcKSth8MRyKQxVnBI9Y1ivX4NgJ+Q9pxXCdobsjUqdDQFhSbXZ rLr4MTU9TG04N8eI0jxlz6plUpNmn4VFpDORwuUY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wesley Cheng Subject: [PATCH 5.11 084/120] usb: dwc3: gadget: Prevent EP queuing while stopping transfers Date: Mon, 22 Mar 2021 13:27:47 +0100 Message-Id: <20210322121932.478878424@linuxfoundation.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210322121929.669628946@linuxfoundation.org> References: <20210322121929.669628946@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wesley Cheng commit f09ddcfcb8c569675066337adac2ac205113471f upstream. In the situations where the DWC3 gadget stops active transfers, once calling the dwc3_gadget_giveback(), there is a chance where a function driver can queue a new USB request in between the time where the dwc3 lock has been released and re-aquired. This occurs after we've already issued an ENDXFER command. When the stop active transfers continues to remove USB requests from all dep lists, the newly added request will also be removed, while controller still has an active TRB for it. This can lead to the controller accessing an unmapped memory address. Fix this by ensuring parameters to prevent EP queuing are set before calling the stop active transfers API. Fixes: ae7e86108b12 ("usb: dwc3: Stop active transfers before halting the controller") Signed-off-by: Wesley Cheng Link: https://lore.kernel.org/r/1615507142-23097-1-git-send-email-wcheng@codeaurora.org Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/gadget.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -783,8 +783,6 @@ static int __dwc3_gadget_ep_disable(stru trace_dwc3_gadget_ep_disable(dep); - dwc3_remove_requests(dwc, dep); - /* make sure HW endpoint isn't stalled */ if (dep->flags & DWC3_EP_STALL) __dwc3_gadget_ep_set_halt(dep, 0, false); @@ -803,6 +801,8 @@ static int __dwc3_gadget_ep_disable(stru dep->endpoint.desc = NULL; } + dwc3_remove_requests(dwc, dep); + return 0; } @@ -1617,7 +1617,7 @@ static int __dwc3_gadget_ep_queue(struct { struct dwc3 *dwc = dep->dwc; - if (!dep->endpoint.desc || !dwc->pullups_connected) { + if (!dep->endpoint.desc || !dwc->pullups_connected || !dwc->connected) { dev_err(dwc->dev, "%s: can't queue to disabled endpoint\n", dep->name); return -ESHUTDOWN; @@ -2150,6 +2150,7 @@ static int dwc3_gadget_pullup(struct usb if (!is_on) { u32 count; + dwc->connected = false; /* * In the Synopsis DesignWare Cores USB3 Databook Rev. 3.30a * Section 4.1.8 Table 4-7, it states that for a device-initiated @@ -2174,7 +2175,6 @@ static int dwc3_gadget_pullup(struct usb dwc->ev_buf->lpos = (dwc->ev_buf->lpos + count) % dwc->ev_buf->length; } - dwc->connected = false; } else { __dwc3_gadget_start(dwc); } @@ -3267,8 +3267,6 @@ static void dwc3_gadget_reset_interrupt( { u32 reg; - dwc->connected = true; - /* * WORKAROUND: DWC3 revisions <1.88a have an issue which * would cause a missing Disconnect Event if there's a @@ -3308,6 +3306,7 @@ static void dwc3_gadget_reset_interrupt( * transfers." */ dwc3_stop_active_transfers(dwc); + dwc->connected = true; reg = dwc3_readl(dwc->regs, DWC3_DCTL); reg &= ~DWC3_DCTL_TSTCTRL_MASK;