* [PATCH] target: sbp: integer overflow and potential memory corruption
@ 2024-01-18 3:19 Fullway Wang
2024-02-05 22:02 ` Martin K. Petersen
0 siblings, 1 reply; 2+ messages in thread
From: Fullway Wang @ 2024-01-18 3:19 UTC (permalink / raw)
To: bootc, martin.petersen
Cc: linux-scsi, target-devel, linux-kernel, fullwaywang, Fullway Wang
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(-)
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)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] target: sbp: integer overflow and potential memory corruption
2024-01-18 3:19 [PATCH] target: sbp: integer overflow and potential memory corruption Fullway Wang
@ 2024-02-05 22:02 ` Martin K. Petersen
0 siblings, 0 replies; 2+ messages in thread
From: Martin K. Petersen @ 2024-02-05 22:02 UTC (permalink / raw)
To: Fullway Wang
Cc: bootc, martin.petersen, linux-scsi, target-devel, linux-kernel,
fullwaywang
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?
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-05 22:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-18 3:19 [PATCH] target: sbp: integer overflow and potential memory corruption Fullway Wang
2024-02-05 22:02 ` Martin K. Petersen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).