mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ziheng Wei <zihengw03@163.com>
To: Neill Kapron <nkapron@google.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] usb: gadget: m66592-udc: recheck ep->queue after reacquiring lock
Date: Mon, 30 Nov 2026 18:34:37 +0800	[thread overview]
Message-ID: <20261130103438.1384118-1-zihengw03@163.com> (raw)

In transfer_complete(), restart is computed from !list_empty(&ep->queue)
before dropping ep->m66592->lock for usb_gadget_giveback_request(). While
unlocked, the completion callback or a concurrent m66592_dequeue() can
empty ep->queue while ep->ep.desc remains set, causing list_entry() to
pass a bogus pointer to start_packet() once the lock is reacquired.

Recheck !list_empty(&ep->queue) after reacquiring ep->m66592->lock.

Found by LLM-assisted static analysis and runtime-tested in QEMU+KASAN
(null-ptr-deref Oops in start_packet() before the fix; 0 findings after).

Signed-off-by: Ziheng Wei <zihengw03@163.com>
---
 drivers/usb/gadget/udc/m66592-udc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/m66592-udc.c b/drivers/usb/gadget/udc/m66592-udc.c
index d77c11c4e..97cca8442 100644
--- a/drivers/usb/gadget/udc/m66592-udc.c
+++ b/drivers/usb/gadget/udc/m66592-udc.c
@@ -729,7 +729,7 @@ __acquires(m66592->lock)
 	usb_gadget_giveback_request(&ep->ep, &req->req);
 	spin_lock(&ep->m66592->lock);
 
-	if (restart) {
+	if (restart && !list_empty(&ep->queue)) {
 		req = list_entry(ep->queue.next, struct m66592_request, queue);
 		if (ep->ep.desc)
 			start_packet(ep, req);

base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
-- 
2.43.0


             reply	other threads:[~2026-11-30 10:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 10:34 Ziheng Wei [this message]
2026-11-30 10:34 ` [PATCH 2/2] usb: gadget: r8a66597-udc: " Ziheng Wei

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=20261130103438.1384118-1-zihengw03@163.com \
    --to=zihengw03@163.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=nkapron@google.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

all inboxes | Powered by JetHome®