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 3AE2F355F2C for ; Mon, 16 Mar 2026 20:17:22 +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=1773692242; cv=none; b=C5MJGPPYgRq1CG6k/dR9DVLSA4euh++NbuMm4qzSjVL4zY4UD8c4gUrDYyaanOSWMlwOajYWXMXpDeRjSMVFKxiokGlDBvkebQWetJ/4ghGSAhZe3NiYyI7jUwB0qJPMyhBRJ5q9UeoF/WJPG/jXbJlWL1TMK6TEp3TOFxeeioQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773692242; c=relaxed/simple; bh=blvrolMKNdBvLh9N1XgDf1YHQV+vPsJq6c54kJkV0P0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jvkVZBwD5yhVoHKj+53bwUWIOL8w2NWISp0Y3J2Kpi6AGviC6xsZn02ulTSbi+ZiOPsmSFApvBmrncFCZSN146JzSo80Lm3xiPkK6npkt3u5m1BePJlmrmmX+g2fc6gg5ZgBQPdSjQeLsA+JEI2TVn/Bf8z8KSvcb88EFEDlDcY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VPV2hO1S; 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="VPV2hO1S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A6EAC19421; Mon, 16 Mar 2026 20:17:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773692241; bh=blvrolMKNdBvLh9N1XgDf1YHQV+vPsJq6c54kJkV0P0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VPV2hO1Sc+bzHYlHForiVLw+ZRQk9TNV5fZZTc+m8+v10fNYGxnNdfvQrPSKlLcDh CzGLKoA5y5s7Ia2ssY3deWvyFQOM4ktfp1Zgwc0E8TdMbxUGzE9Hd7CDcDq6HnmTzn z9Rk7Z2htJREiJw1HYT+x79ZmnuWguCDk9y1tpxw4XIyQlg+q26nhIXwa/lzulTq7e NRnkp8EV+bBQNtc5Vdkb+xKpJg1TPRhq8EAR2NWWDRehdogSG39MU3K4pBaurvkj9t NbV4Ii+/+2RKbu9R0cF/S+WtsKSvJZEI4qKBeo5fQJRMFo6RZYB/+qWTY4w07Oe2iw T8enewBBGlpNQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Jiasheng Jiang , stable , Thinh Nguyen , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH 6.6.y] usb: gadget: f_tcm: Fix NULL pointer dereferences in nexus handling Date: Mon, 16 Mar 2026 16:17:19 -0400 Message-ID: <20260316201719.1375493-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2026031608-staining-monitor-6c94@gregkh> References: <2026031608-staining-monitor-6c94@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 5d0d894953953..3811b7abaf589 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) { __target_init_cmd(se_cmd, @@ -1160,6 +1167,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) { __target_init_cmd(se_cmd, -- 2.51.0