* [PATCH] usb: gadget: f_tcm: put the overlapped command's request back on ep_cmd
@ 2026-11-19 14:06 Yehyeong Lee
2026-11-19 14:21 ` sashiko-bot
0 siblings, 1 reply; 5+ messages in thread
From: Yehyeong Lee @ 2026-11-19 14:06 UTC (permalink / raw)
To: gregkh, nkapron, linux-usb
Cc: Thinh.Nguyen, bigeasy, target-devel, linux-kernel,
lgs201920130244
When usbg_cmd_work() confirms an overlapped command tag it returns the
duplicate command's slot to the session tag pool and cancels the active
command's transfer, but it never hands the duplicate's own request back to
ep_cmd. The two sanity exits just above it pass that request to
usbg_submit_command(), and the status path gives the active command's
request back once its response has been sent, so only this path drops one.
The request is not leaked - it stays in fu->cmd[] until uasp_free_cmdreq()
frees it - but it stops being posted, so the gadget can receive one COMMAND
IU fewer for the rest of the alternate setting. There are USBG_NUM_CMDS of
them, and a host spends one by sending two COMMAND IUs with the same tag,
so the command endpoint ends up with nothing posted and no command is
received at all. There is no memory error to catch here, so count the
posted requests instead: on a dummy_hcd gadget in UAS mode the count falls
by one per overlap and reaches 0 after 32, and the gadget then answers none
of four following commands, while with this patch 33 overlaps leave the
count at 33 and all four are answered. Three fresh boots per arm.
Take the request pointer before the slot goes back to the pool, because
from then on it can belong to a new command, and queue it after the abort
so that nothing else in the path moves. A queue that fails leaves the
request in fu->cmd[] for uasp_free_cmdreq(), as at the other two sites that
post to ep_cmd after setup.
Fixes: 29ed17053872 ("usb: gadget: f_tcm: Check overlapped command")
Cc: stable@vger.kernel.org
Signed-off-by: Yehyeong Lee <yhlee@isslab.korea.ac.kr>
---
drivers/usb/gadget/function/f_tcm.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c
index 9e6d4f39900a27..4dcf2ba0083848 100644
--- a/drivers/usb/gadget/function/f_tcm.c
+++ b/drivers/usb/gadget/function/f_tcm.c
@@ -1275,6 +1275,7 @@ static void usbg_cmd_work(struct work_struct *work)
struct uas_stream *stream = NULL;
struct hlist_node *tmp;
struct usbg_cmd *active_cmd = NULL;
+ struct usb_request *req;
se_sess = cmd->fu->tpg->tpg_nexus->tvn_se_sess;
@@ -1318,6 +1319,12 @@ static void usbg_cmd_work(struct work_struct *work)
return;
}
+ /*
+ * Take the request before the slot goes back to the pool; it
+ * is queued on ep_cmd below.
+ */
+ req = cmd->req;
+
/*
* The command isn't submitted to the target core, so we're safe
* to remove the bitmap index from the session tag pool.
@@ -1333,6 +1340,8 @@ static void usbg_cmd_work(struct work_struct *work)
active_cmd->tmr_rsp = RC_OVERLAPPED_TAG;
usbg_aborted_task(&active_cmd->se_cmd);
+ usb_ep_queue(fu->ep_cmd, req, GFP_ATOMIC);
+
/* Send the response after the transfer is aborted. */
return;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] usb: gadget: f_tcm: put the overlapped command's request back on ep_cmd
2026-11-19 14:06 [PATCH] usb: gadget: f_tcm: put the overlapped command's request back on ep_cmd Yehyeong Lee
@ 2026-11-19 14:21 ` sashiko-bot
2026-11-20 11:41 ` Yehyeong Lee
2026-11-20 15:01 ` Yehyeong Lee
0 siblings, 2 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-19 14:21 UTC (permalink / raw)
To: Yehyeong Lee, linux-usb; +Cc: target-devel
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] usb: gadget: f_tcm: NULL pointer dereference in
usbg_aborted_task() [1]
--
commit 8fc2b5f7f30651e73e59207af565a062eb0d398b
Author: Yehyeong Lee <yhlee@isslab.korea.ac.kr>
usb: gadget: f_tcm: put the overlapped command's request back on ep_cmd
This commit requeues the USB request of a duplicate overlapped command on
ep_cmd before returning its tag slot to the session tag pool in
usbg_cmd_work().
> diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c
> index 9e6d4f39900a2..4dcf2ba008384 100644
> --- a/drivers/usb/gadget/function/f_tcm.c
> +++ b/drivers/usb/gadget/function/f_tcm.c
[ ... ]
> @@ -1333,6 +1340,8 @@ static void usbg_cmd_work(struct work_struct *work)
> active_cmd->tmr_rsp = RC_OVERLAPPED_TAG;
> usbg_aborted_task(&active_cmd->se_cmd);
>
> + usb_ep_queue(fu->ep_cmd, req, GFP_ATOMIC);
[Severity: Critical]
This problem wasn't introduced by this patch, but can usbg_aborted_task()
dereference a NULL stream->req_out pointer in Bulk-Only Transport (BOT)
mode [1]?
The target core also registers usbg_aborted_task() as the .aborted_task
callback and invokes it on task abort sequences such as a LUN reset.
Because stream requests are only allocated for UAS mode, stream->req_out
remains NULL in BOT mode:
drivers/usb/gadget/function/f_tcm.c:usbg_aborted_task() {
...
struct uas_stream *stream = &fu->stream[se_cmd->map_tag];
int ret = 0;
if (stream->req_out->status == -EINPROGRESS)
ret = usb_ep_dequeue(fu->ep_out, stream->req_out);
...
}
Aborting a task in BOT mode therefore causes a NULL pointer dereference and
kernel panic.
[1] https://sashiko.dev/#/bug/linux-02bb90fe-74db-45ad-a2cf-107fe1a41bc4
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119140641.2768465-1-yhlee@isslab.korea.ac.kr?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] usb: gadget: f_tcm: put the overlapped command's request back on ep_cmd
2026-11-19 14:21 ` sashiko-bot
@ 2026-11-20 11:41 ` Yehyeong Lee
2026-11-20 13:43 ` Greg KH
2026-11-20 15:01 ` Yehyeong Lee
1 sibling, 1 reply; 5+ messages in thread
From: Yehyeong Lee @ 2026-11-20 11:41 UTC (permalink / raw)
To: gregkh, nkapron, linux-usb
Cc: Thinh.Nguyen, bigeasy, target-devel, sashiko-reviews,
linux-kernel, lgs201920130244
Right, this is a real bug, but it needs a non-default setup. With
emulate_tas at its default of 1 the core sends TASK ABORTED instead of
calling .aborted_task(), and a BOT session can't send a TMF itself. So
it takes a LUN RESET from a second fabric sharing the backstore, with
emulate_tas set to 0. It's an Oops in the target_completion worker, not
a panic.
Fixed in a separate patch:
https://lore.kernel.org/all/20261120113956.3071640-1-yhlee@isslab.korea.ac.kr/
Best regards,
Yehyeong Lee
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] usb: gadget: f_tcm: put the overlapped command's request back on ep_cmd
2026-11-20 11:41 ` Yehyeong Lee
@ 2026-11-20 13:43 ` Greg KH
0 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2026-11-20 13:43 UTC (permalink / raw)
To: Yehyeong Lee
Cc: nkapron, linux-usb, Thinh.Nguyen, bigeasy, target-devel,
sashiko-reviews, linux-kernel, lgs201920130244
On Fri, Nov 20, 2026 at 08:41:08PM +0900, Yehyeong Lee wrote:
> Right, this is a real bug, but it needs a non-default setup. With
> emulate_tas at its default of 1 the core sends TASK ABORTED instead of
> calling .aborted_task(), and a BOT session can't send a TMF itself. So
> it takes a LUN RESET from a second fabric sharing the backstore, with
> emulate_tas set to 0. It's an Oops in the target_completion worker, not
> a panic.
>
> Fixed in a separate patch:
> https://lore.kernel.org/all/20261120113956.3071640-1-yhlee@isslab.korea.ac.kr/
I see no context.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] usb: gadget: f_tcm: put the overlapped command's request back on ep_cmd
2026-11-19 14:21 ` sashiko-bot
2026-11-20 11:41 ` Yehyeong Lee
@ 2026-11-20 15:01 ` Yehyeong Lee
1 sibling, 0 replies; 5+ messages in thread
From: Yehyeong Lee @ 2026-11-20 15:01 UTC (permalink / raw)
To: gregkh, nkapron, linux-usb
Cc: Thinh.Nguyen, bigeasy, target-devel, sashiko-reviews,
linux-kernel, lgs201920130244
On Thu, Nov 19, 2026 at 02:21:37PM +0000, sashiko-bot@kernel.org wrote:
> [Severity: Critical]
> This problem wasn't introduced by this patch, but can usbg_aborted_task()
> dereference a NULL stream->req_out pointer in Bulk-Only Transport (BOT)
> mode [1]?
>
> Aborting a task in BOT mode therefore causes a NULL pointer dereference and
> kernel panic.
Right, this is a real bug, but it needs a non-default setup. With
emulate_tas at its default of 1 the core sends TASK ABORTED instead of
calling .aborted_task(), and a BOT session can't send a TMF itself. So
it takes a LUN RESET from a second fabric sharing the backstore, with
emulate_tas set to 0. It's an Oops in the target_completion worker, not
a panic.
Fixed in a separate patch:
https://lore.kernel.org/all/20261120113956.3071640-1-yhlee@isslab.korea.ac.kr/
Best regards,
Yehyeong Lee
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-20 15:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 14:06 [PATCH] usb: gadget: f_tcm: put the overlapped command's request back on ep_cmd Yehyeong Lee
2026-11-19 14:21 ` sashiko-bot
2026-11-20 11:41 ` Yehyeong Lee
2026-11-20 13:43 ` Greg KH
2026-11-20 15:01 ` Yehyeong Lee
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.