Skip to content

Commit b2d6b1d

Browse files
Keryermartinkpetersen
authored andcommitted
scsi: firewire: sbp-target: Fix 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: a511ce3 ("sbp-target: Initial merge of firewire/ieee-1394 target mode support") Signed-off-by: Kery Qi <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 4747baf commit b2d6b1d

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/target/sbp/sbp_target.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,12 +1960,12 @@ static struct se_portal_group *sbp_make_tpg(struct se_wwn *wwn,
19601960
container_of(wwn, struct sbp_tport, tport_wwn);
19611961

19621962
struct sbp_tpg *tpg;
1963-
unsigned long tpgt;
1963+
u16 tpgt;
19641964
int ret;
19651965

19661966
if (strstr(name, "tpgt_") != name)
19671967
return ERR_PTR(-EINVAL);
1968-
if (kstrtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX)
1968+
if (kstrtou16(name + 5, 10, &tpgt))
19691969
return ERR_PTR(-EINVAL);
19701970

19711971
if (tport->tpg) {

0 commit comments

Comments
 (0)