Skip to contentSkip to conversation

firewire: sbp-target: fix integer type overflow in sbp_make_tpg()

PATCH Applied Kery Qi 2 participants 2 messages Jan 21 – Jan 24

Subsystems (3)
lore
Share & tools
lore

Kery Qi

author
#0 lore raw

PATCH 1/1 firewire: sbp-target: fix integer type overflow in sbp_make_tpg()

The code in sbp_make_tpg() limits "tpgt" to UINT_MAX but the data type of "tpg->tport_tpgt" is u16. This causes a type truncation issue.

When a user creates a TPG via configfs mkdir, for example:

    mkdir /sys/kernel/config/target/sbp/<wwn>/tpgt_70000

The value 70000 passes the "tpgt > UINT_MAX" check since 70000 is far less than 4294967295. However, when assigned to the u16 field tpg->tport_tpgt, the value is silently truncated to 4464 (70000 & 0xFFFF). This causes the value the user specified to differ from what is actually stored, leading to confusion and potential unexpected behavior.

Fix this by changing the type of "tpgt" to u16 and using kstrtou16() which will properly reject values outside the u16 range.

Fixes a511ce3397803 ("sbp-target: Initial merge of firewire/ieee-1394 target mode support")
---
 drivers/target/sbp/sbp_target.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/target/sbp/sbp_target.c +2 -2
index 9f167ff8da7b..09120a538a40 100644
@@ -1960,12 +1960,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
#1 lore raw
Quoted 8 lines · Kery Qi

The code in sbp_make_tpg() limits "tpgt" to UINT_MAX but the data type of "tpg->tport_tpgt" is u16. This causes a type truncation issue.

When a user creates a TPG via configfs mkdir, for example:

    mkdir /sys/kernel/config/target/sbp/<wwn>/tpgt_70000

[...]

Applied to 6.19/scsi-fixes, thanks!

[1/1] firewire: sbp-target: fix integer type overflow in sbp_make_tpg()

      https://git.kernel.org/mkp/scsi/c/b2d6b1d44300
Signature · 1 line
Martin K. Petersen