From: Albert Wang <albertccwang@google.com>
To: balbi@kernel.org, gregkh@linuxfoundation.org, quic_jackp@quicinc.com
Cc: badhri@google.com, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org,
Albert Wang <albertccwang@google.com>
Subject: [PATCH v3] usb: dwc3: gadget: Move null pinter check after window closed
Date: Fri, 13 May 2022 14:57:09 +0800 [thread overview]
Message-ID: <20220513065709.1606634-1-albertccwang@google.com> (raw)
After inspecting further, we do see the locking is implicit, with the
main gotcha being the unlock/re-lock. That creates a window for a race
to happen. This change moves the NULL check to be adjacent to where
to it's used and after the window is "closed".
Fixes: 26288448120b ("usb: dwc3: gadget: Fix null pointer exception")
Signed-off-by: Albert Wang <albertccwang@google.com>
---
v3: Add change log to be compliant with the canonical patch format
v2: Remove redundant 'else' and add additional comments and more
descriptive commit text
drivers/usb/dwc3/gadget.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 19477f4bbf54..fda58951cf27 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -3366,14 +3366,19 @@ static bool dwc3_gadget_endpoint_trbs_complete(struct dwc3_ep *dep,
struct dwc3 *dwc = dep->dwc;
bool no_started_trb = true;
- if (!dep->endpoint.desc)
- return no_started_trb;
-
+ /*
+ * This function eventually leads to dwc3_giveback() which unlocks
+ * the dwc->lock and relocks afterwards. This actually creates a
+ * a window for a race to happen.
+ */
dwc3_gadget_ep_cleanup_completed_requests(dep, event, status);
if (dep->flags & DWC3_EP_END_TRANSFER_PENDING)
goto out;
+ if (!dep->endpoint.desc)
+ return no_started_trb;
+
if (usb_endpoint_xfer_isoc(dep->endpoint.desc) &&
list_empty(&dep->started_list) &&
(list_empty(&dep->pending_list) || status == -EXDEV))
--
2.36.0.550.gb090851708-goog
next reply other threads:[~2022-05-13 6:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-13 6:57 Albert Wang [this message]
2022-05-13 7:12 ` [PATCH v3] usb: dwc3: gadget: Move null pinter check after window closed Greg KH
2022-05-13 17:16 ` 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=20220513065709.1606634-1-albertccwang@google.com \
--to=albertccwang@google.com \
--cc=badhri@google.com \
--cc=balbi@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=quic_jackp@quicinc.com \
/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).