[PATCH] target: sbp: integer overflow and potential memory corruption

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx>
---
 drivers/target/sbp/sbp_target.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

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) {
-- 
2.39.3 (Apple Git-145)





[Index of Archives]     [Linux SCSI]     [Kernel Newbies]     [Linux SCSI Target Infrastructure]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Device Mapper]

  Powered by Linux