sbp: potential integer overflow in sbp_make_tpg()
Subsystems (3)
PATCH 1/1 sbp: potential integer overflow in sbp_make_tpg()
The variable tpgt in sbp_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 sbp_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").
--- drivers/target/sbp/sbp_target.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/target/sbp/sbp_target.c +2 -2
@@ -1961,12 +1961,12 @@ static struct se_portal_group *sbp_make_tpg(struct se_wwn *wwn, container_of(wwn, struct sbp_tport, tport_wwn);struct sbp_tpg *tpg; -unsigned long tpgt; +u16 tpgt;int ret;if (strstr (name,"tpgt_" ) != name)return ERR_PTR (-EINVAL ); -if (kstrtoul (name +5 ,10 , &tpgt) || tpgt >UINT_MAX ) +if (kstrtou16 (name +5 ,10 , &tpgt))return ERR_PTR (-EINVAL );if (tport->tpg) {
Signature · 1 line
2.34.1
Martin K. Petersen
AppliedQuoted 10 lines · ReBeating
The variable tpgt in
sbp_make_tpg()is defined as unsigned long and is assigned totpgt->tport_tpgt, which is defined as u16. This may cause an integer overflow when tpgt is greater thanUSHRT_MAX(65535). I haven't tried to trigger it myself, but it is possible to trigger it by callingsbp_make_tpg()with a large value for tpgt.I modified the type of tpgt to match
tpgt->tport_tpgtand adjusted the relevant code accordingly.[...]
Applied to 6.20/scsi-queue, thanks!
[1/1] sbp: potential integer overflow in sbp_make_tpg()
https://git.kernel.org/mkp/scsi/c/8e8e8e7e8406
Signature · 1 line
Martin K. Petersen