|
|
6e84c26 |
From: Dan Carpenter <dan.carpenter@oracle.com>
|
|
|
6e84c26 |
Date: Thu, 5 Feb 2015 10:37:33 +0300
|
|
|
6e84c26 |
Subject: [PATCH] vhost/scsi: potential memory corruption
|
|
|
6e84c26 |
|
|
|
6e84c26 |
This code in vhost_scsi_make_tpg() is confusing because we limit "tpgt"
|
|
|
6e84c26 |
to UINT_MAX but the data type of "tpg->tport_tpgt" and that is a u16.
|
|
|
6e84c26 |
|
|
|
6e84c26 |
I looked at the context and it turns out that in
|
|
|
6e84c26 |
vhost_scsi_set_endpoint(), "tpg->tport_tpgt" is used as an offset into
|
|
|
6e84c26 |
the vs_tpg[] array which has VHOST_SCSI_MAX_TARGET (256) elements so
|
|
|
6e84c26 |
anything higher than 255 then it is invalid. I have made that the limit
|
|
|
6e84c26 |
now.
|
|
|
6e84c26 |
|
|
|
6e84c26 |
In vhost_scsi_send_evt() we mask away values higher than 255, but now
|
|
|
6e84c26 |
that the limit has changed, we don't need the mask.
|
|
|
6e84c26 |
|
|
|
6e84c26 |
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
|
|
|
6e84c26 |
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
|
|
|
6e84c26 |
---
|
|
|
6e84c26 |
drivers/vhost/scsi.c | 6 +++---
|
|
|
6e84c26 |
1 file changed, 3 insertions(+), 3 deletions(-)
|
|
|
6e84c26 |
|
|
|
6e84c26 |
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
|
|
|
6e84c26 |
index cb84f69f76ad..28cf2510d33b 100644
|
|
|
6e84c26 |
--- a/drivers/vhost/scsi.c
|
|
|
6e84c26 |
+++ b/drivers/vhost/scsi.c
|
|
|
6e84c26 |
@@ -1251,7 +1251,7 @@ tcm_vhost_send_evt(struct vhost_scsi *vs,
|
|
|
6e84c26 |
* lun[4-7] need to be zero according to virtio-scsi spec.
|
|
|
6e84c26 |
*/
|
|
|
6e84c26 |
evt->event.lun[0] = 0x01;
|
|
|
6e84c26 |
- evt->event.lun[1] = tpg->tport_tpgt & 0xFF;
|
|
|
6e84c26 |
+ evt->event.lun[1] = tpg->tport_tpgt;
|
|
|
6e84c26 |
if (lun->unpacked_lun >= 256)
|
|
|
6e84c26 |
evt->event.lun[2] = lun->unpacked_lun >> 8 | 0x40 ;
|
|
|
6e84c26 |
evt->event.lun[3] = lun->unpacked_lun & 0xFF;
|
|
|
6e84c26 |
@@ -2122,12 +2122,12 @@ tcm_vhost_make_tpg(struct se_wwn *wwn,
|
|
|
6e84c26 |
struct tcm_vhost_tport, tport_wwn);
|
|
|
6e84c26 |
|
|
|
6e84c26 |
struct tcm_vhost_tpg *tpg;
|
|
|
6e84c26 |
- unsigned long tpgt;
|
|
|
6e84c26 |
+ u16 tpgt;
|
|
|
6e84c26 |
int ret;
|
|
|
6e84c26 |
|
|
|
6e84c26 |
if (strstr(name, "tpgt_") != name)
|
|
|
6e84c26 |
return ERR_PTR(-EINVAL);
|
|
|
6e84c26 |
- if (kstrtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX)
|
|
|
6e84c26 |
+ if (kstrtou16(name + 5, 10, &tpgt) || tpgt > VHOST_SCSI_MAX_TARGET)
|
|
|
6e84c26 |
return ERR_PTR(-EINVAL);
|
|
|
6e84c26 |
|
|
|
6e84c26 |
tpg = kzalloc(sizeof(struct tcm_vhost_tpg), GFP_KERNEL);
|
|
|
6e84c26 |
--
|
|
|
6e84c26 |
2.1.0
|
|
|
6e84c26 |
|