Message ID | 20220104015644.2294354-1-baolu.lu@linux.intel.com (mailing list archive) |
---|---|
Headers | show |
Series | Fix BUG_ON in vfio_iommu_group_notifier() | expand |
On Tue, Jan 04, 2022 at 09:56:30AM +0800, Lu Baolu wrote: > v5: > - Move kernel dma ownership auto-claiming from driver core to bus > callback. (Greg) > - Refactor the iommu interfaces to make them more specific. > (Jason/Robin) > - Simplify the dma ownership implementation by removing the owner > type. (Jason) > - Commit message refactoring for PCI drivers. (Bjorn) > - Move iommu_attach/detach_device() improvement patches into another > series as there are a lot of code refactoring and cleanup staffs > in various device drivers. Since you already have the code you should make this 'other series' right now. It should delete iommu_group_attach() and fix iommu_device_attach(). You also didn't really do my suggestion, this messes up the normal __iommu_attach_group()/__iommu_detach_group() instead of adding the clear to purpose iommu_replace_group() for VFIO to use. This just makes it more difficult to normalize the APIs. Otherwise it does seem to have turned out to be more understandable. Jason
Hi Jason, On 1/4/22 8:48 PM, Jason Gunthorpe wrote: > On Tue, Jan 04, 2022 at 09:56:30AM +0800, Lu Baolu wrote: > >> v5: >> - Move kernel dma ownership auto-claiming from driver core to bus >> callback. (Greg) >> - Refactor the iommu interfaces to make them more specific. >> (Jason/Robin) >> - Simplify the dma ownership implementation by removing the owner >> type. (Jason) >> - Commit message refactoring for PCI drivers. (Bjorn) >> - Move iommu_attach/detach_device() improvement patches into another >> series as there are a lot of code refactoring and cleanup staffs >> in various device drivers. > > Since you already have the code you should make this 'other series' > right now. It should delete iommu_group_attach() and fix > iommu_device_attach(). Yes. I am doing the functional and compile tests. I will post it once I complete the testing. > > You also didn't really do my suggestion, this messes up the normal > __iommu_attach_group()/__iommu_detach_group() instead of adding the > clear to purpose iommu_replace_group() for VFIO to use. This just > makes it more difficult to normalize the APIs. I didn't forget that. :-) It's part of the new series. > > Otherwise it does seem to have turned out to be more understandable. > > Jason > Best regards, baolu
On 1/4/22 9:56 AM, Lu Baolu wrote: > Hi folks, > > The iommu group is the minimal isolation boundary for DMA. Devices in > a group can access each other's MMIO registers via peer to peer DMA > and also need share the same I/O address space. > > Once the I/O address space is assigned to user control it is no longer > available to the dma_map* API, which effectively makes the DMA API > non-working. > > Second, userspace can use DMA initiated by a device that it controls > to access the MMIO spaces of other devices in the group. This allows > userspace to indirectly attack any kernel owned device and it's driver. > > Therefore groups must either be entirely under kernel control or > userspace control, never a mixture. Unfortunately some systems have > problems with the granularity of groups and there are a couple of > important exceptions: > > - pci_stub allows the admin to block driver binding on a device and > make it permanently shared with userspace. Since PCI stub does not > do DMA it is safe, however the admin must understand that using > pci_stub allows userspace to attack whatever device it was bound > it. > > - PCI bridges are sometimes included in groups. Typically PCI bridges > do not use DMA, and generally do not have MMIO regions. > > Generally any device that does not have any MMIO registers is a > possible candidate for an exception. > > Currently vfio adopts a workaround to detect violations of the above > restrictions by monitoring the driver core BOUND event, and hardwiring > the above exceptions. Since there is no way for vfio to reject driver > binding at this point, BUG_ON() is triggered if a violation is > captured (kernel driver BOUND event on a group which already has some > devices assigned to userspace). Aside from the bad user experience > this opens a way for root userspace to crash the kernel, even in high > integrity configurations, by manipulating the module binding and > triggering the BUG_ON. > > This series solves this problem by making the user/kernel ownership a > core concept at the IOMMU layer. The driver core enforces kernel > ownership while drivers are bound and violations now result in a error > codes during probe, not BUG_ON failures. > > Patch partitions: > [PATCH 1-7]: Detect DMA ownership conflicts during driver binding; > [PATCH 8-10]: Add security context management for assigned devices; > [PATCH 11-14]: Various cleanups. > > This is also part one of three initial series for IOMMUFD: > * Move IOMMU Group security into the iommu layer > - Generic IOMMUFD implementation > - VFIO ability to consume IOMMUFD Thank you very much for your comments. A new version of this series has been posted here: https://lore.kernel.org/linux-iommu/20220218005521.172832-1-baolu.lu@linux.intel.com/ Best regards, baolu