Skip to contentSkip to conversation

block/iscsi: avoid potential overflow of acb->task->cdb

PATCH In review Peter Lieven 3 participants 6 messages May 24, 2016 – May 31, 2016 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block/iscsi: avoid potential overflow of acb->task->cdb

at least in the path via virtio-blk the maximum size is not restricted.

---
 block/iscsi.c | 7 +++++++
 1 file changed, 7 insertions(+)
block/iscsi.c +7 -0
index 2ca8e72..e7d5f7b 100644
@@ -833,6 +833,13 @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
         return &acb->common;
     }
 
+    if (acb->ioh->cmd_len > SCSI_CDB_MAX_SIZE) {
+        error_report("iSCSI: ioctl error CDB exceeds max size (%d > %d)",
+                     acb->ioh->cmd_len, SCSI_CDB_MAX_SIZE);
+        qemu_aio_unref(acb);
+        return NULL;
+    }
+
     acb->task = malloc(sizeof(struct scsi_task));
     if (acb->task == NULL) {
         error_report("iSCSI: Failed to allocate task for scsi command. %s",
Signature · 1 line
1.9.1
#1 lore raw
Quoted 17 lines · Peter Lieven

at least in the path via virtio-blk the maximum size is not restricted.

---
 block/iscsi.c | 7 +++++++
 1 file changed, 7 insertions(+)
block/iscsi.c +0 -0
index 2ca8e72..e7d5f7b 100644
@@ -833,6 +833,13 @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
         return &acb->common;
     }
 

block/iscsi.c static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs, · line 845

Quoted 10 lines
block/iscsi.c +7 -0
+    if (acb->ioh->cmd_len > SCSI_CDB_MAX_SIZE) {
+        error_report("iSCSI: ioctl error CDB exceeds max size (%d > %d)",
+                     acb->ioh->cmd_len, SCSI_CDB_MAX_SIZE);
+        qemu_aio_unref(acb);
+        return NULL;
+    }
+
     acb->task = malloc(sizeof(struct scsi_task));
     if (acb->task == NULL) {
         error_report("iSCSI: Failed to allocate task for scsi command. %s",

Is it better to invoke the cb and report -EINVAL to the caller?

Fam

#2 lore raw

Am 31.05.2016 um 08:44 hat Fam Zheng geschrieben:

Quoted 18 lines · Peter Lieven
Quoted 17 lines

at least in the path via virtio-blk the maximum size is not restricted.

---
 block/iscsi.c | 7 +++++++
 1 file changed, 7 insertions(+)
block/iscsi.c +0 -0
index 2ca8e72..e7d5f7b 100644
@@ -833,6 +833,13 @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
         return &acb->common;
     }
 
Quoted 12 lines

block/iscsi.c static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs, · line 845

Quoted 10 lines
block/iscsi.c +7 -0
+    if (acb->ioh->cmd_len > SCSI_CDB_MAX_SIZE) {
+        error_report("iSCSI: ioctl error CDB exceeds max size (%d > %d)",
+                     acb->ioh->cmd_len, SCSI_CDB_MAX_SIZE);
+        qemu_aio_unref(acb);
+        return NULL;
+    }
+
     acb->task = malloc(sizeof(struct scsi_task));
     if (acb->task == NULL) {
         error_report("iSCSI: Failed to allocate task for scsi command. %s",

Is it better to invoke the cb and report -EINVAL to the caller?

You need to implement the BH manually then. The difference is -EINVAL vs. -ENOTSUP, which don't result in a different guest behaviour. So I think returning NULL is simpler and therefore better.

Kevin

Reviewed-by
#3 lore raw
Quoted 32 lines · Kevin Wolf

Am 31.05.2016 um 08:44 hat Fam Zheng geschrieben:

Quoted 18 lines · Peter Lieven
Quoted 17 lines

at least in the path via virtio-blk the maximum size is not restricted.

---
 block/iscsi.c | 7 +++++++
 1 file changed, 7 insertions(+)
block/iscsi.c +0 -0
index 2ca8e72..e7d5f7b 100644
@@ -833,6 +833,13 @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
         return &acb->common;
     }
 
Quoted 12 lines

block/iscsi.c static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs, · line 845

Quoted 10 lines
block/iscsi.c +7 -0
+    if (acb->ioh->cmd_len > SCSI_CDB_MAX_SIZE) {
+        error_report("iSCSI: ioctl error CDB exceeds max size (%d > %d)",
+                     acb->ioh->cmd_len, SCSI_CDB_MAX_SIZE);
+        qemu_aio_unref(acb);
+        return NULL;
+    }
+
     acb->task = malloc(sizeof(struct scsi_task));
     if (acb->task == NULL) {
         error_report("iSCSI: Failed to allocate task for scsi command. %s",

Is it better to invoke the cb and report -EINVAL to the caller?

Quoted 3 lines

You need to implement the BH manually then. The difference is -EINVAL vs. -ENOTSUP, which don't result in a different guest behaviour. So I think returning NULL is simpler and therefore better.

Makes sense. Thanks for explaining!

#4 lore raw
In reply to Fam Zheng

Am 31.05.2016 um 08:44 hat Fam Zheng geschrieben:

Quoted 18 lines · Peter Lieven
Quoted 17 lines

at least in the path via virtio-blk the maximum size is not restricted.

---
 block/iscsi.c | 7 +++++++
 1 file changed, 7 insertions(+)
block/iscsi.c +0 -0
index 2ca8e72..e7d5f7b 100644
@@ -833,6 +833,13 @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
         return &acb->common;
     }
 
Quoted 12 lines

block/iscsi.c static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs, · line 845

Quoted 10 lines
block/iscsi.c +7 -0
+    if (acb->ioh->cmd_len > SCSI_CDB_MAX_SIZE) {
+        error_report("iSCSI: ioctl error CDB exceeds max size (%d > %d)",
+                     acb->ioh->cmd_len, SCSI_CDB_MAX_SIZE);
+        qemu_aio_unref(acb);
+        return NULL;
+    }
+
     acb->task = malloc(sizeof(struct scsi_task));
     if (acb->task == NULL) {
         error_report("iSCSI: Failed to allocate task for scsi command. %s",

Is it better to invoke the cb and report -EINVAL to the caller?

By the way, when returning NULL, it looks like bdrv_co_do_ioctl() leaks its BdrvIoctlCompletionData. This code was introduced by your commit 5c5ae76a ("block: Emulate bdrv_ioctl with bdrv_aio_ioctl and track both").

Kevin

#5 lore raw
Quoted 32 lines · Kevin Wolf

Am 31.05.2016 um 08:44 hat Fam Zheng geschrieben:

Quoted 18 lines · Peter Lieven
Quoted 17 lines

at least in the path via virtio-blk the maximum size is not restricted.

---
 block/iscsi.c | 7 +++++++
 1 file changed, 7 insertions(+)
block/iscsi.c +0 -0
index 2ca8e72..e7d5f7b 100644
@@ -833,6 +833,13 @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs,
         return &acb->common;
     }
 
Quoted 12 lines

block/iscsi.c static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *bs, · line 845

Quoted 10 lines
block/iscsi.c +7 -0
+    if (acb->ioh->cmd_len > SCSI_CDB_MAX_SIZE) {
+        error_report("iSCSI: ioctl error CDB exceeds max size (%d > %d)",
+                     acb->ioh->cmd_len, SCSI_CDB_MAX_SIZE);
+        qemu_aio_unref(acb);
+        return NULL;
+    }
+
     acb->task = malloc(sizeof(struct scsi_task));
     if (acb->task == NULL) {
         error_report("iSCSI: Failed to allocate task for scsi command. %s",

Is it better to invoke the cb and report -EINVAL to the caller?

Quoted 4 lines

By the way, when returning NULL, it looks like bdrv_co_do_ioctl() leaks its BdrvIoctlCompletionData. This code was introduced by your commit 5c5ae76a ("block: Emulate bdrv_ioctl with bdrv_aio_ioctl and track both").

I'll send a patch to fix it now.

Fam