[PATCH] vhost-user-gpu: reorder free calls.

Gerd Hoffmann posted 1 patch 2 years, 9 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/next-importer-push tags/patchew/20210604103714.1237414-1-kraxel@redhat.com
Maintainers: "Marc-André Lureau" <marcandre.lureau@redhat.com>, Gerd Hoffmann <kraxel@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>
contrib/vhost-user-gpu/vhost-user-gpu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] vhost-user-gpu: reorder free calls.
Posted by Gerd Hoffmann 2 years, 9 months ago
Free in correct order to avoid use-after-free.

Resolves: CID 1453812
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 contrib/vhost-user-gpu/vhost-user-gpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-gpu/vhost-user-gpu.c
index 6dc6a44f4e26..611360e6b475 100644
--- a/contrib/vhost-user-gpu/vhost-user-gpu.c
+++ b/contrib/vhost-user-gpu/vhost-user-gpu.c
@@ -350,8 +350,8 @@ vg_resource_create_2d(VuGpu *g,
     if (!res->image) {
         g_critical("%s: resource creation failed %d %d %d",
                    __func__, c2d.resource_id, c2d.width, c2d.height);
-        g_free(res);
         vugbm_buffer_destroy(&res->buffer);
+        g_free(res);
         cmd->error = VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY;
         return;
     }
-- 
2.31.1


Re: [PATCH] vhost-user-gpu: reorder free calls.
Posted by Marc-André Lureau 2 years, 9 months ago
On Fri, Jun 4, 2021 at 2:38 PM Gerd Hoffmann <kraxel@redhat.com> wrote:

> Free in correct order to avoid use-after-free.
>
> Resolves: CID 1453812
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

---
>  contrib/vhost-user-gpu/vhost-user-gpu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c
> b/contrib/vhost-user-gpu/vhost-user-gpu.c
> index 6dc6a44f4e26..611360e6b475 100644
> --- a/contrib/vhost-user-gpu/vhost-user-gpu.c
> +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c
> @@ -350,8 +350,8 @@ vg_resource_create_2d(VuGpu *g,
>      if (!res->image) {
>          g_critical("%s: resource creation failed %d %d %d",
>                     __func__, c2d.resource_id, c2d.width, c2d.height);
> -        g_free(res);
>          vugbm_buffer_destroy(&res->buffer);
> +        g_free(res);
>          cmd->error = VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY;
>          return;
>      }
> --
> 2.31.1
>
>
>

-- 
Marc-André Lureau
Re: [PATCH] vhost-user-gpu: reorder free calls.
Posted by Li Qiang 2 years, 9 months ago
Gerd Hoffmann <kraxel@redhat.com> 于2021年6月4日周五 下午6:37写道:
>
> Free in correct order to avoid use-after-free.
>
> Resolves: CID 1453812
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>


Sorry, my fault.

Reviewed-by: Li Qiang <liq3ea@gmail.com>

> ---
>  contrib/vhost-user-gpu/vhost-user-gpu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-gpu/vhost-user-gpu.c
> index 6dc6a44f4e26..611360e6b475 100644
> --- a/contrib/vhost-user-gpu/vhost-user-gpu.c
> +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c
> @@ -350,8 +350,8 @@ vg_resource_create_2d(VuGpu *g,
>      if (!res->image) {
>          g_critical("%s: resource creation failed %d %d %d",
>                     __func__, c2d.resource_id, c2d.width, c2d.height);
> -        g_free(res);
>          vugbm_buffer_destroy(&res->buffer);
> +        g_free(res);
>          cmd->error = VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY;
>          return;
>      }
> --
> 2.31.1
>
>

Re: [PATCH] vhost-user-gpu: reorder free calls.
Posted by Philippe Mathieu-Daudé 2 years, 9 months ago
On 6/4/21 12:37 PM, Gerd Hoffmann wrote:
> Free in correct order to avoid use-after-free.
> 
> Resolves: CID 1453812
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  contrib/vhost-user-gpu/vhost-user-gpu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>