Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2002404ybh; Fri, 24 Jul 2020 01:48:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnbGVJmtZjx3QNmEdn9dT+cGRQe8JnS0qzI/PZ2xzBksgqcHTJtTUAr8S0WC/arlpLhCY6 X-Received: by 2002:aa7:d7cf:: with SMTP id e15mr8123758eds.236.1595580531473; Fri, 24 Jul 2020 01:48:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595580531; cv=none; d=google.com; s=arc-20160816; b=M1Iy8x02ROiVduyd0hC23yy6TETqQ+4MXwk5rASpymRPAAEyhIDWsLez4ZOLh0317X aK/LXR+4fS612e+GKXwfW5qw5Cr53bBCxjGz72tlU56spbatz8IYLxricU7JY/t147l5 tb6OSTdPD9IVssz0udySRSMyxmpPUN4YQinbNn/7gd5z32HwtcRB/VsZyETWPx1atpQf ONX6b9m8s7iICGBYF3hzfnuipLZmiAFRElxccN3QBTdx8J8V5Y3AFVifhb6s78mYDDbM sWYE50EDrL0ikWoUTaPivxJdZVPf1h/ZQU/gEPuhIIanwXzIXkmj87mdtVo2I1c0m0R+ X9nA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=E9xWl2oCmw9fyhHWHPc6b3uDFah8y83MU0G9dJHaMwk=; b=OFjY9lln+bkhgrlrivm3IHBGcM+h8b4vgApdGDm5ZuRGcvUMJxj8ZfomgopE4Uqpm5 1eo58mikOl66wCkbo87Sa2QCGXbSUpsVuH9v6zKbXhSjkkzPzFuWwy/1oHME54IQTZ7T o1WPvOG5LPTkxt9f4fj4Fnz2E/PPtXQdmiPOdBnC8lVc7NYwea0MzfgqzgOSz36tfSF/ FVWSCO05VOwhKmCQmOVe76OQj3I5o20q7QSfJrp2wFwKUBRKfWm6Vh5J4oLWXxrlfTWE OMNgRHG0B0Z2bAk1eQ8tkvbJG+m5A9qYJKTQAfxvtYbtpSbtfnDBYU3RUDWLPY//OtL+ WQvQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q5si117071edr.260.2020.07.24.01.48.28; Fri, 24 Jul 2020 01:48:51 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727075AbgGXIsQ (ORCPT + 99 others); Fri, 24 Jul 2020 04:48:16 -0400 Received: from mga02.intel.com ([134.134.136.20]:45604 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727029AbgGXIsP (ORCPT ); Fri, 24 Jul 2020 04:48:15 -0400 IronPort-SDR: EbfMPQwg4Zhr0nHhDAji4a/Qxg6/mL94Wee3GnuJJwglFMdzl32V6SyJcavybvVDeItMCvu0ET 7qztkk8f/DBg== X-IronPort-AV: E=McAfee;i="6000,8403,9691"; a="138742743" X-IronPort-AV: E=Sophos;i="5.75,390,1589266800"; d="scan'208";a="138742743" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2020 01:48:15 -0700 IronPort-SDR: AM5U8/31lxHM7oT2Jt4jv/KUaOQpNogLBYumBLk+JrltvIM4JwnC7RHjhNzpnT/TnLFyXBcPic LFnb31qunmSg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,390,1589266800"; d="scan'208";a="311335289" Received: from silpixa00400314.ir.intel.com (HELO silpixa00400314.ger.corp.intel.com) ([10.237.222.51]) by fmsmga004.fm.intel.com with ESMTP; 24 Jul 2020 01:48:12 -0700 From: Giovanni Cabiddu To: alex.williamson@redhat.com, herbert@gondor.apana.org.au Cc: cohuck@redhat.com, nhorman@redhat.com, vdronov@redhat.com, bhelgaas@google.com, mark.a.chambers@intel.com, gordon.mcfadden@intel.com, ahsan.atta@intel.com, fiona.trahe@intel.com, qat-linux@intel.com, kvm@vger.kernel.org, linux-crypto@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Giovanni Cabiddu Subject: [PATCH v4 2/5] vfio/pci: Add device denylist Date: Fri, 24 Jul 2020 09:47:57 +0100 Message-Id: <20200724084800.6136-3-giovanni.cabiddu@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200724084800.6136-1-giovanni.cabiddu@intel.com> References: <20200724084800.6136-1-giovanni.cabiddu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add denylist of devices that by default are not probed by vfio-pci. Devices in this list may be susceptible to untrusted application, even if the IOMMU is enabled. To be accessed via vfio-pci, the user has to explicitly disable the denylist. The denylist can be disabled via the module parameter disable_denylist. Signed-off-by: Giovanni Cabiddu --- drivers/vfio/pci/vfio_pci.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 7c0779018b1b..0101f41e7834 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -60,6 +60,10 @@ module_param(enable_sriov, bool, 0644); MODULE_PARM_DESC(enable_sriov, "Enable support for SR-IOV configuration. Enabling SR-IOV on a PF typically requires support of the userspace PF driver, enabling VFs without such support may result in non-functional VFs or PF."); #endif +static bool disable_denylist; +module_param(disable_denylist, bool, 0444); +MODULE_PARM_DESC(disable_denylist, "Disable use of device denylist. Disabling the denylist allows binding to devices with known errata that may lead to exploitable stability or security issues when accessed by untrusted users."); + static inline bool vfio_vga_disabled(void) { #ifdef CONFIG_VFIO_PCI_VGA @@ -69,6 +73,29 @@ static inline bool vfio_vga_disabled(void) #endif } +static bool vfio_pci_dev_in_denylist(struct pci_dev *pdev) +{ + return false; +} + +static bool vfio_pci_is_denylisted(struct pci_dev *pdev) +{ + if (!vfio_pci_dev_in_denylist(pdev)) + return false; + + if (disable_denylist) { + pci_warn(pdev, + "device denylist disabled - allowing device %04x:%04x.\n", + pdev->vendor, pdev->device); + return false; + } + + pci_warn(pdev, "%04x:%04x exists in vfio-pci device denylist, driver probing disallowed.\n", + pdev->vendor, pdev->device); + + return true; +} + /* * Our VGA arbiter participation is limited since we don't know anything * about the device itself. However, if the device is the only VGA device @@ -1847,6 +1874,9 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) struct iommu_group *group; int ret; + if (vfio_pci_is_denylisted(pdev)) + return -EINVAL; + if (pdev->hdr_type != PCI_HEADER_TYPE_NORMAL) return -EINVAL; @@ -2336,6 +2366,9 @@ static int __init vfio_pci_init(void) vfio_pci_fill_ids(); + if (disable_denylist) + pr_warn("device denylist disabled.\n"); + return 0; out_driver: -- 2.26.2