Received: by 10.213.65.68 with SMTP id h4csp63787imn; Wed, 21 Mar 2018 12:26:55 -0700 (PDT) X-Google-Smtp-Source: AG47ELtSeYVnXOG9l5tPqL71npnJd0R4ujXgabN+AszHluWqqEffuvdRAyUUppsjMDYbCfm4MpUR X-Received: by 2002:a17:902:41:: with SMTP id 59-v6mr22260577pla.248.1521660415602; Wed, 21 Mar 2018 12:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521660415; cv=none; d=google.com; s=arc-20160816; b=T9iFzM7TyEtu2nQLlLDteQS3BLTXBXHHufwSt7mmHPWSFYil9RSdG9aViGvFoEKdcj O0Z0LNBeVeWt/JyE+a+kF/LnRxjNMINVz2lioy+4ZTkEdRJfdNFs3E4nVtLDuYvffGVx JXhg7HD26P/+VIBrL7uexVLzLeZoHZEaU8Dj2Md3uGFI2Mm+2AtFpIS0XMHt40CdlzJ7 T3/UTsWsO17Y28bMiGEUPL6uHk1nl+PWs1UfeMIqMzcAI6ifG6v1Jftwv9kD9j9XkWXp 8lsiipkRtBgBwlufqQMk3OTQyb72lUHHkyHMvw2EK7s6RcsMEzal+V7M4llMjJ8qQbjn OLXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=URId3c2WmqYYhZly86thzcCK1V0EQSmYklCk1RowXBg=; b=Tk4Cc6p7TaE79IfnCR0DfXJp7Cv9TORSJJB9MDrHp9X72DA2ZSZzyvhNtGc9WMXTQX wPrEQRX98i4YgadRxul8E80Lp7ugs+Ezx36l17HCLhlmHDNsMEMlcHpJkbW5VEwlbtOM Hh/o1woKdKWbtryz5gT/VJUQpkfQAW3GIJ3kX1BWlojveVPEgAO8x1xguv/40X8JN70H 7hRVZGVVYz0HRWjQbxBWkYos/4j4VRrRfnDgyZIvJJ5m1TNynrKbklwjFxCmAiM/kaD1 aDigw4VtNXCFMmI2fbn0zFdqGyGNOqYoXpHmU3zqyrezlTYuBD5jiDXvVEvYlMGNRKb5 DgNA== 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 y12si3531720pfk.42.2018.03.21.12.26.26; Wed, 21 Mar 2018 12:26:55 -0700 (PDT) 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 S1753419AbeCUTYb (ORCPT + 99 others); Wed, 21 Mar 2018 15:24:31 -0400 Received: from smtprelay0091.hostedemail.com ([216.40.44.91]:42771 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753348AbeCUTYP (ORCPT ); Wed, 21 Mar 2018 15:24:15 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay07.hostedemail.com (Postfix) with ESMTP id 63AB1181D330D; Wed, 21 Mar 2018 19:24:14 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::::,RULES_HIT:41:355:379:541:599:800:960:968:973:981:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2692:2828:3138:3139:3140:3141:3142:3355:3622:3865:3866:3867:3868:3870:3871:3872:3874:4321:5007:6238:7208:7576:7903:8957:9113:9707:10004:10400:10848:11026:11232:11473:11657:11658:11914:12043:12048:12438:12555:12740:12760:12895:12986:13153:13228:13439:14093:14097:14181:14659:14721:21080:21433:21451:21627:21740:30054:30055:30070:30090:30091,0,RBL:47.151.150.235:@perches.com:.lbl8.mailshell.net-62.8.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: watch83_24a2fef5a020f X-Filterd-Recvd-Size: 3782 Received: from XPS-9350 (unknown [47.151.150.235]) (Authenticated sender: joe@perches.com) by omf07.hostedemail.com (Postfix) with ESMTPA; Wed, 21 Mar 2018 19:24:11 +0000 (UTC) Message-ID: <1521660250.7999.29.camel@perches.com> Subject: Re: [PATCH] drm/i915/gvt: don't dereference 'workload' before null checking it From: Joe Perches To: Colin Ian King , Zhenyu Wang , Zhi Wang , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie , intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 21 Mar 2018 12:24:10 -0700 In-Reply-To: References: <20180321190653.3829-1-colin.king@canonical.com> <1521659361.7999.27.camel@perches.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.26.1-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2018-03-21 at 19:18 +0000, Colin Ian King wrote: > On 21/03/18 19:09, Joe Perches wrote: > > On Wed, 2018-03-21 at 19:06 +0000, Colin King wrote: > > > From: Colin Ian King > > > > > > The pointer workload is dereferenced before it is null checked, hence > > > there is a potential for a null pointer dereference on workload. Fix > > > this by only dereferencing workload after it is null checked. > > > > > > Detected by CoverityScan, CID#1466017 ("Dereference before null check") > > > > Maybe true, but is it possible for workload to be null? > > Maybe the null test should be removed instead. > > From what I understand from the static analysis, there may be a > potential for workload to be null, I couldn't rule it out so I went with > the more paranoid stance of keeping the null check in. workload cannot be null here. Look at the uses of sr_oa_regs and see that workload has already been dereferenced. > > > > > Fixes: fa3dd623e559 ("drm/i915/gvt: keep oa config in shadow ctx") > > > Signed-off-by: Colin Ian King > > > --- > > > drivers/gpu/drm/i915/gvt/scheduler.c | 10 +++++++--- > > > 1 file changed, 7 insertions(+), 3 deletions(-) > > > > > > diff --git a/drivers/gpu/drm/i915/gvt/scheduler.c b/drivers/gpu/drm/i915/gvt/scheduler.c > > > index 068126404151..f3010e365a48 100644 > > > --- a/drivers/gpu/drm/i915/gvt/scheduler.c > > > +++ b/drivers/gpu/drm/i915/gvt/scheduler.c > > > @@ -60,9 +60,9 @@ static void set_context_pdp_root_pointer( > > > static void sr_oa_regs(struct intel_vgpu_workload *workload, > > > u32 *reg_state, bool save) > > > { > > > - struct drm_i915_private *dev_priv = workload->vgpu->gvt->dev_priv; > > > - u32 ctx_oactxctrl = dev_priv->perf.oa.ctx_oactxctrl_offset; > > > - u32 ctx_flexeu0 = dev_priv->perf.oa.ctx_flexeu0_offset; > > > + struct drm_i915_private *dev_priv; > > > + u32 ctx_oactxctrl; > > > + u32 ctx_flexeu0; > > > int i = 0; > > > u32 flex_mmio[] = { > > > i915_mmio_reg_offset(EU_PERF_CNTL0), > > > @@ -77,6 +77,10 @@ static void sr_oa_regs(struct intel_vgpu_workload *workload, > > > if (!workload || !reg_state || workload->ring_id != RCS) > > > return; > > > > > > + dev_priv = workload->vgpu->gvt->dev_priv; > > > + ctx_oactxctrl = dev_priv->perf.oa.ctx_oactxctrl_offset; > > > + ctx_flexeu0 = dev_priv->perf.oa.ctx_flexeu0_offset; > > > + > > > if (save) { > > > workload->oactxctrl = reg_state[ctx_oactxctrl + 1]; > > > > >