From patchwork Wed Apr 18 11:40:43 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: 133615 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp5776294ljb; Wed, 18 Apr 2018 04:44:16 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+1wvwIRlWtjfr4bH8bks8Az8ToJvbJq/avF0WmZemk51HcrXWyTYpOiMysPO7xCdglz87F X-Received: by 10.101.77.145 with SMTP id p17mr1484014pgq.275.1524051856371; Wed, 18 Apr 2018 04:44:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524051856; cv=none; d=google.com; s=arc-20160816; b=P7zxDs9C6tER2jTUQwPuwFAjQxeQmImVr2OM9fYQq4iawamEaOSWM9jKRVpVDq/FA4 tmcXnz4fMYSfUALQ0OG0szp+n/MFSNQ1M1mYMO4enLacpbKD0UiGmL57CsUw2So/JBwD jhIxmxiZk862VpcvpCuOzUrFTTUExPWojXRu5gDONrzaReHuPTOktYR/nAeitIVMTZUq 7XT9cXHvVIhjj0AQvUAzzMmwsbjcgwWvW9hIROS9x844ZI821iMNVeSO6HO4onjZTSxz 7+6lTB+1lTgnlpr8W7FXU7e98RHHiQodPcz9oCFx6ZUJ4+m8WEkICvUbdTbyw3EQ7a8W itgQ== 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=UM2lyCnUqJxsXLV3vRdUsI1uIb3I4qlUopzMyO1KhyQ=; b=mevi4qkh7cez2CJI24u5pO1iYCy/kcdZ/s5wqy2jadnqQ2dFmEC2kMZHDSCkBCYmPU da25P67r9CnjIJQdwncn/DUe5FgKbuy2VsgDOynQcJ5D+kRKEjNEPgeQGOkciZayOAig b05PG28imnp1czQUM+q5PSbSq+LcrzAiUFI3HRwhfIuSNCwdTOLR7vwUISP7yVeTvKjr U0ITxK3nH4w9Mf//4PIE9bidGKYZ19SGnyQAG7uQbNxpPMHFVY6AH3JfQEZSV9nTNz/3 xl8Yk3Ued1wW+h4LMyiAAnL9RgQNRoWgKPXZzS1bNbVQ7gkLEzac3IyIFVz7dQkbjLrt +viw== 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 f3-v6si1092917plf.446.2018.04.18.04.44.16; Wed, 18 Apr 2018 04:44:16 -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 S1754096AbeDRLoN (ORCPT + 29 others); Wed, 18 Apr 2018 07:44:13 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:7179 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754070AbeDRLoK (ORCPT ); Wed, 18 Apr 2018 07:44:10 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 64398AB964606; Wed, 18 Apr 2018 19:43:56 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.202.227.237) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.361.1; Wed, 18 Apr 2018 19:43:49 +0800 From: Shameer Kolothum To: , , CC: , , , , , , Shameer Kolothum Subject: [PATCH v6 5/7] vfio/type1: check dma map request is within a valid iova range Date: Wed, 18 Apr 2018 12:40:43 +0100 Message-ID: <20180418114045.7968-6-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20180418114045.7968-1-shameerali.kolothum.thodi@huawei.com> References: <20180418114045.7968-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 6fd6841..bf33281 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -1091,6 +1091,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) { @@ -1129,6 +1146,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;