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 0C2B6202F70; Tue, 8 Jul 2025 16:56:21 +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=1751993781; cv=none; b=nnHTXppaIyVevLAs9HiEFiRPsPd4YNRnlH9ho9zyQSbo81c+sUqSnuuIrm/orluRK1GOT/nfjPKnAj767rEh/qUNlYzSS4g6zMnM7PF/ZcCoMmMKq2VL0xiin7G50R9bT4xLdzYsYjbBAkBOFKuHXp0I4i1nL5jQEk6n06sLv5M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751993781; c=relaxed/simple; bh=dEGKn04sl7WyPRSIk2F3GyRiLpOwqT1qa9pfnvqv8uE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K3eo/RbKZeA8ViiS1A0WvR5gnYwHkZHh1D9qEYOWsHKObujrFP1Q+ACG6uqSncvmzX6bBWp9v143JrnHvxA1AX7PcQZL8r+nnM02KpV08YMmcN4XqhXjQHE94Df0EaQ8kFxIYD6t0MZ8owFS2tWypE5T4MXOh8XIqdBTFDBWUyg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=usuZTLDu; 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="usuZTLDu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81B37C4CEED; Tue, 8 Jul 2025 16:56:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1751993780; bh=dEGKn04sl7WyPRSIk2F3GyRiLpOwqT1qa9pfnvqv8uE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=usuZTLDuQKUm0gIPOx0I4Obi2vNliToadUPNa47kKTYNHnA1+BG7cDTGkq/Y0dmWz dqxeNuZ8tcsnmK6HJep2t5y9wQot/NEqlcXCWaiMud2G2gsTbz47zkN9GrFSfChIIA 9HFx2aFiSHafUPjECnXZdZYKlZY5aa1Pk9GoztD4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chen Yufeng , Sasha Levin Subject: [PATCH 5.15 016/160] usb: potential integer overflow in usbg_make_tpg() Date: Tue, 8 Jul 2025 18:20:53 +0200 Message-ID: <20250708162231.955493210@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250708162231.503362020@linuxfoundation.org> References: <20250708162231.503362020@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 5.15-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 934e4b2a049ff..de54b0143894f 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -1321,14 +1321,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