Commit 14cf1ad3 authored by Dariusz Stojaczyk's avatar Dariusz Stojaczyk Committed by Jim Harris
Browse files

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: default avatarDariusz Stojaczyk <darek.stojaczyk@gmail.com>
Reviewed-on: https://review.gerrithub.io/409671


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent e18d2b76
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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");