Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp769800ybl; Thu, 23 Jan 2020 07:26:04 -0800 (PST) X-Google-Smtp-Source: APXvYqykOTuzOdaM0Uu4BT6sE7oHVuRKT+JQM61TmzVDpW+p9Al4lwUdmc8A0KlTyK410lD99ug6 X-Received: by 2002:a05:6808:53:: with SMTP id v19mr11245514oic.18.1579793164714; Thu, 23 Jan 2020 07:26:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579793164; cv=none; d=google.com; s=arc-20160816; b=WolyEcXfoEsxLrFKsDjMafwh+0n9YAdwaZsvyp+wj1X2ylrPgSPEBXmCZ9Cy5NsxC9 kuJaDF5ZBxijmnCipEVn+Zy/ApbueAE5FYp5A4kJgGNUFiqIPKey92ZZUWH4TfP1ocsf 28Hxx/mGALDG/BXrZqMlFWwyyFlKlgRt0y88/Dhldi1iDz+A0wHNJBecwEN1LPT5F3oB 4PD8/hq1UsP0+dcXTH9CdLhllLp04JImuKyOFQJSV3a/MAC87PdPfKj6d4qqzriqjoYL 3mQOnnW1HSzWxr+9uQ3JyDI17R/ZnEgqZM1z2TelgPoeOkhhYXOwYRpjuNEkrRMtq0G2 33yg== 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 :message-id:date:subject:cc:to:from; bh=V//7E+JAdR95M33ZT7p7gmYsIVimnkVvu+XVJBtz03U=; b=jFK/Zgo2fqhQwV3my9rFBQybQG3PQK9m1YASMPvCFaGgFpNO3pGCSQgLLGF5fWLpsQ zO/1Gi4SvINWd3d1JFP2waeZDT8VZC1Dzvay6kHAp+N3Irm6XJ0A/R0xhOOhytNUSpCj AqBv+Meh6mkYpXcs2Z9H5mexHJ7ofON+SgntEslcmASg5LdJikqFWjpC4owByvsdGRWG cXsHVpAQPYkjdX/J6PTlSXHb0OTDSSZg6YtAGJ91VA0QSq+DNgDqv+gEHkZftAoDL3Wa zDEhX9VkG8FvmUFUWpNmL9hXqQLlVDanFt9gE0cqy5lvEoa8EttlvveaSeAGyjDoXfo3 B6Og== 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 i6si1326479otp.5.2020.01.23.07.25.51; Thu, 23 Jan 2020 07:26:04 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728904AbgAWPOS (ORCPT + 99 others); Thu, 23 Jan 2020 10:14:18 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:43608 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727278AbgAWPOS (ORCPT ); Thu, 23 Jan 2020 10:14:18 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iueBK-0001Dl-AD; Thu, 23 Jan 2020 15:14:06 +0000 From: Colin King To: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie , Daniel Vetter , "Michael J . Ruhl" , Chris Wilson , Tvrtko Ursulin , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] drm/i915/gem: fix null pointer dereference on vm Date: Thu, 23 Jan 2020 15:14:06 +0000 Message-Id: <20200123151406.51679-1-colin.king@canonical.com> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King Currently if the call to function context_get_vm_rcu returns a null pointer for vm then the error exit path via label err_put will call i915_vm_put on the null vm, causing a null pointer dereference. Fix this by adding a null check on vm and returning without calling the i915_vm_put. Fixes: 5dbd2b7be61e ("drm/i915/gem: Convert vm idr to xarray") Signed-off-by: Colin Ian King --- drivers/gpu/drm/i915/gem/i915_gem_context.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c index 5d4157e1ccf7..3e6e34ec9fa8 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_context.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c @@ -1005,9 +1005,12 @@ static int get_ppgtt(struct drm_i915_file_private *file_priv, err = -ENODEV; rcu_read_lock(); vm = context_get_vm_rcu(ctx); - if (vm) - err = xa_alloc(&file_priv->vm_xa, &id, vm, - xa_limit_32b, GFP_KERNEL); + if (!vm) { + rcu_read_unlock(); + return err; + } + err = xa_alloc(&file_priv->vm_xa, &id, vm, + xa_limit_32b, GFP_KERNEL); rcu_read_unlock(); if (err) goto err_put; -- 2.24.0