Commit c037b6c8 authored by Rajat Jain's avatar Rajat Jain Committed by Greg Kroah-Hartman

PCI: Add sysfs "removable" attribute

A PCI device is "external_facing" if it's a Root Port with the ACPI
"ExternalFacingPort" property or if it has the DT "external-facing"
property.  We consider everything downstream from such a device to
be removable by user.

We're mainly concerned with consumer platforms with user accessible
Thunderbolt ports that are vulnerable to DMA attacks, and we expect those
ports to be identified by firmware as "ExternalFacingPort". Devices in
traditional hotplug slots can technically be removed, but the expectation
is that unless the port is marked with "ExternalFacingPort", such devices
are less accessible to user / may not be removed by end user, and thus not
exposed as "removable" to userspace.

This can be used to implement userspace policies tailored for
user removable devices. Eg usage:
https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2591812
https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2795038
(code uses such an attribute to remove external PCI devices or disable
features on them as needed by the policy desired)
Acked-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Signed-off-by: default avatarRajat Jain <rajatja@google.com>
Link: https://lore.kernel.org/r/20210524171812.18095-2-rajatja@google.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 70f400d4
...@@ -14,4 +14,5 @@ Description: ...@@ -14,4 +14,5 @@ Description:
Currently this is only supported by USB (which infers the Currently this is only supported by USB (which infers the
information from a combination of hub descriptor bits and information from a combination of hub descriptor bits and
platform-specific data such as ACPI). platform-specific data such as ACPI) and PCI (which gets this
from ACPI / device tree).
...@@ -1575,6 +1575,26 @@ static void set_pcie_untrusted(struct pci_dev *dev) ...@@ -1575,6 +1575,26 @@ static void set_pcie_untrusted(struct pci_dev *dev)
dev->untrusted = true; dev->untrusted = true;
} }
static void pci_set_removable(struct pci_dev *dev)
{
struct pci_dev *parent = pci_upstream_bridge(dev);
/*
* We (only) consider everything downstream from an external_facing
* device to be removable by the user. We're mainly concerned with
* consumer platforms with user accessible thunderbolt ports that are
* vulnerable to DMA attacks, and we expect those ports to be marked by
* the firmware as external_facing. Devices in traditional hotplug
* slots can technically be removed, but the expectation is that unless
* the port is marked with external_facing, such devices are less
* accessible to user / may not be removed by end user, and thus not
* exposed as "removable" to userspace.
*/
if (parent &&
(parent->external_facing || dev_is_removable(&parent->dev)))
dev_set_removable(&dev->dev, DEVICE_REMOVABLE);
}
/** /**
* pci_ext_cfg_is_aliased - Is ext config space just an alias of std config? * pci_ext_cfg_is_aliased - Is ext config space just an alias of std config?
* @dev: PCI device * @dev: PCI device
...@@ -1822,6 +1842,8 @@ int pci_setup_device(struct pci_dev *dev) ...@@ -1822,6 +1842,8 @@ int pci_setup_device(struct pci_dev *dev)
/* Early fixups, before probing the BARs */ /* Early fixups, before probing the BARs */
pci_fixup_device(pci_fixup_early, dev); pci_fixup_device(pci_fixup_early, dev);
pci_set_removable(dev);
pci_info(dev, "[%04x:%04x] type %02x class %#08x\n", pci_info(dev, "[%04x:%04x] type %02x class %#08x\n",
dev->vendor, dev->device, dev->hdr_type, dev->class); dev->vendor, dev->device, dev->hdr_type, dev->class);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment