Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp435733yba; Wed, 15 May 2019 04:04:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2sohniGW0Pl/J8E+PFW8494cX75ulM/32pR9x0EQ/cCMy+ZwSeWY+0WYgIbZg20Km26sS X-Received: by 2002:a17:902:9042:: with SMTP id w2mr43143187plz.91.1557918275537; Wed, 15 May 2019 04:04:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557918275; cv=none; d=google.com; s=arc-20160816; b=iiRzk9skvzxMsLXYCeg/LOXZZnpAb6VG+Jls7hVxDqnCPw389DDA/jthyxEr/KYcfw x11VbQ6arC28EylhY5q/TmWZdzHj+qYvMsowNeLepSvsyGDcWmuvWfs5hh51lJcxjfbH LSwBW5XJt2YXlACyunq9dVb9m5lE94LKBKuYwt8ztEfIFM9VUmBv+BmnZzHqalOZbnMJ H4xpeepv1jHO/Ysy6I0z4161Y1sbRh8mFCQ4HOOzXwbkf4K/n3Cz5wjcdaU7QgkrtC03 G/2K+GfQ1soYGZbzXIhRe8/oMLvqNDYCPLl45XX1tTNBPiw+/D7R4mJUhxX0IUTuA89R /Bdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gMEtlwUlzEooUbjZ0fKcDDigFFuO4guJU0iYsEkMILc=; b=lBhywMb7TG7Ro5cHAcQHzIlCdtEnbCkLIDBuIZnYpZvQpTAYhWumW3PSBIxTSI0e4h CANVULvzh+ijZSEId5ALgYNLsmDVZ1Zx90KVf6afbTlXZy6ewtcfC2LJXCwMioepAibf jz/8XHMh8uK+jZIJkxgAuzuaS8/XzRjjSTbQjj9yPyzsLmhXVe2p2whWa8JrzN6XAzeY Q691Murkb0HdRM591o64o99seKC1wbdC/bFQ9aGl5WD2Ht2GvREEfZ1Y1uRfmJ81ko5+ zY29wH10uMBNBXAsOM9Z7Wngo8tdLwkVzM995PlAUsj7eCx9n09Y3//eXnFzzPkGnkD0 4hfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Q+6qT4if; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g14si1532010plm.192.2019.05.15.04.04.17; Wed, 15 May 2019 04:04:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Q+6qT4if; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727461AbfEOLAd (ORCPT + 99 others); Wed, 15 May 2019 07:00:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:57272 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727423AbfEOLA2 (ORCPT ); Wed, 15 May 2019 07:00:28 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C790F2173C; Wed, 15 May 2019 11:00:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557918027; bh=8h2+eYVUnwyN4zDs1fgarkI9kYsmPRaRdslM8QT/jos=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q+6qT4ifrae2jSw/+nlSqBmycaLP1NGKdaGRFZLS8zTxcmED0QvJxxrPaq3tcBI5D jZ07NnD8PilBP06xUbJb5Ocbs1F8+wEjgFCl46I7HYXTYxfRyp2P3Y1nsiNvVSdmW6 mFWydShBAs8lBMz75erA8jM0c8RfYtQibxYbh2z8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alan Stern , Guido Kiener , Felipe Balbi , "Sasha Levin (Microsoft)" Subject: [PATCH 3.18 15/86] usb: gadget: net2280: Fix overrun of OUT messages Date: Wed, 15 May 2019 12:54:52 +0200 Message-Id: <20190515090645.715262232@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090642.339346723@linuxfoundation.org> References: <20190515090642.339346723@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 9d6a54c1430647355a5e23434881b2ca3d192b48 ] The OUT endpoint normally blocks (NAK) subsequent packets when a short packet was received and returns an incomplete queue entry to the gadget driver. Thereby the gadget driver can detect a short packet when reading queue entries with a length that is not equal to a multiple of packet size. The start_queue() function enables receiving OUT packets regardless of the content of the OUT FIFO. This results in a race: With the current code, it's possible that the "!ep->is_in && (readl(&ep->regs->ep_stat) & BIT(NAK_OUT_PACKETS))" test in start_dma() will fail, then a short packet will be received, and then start_queue() will call stop_out_naking(). That's what we don't want (OUT naking gets turned off while there is data in the FIFO) because then the next driver request might receive a mixture of old and new packets. With the patch, this race can't occur because the FIFO's state is tested after we know that OUT naking is already turned on, and OUT naking is stopped only when both of the conditions are met. This ensures that all received data is delivered to the gadget driver, which can detect a short packet now before new packets are appended to the last short packet. Acked-by: Alan Stern Signed-off-by: Guido Kiener Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin (Microsoft) --- drivers/usb/gadget/udc/net2280.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c index 8d13337e2dde..931765208286 100644 --- a/drivers/usb/gadget/udc/net2280.c +++ b/drivers/usb/gadget/udc/net2280.c @@ -800,9 +800,6 @@ static void start_queue(struct net2280_ep *ep, u32 dmactl, u32 td_dma) (void) readl(&ep->dev->pci->pcimstctl); writel(BIT(DMA_START), &dma->dmastat); - - if (!ep->is_in) - stop_out_naking(ep); } static void start_dma(struct net2280_ep *ep, struct net2280_request *req) @@ -841,6 +838,7 @@ static void start_dma(struct net2280_ep *ep, struct net2280_request *req) writel(BIT(DMA_START), &dma->dmastat); return; } + stop_out_naking(ep); } tmp = dmactl_default; -- 2.19.1