* [PATCH 1/2] vhost-user-blk: handle errors in vhost_user_blk_connect
@ 2022-02-10 11:46 Konstantin Khlebnikov
2022-02-10 11:46 ` [PATCH 2/2] vhost-user-blk: check connection state in vhost_user_blk_set_config Konstantin Khlebnikov
2022-02-10 11:56 ` [PATCH 1/2] vhost-user-blk: handle errors in vhost_user_blk_connect Philippe Mathieu-Daudé via
0 siblings, 2 replies; 4+ messages in thread
From: Konstantin Khlebnikov @ 2022-02-10 11:46 UTC (permalink / raw)
To: qemu-devel; +Cc: yc-core
Cleanup vhost device and update connection state when initialization fails.
Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
---
hw/block/vhost-user-blk.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
index 1a42ae9187..35ac188ca4 100644
--- a/hw/block/vhost-user-blk.c
+++ b/hw/block/vhost-user-blk.c
@@ -340,18 +340,24 @@ static int vhost_user_blk_connect(DeviceState *dev, Error **errp)
ret = vhost_dev_init(&s->dev, &s->vhost_user, VHOST_BACKEND_TYPE_USER, 0,
errp);
if (ret < 0) {
- return ret;
+ goto err_init;
}
/* restore vhost state */
if (virtio_device_started(vdev, vdev->status)) {
ret = vhost_user_blk_start(vdev, errp);
if (ret < 0) {
- return ret;
+ goto err_start;
}
}
return 0;
+
+err_start:
+ vhost_dev_cleanup(&s->dev);
+err_init:
+ s->connected = false;
+ return ret;
}
static void vhost_user_blk_disconnect(DeviceState *dev)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] vhost-user-blk: check connection state in vhost_user_blk_set_config
2022-02-10 11:46 [PATCH 1/2] vhost-user-blk: handle errors in vhost_user_blk_connect Konstantin Khlebnikov
@ 2022-02-10 11:46 ` Konstantin Khlebnikov
2022-02-10 11:56 ` [PATCH 1/2] vhost-user-blk: handle errors in vhost_user_blk_connect Philippe Mathieu-Daudé via
1 sibling, 0 replies; 4+ messages in thread
From: Konstantin Khlebnikov @ 2022-02-10 11:46 UTC (permalink / raw)
To: qemu-devel; +Cc: yc-core
Fuzzing found that ->set_config() could be called without connection.
Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
---
hw/block/vhost-user-blk.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
index 35ac188ca4..9ac50443bc 100644
--- a/hw/block/vhost-user-blk.c
+++ b/hw/block/vhost-user-blk.c
@@ -72,6 +72,10 @@ static void vhost_user_blk_set_config(VirtIODevice *vdev, const uint8_t *config)
struct virtio_blk_config *blkcfg = (struct virtio_blk_config *)config;
int ret;
+ if (!s->connected) {
+ return;
+ }
+
if (blkcfg->wce == s->blkcfg.wce) {
return;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] vhost-user-blk: handle errors in vhost_user_blk_connect
2022-02-10 11:46 [PATCH 1/2] vhost-user-blk: handle errors in vhost_user_blk_connect Konstantin Khlebnikov
2022-02-10 11:46 ` [PATCH 2/2] vhost-user-blk: check connection state in vhost_user_blk_set_config Konstantin Khlebnikov
@ 2022-02-10 11:56 ` Philippe Mathieu-Daudé via
2022-02-10 12:06 ` Konstantin Khlebnikov
1 sibling, 1 reply; 4+ messages in thread
From: Philippe Mathieu-Daudé via @ 2022-02-10 11:56 UTC (permalink / raw)
To: Konstantin Khlebnikov, qemu-devel; +Cc: yc-core
On 10/2/22 12:46, Konstantin Khlebnikov wrote:
> Cleanup vhost device and update connection state when initialization fails.
>
> Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
> ---
> hw/block/vhost-user-blk.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
> index 1a42ae9187..35ac188ca4 100644
> --- a/hw/block/vhost-user-blk.c
> +++ b/hw/block/vhost-user-blk.c
> @@ -340,18 +340,24 @@ static int vhost_user_blk_connect(DeviceState *dev, Error **errp)
> ret = vhost_dev_init(&s->dev, &s->vhost_user, VHOST_BACKEND_TYPE_USER, 0,
> errp);
> if (ret < 0) {
> - return ret;
> + goto err_init;
> }
>
> /* restore vhost state */
> if (virtio_device_started(vdev, vdev->status)) {
> ret = vhost_user_blk_start(vdev, errp);
> if (ret < 0) {
> - return ret;
> + goto err_start;
> }
> }
What about moving here ...:
s->connected = true;
>
> return 0;
> +
> +err_start:
> + vhost_dev_cleanup(&s->dev);
> +err_init:
> + s->connected = false;
... to have a single 'err' label?
> + return ret;
> }
>
> static void vhost_user_blk_disconnect(DeviceState *dev)
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] vhost-user-blk: handle errors in vhost_user_blk_connect
2022-02-10 11:56 ` [PATCH 1/2] vhost-user-blk: handle errors in vhost_user_blk_connect Philippe Mathieu-Daudé via
@ 2022-02-10 12:06 ` Konstantin Khlebnikov
0 siblings, 0 replies; 4+ messages in thread
From: Konstantin Khlebnikov @ 2022-02-10 12:06 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel; +Cc: yc-core
[-- Attachment #1: Type: text/html, Size: 2354 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-02-10 12:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-10 11:46 [PATCH 1/2] vhost-user-blk: handle errors in vhost_user_blk_connect Konstantin Khlebnikov
2022-02-10 11:46 ` [PATCH 2/2] vhost-user-blk: check connection state in vhost_user_blk_set_config Konstantin Khlebnikov
2022-02-10 11:56 ` [PATCH 1/2] vhost-user-blk: handle errors in vhost_user_blk_connect Philippe Mathieu-Daudé via
2022-02-10 12:06 ` Konstantin Khlebnikov
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.