From: Liu Chao <liuc63@xiaopeng.com>
To: gregkh@linuxfoundation.org
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, liuwb@xiaopeng.com,
Liu Chao <liuc63@xiaopeng.com>
Subject: [PATCH] usb: gadget: f_printer: fix list corruption in printer_soft_reset()
Date: Thu, 17 Sep 2026 16:16:16 +0800 [thread overview]
Message-ID: <20260917081616.174096-1-liuc63@xiaopeng.com> (raw)
printer_soft_reset() has three loops that drain different lists back to
rx_reqs / tx_reqs. The second loop's condition tests rx_reqs_active but
its body was copy-pasted from the first loop and still reads from
rx_buffers:
while (!list_empty(&dev->rx_reqs_active)) {
req = container_of(dev->rx_buffers.next, ...); /* BUG */
The first loop already empties rx_buffers, so by the time the second
loop runs, dev->rx_buffers.next points back to the list head itself.
Consequently:
- list_del_init() treats the list head as an entry and poisons it
- list_add() splices the rx_buffers head into rx_reqs
- rx_reqs_active is never drained, so the loop condition stays true
indefinitely
This results in linked-list corruption and a hang that is trivially
triggered by a USB host sending a SOFT_RESET class request.
Fix by reading from rx_reqs_active.next, matching the loop condition.
Fixes: 856c5e59aa0d ("usb: gadget: f_printer: copy Data Interface instead of using a singleton")
Cc: stable@vger.kernel.org
Reviewed-by: Weibin Liu <liuwb@xiaopeng.com>
Signed-off-by: Liu Chao <liuc63@xiaopeng.com>
---
drivers/usb/gadget/function/f_printer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c
index 1857d7861..2305733fe 100644
--- a/drivers/usb/gadget/function/f_printer.c
+++ b/drivers/usb/gadget/function/f_printer.c
@@ -940,7 +940,7 @@ static void printer_soft_reset(struct printer_dev *dev)
}
while (likely(!(list_empty(&dev->rx_reqs_active)))) {
- req = container_of(dev->rx_buffers.next, struct usb_request,
+ req = container_of(dev->rx_reqs_active.next, struct usb_request,
list);
list_del_init(&req->list);
list_add(&req->list, &dev->rx_reqs);
--
2.50.1
reply other threads:[~2026-09-17 8:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260917081616.174096-1-liuc63@xiaopeng.com \
--to=liuc63@xiaopeng.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=liuwb@xiaopeng.com \
--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
all inboxes | Powered by JetHome®