diff mbox series

target: sbp: integer overflow and potential memory corruption

Message ID PH7PR20MB59258C767EF853A54273B3A7BF712@PH7PR20MB5925.namprd20.prod.outlook.com (mailing list archive)
State New, archived
Headers show
Series target: sbp: integer overflow and potential memory corruption | expand

Commit Message

Fullway Wang Jan. 18, 2024, 3:19 a.m. UTC
The code in sbp_make_tpg() is confusing because tpgt was limited
to UINT_MAX but the datatype of tpg->tport_tpgt is actually u16.
Correctly fix the data type problem to avoid integer overflow.

This is similar to CVE-2015-4036 in the sense that sbp is a clone
of vhost/scsi, and the bug was inherited but never fixed.

Signed-off-by: Fullway Wang <fullwaywang@outlook.com>
---
 drivers/target/sbp/sbp_target.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Martin K. Petersen Feb. 5, 2024, 10:02 p.m. UTC | #1
Fullway,

> The code in sbp_make_tpg() is confusing because tpgt was limited
> to UINT_MAX but the datatype of tpg->tport_tpgt is actually u16.
> Correctly fix the data type problem to avoid integer overflow.
>
> This is similar to CVE-2015-4036 in the sense that sbp is a clone
> of vhost/scsi, and the bug was inherited but never fixed.

> +#define SBP_MAX_TARGET	256

Why 256?
diff mbox series

Patch

diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
index b604fcae21e1..1ba742ee48b0 100644
--- a/drivers/target/sbp/sbp_target.c
+++ b/drivers/target/sbp/sbp_target.c
@@ -43,6 +43,7 @@  static const u32 sbp_unit_directory_template[] = {
 };
 
 #define SESSION_MAINTENANCE_INTERVAL HZ
+#define SBP_MAX_TARGET	256
 
 static atomic_t login_id = ATOMIC_INIT(0);
 
@@ -1961,12 +1962,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) || tpgt >= SBP_MAX_TARGET)
 		return ERR_PTR(-EINVAL);
 
 	if (tport->tpg) {