Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6270087imu; Mon, 21 Jan 2019 06:09:07 -0800 (PST) X-Google-Smtp-Source: ALg8bN5dxm0ONBv5EgsnkrKkCRqWXbAotmUQ5PqtgQFS+3/6EmnLxN5lqmIYxrAbECBg83FCsCeG X-Received: by 2002:a17:902:7044:: with SMTP id h4mr30101887plt.35.1548079747206; Mon, 21 Jan 2019 06:09:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548079747; cv=none; d=google.com; s=arc-20160816; b=XW8En1aJUekGuKACSYCELJ7iT7xO+RVwzSmnCkIt6iCJhpMMgE3iTXaKt2DMwtd0Rc TOJr0p871QmjEp9IZc7q1W+GNCkbmg7MUgQ1WhUSdcggMA9/ya6TYY76WbHj8Ve97h2d OdKZtfnp75FbXFaMuLBfZS7850NWcbqjJRoIhHQiDr84aYAv55pQM2VRaVHgwUMzWY5R E+n/VPg5md5q6pO5CQgeg8nYeE3KldvRd7LeQ5B8ko4vJ2ris5xg9RBN/S/1jrm+jiHS 5WL/c0Jt91Sh9pijMEJW0PP+kzTyB+Qw7v6pM+ZEMI1Ybx/574idriWDhLFdnYvtpq1p DBwA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cReFj0CA+nrd0AQ/j8Rql+9IKjywqoNhDSQMm2FOaDc=; b=ZvpvfglzojLtXXv032MZLgXJH9WCzWFgHmw6KTGFD855s5EH+ILrYK220BnASw35tM q/6DoWHHKJk69nCQ8KOvvR5iG/C1haQjJsIZAERhl/SrGIbDq0o2VdRXNlKvHSNro4eZ 8A4D2jC+bEJJa3+e2LDczzxhXd0HjZZJUSSVKwjteFoSTjycCir170RrbDHY9qRtL7Mp eAnWQuvGc8qscYV4CQ9beGPLjy3n2mNUEQSPxu3AgQIgAcqFDHPJpIJh1UG/QcXUsRfq Zmgorq6z6MDomsyuDgNIN9BPmHXGUz6d3/feIL5kQQ9yEm9yjcnfM5ykxd4Ol/ud/oJk JAww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FFbMfr1T; 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 3si12489771plv.258.2019.01.21.06.08.52; Mon, 21 Jan 2019 06:09:07 -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; dkim=pass header.i=@kernel.org header.s=default header.b=FFbMfr1T; 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 S1732325AbfAUOAR (ORCPT + 99 others); Mon, 21 Jan 2019 09:00:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:46718 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732339AbfAUOAP (ORCPT ); Mon, 21 Jan 2019 09:00:15 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E69512084C; Mon, 21 Jan 2019 14:00:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548079214; bh=bH7m0xXyEh4jBRVdJ50knXNSm5tafn4UecEOSK3lRfE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FFbMfr1TnTSpa3SStHCK0t1+yFyJc+JtlvK104pon+ISKrdCwPe64h7Ej1MGTDSe6 vejC5L+B9AW3Gy7irXNl0H+QxpjAVopO7KbulIdgQzhmOy2/8aHIyQBE8mUaDpAEnh 7X4NJ/nP+UxGmjs9JngYLd67tppLecBMQ2zOktJc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Monroy, Rodrigo Axel" , "Orrala Contreras, Alfredo" , Hang Yuan , Zhenyu Wang Subject: [PATCH 4.19 48/99] drm/i915/gvt: Fix mmap range check Date: Mon, 21 Jan 2019 14:48:40 +0100 Message-Id: <20190121134915.802139323@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121134913.924726465@linuxfoundation.org> References: <20190121134913.924726465@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhenyu Wang commit 51b00d8509dc69c98740da2ad07308b630d3eb7d upstream. This is to fix missed mmap range check on vGPU bar2 region and only allow to map vGPU allocated GMADDR range, which means user space should support sparse mmap to get proper offset for mmap vGPU aperture. And this takes care of actual pgoff in mmap request as original code always does from beginning of vGPU aperture. Fixes: 659643f7d814 ("drm/i915/gvt/kvmgt: add vfio/mdev support to KVMGT") Cc: "Monroy, Rodrigo Axel" Cc: "Orrala Contreras, Alfredo" Cc: stable@vger.kernel.org # v4.10+ Reviewed-by: Hang Yuan Signed-off-by: Zhenyu Wang Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/i915/gvt/kvmgt.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -996,7 +996,7 @@ static int intel_vgpu_mmap(struct mdev_d { unsigned int index; u64 virtaddr; - unsigned long req_size, pgoff = 0; + unsigned long req_size, pgoff, req_start; pgprot_t pg_prot; struct intel_vgpu *vgpu = mdev_get_drvdata(mdev); @@ -1014,7 +1014,17 @@ static int intel_vgpu_mmap(struct mdev_d pg_prot = vma->vm_page_prot; virtaddr = vma->vm_start; req_size = vma->vm_end - vma->vm_start; - pgoff = vgpu_aperture_pa_base(vgpu) >> PAGE_SHIFT; + pgoff = vma->vm_pgoff & + ((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1); + req_start = pgoff << PAGE_SHIFT; + + if (!intel_vgpu_in_aperture(vgpu, req_start)) + return -EINVAL; + if (req_start + req_size > + vgpu_aperture_offset(vgpu) + vgpu_aperture_sz(vgpu)) + return -EINVAL; + + pgoff = (gvt_aperture_pa_base(vgpu->gvt) >> PAGE_SHIFT) + pgoff; return remap_pfn_range(vma, virtaddr, pgoff, req_size, pg_prot); }