Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Jack Pham <jackp@codeaurora.org>
To: Felipe Balbi <balbi@kernel.org>
Cc: linux-usb@vger.kernel.org, Mayank Rana <mrana@codeaurora.org>,
	stable@vger.kernel.org, Jack Pham <jackp@codeaurora.org>
Subject: [PATCH] usb: dwc3: gadget: Fix list_del corruption in dwc3_ep_dequeue
Date: Fri, 23 Mar 2018 10:05:33 -0700	[thread overview]
Message-ID: <20180323170533.26927-1-jackp@codeaurora.org> (raw)

From: Mayank Rana <mrana@codeaurora.org>

dwc3_ep_dequeue() waits for completion of End Transfer command
using wait_event_lock_irq(), which will release the dwc3->lock
while waiting and reacquire after completion. This allows a
potential race condition with ep_disable() which also removes
all requests from started_list and pending_list. The check for
NULL r->trb should catch this but currently it exits to the
wrong 'out1' label which calls dwc3_gadget_giveback(). Since
its list entry was already removed, if CONFIG_DEBUG_LIST is
enabled a 'list_del corruption' bug is thrown since its
next/prev pointers are already LIST_POISON1/2. If r->trb is
NULL it should simply exit to 'out0'.

Fixes: cf3113d893d4 ("usb: dwc3: gadget: properly increment dequeue pointer on ep_dequeue")
Cc: stable@vger.kernel.org
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
Signed-off-by: Jack Pham <jackp@codeaurora.org>
---
 drivers/usb/dwc3/gadget.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 2bda4eb..1238a97 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1417,7 +1417,7 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep,
 					dwc->lock);
 
 			if (!r->trb)
-				goto out1;
+				goto out0;
 
 			if (r->num_pending_sgs) {
 				struct dwc3_trb *trb;
-- 
2.9.1.200.gb1ec08f

             reply	other threads:[~2018-03-23 17:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-23 17:05 Jack Pham [this message]
2018-03-23 17:23 ` [PATCH] usb: dwc3: gadget: Fix list_del corruption in dwc3_ep_dequeue Jack Pham

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=20180323170533.26927-1-jackp@codeaurora.org \
    --to=jackp@codeaurora.org \
    --cc=balbi@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mrana@codeaurora.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