Skip to contentSkip to conversation

aspeed-vhub: epn: fix an incorrect member check on list iterator

PATCH In review Xiaomeng Tong 2 participants 2 messages Mar 27, 2022 – Apr 22, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 aspeed-vhub: epn: fix an incorrect member check on list iterator

The bug is here:

	if (&req->req == u_req) {

The list iterator 'req' will point to a bogus position containing HEAD if the list is empty or no element is found. This case must be checked before any use of the iterator, otherwise it may bypass the 'if (&req->req == u_req) {' check in theory, if '*u_req' obj is just allocated in the same addr with '&req->req'.

To fix this bug, just mova all thing inside the loop and return 0, otherwise return error.

Cc stable at vger.kernel.org
Fixes 7ecca2a4080cb ("usb/gadget: Add driver for Aspeed SoC virtual hub")
---
 drivers/usb/gadget/udc/aspeed-vhub/epn.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
drivers/usb/gadget/udc/aspeed-vhub/epn.c +10 -13
index 917892ca8753..aae4ce3e1029 100644
@@ -468,27 +468,24 @@ static int ast_vhub_epn_dequeue(struct usb_ep* u_ep, struct usb_request *u_req)
 	struct ast_vhub *vhub = ep->vhub;
 	struct ast_vhub_req *req;
 	unsigned long flags;
-	int rc = -EINVAL;
 
 	spin_lock_irqsave(&vhub->lock, flags);
 
 	/* Make sure it's actually queued on this endpoint */
 	list_for_each_entry (req, &ep->queue, queue) {
-		if (&req->req == u_req)
-			break;
-	}
-
-	if (&req->req == u_req) {
-		EPVDBG(ep, "dequeue req @%p active=%d\n",
-		       req, req->active);
-		if (req->active)
-			ast_vhub_stop_active_req(ep, true);
-		ast_vhub_done(ep, req, -ECONNRESET);
-		rc = 0;
+		if (&req->req == u_req) {
+			EPVDBG(ep, "dequeue req @%p active=%d\n",
+				req, req->active);
+			if (req->active)
+				ast_vhub_stop_active_req(ep, true);
+			ast_vhub_done(ep, req, -ECONNRESET);
+			spin_unlock_irqrestore(&vhub->lock, flags);
+			return 0;
+		}
 	}
 
 	spin_unlock_irqrestore(&vhub->lock, flags);
-	return rc;
+	return -EINVAL;
 }
 
 void ast_vhub_update_epn_stall(struct ast_vhub_ep *ep)
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 12 lines · Xiaomeng Tong

The bug is here:

	if (&req->req == u_req) {

The list iterator 'req' will point to a bogus position containing HEAD if the list is empty or no element is found. This case must be checked before any use of the iterator, otherwise it may bypass the 'if (&req->req == u_req) {' check in theory, if '*u_req' obj is just allocated in the same addr with '&req->req'.

To fix this bug, just mova all thing inside the loop and return 0, otherwise return error.

Quoted 6 lines
Cc stable at vger.kernel.org
Fixes 7ecca2a4080cb ("usb/gadget: Add driver for Aspeed SoC virtual hub")
---
 drivers/usb/gadget/udc/aspeed-vhub/epn.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

Does not apply anymore :(