mbox series

[0/2] vhost-vdpa: fix issues around v->config_ctx handling

Message ID 20210311135257.109460-1-sgarzare@redhat.com
Headers show
Series vhost-vdpa: fix issues around v->config_ctx handling | expand

Message

Stefano Garzarella March 11, 2021, 1:52 p.m. UTC
While writing a test for a Rust library [1] to handle vhost-vdpa devices,
I experienced the 'use-after-free' issue fixed in patch 1, then I
discovered the potential issue when eventfd_ctx_fdget() fails fixed in
patch 2.

Do you think it might be useful to write a vdpa test suite, perhaps using
this Rust library [2] ?
Could we put it in the kernel tree in tool/testing?

Thanks,
Stefano

[1] https://github.com/stefano-garzarella/vhost/tree/vdpa
[2] https://github.com/rust-vmm/vhost

Stefano Garzarella (2):
  vhost-vdpa: fix use-after-free of v->config_ctx
  vhost-vdpa: set v->config_ctx to NULL if eventfd_ctx_fdget() fails

 drivers/vhost/vdpa.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

Jason Wang March 12, 2021, 6:34 a.m. UTC | #1
On 2021/3/11 9:52 下午, Stefano Garzarella wrote:
> 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: 776f395004d8 ("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>



Acked-by: Jason Wang <jasowang@redhat.com>



> ---

>   drivers/vhost/vdpa.c | 8 ++++++--

>   1 file changed, 6 insertions(+), 2 deletions(-)

>

> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c

> index 00796e4ecfdf..f9ecdce5468a 100644

> --- a/drivers/vhost/vdpa.c

> +++ b/drivers/vhost/vdpa.c

> @@ -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);

>