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 72A052EF9DB; Thu, 3 Jul 2025 15:12:05 +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=1751555525; cv=none; b=ERSj7M2bcININnXWTywJs5lyEwTZ7PNOxICsvzCeGynzT08D69skadZSVHvEq6HJU7PLh318N7gA6QXVDWHl2t3rAnNPP8JaMgYVpXzZKfvk79Agl/14GScmQSt+VcW4+VUISZUH02cOpyx8mY/Gv+oEiupT1f14tCJWZPBwMkA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751555525; c=relaxed/simple; bh=Bf6sAakgD0KzudoacidBezUDFCLQrkAqPvq/UaFgceI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hw9SWM6Me1ZkqOaUGFjs3pZaXZbbnk+KuLmdpclTkCQe69s659goKvWvhZ5NvduPGFFVruN+5HWmrAQzhsdIJhetTs33YVjblyZfFubLYcIjR59eGhyDvF/aqU83cWwmDqn8ntsmjOBYZwqUYoe1ZHKCd9Pn5o1dpKx1P0VTLgo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=bw3J0W1/; 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="bw3J0W1/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0C62C4CEE3; Thu, 3 Jul 2025 15:12:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1751555525; bh=Bf6sAakgD0KzudoacidBezUDFCLQrkAqPvq/UaFgceI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bw3J0W1/8a2SEGavudyGQCFlv3e4QXZSTPL/X9NZkQKPggNetzS9rTR454O/7QP/P 0ExPFmN1rkroOLycee2yB8Jj4vmvL2J44vw/PQNaTAuUxMdavBcsd5JQtzWs+8hk4U IWyDDZSipCQAh+UtIQUwp7ZXAsIBIoNACiFLTPfg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chen Yufeng , Sasha Levin Subject: [PATCH 6.6 033/139] usb: potential integer overflow in usbg_make_tpg() Date: Thu, 3 Jul 2025 16:41:36 +0200 Message-ID: <20250703143942.480111560@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250703143941.182414597@linuxfoundation.org> References: <20250703143941.182414597@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-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 a7cd0a06879e6..5d0d894953953 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