linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Guido Kiener <guido@kiener-muenchen.de>,
	Guido Kiener <guido.kiener@rohde-schwarz.com>,
	Felipe Balbi <felipe.balbi@linux.intel.com>,
	Sasha Levin <sashal@kernel.org>,
	linux-usb@vger.kernel.org
Subject: [PATCH AUTOSEL 4.4 04/21] usb: gadget: net2280: Fix overrun of OUT messages
Date: Mon, 22 Apr 2019 15:49:24 -0400	[thread overview]
Message-ID: <20190422194941.13433-4-sashal@kernel.org> (raw)
In-Reply-To: <20190422194941.13433-1-sashal@kernel.org>

From: Guido Kiener <guido@kiener-muenchen.de>

[ 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 <stern@rowland.harvard.edu>
Signed-off-by: Guido Kiener <guido.kiener@rohde-schwarz.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Sasha Levin (Microsoft) <sashal@kernel.org>
---
 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 8efeadf30b4d..fc94a09e2a5a 100644
--- a/drivers/usb/gadget/udc/net2280.c
+++ b/drivers/usb/gadget/udc/net2280.c
@@ -870,9 +870,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)
@@ -911,6 +908,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


  parent reply	other threads:[~2019-04-22 19:53 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-22 19:49 [PATCH AUTOSEL 4.4 01/21] qlcnic: Avoid potential NULL pointer dereference Sasha Levin
2019-04-22 19:49 ` [PATCH AUTOSEL 4.4 02/21] netfilter: bridge: set skb transport_header before entering NF_INET_PRE_ROUTING Sasha Levin
2019-04-22 19:49 ` [PATCH AUTOSEL 4.4 03/21] sc16is7xx: missing unregister/delete driver on error in sc16is7xx_init() Sasha Levin
2019-04-22 19:49 ` Sasha Levin [this message]
2019-04-22 19:49 ` [PATCH AUTOSEL 4.4 05/21] usb: gadget: net2280: Fix net2280_dequeue() Sasha Levin
2019-04-22 19:49 ` [PATCH AUTOSEL 4.4 06/21] usb: gadget: net2272: Fix net2272_dequeue() Sasha Levin
2019-04-22 19:49 ` [PATCH AUTOSEL 4.4 07/21] ARM: dts: pfla02: increase phy reset duration Sasha Levin
2019-04-22 19:49 ` [PATCH AUTOSEL 4.4 08/21] net: ks8851: Dequeue RX packets explicitly Sasha Levin
2019-04-22 19:49 ` [PATCH AUTOSEL 4.4 09/21] net: ks8851: Reassert reset pin if chip ID check fails Sasha Levin
2019-04-22 19:49 ` [PATCH AUTOSEL 4.4 10/21] net: ks8851: Delay requesting IRQ until opened Sasha Levin
2019-04-22 19:49 ` [PATCH AUTOSEL 4.4 11/21] net: ks8851: Set initial carrier state to down Sasha Levin
2019-04-22 19:49 ` [PATCH AUTOSEL 4.4 12/21] net: xilinx: fix possible object reference leak Sasha Levin
2019-04-22 19:49 ` [PATCH AUTOSEL 4.4 13/21] net: ibm: " Sasha Levin
2019-04-22 19:49 ` [PATCH AUTOSEL 4.4 14/21] net: ethernet: ti: " Sasha Levin
2019-04-22 19:49 ` [PATCH AUTOSEL 4.4 15/21] scsi: qla4xxx: fix a potential NULL pointer dereference Sasha Levin
2019-04-22 19:49 ` [PATCH AUTOSEL 4.4 16/21] usb: u132-hcd: fix resource leak Sasha Levin
2019-04-22 19:49 ` [PATCH AUTOSEL 4.4 17/21] tty: fix NULL pointer issue when tty_port ops is not set Sasha Levin
2019-04-22 19:49 ` [PATCH AUTOSEL 4.4 18/21] ceph: fix use-after-free on symlink traversal Sasha Levin
2019-04-22 19:49 ` [PATCH AUTOSEL 4.4 19/21] scsi: zfcp: reduce flood of fcrscn1 trace records on multi-element RSCN Sasha Levin
2019-04-22 19:49 ` [PATCH AUTOSEL 4.4 20/21] libata: fix using DMA buffers on stack Sasha Levin
2019-04-22 19:49 ` [PATCH AUTOSEL 4.4 21/21] kconfig/[mn]conf: handle backspace (^H) key Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190422194941.13433-4-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=felipe.balbi@linux.intel.com \
    --cc=guido.kiener@rohde-schwarz.com \
    --cc=guido@kiener-muenchen.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).