Received: by 10.213.65.68 with SMTP id h4csp59142imn; Wed, 21 Mar 2018 12:19:50 -0700 (PDT) X-Google-Smtp-Source: AG47ELuhT9dtE09f9SJhvanGFV4vG34W5a2Icx29nf/kr0/ZyKdiNNvn7ZntbIWf/X0KsDjH1UKi X-Received: by 2002:a17:902:5609:: with SMTP id h9-v6mr21807236pli.121.1521659990945; Wed, 21 Mar 2018 12:19:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521659990; cv=none; d=google.com; s=arc-20160816; b=IHHRxVNePQRsjV/XLDP3bkd4OyR3jxfevRXf2dDN5BLSKnFwLg03vp9O4BHi75zj0M NbFCYvph4XJItzuKLiWdjbZ/jIuU6bfJNjH36MVVLVKNXHUYKa/YTchplPk5CTq9lkax SI76eTj4BghuB/xfxkHLNxMgwLwfzTe03GvlSgJwwBU7ZAgyf7SVCp1P3q24oNhe8GhJ qAP7t8O8riNyyUanfez1O3jZCB9JF3gzPfAcKNWJtX9jOTAax8tzMRJEIvJvp06YVwOX fh1Q9EGB8n4ciCS5nibIbKPOLy0ois2AAY0m5BWUkHgkHBWEFR2IpiSQeq0ENNphSZEO x5Qg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=eqaEHMdOvNFFwduPpScuBvAbKDh/4PN3ANyPJrikkic=; b=RTPKgZRI6EaL2fP9CF8YiMaYgA7k/Pes8m+78+9MIrLGgU5k8nyrN/2OITlz/T/4E8 whaYgOvICKhHCCGSMq/Wr/rghPASu5/px3tdmxJk+r6SbhBxIdG+YN9HDA1LufaEzpSa TrdMHDmCOUW0ijhzkoIq3Wx7GKDq0CTvC/4BAvPSegYB3ZArHBW3RD9NzS/r8mjVYY7e hHi23xnnNVd2QaclAjRfEoS6zG268L9YWrcavUQfPBCY9l4rR3H0tbVUfqE1arlOvdu7 KY4XqSPnYE9UtzggHA+3EKXRP+N8cq6+0lZpNxefyOabj4wNulR5TyU3ptiGZon5H5fx LM0A== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p18si3103029pgv.334.2018.03.21.12.19.32; Wed, 21 Mar 2018 12:19:50 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752891AbeCUTSc (ORCPT + 99 others); Wed, 21 Mar 2018 15:18:32 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:54791 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752637AbeCUTSa (ORCPT ); Wed, 21 Mar 2018 15:18:30 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212]) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1eyjFl-0002KE-P5; Wed, 21 Mar 2018 19:18:29 +0000 Subject: Re: [PATCH] drm/i915/gvt: don't dereference 'workload' before null checking it To: Joe Perches , 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 References: <20180321190653.3829-1-colin.king@canonical.com> <1521659361.7999.27.camel@perches.com> From: Colin Ian King Message-ID: Date: Wed, 21 Mar 2018 19:18:28 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1521659361.7999.27.camel@perches.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > >> 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]; >>