dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/nouveau: avoid null deref on bad arguments to nouveau_vma_getmap
@ 2013-08-22  0:10 Ilia Mirkin
  2013-08-22  6:41 ` Ben Skeggs
  2013-08-22  7:12 ` Maarten Lankhorst
  0 siblings, 2 replies; 22+ messages in thread
From: Ilia Mirkin @ 2013-08-22  0:10 UTC (permalink / raw)
  To: Ben Skeggs
  Cc: nouveau, Maarten Lankhorst, dri-devel, Pasi Kärkkäinen

The code expects non-VRAM mem nodes to have a pages list. If that's not
set, it will do a null deref down the line. Warn on that condition and
return an error.

See https://bugs.freedesktop.org/show_bug.cgi?id=64774

Reported-by: Pasi Kärkkäinen <pasik@iki.fi>
Tested-by: Pasi Kärkkäinen <pasik@iki.fi>
Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Cc: <stable@vger.kernel.org> # 3.8+
---

I don't exactly understand what's going on, but this is just a
straightforward way to avoid a null deref that you see happens in the
bug. I haven't figured out the root cause of this, but it's getting
well into the "I have no idea how TTM works" space. However this seems
like a bit of defensive programming -- nouveau_vm_map_sg will pass
node->pages as a list down, which will be dereferenced by
nvc0_vm_map_sg. Perhaps the other arguments should make that
dereferencing not happen, but it definitely was happening here, as you
can see in the bug.

Ben/Maarten, I'll let you judge whether this check is appropriate,
since like I hope I was able to convey above, I'm just not really sure :)

 drivers/gpu/drm/nouveau/nouveau_bo.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index cdc3282..191145d 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -963,6 +963,12 @@ nouveau_vma_getmap(struct nouveau_channel *chan, struct nouveau_bo *nvbo,
 	struct nouveau_mem *node = mem->mm_node;
 	int ret;
 
+	/* If we ever get here for a non-vram mem node that doesn't
+	 * have pages, we will end up doing a null deref in
+	 * nouveau_vm_map_sg. */
+	if (WARN_ON(mem->mem_type != TTM_PL_VRAM && !node->pages))
+		return -EINVAL;
+
 	ret = nouveau_vm_get(nv_client(chan->cli)->vm, mem->num_pages <<
 			     PAGE_SHIFT, node->page_shift,
 			     NV_MEM_ACCESS_RW, vma);
-- 
1.8.1.5

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

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

end of thread, other threads:[~2014-01-03 18:32 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-22  0:10 [PATCH] drm/nouveau: avoid null deref on bad arguments to nouveau_vma_getmap Ilia Mirkin
2013-08-22  6:41 ` Ben Skeggs
     [not found]   ` <CACAvsv4zNrgnBkaJOJyDyDq1bnW37eccjsT=c4yfBJHcNgaaWQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-08-22  6:54     ` Pasi Kärkkäinen
2013-08-22  7:12 ` Maarten Lankhorst
     [not found]   ` <5215B9E8.5080108-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
2013-08-22  7:58     ` Pasi Kärkkäinen
2013-08-23 20:20   ` Pasi Kärkkäinen
     [not found]     ` <20130823202042.GS2924-GxtO3QLqHcLR7s880joybQ@public.gmane.org>
2013-08-28  6:29       ` Pasi Kärkkäinen
     [not found]         ` <20130828062948.GE2924-GxtO3QLqHcLR7s880joybQ@public.gmane.org>
2013-08-28  7:44           ` Maarten Lankhorst
2013-09-03 14:20             ` Pasi Kärkkäinen
2013-09-03 14:34               ` Maarten Lankhorst
2013-09-03 14:48                 ` Pasi Kärkkäinen
2013-09-03 17:58                   ` Pasi Kärkkäinen
2013-09-04  3:41   ` Ben Skeggs
     [not found]     ` <CACAvsv7ygYoM6ZzFdY-Zov0herPMQDERaw6jzj6VuB+p20FcJQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-09-04  6:59       ` Maarten Lankhorst
2013-09-10 10:39         ` Pasi Kärkkäinen
2013-09-25 14:41         ` Pasi Kärkkäinen
2013-09-25 16:48           ` Ben Skeggs
2013-09-25 16:53             ` Pasi Kärkkäinen
2013-10-18 14:44             ` Pasi Kärkkäinen
     [not found]               ` <20131018144445.GP2924-GxtO3QLqHcLR7s880joybQ@public.gmane.org>
2014-01-03 18:32                 ` Pasi Kärkkäinen
2013-09-25 14:42         ` Pasi Kärkkäinen
2013-10-18 14:45           ` Pasi Kärkkäinen

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