Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2702102pxj; Mon, 31 May 2021 08:36:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGpFOWLo2olm/iX1aL/ZWyK3pgdUODwLDiSpM+tBlp0HLtfHrH0DZexqrrxiWooAsEveDI X-Received: by 2002:a17:907:988a:: with SMTP id ja10mr741254ejc.527.1622475387987; Mon, 31 May 2021 08:36:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622475387; cv=none; d=google.com; s=arc-20160816; b=Uau6+i1IjsVl1tUnNUX5UvG1o7ex0qGaFEE6++H9ZGUJLdL1OBOgokqC0ghRzRvpA2 wdbDR9+CA58U6SGjh1XhsHhFmehyREkAsaJh+S1S5a1tFQ7YQVc77HWI/SxV4oEMXrPB pV2cgCUfRaz5Mfni0pLsl0SBOC/fx9Odrah/ZeD1StnWNiEjxZ4hIJDcowVgub4mX2J4 ydVqzuffbXdvDCB8kPGK8zwavS1Zkcsm9rmhqDe7MzAPC6zy6zUHE4y1ezK/W/F8nNSQ aO+10mOLnkNjPeWzmjMX9H3M27F8AtZr0jEIMNDhwt2jIsNKrFt/ub5Fe3AJKuPWQ1TN rnmw== 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=F3lsz2wn+CLzjlp5QUgJ5khyhEVaB5yMrH8ar4Zc06Y=; b=Ft8ngzpgDSfoVU2UagYfsaeY76NW+76NLxi0Eoq+evwojG9h0CkbhEHbSGo09pBMno 1+IH92ikIUcogk2TYk1jxpBdy0QZ9hk3Hrx/g6w4nYlaWX1EXMbqQqf79fxG8saya/ni +WRkT3cMS4UyZkuRX5+uHVaY3Zq4H4P5bcn+0xRlBmgKWEBXNzoNo2vDNWRbBDL9dMYW hLtK/s8ulxN5ELXtHrI+GeuLNm/Fyfar+kbt0lR2H0NYb5juIxhaWQzwK7F0+y4N7oxf sfMurRXzgeLf00xZArqBFcA+Ehc3IBW7viq6UFoOHohP1EXPrirzN3n70QARhpCVD0vs 0vCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tlA3YTjU; 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 k3si13890264eds.334.2021.05.31.08.36.05; Mon, 31 May 2021 08:36:27 -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=tlA3YTjU; 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 S233086AbhEaPeo (ORCPT + 99 others); Mon, 31 May 2021 11:34:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:43304 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233083AbhEaORj (ORCPT ); Mon, 31 May 2021 10:17:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 08190619A8; Mon, 31 May 2021 13:43:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468621; bh=jiGlot0zVWrzzRPERQIkJbnbZREjL7ezFimv9H6oI/o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tlA3YTjUeSEF/1Y0S6JAq8uKxGtYrjI5V8T2wZvInNaYP40AxBgRFGHQRVqU2hTyc SLaPC0sMIswglbhpbXcK9kyB/tPXLzNf5v+53GpjLCfuYCXxvMBm9s78fKM+AU7t+r Qk0J0Oe0BRwrh/ApUyC2qEHbuXSHGn7ke0QDIqRY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH 5.4 062/177] usb: gadget: udc: renesas_usb3: Fix a race in usb3_start_pipen() Date: Mon, 31 May 2021 15:13:39 +0200 Message-Id: <20210531130650.046938260@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130647.887605866@linuxfoundation.org> References: <20210531130647.887605866@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: Yoshihiro Shimoda commit e752dbc59e1241b13b8c4f7b6eb582862e7668fe upstream. The usb3_start_pipen() is called by renesas_usb3_ep_queue() and usb3_request_done_pipen() so that usb3_start_pipen() is possible to cause a race when getting usb3_first_req like below: renesas_usb3_ep_queue() spin_lock_irqsave() list_add_tail() spin_unlock_irqrestore() usb3_start_pipen() usb3_first_req = usb3_get_request() --- [1] --- interrupt --- usb3_irq_dma_int() usb3_request_done_pipen() usb3_get_request() usb3_start_pipen() usb3_first_req = usb3_get_request() ... (the req is possible to be finished in the interrupt) The usb3_first_req [1] above may have been finished after the interrupt ended so that this driver caused to start a transfer wrongly. To fix this issue, getting/checking the usb3_first_req are under spin_lock_irqsave() in the same section. Fixes: 746bfe63bba3 ("usb: gadget: renesas_usb3: add support for Renesas USB3.0 peripheral controller") Cc: stable Signed-off-by: Yoshihiro Shimoda Link: https://lore.kernel.org/r/20210524060155.1178724-1-yoshihiro.shimoda.uh@renesas.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/udc/renesas_usb3.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/usb/gadget/udc/renesas_usb3.c +++ b/drivers/usb/gadget/udc/renesas_usb3.c @@ -1473,7 +1473,7 @@ static void usb3_start_pipen(struct rene struct renesas_usb3_request *usb3_req) { struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep); - struct renesas_usb3_request *usb3_req_first = usb3_get_request(usb3_ep); + struct renesas_usb3_request *usb3_req_first; unsigned long flags; int ret = -EAGAIN; u32 enable_bits = 0; @@ -1481,7 +1481,8 @@ static void usb3_start_pipen(struct rene spin_lock_irqsave(&usb3->lock, flags); if (usb3_ep->halt || usb3_ep->started) goto out; - if (usb3_req != usb3_req_first) + usb3_req_first = __usb3_get_request(usb3_ep); + if (!usb3_req_first || usb3_req != usb3_req_first) goto out; if (usb3_pn_change(usb3, usb3_ep->num) < 0)