3

I am looking into the protection provided by IOMMU against DMA attacks. I noticed that the Linux kernel provides a feature called bounce buffers for untrusted PCI devices (https://lwn.net/Articles/786558/) when the device drivers allocate memory that is not aligned with 4KiB pages. According to the article, it seems like all external devices are considered untrusted (it would be great if someone can confirm this is true for the latest Linux kernel as well, the article seems a few years old).

Is there a way to check which PCI devices are trusted and which devices are untrusted from inside the Linux kernel (command to check whether a particular device is trusted)? I just want to confirm how devices are identified by the kernel (as trusted or untrusted).

Also, is there a way to set internal PCI devices as untrusted in the current Linux kernel?

1 Answer 1

0

I checked the kernel source code and found that the pci_dev struct contains a member called untrusted.

If I read the code for the pci_get_device correctly you can get the pci_dev if you know the vendor and device id. These can be found via lspci -n

Using pci_get_device will increment the reference count for that device. Which you will need to decrement using pci_dev_put after you are done.

I would not recommend setting a pci device as untrusted this way.

PCI devices usually are controlled by a driver and you might interfere with its function, leading to unintended side effects.

For checking I would try this (untested):

const unsigned int VENDOR_ID = VVVV; // Replace VVVV with vendor id from lspci
const unsigned int DEVICE_ID = DDDD; // Replace DDDD with device id from lpsci

struct pci_dev * my_pdev = pci_get_device(VENDOR_ID, DEVICE_ID, null);

if (my_pdev->untrusted == 1) {
    pr_info("Device is untrusted\n");
} else {
    pr_info("Device is trusted\n");
}

pci_dev_put(my_pdev); 

Afterwards the result should be visible in the kernel buffer (dmesg)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .