From 436c0c189bcad16ea58f38d7e71b7b1317f57d64 Mon Sep 17 00:00:00 2001 From: Dariusz Stojaczyk Date: Tue, 3 Jul 2018 09:26:33 +0200 Subject: [PATCH] virtio: check F_CONFIG feature before sending GET/SET_CONFIG The device might not have this message implemented. Sending it could result in a connection being terminated. Change-Id: I53c08f1108ebc7de630569f3983c317cc6510fa4 Signed-off-by: Dariusz Stojaczyk Reviewed-on: https://review.gerrithub.io/417636 Reviewed-by: Ben Walker Reviewed-by: Jim Harris Tested-by: SPDK Automated Test System --- lib/virtio/virtio_user.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/virtio/virtio_user.c b/lib/virtio/virtio_user.c index c688d61d6..cc1b3a18d 100644 --- a/lib/virtio/virtio_user.c +++ b/lib/virtio/virtio_user.c @@ -222,6 +222,10 @@ virtio_user_read_dev_config(struct virtio_dev *vdev, size_t offset, struct virtio_user_dev *dev = vdev->ctx; struct vhost_user_config cfg = {0}; + if ((dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_CONFIG)) == 0) { + return -ENOTSUP; + } + cfg.offset = 0; cfg.size = VHOST_USER_MAX_CONFIG_SIZE; @@ -241,6 +245,10 @@ virtio_user_write_dev_config(struct virtio_dev *vdev, size_t offset, struct virtio_user_dev *dev = vdev->ctx; struct vhost_user_config cfg = {0}; + if ((dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_CONFIG)) == 0) { + return -ENOTSUP; + } + cfg.offset = offset; cfg.size = length; memcpy(cfg.region, src, length);