From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F008835B65A for ; Mon, 16 Mar 2026 21:23:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773696208; cv=none; b=ZjDsxP280nPkQ2tYjYYrb6BPmkNwniCIIG36hQhN8KBjsBWzr30SdgtH2ynx7h1SNcS0kUX0p8GHz/wmGTTPncfrByneBCyvEDFiBtlIYp4rAwq/IiusttEUAzU4E3rdHBMOgQREcQKyuhixNjoQeTUhBGx0MKyD3/5qOoFQg0A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773696208; c=relaxed/simple; bh=3roEeyufw9Fbby9m1ppuyujqpSzhttMLa6Bw2qQDHqw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=szJIKsf+WStl13MLWHKplEP3KrcmIn6tvM3rMyxOE/X/wWrl+FVipX2MjwKmWBRBMptJuY6D81JqfgOCG9c6cEWzsdbibcPMfjbhdGiO+3cR0Sd6OlMz7Ul4TTeh1LDLPErBS6ky0K0O4L8+JZjveEcqUDm5fFN/fN1b3CnjtiU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DCq1EMBe; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DCq1EMBe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6CECC19421; Mon, 16 Mar 2026 21:23:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773696207; bh=3roEeyufw9Fbby9m1ppuyujqpSzhttMLa6Bw2qQDHqw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DCq1EMBeJH/e5P4BgfmQIewJWD8rzHikRS31xYFaybLx6EKuPoEBDX0DYmGPXKwJe ImLsGkPyZj053G1F5LaiABYPEkHU5c1Zsm8PO3po+u+8eh+VnSntf4Vs8dDhmz/vEu qfERbrPLhDGGRtOwY7X/nLcRNGchUF/S+dac8gDntbuGAhQtAxvEPjyhDGIiSaAqXi MvCqsDFmljaaBWk6HkzRo72XPzN0gXiyc5vdH2k2OmmfATvFO2xJ3NnoBn8b4iqwIG 8KPq0SljiMmkTVxYr72DwmPQimL8yCUSsHQ8gmdiLeaoTRf4uOGnr+oDX925IY//2Q Qy6/njVBxKrGQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Jiasheng Jiang , stable , Thinh Nguyen , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH 5.10.y] usb: gadget: f_tcm: Fix NULL pointer dereferences in nexus handling Date: Mon, 16 Mar 2026 17:23:25 -0400 Message-ID: <20260316212325.1415578-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2026031610-unlearned-sturdy-3047@gregkh> References: <2026031610-unlearned-sturdy-3047@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Jiasheng Jiang [ Upstream commit b9fde507355342a2d64225d582dc8b98ff5ecb19 ] The `tpg->tpg_nexus` pointer in the USB Target driver is dynamically managed and tied to userspace configuration via ConfigFS. It can be NULL if the USB host sends requests before the nexus is fully established or immediately after it is dropped. Currently, functions like `bot_submit_command()` and the data transfer paths retrieve `tv_nexus = tpg->tpg_nexus` and immediately dereference `tv_nexus->tvn_se_sess` without any validation. If a malicious or misconfigured USB host sends a BOT (Bulk-Only Transport) command during this race window, it triggers a NULL pointer dereference, leading to a kernel panic (local DoS). This exposes an inconsistent API usage within the module, as peer functions like `usbg_submit_command()` and `bot_send_bad_response()` correctly implement a NULL check for `tv_nexus` before proceeding. Fix this by bringing consistency to the nexus handling. Add the missing `if (!tv_nexus)` checks to the vulnerable BOT command and request processing paths, aborting the command gracefully with an error instead of crashing the system. Fixes: c52661d60f63 ("usb-gadget: Initial merge of target module for UASP + BOT") Cc: stable Signed-off-by: Jiasheng Jiang Reviewed-by: Thinh Nguyen Link: https://patch.msgid.link/20260219023834.17976-1-jiashengjiangcool@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/gadget/function/f_tcm.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index 30c3a44abb183..cbab39a5e7537 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -1032,6 +1032,13 @@ static void usbg_cmd_work(struct work_struct *work) se_cmd = &cmd->se_cmd; tpg = cmd->fu->tpg; tv_nexus = tpg->tpg_nexus; + if (!tv_nexus) { + struct usb_gadget *gadget = fuas_to_gadget(cmd->fu); + + dev_err(&gadget->dev, "Missing nexus, ignoring command\n"); + return; + } + dir = get_cmd_dir(cmd->cmd_buf); if (dir < 0) { transport_init_se_cmd(se_cmd, @@ -1162,6 +1169,13 @@ static void bot_cmd_work(struct work_struct *work) se_cmd = &cmd->se_cmd; tpg = cmd->fu->tpg; tv_nexus = tpg->tpg_nexus; + if (!tv_nexus) { + struct usb_gadget *gadget = fuas_to_gadget(cmd->fu); + + dev_err(&gadget->dev, "Missing nexus, ignoring command\n"); + return; + } + dir = get_cmd_dir(cmd->cmd_buf); if (dir < 0) { transport_init_se_cmd(se_cmd, -- 2.51.0