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 BAE6B30BF4F for ; Mon, 16 Mar 2026 20:58:38 +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=1773694718; cv=none; b=VFOojJuzMXjNa5gLwsm9NuRU6HM2jUxmY7JMcY6GuuLVR4yyyGPB0fBQSTSCHumOaQ5A3OeWOB0mm0/4ITndd1vnFSlqlcbngkid6XcCw0TNrVGNwmJw7QE7aaHEp1xmU2gW+G+o0H+ZsI2S2u6U694iIvc83j8DIJi6Ol2Vzl8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773694718; c=relaxed/simple; bh=E6J7cXtEMUkamxOag035WAzI+lByzB9w+aydx8xqTNk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S55f+q87bLOp545UVcalx4HIB9Y5XK+cCGLp/L/7jE4GNs10iTKP02OCeeLVUUBGVUr3FJ6uRk5yhR4cKxRn1cteYUCNuruI0fVh4c595SmD7uafrYFWh2x1OAkeR0NeU0DnZLThOcy9JJQppEqljy/vmLrZFWfATJtJqddAkTM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qnhyS7i1; 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="qnhyS7i1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5B0BC19421; Mon, 16 Mar 2026 20:58:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773694718; bh=E6J7cXtEMUkamxOag035WAzI+lByzB9w+aydx8xqTNk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qnhyS7i1IVCsb7Sy59gif2OuwaMNMAcGXtg8ynQQWWaoFdQa0jNUe83tKWPs+fUo8 qj82M5zReBeTi5cDT8Fxj1N6RywOyB1GyfYqDCLD2ooxDBr9kSriWfQvT7iPWgBymg 4OTW5UptYb/pZsmXEQ73Hu7/XQyDmOEYZS9puFJMc3hF8gV+EbW4fbOlUb+PWAXv6S OUtcjmN3IL/ninufvfl8TS70oXkyHl3ZmGx3Xp0zV/+4rlXN/IybwSd2jkDZyvLzSg Mlj8bOtr2ODotI6sv0uqmO2qWfIsbzXqu339TypBYEDjr2c3p0AU9lcYUgc9zY472F OFVlZUy43o0Yw== From: Sasha Levin To: stable@vger.kernel.org Cc: Jiasheng Jiang , stable , Thinh Nguyen , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH 5.15.y] usb: gadget: f_tcm: Fix NULL pointer dereferences in nexus handling Date: Mon, 16 Mar 2026 16:58:36 -0400 Message-ID: <20260316205836.1406156-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2026031609-supper-smitten-f64e@gregkh> References: <2026031609-supper-smitten-f64e@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 de54b0143894f..8ccac2ff60397 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