uio: uio_pci_generic_sva: reject multiple opens
PATCH 1/1 uio: uio_pci_generic_sva: reject multiple opens
uio_pci_sva_open() stores an SVA binding handle in device-wide state. A second open from another address space overwrites that handle. Closing the two descriptors then unbinds the second handle twice and leaves the first binding active.
Reject another open while a binding is active and clear the handle on release. UIO core already serializes the callbacks under info_lock.
--- drivers/uio/uio_pci_generic_sva.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/uio/uio_pci_generic_sva.c +4 -0
@@ -32,6 +32,9 @@ static int uio_pci_sva_open(struct uio_info *info, struct inode *inode)if (!udev || !udev->pdev)return -ENODEV ; +if (udev->sva_handle) +return -EBUSY ; + domain =iommu_get_domain_for_dev (&udev->pdev->dev);if (domain)iommu_detach_device (domain, &udev->pdev->dev);
@@ -55,6 +58,7 @@ static int uio_pci_sva_release(struct uio_info *info, struct inode *inode)return -ENODEV ;iommu_sva_unbind_device (udev->sva_handle); + udev->sva_handle =NULL ;return 0 ; }
base-commit: 65ba8f34ec886ec72b2c07ddc8cf3d815c32869d
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerQuoted 7 lines · Avi Weiss
uio_pci_sva_open()stores an SVA binding handle in device-wide state. A second open from another address space overwrites that handle. Closing the two descriptors then unbinds the second handle twice and leaves the first binding active.Reject another open while a binding is active and clear the handle on release. UIO core already serializes the callbacks under
info_lock.
That's up to userspace to protect, as it can pass around file descriptors to other processes just fine, and the kernel can't do anything about that, so this type of change doesn't make much sense.
In other words, if you open the device multiple times, that's your problem, you get to keep both pieces :)
thanks,
greg k-h