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 A91332E7620; Thu, 3 Jul 2025 14:46:12 +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=1751553972; cv=none; b=nnDmrCkQFhCTaNe2EuTND01Nn6vg/5MUIkDFlM/57PwuvDijhFQGHfCyll/VcA36W+HuYuyehIZ2UZbPxyoeOwqFaWj+8cPSYZ9KtLyu9bk/MubS42USQ+mMtXC1vVzl0xEBPfzoaYiCaafioVQWgDKRw4zwFoYYJqjwJqnGkzc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751553972; c=relaxed/simple; bh=iEYhz7eWAI1MuWsBF6+PxSflazvDxYHW9rrCfhqQc00=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aZl/a9EjzZuP+gDQ/rTI831Wc+W9GK02e7KYOvZS72/oG6Zl8SvYh5BQfuP298dRjPBdmX07H/veAqDdd1VlYjz+ci9bw5xSe3nWR0nvWXIsbOUhQ9xApLjS+DWCLgWGB3NmCcc+tRZrkFArBVuMOaq2qFcSb8bB/XkywqJbjyo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=avAqMrgi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="avAqMrgi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3071CC4CEE3; Thu, 3 Jul 2025 14:46:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1751553972; bh=iEYhz7eWAI1MuWsBF6+PxSflazvDxYHW9rrCfhqQc00=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=avAqMrgiyAAm4tesE44YusL/5dA+jjvYYY+jf9uM9bnxvnG2Bl57x6q2pipo5Lv/f IB41/om1oMwhOtPGkSHjXceRW2hzg4Ugwaha1avqNceplxRZbxSHQPMIzImdpEajot LYhgTqdSROOwEjIplYwLRzTdUQYNd6jvqxueLHGw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chen Yufeng , Sasha Levin Subject: [PATCH 6.12 041/218] usb: potential integer overflow in usbg_make_tpg() Date: Thu, 3 Jul 2025 16:39:49 +0200 Message-ID: <20250703143957.585913756@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250703143955.956569535@linuxfoundation.org> References: <20250703143955.956569535@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chen Yufeng [ Upstream commit 153874010354d050f62f8ae25cbb960c17633dc5 ] The variable tpgt in usbg_make_tpg() is defined as unsigned long and is assigned to tpgt->tport_tpgt, which is defined as u16. This may cause an integer overflow when tpgt is greater than USHRT_MAX (65535). I haven't tried to trigger it myself, but it is possible to trigger it by calling usbg_make_tpg() with a large value for tpgt. I modified the type of tpgt to match tpgt->tport_tpgt and adjusted the relevant code accordingly. This patch is similar to commit 59c816c1f24d ("vhost/scsi: potential memory corruption"). Signed-off-by: Chen Yufeng Link: https://lore.kernel.org/r/20250415065857.1619-1-chenyufeng@iie.ac.cn Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/gadget/function/f_tcm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index 7b23631f47449..6ad205046032c 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -1297,14 +1297,14 @@ static struct se_portal_group *usbg_make_tpg(struct se_wwn *wwn, struct usbg_tport *tport = container_of(wwn, struct usbg_tport, tport_wwn); struct usbg_tpg *tpg; - unsigned long tpgt; + u16 tpgt; int ret; struct f_tcm_opts *opts; unsigned i; if (strstr(name, "tpgt_") != name) return ERR_PTR(-EINVAL); - if (kstrtoul(name + 5, 0, &tpgt) || tpgt > UINT_MAX) + if (kstrtou16(name + 5, 0, &tpgt)) return ERR_PTR(-EINVAL); ret = -ENODEV; mutex_lock(&tpg_instances_lock); -- 2.39.5