linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpu/xen: Fix a use after free in xen_drm_drv_init
@ 2021-03-23  1:46 Lv Yunlong
  2021-03-25  6:53 ` Oleksandr Andrushchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Lv Yunlong @ 2021-03-23  1:46 UTC (permalink / raw)
  To: oleksandr_andrushchenko, airlied, daniel
  Cc: dri-devel, xen-devel, linux-kernel, Lv Yunlong

In function displback_changed, has the call chain
displback_connect(front_info)->xen_drm_drv_init(front_info).
We can see that drm_info is assigned to front_info->drm_info
and drm_info is freed in fail branch in xen_drm_drv_init().

Later displback_disconnect(front_info) is called and it calls
xen_drm_drv_fini(front_info) cause a use after free by
drm_info = front_info->drm_info statement.

My patch has done two things. First fixes the fail label which
drm_info = kzalloc() failed and still free the drm_info.
Second sets front_info->drm_info to NULL to avoid uaf.

Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
---
 drivers/gpu/drm/xen/xen_drm_front.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/xen/xen_drm_front.c b/drivers/gpu/drm/xen/xen_drm_front.c
index 30d9adf31c84..9f14d99c763c 100644
--- a/drivers/gpu/drm/xen/xen_drm_front.c
+++ b/drivers/gpu/drm/xen/xen_drm_front.c
@@ -521,7 +521,7 @@ static int xen_drm_drv_init(struct xen_drm_front_info *front_info)
 	drm_dev = drm_dev_alloc(&xen_drm_driver, dev);
 	if (IS_ERR(drm_dev)) {
 		ret = PTR_ERR(drm_dev);
-		goto fail;
+		goto fail_dev;
 	}
 
 	drm_info->drm_dev = drm_dev;
@@ -551,8 +551,10 @@ static int xen_drm_drv_init(struct xen_drm_front_info *front_info)
 	drm_kms_helper_poll_fini(drm_dev);
 	drm_mode_config_cleanup(drm_dev);
 	drm_dev_put(drm_dev);
-fail:
+fail_dev:
 	kfree(drm_info);
+	front_info->drm_info = NULL;
+fail:
 	return ret;
 }
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] gpu/xen: Fix a use after free in xen_drm_drv_init
  2021-03-23  1:46 [PATCH] gpu/xen: Fix a use after free in xen_drm_drv_init Lv Yunlong
@ 2021-03-25  6:53 ` Oleksandr Andrushchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Oleksandr Andrushchenko @ 2021-03-25  6:53 UTC (permalink / raw)
  To: Lv Yunlong, airlied, daniel; +Cc: dri-devel, xen-devel, linux-kernel

Hi,

good catch

On 3/23/21 3:46 AM, Lv Yunlong wrote:
> In function displback_changed, has the call chain
> displback_connect(front_info)->xen_drm_drv_init(front_info).
> We can see that drm_info is assigned to front_info->drm_info
> and drm_info is freed in fail branch in xen_drm_drv_init().
>
> Later displback_disconnect(front_info) is called and it calls
> xen_drm_drv_fini(front_info) cause a use after free by
> drm_info = front_info->drm_info statement.
>
> My patch has done two things. First fixes the fail label which
> drm_info = kzalloc() failed and still free the drm_info.
> Second sets front_info->drm_info to NULL to avoid uaf.
>
> Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>

Thank you for the patch,

Reviewed-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>

Will apply to drm-misc-next-fixes

Thank you,

Oleksandr

> ---
>   drivers/gpu/drm/xen/xen_drm_front.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/xen/xen_drm_front.c b/drivers/gpu/drm/xen/xen_drm_front.c
> index 30d9adf31c84..9f14d99c763c 100644
> --- a/drivers/gpu/drm/xen/xen_drm_front.c
> +++ b/drivers/gpu/drm/xen/xen_drm_front.c
> @@ -521,7 +521,7 @@ static int xen_drm_drv_init(struct xen_drm_front_info *front_info)
>   	drm_dev = drm_dev_alloc(&xen_drm_driver, dev);
>   	if (IS_ERR(drm_dev)) {
>   		ret = PTR_ERR(drm_dev);
> -		goto fail;
> +		goto fail_dev;
>   	}
>   
>   	drm_info->drm_dev = drm_dev;
> @@ -551,8 +551,10 @@ static int xen_drm_drv_init(struct xen_drm_front_info *front_info)
>   	drm_kms_helper_poll_fini(drm_dev);
>   	drm_mode_config_cleanup(drm_dev);
>   	drm_dev_put(drm_dev);
> -fail:
> +fail_dev:
>   	kfree(drm_info);
> +	front_info->drm_info = NULL;
> +fail:
>   	return ret;
>   }
>   

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-25  8:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-23  1:46 [PATCH] gpu/xen: Fix a use after free in xen_drm_drv_init Lv Yunlong
2021-03-25  6:53 ` Oleksandr Andrushchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).