bdev/virtio/scsi: validate bs and num_blocks before creating a bdev
This becomes especially useful when accidentally trying to use vhost-blk socket as a vhost-scsi one. There's no SCSI/Block identification within the protocol, so blk messages can be interpreted as scsi ones. This usually results in a bdev being created with bs==0 && blocksize==0 and leads to a crash. Nevertheless, this extra check should be here to protect against malicious/incomplete vhost-scsi targets crashing entire initiator apps. Change-Id: I06cfe3852c35fbd3e6a9f9a337a5abe5febaddf2 Signed-off-by: Dariusz Stojaczyk <darek.stojaczyk@gmail.com> Reviewed-on: https://review.gerrithub.io/409671 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
e18d2b7687
commit
14cf1ad3ac
@ -1303,6 +1303,12 @@ virtio_scsi_dev_add_tgt(struct virtio_scsi_dev *svdev, struct virtio_scsi_scan_i
|
||||
}
|
||||
}
|
||||
|
||||
if (info->block_size == 0 || info->num_blocks == 0) {
|
||||
SPDK_ERRLOG("%s: invalid target %u: bs=%"PRIu32" blocks=%"PRIu64"\n",
|
||||
svdev->vdev.name, info->target, info->block_size, info->num_blocks);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
disk = calloc(1, sizeof(*disk));
|
||||
if (disk == NULL) {
|
||||
SPDK_ERRLOG("could not allocate disk\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user