From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Guangshuo Li <lgs201920130244@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiasheng Jiang <jiashengjiangcool@gmail.com>,
Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
Mike Christie <michael.christie@oracle.com>,
Kees Cook <kees@kernel.org>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] usb: gadget: f_tcm: fix remaining nexus NULL dereferences
Date: Sat, 27 Jun 2026 00:31:59 +0000 [thread overview]
Message-ID: <aj8YyBVR90FGSki2@vbox> (raw)
In-Reply-To: <20260604123929.1427579-1-lgs201920130244@gmail.com>
On Thu, Jun 04, 2026, Guangshuo Li wrote:
> The previous nexus NULL-dereference fix added checks to the normal
> command submission paths, but two UASP paths still dereference
> tpg->tpg_nexus without checking it first.
>
> A TASK MANAGEMENT request reaches usbg_submit_tmr(), which fetches
> tvn_se_sess directly from tpg->tpg_nexus. The RC_OVERLAPPED_TAG path in
> usbg_cmd_work() does the same before walking sess_cmd_map for the active
> command with the same tag.
>
> If userspace drops the nexus after the command is queued, these paths can
> observe a NULL tpg_nexus and crash before they can ignore the command like
> the already-fixed command paths do.
>
> Check tpg_nexus in both remaining paths and use the checked local nexus
> before dereferencing tvn_se_sess.
>
> Fixes: b9fde5073553 ("usb: gadget: f_tcm: Fix NULL pointer dereferences in nexus handling")
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
> drivers/usb/gadget/function/f_tcm.c | 22 ++++++++++++++++++++--
> 1 file changed, 20 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c
> index 34d9f49e9987..1717fdd1c466 100644
> --- a/drivers/usb/gadget/function/f_tcm.c
> +++ b/drivers/usb/gadget/function/f_tcm.c
> @@ -1188,12 +1188,21 @@ static void usbg_aborted_task(struct se_cmd *se_cmd);
>
> static void usbg_submit_tmr(struct usbg_cmd *cmd)
> {
> + struct tcm_usbg_nexus *tv_nexus;
> struct se_session *se_sess;
> struct se_cmd *se_cmd;
> int flags = TARGET_SCF_ACK_KREF;
>
> se_cmd = &cmd->se_cmd;
> - se_sess = cmd->fu->tpg->tpg_nexus->tvn_se_sess;
> + tv_nexus = cmd->fu->tpg->tpg_nexus;
> + if (!tv_nexus) {
> + struct usb_gadget *gadget = fuas_to_gadget(cmd->fu);
> +
> + dev_err(&gadget->dev, "Missing nexus for TMR, ignoring command\n");
This is called after usbg_get_cmd(). We need to cleanup the
sbitmap_queue and the hash (sbitmap_queue_clear and hash_del) before
returning.
> + return;
> + }
> +
> + se_sess = tv_nexus->tvn_se_sess;
>
> target_submit_tmr(se_cmd, se_sess,
> cmd->response_iu.add_response_info,
> @@ -1271,12 +1280,21 @@ static void usbg_cmd_work(struct work_struct *work)
> skip:
> if (cmd->tmr_rsp == RC_OVERLAPPED_TAG) {
> struct f_uas *fu = cmd->fu;
> + struct tcm_usbg_nexus *tv_nexus;
> struct se_session *se_sess;
> struct uas_stream *stream = NULL;
> struct hlist_node *tmp;
> struct usbg_cmd *active_cmd = NULL;
>
> - se_sess = cmd->fu->tpg->tpg_nexus->tvn_se_sess;
> + tv_nexus = fu->tpg->tpg_nexus;
> + if (!tv_nexus) {
Same here. Also check for other if (!tv_nexus) checks.
Maybe we need a helper function to do this cleanup?
Thanks,
Thinh
> + struct usb_gadget *gadget = fuas_to_gadget(fu);
> +
> + dev_err(&gadget->dev, "Missing nexus for overlapped tag, ignoring command\n");
> + return;
> + }
> +
> + se_sess = tv_nexus->tvn_se_sess;
>
> hash_for_each_possible_safe(fu->stream_hash, stream, tmp, node, cmd->tag) {
> int i = stream - &fu->stream[0];
> --
> 2.43.0
>
prev parent reply other threads:[~2026-06-27 0:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 12:39 [PATCH] usb: gadget: f_tcm: fix remaining nexus NULL dereferences Guangshuo Li
2026-06-27 0:31 ` Thinh Nguyen [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=aj8YyBVR90FGSki2@vbox \
--to=thinh.nguyen@synopsys.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=gregkh@linuxfoundation.org \
--cc=jiashengjiangcool@gmail.com \
--cc=kees@kernel.org \
--cc=lgs201920130244@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=michael.christie@oracle.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 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.