nouveau.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/nouveau: avoid a use-after-free when BO init fails
@ 2020-12-03  0:02 Jeremy Cline
  2021-03-26 21:41 ` [Nouveau] " Lyude Paul
  0 siblings, 1 reply; 3+ messages in thread
From: Jeremy Cline @ 2020-12-03  0:02 UTC (permalink / raw)
  To: Ben Skeggs
  Cc: David Airlie, nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW, Daniel Vetter,
	Thierry Reding

nouveau_bo_init() is backed by ttm_bo_init() and ferries its return code
back to the caller. On failures, ttm_bo_init() invokes the provided
destructor which should de-initialize and free the memory.

Thus, when nouveau_bo_init() returns an error the gem object has already
been released and the memory freed by nouveau_bo_del_ttm().

Fixes: 019cbd4a4feb ("drm/nouveau: Initialize GEM object before TTM object")
Cc: Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Jeremy Cline <jcline-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 drivers/gpu/drm/nouveau/nouveau_gem.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
index 787d05eefd9c..d30157cc7169 100644
--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
@@ -211,10 +211,8 @@ nouveau_gem_new(struct nouveau_cli *cli, u64 size, int align, uint32_t domain,
 	}
 
 	ret = nouveau_bo_init(nvbo, size, align, domain, NULL, NULL);
-	if (ret) {
-		nouveau_bo_ref(NULL, &nvbo);
+	if (ret)
 		return ret;
-	}
 
 	/* we restrict allowed domains on nv50+ to only the types
 	 * that were requested at creation time.  not possibly on
-- 
2.28.0

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

* Re: [Nouveau] [PATCH] drm/nouveau: avoid a use-after-free when BO init fails
  2020-12-03  0:02 [PATCH] drm/nouveau: avoid a use-after-free when BO init fails Jeremy Cline
@ 2021-03-26 21:41 ` Lyude Paul
  2021-09-28 11:06   ` Karol Herbst
  0 siblings, 1 reply; 3+ messages in thread
From: Lyude Paul @ 2021-03-26 21:41 UTC (permalink / raw)
  To: Jeremy Cline, Ben Skeggs
  Cc: David Airlie, nouveau, Thierry Reding, linux-kernel, dri-devel

Reviewed-by: Lyude Paul <lyude@redhat.com>

On Wed, 2020-12-02 at 19:02 -0500, Jeremy Cline wrote:
> nouveau_bo_init() is backed by ttm_bo_init() and ferries its return code
> back to the caller. On failures, ttm_bo_init() invokes the provided
> destructor which should de-initialize and free the memory.
> 
> Thus, when nouveau_bo_init() returns an error the gem object has already
> been released and the memory freed by nouveau_bo_del_ttm().
> 
> Fixes: 019cbd4a4feb ("drm/nouveau: Initialize GEM object before TTM object")
> Cc: Thierry Reding <treding@nvidia.com>
> Signed-off-by: Jeremy Cline <jcline@redhat.com>
> ---
>  drivers/gpu/drm/nouveau/nouveau_gem.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c
> b/drivers/gpu/drm/nouveau/nouveau_gem.c
> index 787d05eefd9c..d30157cc7169 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
> @@ -211,10 +211,8 @@ nouveau_gem_new(struct nouveau_cli *cli, u64 size, int
> align, uint32_t domain,
>         }
>  
>         ret = nouveau_bo_init(nvbo, size, align, domain, NULL, NULL);
> -       if (ret) {
> -               nouveau_bo_ref(NULL, &nvbo);
> +       if (ret)
>                 return ret;
> -       }
>  
>         /* we restrict allowed domains on nv50+ to only the types
>          * that were requested at creation time.  not possibly on

-- 
Sincerely,
   Lyude Paul (she/her)
   Software Engineer at Red Hat
   
Note: I deal with a lot of emails and have a lot of bugs on my plate. If you've
asked me a question, are waiting for a review/merge on a patch, etc. and I
haven't responded in a while, please feel free to send me another email to check
on my status. I don't bite!

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/nouveau

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

* Re: [Nouveau] [PATCH] drm/nouveau: avoid a use-after-free when BO init fails
  2021-03-26 21:41 ` [Nouveau] " Lyude Paul
@ 2021-09-28 11:06   ` Karol Herbst
  0 siblings, 0 replies; 3+ messages in thread
From: Karol Herbst @ 2021-09-28 11:06 UTC (permalink / raw)
  To: Lyude Paul
  Cc: Jeremy Cline, Ben Skeggs, David Airlie, nouveau, Thierry Reding,
	LKML, dri-devel

Reviewed-by: Karol Herbst <kherbst@redhat.com>

and queued

On Fri, Mar 26, 2021 at 10:41 PM Lyude Paul <lyude@redhat.com> wrote:
>
> Reviewed-by: Lyude Paul <lyude@redhat.com>
>
> On Wed, 2020-12-02 at 19:02 -0500, Jeremy Cline wrote:
> > nouveau_bo_init() is backed by ttm_bo_init() and ferries its return code
> > back to the caller. On failures, ttm_bo_init() invokes the provided
> > destructor which should de-initialize and free the memory.
> >
> > Thus, when nouveau_bo_init() returns an error the gem object has already
> > been released and the memory freed by nouveau_bo_del_ttm().
> >
> > Fixes: 019cbd4a4feb ("drm/nouveau: Initialize GEM object before TTM object")
> > Cc: Thierry Reding <treding@nvidia.com>
> > Signed-off-by: Jeremy Cline <jcline@redhat.com>
> > ---
> >  drivers/gpu/drm/nouveau/nouveau_gem.c | 4 +---
> >  1 file changed, 1 insertion(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c
> > b/drivers/gpu/drm/nouveau/nouveau_gem.c
> > index 787d05eefd9c..d30157cc7169 100644
> > --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
> > +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
> > @@ -211,10 +211,8 @@ nouveau_gem_new(struct nouveau_cli *cli, u64 size, int
> > align, uint32_t domain,
> >         }
> >
> >         ret = nouveau_bo_init(nvbo, size, align, domain, NULL, NULL);
> > -       if (ret) {
> > -               nouveau_bo_ref(NULL, &nvbo);
> > +       if (ret)
> >                 return ret;
> > -       }
> >
> >         /* we restrict allowed domains on nv50+ to only the types
> >          * that were requested at creation time.  not possibly on
>
> --
> Sincerely,
>    Lyude Paul (she/her)
>    Software Engineer at Red Hat
>
> Note: I deal with a lot of emails and have a lot of bugs on my plate. If you've
> asked me a question, are waiting for a review/merge on a patch, etc. and I
> haven't responded in a while, please feel free to send me another email to check
> on my status. I don't bite!
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


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

end of thread, other threads:[~2021-09-28 11:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-03  0:02 [PATCH] drm/nouveau: avoid a use-after-free when BO init fails Jeremy Cline
2021-03-26 21:41 ` [Nouveau] " Lyude Paul
2021-09-28 11:06   ` Karol Herbst

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).