From patchwork Thu Mar 15 16:35:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shameerali Kolothum Thodi X-Patchwork-Id: 131821 Delivered-To: patch@linaro.org Received: by 10.80.210.197 with SMTP id q5csp1698307edg; Thu, 15 Mar 2018 09:38:59 -0700 (PDT) X-Google-Smtp-Source: AG47ELuCg6CR+VShbvmPSZLVLGkHwi9pqQeJQedJn+9owcphyVmQ+gTvnkan7PXsRRtzeFmmPbt5 X-Received: by 2002:a17:902:69ce:: with SMTP id m14-v6mr7812505pln.358.1521131939402; Thu, 15 Mar 2018 09:38:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521131939; cv=none; d=google.com; s=arc-20160816; b=ScuQfdXhAERHifPHHILBzmLUfZQtGgdutYQQXCU1WWwo84YU956raXFOoip2JE27uB /ilYO5l7ndbAAZbTrG5euE5unQhuoZd9kkXGcKBQrw6iqaSFxNVNVTPLOpS/cg4tciZi sVa73lu1yn/xSWpYg+sQznUmtuC84EiBjwBFKLyXBanx7+5BhpvIu7d3vzjiqUO0OxYH jJ7MX1La7mQJyvEzUXw1L+E10mMdQeA13inq/roma52+DSZpQNrZ5KanP8APq4CSyajp NgvQDBP3l6EApg02TrerBc2YDpVOjcHw70HScxQqqror6rVKoSCsKzhwxj4caAnfFQgj uUAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=c4bEcsrt7QIT/XX1gs7dW/M+sYF/aSEifXn0VsAwbBA=; b=HqUB3BwjmcjBNaqTt1XlQtjUgusA74MUC2pOFk6A/HYAxHmg07TuKyLsHxo+exhnwY X9GAYpB8Ih9/dV/pf4bWynukVfCQgo4xuF7yMG0LmMkqHxbZS116T6AzBOf97wydm1ZU Pb82F04qqp3VgS3omaJKiuoakdlYDAg1Clh7aeAhV1HGXfzqfd0XfQAkRXsc4/6VZnQ/ ahkOEYs5pQhR7/qFgRYEyYncH0xSztul+lRuOeHYcT/+NyeAM3TtKI5wdVKf/lX5G7Wt /XgYl1V645lxpYB6FbK/GfscrA4LNwtCPvhi3YDBME6vfUi1FoU4eAlxNcsOsa+ETIym 74Tw== 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 b10si3674019pgn.140.2018.03.15.09.38.59; Thu, 15 Mar 2018 09:38:59 -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 S1752333AbeCOQiY (ORCPT + 28 others); Thu, 15 Mar 2018 12:38:24 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:39687 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752158AbeCOQiN (ORCPT ); Thu, 15 Mar 2018 12:38:13 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 538006AB55BD0; Fri, 16 Mar 2018 00:37:59 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.202.227.237) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.361.1; Fri, 16 Mar 2018 00:37:54 +0800 From: Shameer Kolothum To: , , CC: , , , , , , Shameer Kolothum Subject: [PATCH v5 4/7] vfio/type1: check dma map request is within a valid iova range Date: Thu, 15 Mar 2018 16:35:06 +0000 Message-ID: <20180315163509.17740-5-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20180315163509.17740-1-shameerali.kolothum.thodi@huawei.com> References: <20180315163509.17740-1-shameerali.kolothum.thodi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.227.237] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This checks and rejects any dma map request outside valid iova range. Signed-off-by: Shameer Kolothum --- drivers/vfio/vfio_iommu_type1.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) -- 2.7.4 diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 25e6920..d59db31 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -982,6 +982,23 @@ static int vfio_pin_map_dma(struct vfio_iommu *iommu, struct vfio_dma *dma, return ret; } +/* + * Check dma map request is within a valid iova range + */ +static bool vfio_iommu_iova_dma_valid(struct vfio_iommu *iommu, + dma_addr_t start, dma_addr_t end) +{ + struct list_head *iova = &iommu->iova_list; + struct vfio_iova *node; + + list_for_each_entry(node, iova, list) { + if ((start >= node->start) && (end <= node->end)) + return true; + } + + return false; +} + static int vfio_dma_do_map(struct vfio_iommu *iommu, struct vfio_iommu_type1_dma_map *map) { @@ -1020,6 +1037,11 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu, goto out_unlock; } + if (!vfio_iommu_iova_dma_valid(iommu, iova, iova + size - 1)) { + ret = -EINVAL; + goto out_unlock; + } + dma = kzalloc(sizeof(*dma), GFP_KERNEL); if (!dma) { ret = -ENOMEM;