From patchwork Fri Aug 23 20:20:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UGFzaSBLw6Rya2vDpGluZW4=?= X-Patchwork-Id: 2849055 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 49D459F485 for ; Fri, 23 Aug 2013 20:21:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 85F7120266 for ; Fri, 23 Aug 2013 20:21:22 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id CCFC420265 for ; Fri, 23 Aug 2013 20:21:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BBF6EE6A4B for ; Fri, 23 Aug 2013 13:21:20 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from emh01.mail.saunalahti.fi (emh01.mail.saunalahti.fi [62.142.5.107]) by gabe.freedesktop.org (Postfix) with ESMTP id 749B9E6B97; Fri, 23 Aug 2013 13:20:45 -0700 (PDT) Received: from ydin.reaktio.net (reaktio.net [85.76.255.15]) by emh01.mail.saunalahti.fi (Postfix) with ESMTP id 4C41D90017; Fri, 23 Aug 2013 23:20:42 +0300 (EEST) Received: by ydin.reaktio.net (Postfix, from userid 1001) id B184E36C0A0; Fri, 23 Aug 2013 23:20:42 +0300 (EEST) Date: Fri, 23 Aug 2013 23:20:42 +0300 From: Pasi =?iso-8859-1?Q?K=E4rkk=E4inen?= To: Maarten Lankhorst Subject: Re: [PATCH] drm/nouveau: avoid null deref on bad arguments to nouveau_vma_getmap Message-ID: <20130823202042.GS2924@reaktio.net> References: <1377130214-17522-1-git-send-email-imirkin@alum.mit.edu> <5215B9E8.5080108@canonical.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5215B9E8.5080108@canonical.com> User-Agent: Mutt/1.5.20 (2009-06-14) Cc: nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Maarten Lankhorst , Ben Skeggs X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Aug 22, 2013 at 09:12:40AM +0200, Maarten Lankhorst wrote: > Op 22-08-13 02:10, Ilia Mirkin schreef: > > 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 > > Tested-by: Pasi Kärkkäinen > > Signed-off-by: Ilia Mirkin > > Cc: # 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 :) > Not it really isn't appropriate.. > > You'd have to call call nouveau_vm_map_sg_table instead, the only place that doesn't handle that correctly > is where it's not expected to be called. > > Here, have a completely untested patch to fix things... > Maarten: I've been testing this stuff with Linux 3.10.x, so I had to modify the patch a bit to make it apply there.. I've attached the modified copy that applies to 3.10.9, hopefully I did the backport correctly. With Linux 3.10.9 and the patch applied the kernel doesn't crash anymore, and I get this error in dmesg: [ 76.105643] nouveau W[ DRM] Trying to create a fb in vram with valid_domains=00000004 Does that help? -- Pasi --- linux-3.10.9-100.fc18.x86_64/drivers/gpu/drm/nouveau/nouveau_display.c.orig 2013-07-01 01:13:29.000000000 +0300 +++ linux-3.10.9-100.fc18.x86_64/drivers/gpu/drm/nouveau/nouveau_display.c 2013-08-23 19:56:52.038234281 +0300 @@ -137,18 +137,31 @@ { struct nouveau_framebuffer *nouveau_fb; struct drm_gem_object *gem; + struct nouveau_bo *nvbo; int ret; gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handles[0]); if (!gem) return ERR_PTR(-ENOENT); + nvbo = nouveau_gem_object(gem); + if (!(nvbo->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM)) { + nv_warn(nouveau_drm(dev), "Trying to create a fb in vram with" + " valid_domains=%08x\n", nvbo->valid_domains); + ret = -EINVAL; + drm_gem_object_unreference(gem); + return ERR_PTR(ret); + } + nouveau_fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL); - if (!nouveau_fb) + if (!nouveau_fb) { + drm_gem_object_unreference(gem); return ERR_PTR(-ENOMEM); + } - ret = nouveau_framebuffer_init(dev, nouveau_fb, mode_cmd, nouveau_gem_object(gem)); + ret = nouveau_framebuffer_init(dev, nouveau_fb, mode_cmd, nvbo); if (ret) { + kfree(nouveau_fb); drm_gem_object_unreference(gem); return ERR_PTR(ret); }