Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2468411pxb; Mon, 19 Apr 2021 06:30:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTJMV1noCuEuBLR5QbyuEeUbiSbmlp5bH5YH6cRYNKc8BlV0n7h0pwGE1Re3lc1bH8VCvC X-Received: by 2002:a05:6402:1698:: with SMTP id a24mr11979144edv.62.1618839034374; Mon, 19 Apr 2021 06:30:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618839034; cv=none; d=google.com; s=arc-20160816; b=jg7q6tRMjAZTLld8V5/4lkH7tH7zJYIvgUXkH2OnT1Zj51UBtBL86IHkitU4c/EazE kBHjLxKk0lJaEoFwm3qSp87IrlKnwDkArVwrlUFzDzr3sTFFXReU15Prb1PVpi9axDh1 Lt7m6nZ0IqSa1p4RGsMmUXovHAy11F1o00+1bOp79nnYE8lBMuzbbaXOvzdINk1/Si8Z FnM5qy9BtZggUs5EA4YJRKLOFQf6wA6kcepdEd0tQ5NvCa1CYXxoW5V9Tpd/ug/BsOas IkC8zZtdWli5IG3xwbGLIB+FXNnev9Ajm90zQ+RlQfDYmGcVFl00RTlKFSQQrlBzcZpX /EwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=F7etvW1Ei3z0wIBtZsM2SHvszyBIGE9sIAgfPsZQsHI=; b=gA9FJ/d91wST8AfvZwD8Uj34bYDArMWJl+J4tjstFIPAd8nttKFOAVCuQcCqh0OxeE Z2T4mKd8OW1fPIned6ppuKOYebz4kJFZGEdOuxK5tDy2xmyroJVBeVEDoP+5kdQ8MIJ8 7BrYammUZxMSBR83c/X1MGlKwKB83EZowXh+XjjvzbXEgVYoPghI1EfUma8/qSjqm9cz g35htKOAfrDUBunwEqsyYj7mWVffAWa+xQVDUCgvFsJrGvpfrFKziOcJYZ9AC0LLldZo dnqapqGnEMVVke5pcCyXKD2ym0DNNRbCxILciy3KllaUyYBgJ4TwVA5w3PKlIqL9iwtu xfMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tuQ5Tha4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id zo17si12303679ejb.1.2021.04.19.06.30.08; Mon, 19 Apr 2021 06:30:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tuQ5Tha4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241365AbhDSN1x (ORCPT + 99 others); Mon, 19 Apr 2021 09:27:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:56846 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241117AbhDSNTz (ORCPT ); Mon, 19 Apr 2021 09:19:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A8AC3613C7; Mon, 19 Apr 2021 13:15:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618838130; bh=m83Jsjv1frtpyFiCelm+5L0QoMSJo7QdUF1BOkmsDbw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tuQ5Tha4nZTGsCW4OW63I6akkUkZRNgvhnm/dZpbYALSeKueB95dQEKcZOFAL72ad 69/DAWl6w4GUq+VHUdG/4xycYBwi8oyiLmo9jjYGmqGV+uugm9jsySqAQ0SESUSKMK kVgYDppAIzXMh9+0s6IlIi5xGcTdEV2DWkcs75QI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Christian A. Ehrhardt" , David Gibson , Cornelia Huck , Alex Williamson Subject: [PATCH 5.10 054/103] vfio/pci: Add missing range check in vfio_pci_mmap Date: Mon, 19 Apr 2021 15:06:05 +0200 Message-Id: <20210419130529.664687421@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210419130527.791982064@linuxfoundation.org> References: <20210419130527.791982064@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christian A. Ehrhardt commit 909290786ea335366e21d7f1ed5812b90f2f0a92 upstream. When mmaping an extra device region verify that the region index derived from the mmap offset is valid. Fixes: a15b1883fee1 ("vfio_pci: Allow mapping extra regions") Cc: stable@vger.kernel.org Signed-off-by: Christian A. Ehrhardt Message-Id: <20210412214124.GA241759@lisa.in-ulm.de> Reviewed-by: David Gibson Reviewed-by: Cornelia Huck Signed-off-by: Alex Williamson Signed-off-by: Greg Kroah-Hartman --- drivers/vfio/pci/vfio_pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -1658,6 +1658,8 @@ static int vfio_pci_mmap(void *device_da index = vma->vm_pgoff >> (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT); + if (index >= VFIO_PCI_NUM_REGIONS + vdev->num_regions) + return -EINVAL; if (vma->vm_end < vma->vm_start) return -EINVAL; if ((vma->vm_flags & VM_SHARED) == 0) @@ -1666,7 +1668,7 @@ static int vfio_pci_mmap(void *device_da int regnum = index - VFIO_PCI_NUM_REGIONS; struct vfio_pci_region *region = vdev->region + regnum; - if (region && region->ops && region->ops->mmap && + if (region->ops && region->ops->mmap && (region->flags & VFIO_REGION_INFO_FLAG_MMAP)) return region->ops->mmap(vdev, region, vma); return -EINVAL;