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 2/2] usb: gadget: r8a66597-udc: recheck ep->queue after reacquiring lock
Date: Mon, 30 Nov 2026 18:34:38 +0800	[thread overview]
Message-ID: <20261130103438.1384118-2-zihengw03@163.com> (raw)
In-Reply-To: <20261130103438.1384118-1-zihengw03@163.com>

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

Recheck !list_empty(&ep->queue) after reacquiring ep->r8a66597->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/r8a66597-udc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/r8a66597-udc.c b/drivers/usb/gadget/udc/r8a66597-udc.c
index 469075b06..9e65a5dd9 100644
--- a/drivers/usb/gadget/udc/r8a66597-udc.c
+++ b/drivers/usb/gadget/udc/r8a66597-udc.c
@@ -925,7 +925,7 @@ __acquires(r8a66597->lock)
 	usb_gadget_giveback_request(&ep->ep, &req->req);
 	spin_lock(&ep->r8a66597->lock);
 
-	if (restart) {
+	if (restart && !list_empty(&ep->queue)) {
 		req = get_request_from_ep(ep);
 		if (ep->ep.desc)
 			start_packet(ep, req);
-- 
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 [PATCH 1/2] usb: gadget: m66592-udc: " Ziheng Wei
2026-11-30 10:34 ` Ziheng Wei [this message]

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-2-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®