block/iscsi: avoid potential overflow of acb->task->cdb
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
@@ -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
Quoted 17 lines · Peter Lieven
at least in the path via virtio-blk the maximum size is not restricted.
Signed-off-by Peter Lieven <[email protected]>--- block/iscsi.c | 7 +++++++ 1 file changed, 7 insertions(+)block/iscsi.c +0
-0@@ -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
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.
Signed-off-by Peter Lieven <[email protected]>--- block/iscsi.c | 7 +++++++ 1 file changed, 7 insertions(+)block/iscsi.c +0
-0@@ -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
-EINVALto 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
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.
Signed-off-by Peter Lieven <[email protected]>--- block/iscsi.c | 7 +++++++ 1 file changed, 7 insertions(+)block/iscsi.c +0
-0@@ -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
-EINVALto 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
Fam Zheng
Reviewed-byQuoted 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.
Signed-off-by Peter Lieven <[email protected]>--- block/iscsi.c | 7 +++++++ 1 file changed, 7 insertions(+)block/iscsi.c +0
-0@@ -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
-EINVALto the caller?
Quoted 3 lines
You need to implement the BH manually then. The difference is
-EINVALvs.-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!
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.
Signed-off-by Peter Lieven <[email protected]>--- block/iscsi.c | 7 +++++++ 1 file changed, 7 insertions(+)block/iscsi.c +0
-0@@ -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
-EINVALto 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 commit5c5ae76a("block: Emulatebdrv_ioctlwithbdrv_aio_ioctland track both").
I'll send a patch to fix it now.
Fam