Received: by 10.223.176.5 with SMTP id f5csp543748wra; Sat, 3 Feb 2018 05:08:29 -0800 (PST) X-Google-Smtp-Source: AH8x226LvCunxrR5mATnJgUjFVItcoMrao3ndwHhDijEQfcs/MaZc5CjU4QSamcLKkOebF6W/XnB X-Received: by 10.99.116.23 with SMTP id p23mr1228537pgc.16.1517663308883; Sat, 03 Feb 2018 05:08:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517663308; cv=none; d=google.com; s=arc-20160816; b=gGMjCqUHLLe5RNgSXrDdwOwf7QNFcRjJ6OKjvg6wHtgFDkOAqJs7iTVcVkKibx+Fwi eQJgCQ0xm0NuR1YcIe8WGPWT+hiWxU+jwMcM4JsXbj4I3AQ509GbmdMt765+U//cD5rH e9DQAcSgqXlYG+pOhOSHotTz7z+lK5/rArI1JOhhHNZZIXUukvkqcCpD7SSb96OgHgfy Nei/zMuSYrnFvr1z36brOw9VxGeEOqXN16+nOuogSMQBEcj5Jh4dOFX1AVRc7ACdHsiY qyEHVZFb2wwMPiFcgUPqj0vZbIc3Z3lU0fDiIeRl85TRr+NWLfbVqlEqpK1AL3/dNBlH Ax3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :user-agent:in-reply-to:references:subject:cc:to:from:message-id :date:arc-authentication-results; bh=yBNlGKTikNpqFn4cDUZg17o6otTF8Lm0bJ9lHETytyY=; b=U78blCQv4W86BdvAw3ZqhNzOwNlnFKJ8/BCK8wtOvUyTTZtKl1XYGPt/nYVtICbz90 47o8Tqt40mcjLhiV6JTARBXOA81b14xJoVsISE0K+1+IgJ7cqc3CqyhJhHuTH+S9u3Cp io96R6bdaF51u+iMQ79/eKvMel4jBLAlA82bLSswXDWFiip2qW3hyrPpG8bl+GVq+PHQ ZO5mnfr6bUxfedyWNHPZUefq3Zqh8HqAFvVhGXMpV2EjSQP3OY/g/bzbrur+YN+GS0ac AWWs/upaRIxE41PnANqGIurXwC2yhwBQsrm4EIqBV79rns/+qVCC/tdNwrwoFCsuyaVx et0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f15si2925557pgv.204.2018.02.03.05.08.00; Sat, 03 Feb 2018 05:08:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752042AbeBCMpR (ORCPT + 99 others); Sat, 3 Feb 2018 07:45:17 -0500 Received: from gateway34.websitewelcome.com ([192.185.149.46]:21983 "EHLO gateway34.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751702AbeBCMpK (ORCPT ); Sat, 3 Feb 2018 07:45:10 -0500 X-Greylist: delayed 1360 seconds by postgrey-1.27 at vger.kernel.org; Sat, 03 Feb 2018 07:45:10 EST Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway34.websitewelcome.com (Postfix) with ESMTP id EE2AE4DD609 for ; Sat, 3 Feb 2018 06:22:28 -0600 (CST) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id hwpweBY5P0aRHhwpweWY5P; Sat, 03 Feb 2018 06:22:28 -0600 Received: from gator4166.hostgator.com ([108.167.133.22]:28576) by gator4166.hostgator.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89_1) (envelope-from ) id 1ehwpw-002EDK-JN; Sat, 03 Feb 2018 06:22:28 -0600 Received: from 189.152.201.65 ([189.152.201.65]) by gator4166.hostgator.com (Horde Framework) with HTTPS; Sat, 03 Feb 2018 06:22:28 -0600 Date: Sat, 03 Feb 2018 06:22:28 -0600 Message-ID: <20180203062228.Horde.Yi_1isNJ5NW9KaWlA9DyQsP@gator4166.hostgator.com> From: "Gustavo A. R. Silva" To: Rob Clark Cc: David Airlie , linux-arm-msm , dri-devel , freedreno , Linux Kernel Mailing List Subject: Re: [PATCH] drm/msm/adreno/a5xx_debugfs: fix potential NULL pointer dereference References: <20180202123223.GA4410@embeddedor.com> <20180202163006.GA878@jcrouse-lnx.qualcomm.com> In-Reply-To: User-Agent: Horde Application Framework 5 Content-Type: text/plain; charset=utf-8; format=flowed; DelSp=Yes MIME-Version: 1.0 Content-Disposition: inline X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 108.167.133.22 X-Source-L: Yes X-Exim-ID: 1ehwpw-002EDK-JN X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: gator4166.hostgator.com [108.167.133.22]:28576 X-Source-Auth: garsilva@embeddedor.com X-Email-Count: 6 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Rob Clark : > On Fri, Feb 2, 2018 at 11:30 AM, Jordan Crouse > wrote: >> On Fri, Feb 02, 2018 at 06:32:23AM -0600, Gustavo A. R. Silva wrote: >>> _minor_ is being dereferenced before it is null checked, hence there >>> is a potential null pointer dereference. Fix this by moving the pointer >>> dereference after _minor_ has been null checked. >>> >>> Fixes: 024ad8df763f ("drm/msm: add a5xx specific debugfs") >>> Signed-off-by: Gustavo A. R. Silva >>> --- >>> >>> I wonder if a better solution for this would be to WARN_ON in case _minor_ >>> happens to be NULL and return -EINVAL, instead of just returning zero. >>> >>> Something like: >>> >>> struct drm_device *dev; >>> >>> if (WARN_ON(!minor) >>> return -EINVAL; >>> >>> dev = minor->dev; >>> >>> What do you think? >> >> In my opinion everything in debugfs is optional. I'm not sure if it is even >> possible for dev->primary, dev->render or dev->control to be NULL >> from the DRM >> core but if so I think the failure should be silent. >> > > Don't have code in front of me atm, but I think this is one of those > things you can hit both before and after we have the minor, depending > on whether filesystem and fw are present when the driver loads or > not.. so I don't think it should be a WARN_ON(). > I get it. Then in this case this patch should work just fine. Thank you both Jordan and Rob for the feedback. -- Gustavo > BR, > -R > > >> Jordan >>> >>> drivers/gpu/drm/msm/adreno/a5xx_debugfs.c | 4 +++- >>> 1 file changed, 3 insertions(+), 1 deletion(-) >>> >>> diff --git a/drivers/gpu/drm/msm/adreno/a5xx_debugfs.c >>> b/drivers/gpu/drm/msm/adreno/a5xx_debugfs.c >>> index 6b27941..059ec7d 100644 >>> --- a/drivers/gpu/drm/msm/adreno/a5xx_debugfs.c >>> +++ b/drivers/gpu/drm/msm/adreno/a5xx_debugfs.c >>> @@ -159,13 +159,15 @@ DEFINE_SIMPLE_ATTRIBUTE(reset_fops, NULL, >>> reset_set, "%llx\n"); >>> >>> int a5xx_debugfs_init(struct msm_gpu *gpu, struct drm_minor *minor) >>> { >>> - struct drm_device *dev = minor->dev; >>> + struct drm_device *dev; >>> struct dentry *ent; >>> int ret; >>> >>> if (!minor) >>> return 0; >>> >>> + dev = minor->dev; >>> + >>> ret = drm_debugfs_create_files(a5xx_debugfs_list, >>> ARRAY_SIZE(a5xx_debugfs_list), >>> minor->debugfs_root, minor); >>> -- >>> 2.7.4 >>> >>> -- >>> To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in >>> the body of a message to majordomo@vger.kernel.org >>> More majordomo info at http://vger.kernel.org/majordomo-info.html >> >> -- >> The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, >> a Linux Foundation Collaborative Project