From patchwork Thu Feb 15 09:45:02 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: 128398 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1558012ljc; Thu, 15 Feb 2018 01:48:05 -0800 (PST) X-Google-Smtp-Source: AH8x226cqX8QF5nnLrz56ANfjkoOGKo6YsdJa4VRKSQjbUCI+nJ+yzDVhphCzERiEbXv+iRGCVXg X-Received: by 10.101.70.69 with SMTP id k5mr1768728pgr.61.1518688085490; Thu, 15 Feb 2018 01:48:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518688085; cv=none; d=google.com; s=arc-20160816; b=cacY9P+F+MaU6t486xJmamZRw8AamJUn+YLRVgNWdheXDP1b3yicpAEw6ZGMrC4iGK E0Cq6j5W4akrt/ar8xbLVui9Xto3tdav7si91LalNUMLyAFxqZOPVEH5EzKa/Y/o5XUd GvvNUc5pDACA/zgOdF9oVmFnRjDpXHnLIwZ7oMklamT6XXuJ0htzTx5Avs3QMyvimnQo 8Q18Ex9DsIrSuQhi64Ii1D8kZPq5ixkVmcMtzoBjcDfliA6Rz5ey8nHHx/Ra+jeW8iIf dCX1jvUueVmfC9adskjHKVSFIIx8smMrMDzQ3izamj0ksz2Rq0S5G3KQ17an6wQfsWou Tjdg== 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=XrS8nbDW5EQTjAsoFt1auo83rno7Es2YVkLOdzanwII=; b=d7VBvk3/N4RnsWlewPSSGXbAFi7V252Mowekp/yRE8SQ/yYh68blTAaHIDTxd+Vvq2 5dMvlI5BbWh+Af2rD0gwPB9fGFQR2RYnR6BQ0E8ckL6J/LdpTb8rYjP+dwed+dA4z5Di YmSrhyAy05/diN3+bXysa9z/Tq8efGSPuiJAt91tpH//xA/86djMQEEaRnoQlT5cRM8r LURMWB2mN3yLrBZIVzDkKHPlcuSUkwAdegt9bcWE/i4UgIvCwTXFTDeqlQaa3A5wLoKj EF0iFJnNwD40uAO+/4Vmx4Gzwx1F+zWCqFaLoi5DTYKm5zWSw+e7vn5LGHvjkxaPXRl6 mTTA== 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 30-v6si1352272pla.812.2018.02.15.01.48.05; Thu, 15 Feb 2018 01:48:05 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967688AbeBOJrY (ORCPT + 28 others); Thu, 15 Feb 2018 04:47:24 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:51614 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1755343AbeBOJrQ (ORCPT ); Thu, 15 Feb 2018 04:47:16 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id BD08CD432DAE7; Thu, 15 Feb 2018 17:47:12 +0800 (CST) Received: from S00345302A-PC.china.huawei.com (10.202.227.237) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.361.1; Thu, 15 Feb 2018 17:47:04 +0800 From: Shameer Kolothum To: , , CC: , , , , , Shameer Kolothum Subject: [PATCH v3 4/6] vfio/type1: check dma map request is within a valid iova range Date: Thu, 15 Feb 2018 09:45:02 +0000 Message-ID: <20180215094504.4972-5-shameerali.kolothum.thodi@huawei.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20180215094504.4972-1-shameerali.kolothum.thodi@huawei.com> References: <20180215094504.4972-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 8d8ddd7..dae01c5 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -970,6 +970,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) { @@ -1008,6 +1025,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;