Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2734722pxj; Mon, 31 May 2021 09:24:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcM7UCSHnLdc4Yq9fT4yL0KG5yu8jJUU8birj7KGeu+BJMDq2fdNwOPijF9Hy/1u+oK/Rt X-Received: by 2002:a5e:9907:: with SMTP id t7mr17569385ioj.155.1622478239998; Mon, 31 May 2021 09:23:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622478239; cv=none; d=google.com; s=arc-20160816; b=k9ySHTiEBq1/zjLDUvEYduYLLQqFHipimkGXLVlwyceBZUO9OWWk52f0mCQY+6IlKf jvWM4+cUZqa9iwB/P1H8yLY/5X0RfLlpi777z+WA+hdePIdMa969//0LJ58rWs/YweLD /BUnpmIug4novYi9H7L8PWltLNNOJ4V4WXF4vXBBYtllLj7AId6iZKDmVsYvgr8Wip0d kI431otqFkKyvUcLuuuWEmU7K2eGkbSJRSBvuuQCPexSAb6oo1Lr0x0s6Fn4PpLntAob eJ4Jb60OaliVy+B+xSgUqer5xajpdkRucQL8TmOiommARn+NF2E7scoUfaRU9tQtsa5t HV6A== 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=V68Py5Uou2SO3HrTRnis1tjzHkvvpbUZ0zgCTmV8Bpk=; b=l2+guZg/5EFQK3bQTvn0NwzxZ7GgjmiAAx6eNeOnj//Vk8ucW5xjapeazmSlP4qMu2 9b286NAbYWkLSuPHKA1b/jXj/Mq8Hs1+KbfFrOJEGyMYdQlaIi5v8DjsED69ZlSue5Ru cqf2tjQ/p15vWBvC6aP1sy3ibxwP6+V3IV94fpXzcXcd6DqafhcVu+uyl1814mmLgPox Gi/MARHWM1yP2a8YOnuRwlPIwO0kk4JhFYI37WzR2FSEX8kxbZGCBKhU20jdpkXRFMCE tT/z2fCv9J3BB+PJ8iskVPHpfrD/8qnEOZ4GfLi+6qA1GUQqeJtW9DkiYOlW3tbfBF+j Jonw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RPchp5er; 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 y10si14129756jaf.62.2021.05.31.09.23.46; Mon, 31 May 2021 09:23:59 -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=RPchp5er; 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 S234591AbhEaQYC (ORCPT + 99 others); Mon, 31 May 2021 12:24:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:37860 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233178AbhEaOlX (ORCPT ); Mon, 31 May 2021 10:41:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1ED3E61435; Mon, 31 May 2021 13:53:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469190; bh=IGnyTuQjYOOw4G6t0SNltBrM51l310tTmm7+guOXb0o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RPchp5ercswbNHupRAZwfxSlWRzVKpGvlTrjpYN6b59xnLRw4+XLZ3uvLLh6PScRT sLJS2EmFvkZyNRc08Syo7tP5fIj/U+OCXNPrHnPwp4TiPCbjN+SC/P8Afqf1b8IC5r sMaNbMKADvMEnGx5QM+K1QBbnH1XPftLyYGbv4wo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH 5.12 104/296] usb: gadget: udc: renesas_usb3: Fix a race in usb3_start_pipen() Date: Mon, 31 May 2021 15:12:39 +0200 Message-Id: <20210531130707.430694783@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@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 @@ -1488,7 +1488,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; @@ -1496,7 +1496,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)