]> git.baikalelectronics.ru Git - kernel.git/commitdiff
vhost-vdpa: set v->config_ctx to NULL if eventfd_ctx_fdget() fails
authorStefano Garzarella <sgarzare@redhat.com>
Thu, 11 Mar 2021 13:52:57 +0000 (14:52 +0100)
committerMichael S. Tsirkin <mst@redhat.com>
Sun, 14 Mar 2021 22:10:07 +0000 (18:10 -0400)
In vhost_vdpa_set_config_call() if eventfd_ctx_fdget() fails the
'v->config_ctx' contains an error instead of a valid pointer.

Since we consider 'v->config_ctx' valid if it is not NULL, we should
set it to NULL in this case to avoid to use an invalid pointer in
other functions such as vhost_vdpa_config_put().

Fixes: df57e9aa15a4 ("vhost_vdpa: Support config interrupt in vdpa")
Cc: lingshan.zhu@intel.com
Cc: stable@vger.kernel.org
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Link: https://lore.kernel.org/r/20210311135257.109460-3-sgarzare@redhat.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
drivers/vhost/vdpa.c

index 4fc768813c4ad2d5b035c1d0bafb60c6ae3c1878..e0a27e3362935651067c87f7afc1099d54978924 100644 (file)
@@ -331,8 +331,12 @@ static long vhost_vdpa_set_config_call(struct vhost_vdpa *v, u32 __user *argp)
        if (!IS_ERR_OR_NULL(ctx))
                eventfd_ctx_put(ctx);
 
-       if (IS_ERR(v->config_ctx))
-               return PTR_ERR(v->config_ctx);
+       if (IS_ERR(v->config_ctx)) {
+               long ret = PTR_ERR(v->config_ctx);
+
+               v->config_ctx = NULL;
+               return ret;
+       }
 
        v->vdpa->config->set_config_cb(v->vdpa, &cb);