Skip to content

Commit 358d5ba

Browse files
Chen Yufenggregkh
authored andcommitted
usb: potential integer overflow in usbg_make_tpg()
[ Upstream commit 1538740 ] 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 59c816c ("vhost/scsi: potential memory corruption"). Signed-off-by: Chen Yufeng <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent a10c8bf commit 358d5ba

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/usb/gadget/function/f_tcm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,14 +1297,14 @@ static struct se_portal_group *usbg_make_tpg(struct se_wwn *wwn,
12971297
struct usbg_tport *tport = container_of(wwn, struct usbg_tport,
12981298
tport_wwn);
12991299
struct usbg_tpg *tpg;
1300-
unsigned long tpgt;
1300+
u16 tpgt;
13011301
int ret;
13021302
struct f_tcm_opts *opts;
13031303
unsigned i;
13041304

13051305
if (strstr(name, "tpgt_") != name)
13061306
return ERR_PTR(-EINVAL);
1307-
if (kstrtoul(name + 5, 0, &tpgt) || tpgt > UINT_MAX)
1307+
if (kstrtou16(name + 5, 0, &tpgt))
13081308
return ERR_PTR(-EINVAL);
13091309
ret = -ENODEV;
13101310
mutex_lock(&tpg_instances_lock);

0 commit comments

Comments
 (0)