Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 59c816c

Browse files
Dan CarpenterNicholas Bellinger
authored andcommitted
vhost/scsi: potential memory corruption
This code in vhost_scsi_make_tpg() is confusing because we limit "tpgt" to UINT_MAX but the data type of "tpg->tport_tpgt" and that is a u16. I looked at the context and it turns out that in vhost_scsi_set_endpoint(), "tpg->tport_tpgt" is used as an offset into the vs_tpg[] array which has VHOST_SCSI_MAX_TARGET (256) elements so anything higher than 255 then it is invalid. I have made that the limit now. In vhost_scsi_send_evt() we mask away values higher than 255, but now that the limit has changed, we don't need the mask. Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Nicholas Bellinger <[email protected]>
1 parent 1a1ff82 commit 59c816c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/vhost/scsi.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ vhost_scsi_send_evt(struct vhost_scsi *vs,
12491249
* lun[4-7] need to be zero according to virtio-scsi spec.
12501250
*/
12511251
evt->event.lun[0] = 0x01;
1252-
evt->event.lun[1] = tpg->tport_tpgt & 0xFF;
1252+
evt->event.lun[1] = tpg->tport_tpgt;
12531253
if (lun->unpacked_lun >= 256)
12541254
evt->event.lun[2] = lun->unpacked_lun >> 8 | 0x40 ;
12551255
evt->event.lun[3] = lun->unpacked_lun & 0xFF;
@@ -2120,12 +2120,12 @@ vhost_scsi_make_tpg(struct se_wwn *wwn,
21202120
struct vhost_scsi_tport, tport_wwn);
21212121

21222122
struct vhost_scsi_tpg *tpg;
2123-
unsigned long tpgt;
2123+
u16 tpgt;
21242124
int ret;
21252125

21262126
if (strstr(name, "tpgt_") != name)
21272127
return ERR_PTR(-EINVAL);
2128-
if (kstrtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX)
2128+
if (kstrtou16(name + 5, 10, &tpgt) || tpgt >= VHOST_SCSI_MAX_TARGET)
21292129
return ERR_PTR(-EINVAL);
21302130

21312131
tpg = kzalloc(sizeof(struct vhost_scsi_tpg), GFP_KERNEL);

0 commit comments

Comments
 (0)