Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2624334pxj; Mon, 31 May 2021 06:50:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFmmDccmTi0RylRFW2rki99mQBHO3y9wCmg7NvSPSUmHmXO6YSuag+cZufEvZZ3m6qWbNg X-Received: by 2002:a6b:e70e:: with SMTP id b14mr1414759ioh.65.1622469012445; Mon, 31 May 2021 06:50:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622469012; cv=none; d=google.com; s=arc-20160816; b=XyhINuq10fFfNEu6zCw/kOQh40uczzDySI3yYADODa59mzXQnQmlGvcyk6lSSHWgQ2 dc87XzyOFqhX5dD5VIaI034RNA9NKVhy0m5IK0Sy83qYr6j8Wi1xV+0th1cEG5Gjy/+n Nu0a7hLPt0ohnRAxu5CMQVkda0zJxIUcVqDsclotP92N52Bd4C+Py0W80wzwRok27AWq JUtGStc1W6gRgtlgTK0ETCp0JBazUAWU7KcoLWlQJSdza1+2jjJFGb+rhQVmBQ0zh3Pw NVLUNQr52OPnHKxw7WZuX/7TEpCowJDAVPjbCJqhddvufr5xCzT5dCdWGymdMz+XZkqK Ej9w== 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=qIZnrwZejlRbvGH3LyVPHUaNM2eWqnyn0VUkNQIjxWM=; b=Xbwm4wTluEcDBproW1E68hsGHdcRyeuMi03KnB0uxtjIIYhjmn1DvPm5WJ7mfpH/Ff lkhob/D+GMiBxZJ2LqqPmarIkZ7OFyF0Oo0Rr3FB2lCS/bjERID/ak8cSh7o4dlhuuSv OlmEFp2a/Omzyl+VkRx7ntb9aEVRoOIRBJegsRMc246r3VdLeD+cA/5zzStZFZ98qqUr RI0mOMjga0q6JSZq0LhrU9KC68U0qNjHaGLXsFIN5u+66qiAWN0UliHBMv1AtggMkczH 1zRHYjAjza/hwMWtoHXslQInLVR6Re8LqM447ilERFdKcVYDZcM5QJCafh1OUeK6RVF5 SADg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xuC5pqSi; 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 t2si10522586ilo.160.2021.05.31.06.49.58; Mon, 31 May 2021 06:50:12 -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=xuC5pqSi; 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 S233243AbhEaNu0 (ORCPT + 99 others); Mon, 31 May 2021 09:50:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:38982 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232615AbhEaNdQ (ORCPT ); Mon, 31 May 2021 09:33:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9B968613F7; Mon, 31 May 2021 13:24:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622467459; bh=KivrGtHjjpCRgtwd3ANpv4ErgRp103yVUBU09k8GwXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xuC5pqSimiqwIlea+Ne+ziPvvFMGU639DpXA5MrM3ddDPLWgBXAIMayAAnIa3lp5j EbxKfvkIbNE91b7hirMkyfyu2PJ0/03li/wGxCBJGufULKmUNVS5kdUkmBzgV9taqq Iv3crjMjjkhglF+JzpCo/NaQjFsqYfcKEP2G5HV4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH 4.19 038/116] usb: gadget: udc: renesas_usb3: Fix a race in usb3_start_pipen() Date: Mon, 31 May 2021 15:13:34 +0200 Message-Id: <20210531130641.457537410@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130640.131924542@linuxfoundation.org> References: <20210531130640.131924542@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 @@ -1466,7 +1466,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; @@ -1474,7 +1474,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)