diff options
author | Venkatesh Srinivas <venkateshs@google.com> | 2019-01-23 06:27:51 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-01-31 10:22:51 -0500 |
commit | 865a11f987ab5f03089b2728420b61a2a1f7051a (patch) | |
tree | 297392fb063a48e7b8faa6db2759453703dc6030 /drivers/uio | |
parent | e5bae74338b37fb88d33d7c18acb694670c24b09 (diff) |
uio/uio_pci_generic: Disable bus-mastering on release
Userspace code using uio_pci_generic may enable bus-mastering by
directly manipulating a PCI device's command register. If a userspace
program enables bus-mastering but exits/crashes uncleanly, bus-
mastering will still be enabled and stale DMA addresses may be
programmed and live in the device.
Disable bus-mastering unconditionally on last close of a UIO PCI fd
to avoid this. If the device did not have bus-mastering enabled,
pci_clear_master() is a no-op.
Signed-off-by: Venkatesh Srinivas <venkateshs@google.com>
Reviewed-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Catherine Sullivan <csully@google.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/uio')
-rw-r--r-- | drivers/uio/uio_pci_generic.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/drivers/uio/uio_pci_generic.c b/drivers/uio/uio_pci_generic.c index 8773e373ffe5..dde5cbb27178 100644 --- a/drivers/uio/uio_pci_generic.c +++ b/drivers/uio/uio_pci_generic.c | |||
@@ -39,6 +39,22 @@ to_uio_pci_generic_dev(struct uio_info *info) | |||
39 | return container_of(info, struct uio_pci_generic_dev, info); | 39 | return container_of(info, struct uio_pci_generic_dev, info); |
40 | } | 40 | } |
41 | 41 | ||
42 | static int release(struct uio_info *info, struct inode *inode) | ||
43 | { | ||
44 | struct uio_pci_generic_dev *gdev = to_uio_pci_generic_dev(info); | ||
45 | |||
46 | /* | ||
47 | * This driver is insecure when used with devices doing DMA, but some | ||
48 | * people (mis)use it with such devices. | ||
49 | * Let's at least make sure DMA isn't left enabled after the userspace | ||
50 | * driver closes the fd. | ||
51 | * Note that there's a non-zero chance doing this will wedge the device | ||
52 | * at least until reset. | ||
53 | */ | ||
54 | pci_clear_master(gdev->pdev); | ||
55 | return 0; | ||
56 | } | ||
57 | |||
42 | /* Interrupt handler. Read/modify/write the command register to disable | 58 | /* Interrupt handler. Read/modify/write the command register to disable |
43 | * the interrupt. */ | 59 | * the interrupt. */ |
44 | static irqreturn_t irqhandler(int irq, struct uio_info *info) | 60 | static irqreturn_t irqhandler(int irq, struct uio_info *info) |
@@ -78,6 +94,7 @@ static int probe(struct pci_dev *pdev, | |||
78 | 94 | ||
79 | gdev->info.name = "uio_pci_generic"; | 95 | gdev->info.name = "uio_pci_generic"; |
80 | gdev->info.version = DRIVER_VERSION; | 96 | gdev->info.version = DRIVER_VERSION; |
97 | gdev->info.release = release; | ||
81 | gdev->pdev = pdev; | 98 | gdev->pdev = pdev; |
82 | if (pdev->irq) { | 99 | if (pdev->irq) { |
83 | gdev->info.irq = pdev->irq; | 100 | gdev->info.irq = pdev->irq; |