From: Alan Cox <alan@lxorguk.ukuu.org.uk>
To: "Tom Lyon" <pugs@cisco.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
chrisw@sous-sol.org, joro@8bytes.org, hjk@linutronix.de,
mst@redhat.com, avi@redhat.com, gregkh@suse.de,
aafabbri@cisco.com, scofeldm@cisco.com
Subject: Re: [PATCH] VFIO driver: Non-privileged user level PCI drivers
Date: Mon, 31 May 2010 18:17:35 +0100 [thread overview]
Message-ID: <20100531181735.6bb71a5c@lxorguk.ukuu.org.uk> (raw)
In-Reply-To: <4c004cba.Z/2Hpd7reetFaFC5%pugs@cisco.com>
> +/*
> + * Map usr buffer at specific IO virtual address
> + */
> +static int vfio_dma_map_iova(
> + mlp = kzalloc(sizeof *mlp, GFP_KERNEL);
Not good at that point. I think you need to allocate it first, error if
it can't be allocated and then do the work and free it on error ?
> + mlp = kzalloc(sizeof *mlp, GFP_KERNEL);
> + mlp->pages = pages;
Ditto
> +int vfio_enable_msix(struct vfio_dev *vdev, int nvec, void __user *uarg)
> +{
> + struct pci_dev *pdev = vdev->pdev;
> + struct eventfd_ctx *ctx;
> + int ret = 0;
> + int i;
> + int fd;
> +
> + vdev->msix = kzalloc(nvec * sizeof(struct msix_entry),
> + GFP_KERNEL);
> + vdev->ev_msix = kzalloc(nvec * sizeof(struct eventfd_ctx *),
> + GFP_KERNEL);
These don't seem to get freed on the error path - or indeed protected
against being allocated twice (eg two parallel ioctls ?)
> + case VFIO_DMA_MAP_ANYWHERE:
> + case VFIO_DMA_MAP_IOVA:
> + if (copy_from_user(&dm, uarg, sizeof dm))
> + return -EFAULT;
> + ret = vfio_dma_map_common(listener, cmd, &dm);
> + if (!ret && copy_to_user(uarg, &dm, sizeof dm))
So the vfio_dma_map is untrusted. That seems to be checked ok later but
the dma_map_common code then plays in current->mm-> without apparently
holding any locks to stop the values getting corrupted by a parallel
mlock ?
Actually no I take that back
dmp->size is 64bit
So npage can end up with values like 0xFFFFFFFF and cause 32bit
boxes to go kerblam
> +
> + case VFIO_EVENTFD_IRQ:
> + if (copy_from_user(&fd, uarg, sizeof fd))
> + return -EFAULT;
> + if (vdev->ev_irq)
> + eventfd_ctx_put(vdev->ev_irq);
These paths need locking - suppose two EVENTFD irq ioctls occur at once
(in general these paths seem not to be covered)
>
> + case VFIO_BAR_LEN:
> + if (copy_from_user(&bar, uarg, sizeof bar))
> + return -EFAULT;
> + if (bar < 0 || bar > PCI_ROM_RESOURCE)
> + return -EINVAL;
> + bar = pci_resource_len(pdev, bar);
> + if (copy_to_user(uarg, &bar, sizeof bar))
> + return -EFAULT;
How does this all work out if the device is a bridge ?
> + pci_read_config_byte(pdev, PCI_INTERRUPT_LINE, &line);
> + if (line == 0)
> + goto out;
That may produce some interestingly wrong answers. Firstly the platform
has interrupt abstraction so dev->irq may not match PCI_INTERRUPT_LINE,
secondly you have devices that report their IRQ via other paths as per
spec (notably IDE class devices in non-native mode)
So that would also want extra checks.
> + pci_read_config_word(pdev, PCI_COMMAND, &orig);
> + ret = orig & PCI_COMMAND_MASTER;
> + if (!ret) {
> + new = orig | PCI_COMMAND_MASTER;
> + pci_write_config_word(pdev, PCI_COMMAND, new);
> + pci_read_config_word(pdev, PCI_COMMAND, &new);
> + ret = new & PCI_COMMAND_MASTER;
> + pci_write_config_word(pdev, PCI_COMMAND, orig);
The master bit on some devices can be turned on but not off. Not sure it
matters here.
> + vdev->pdev = pdev;
Probably best to take/drop a reference. Not needed if you can prove your
last use is before the end of the remove path though.
Does look like it needs a locking audit, some memory and error checks
reviewing and some further review of the ioctl security and
overflows/trusted values.
Rather a nice way of attacking the user space PCI problem.
next prev parent reply other threads:[~2010-05-31 17:10 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-28 23:07 Tom Lyon
2010-05-28 23:36 ` Randy Dunlap
2010-05-28 23:56 ` Randy Dunlap
2010-05-29 11:55 ` Arnd Bergmann
2010-05-29 12:16 ` Avi Kivity
2010-05-30 12:19 ` Michael S. Tsirkin
2010-05-30 12:27 ` Avi Kivity
2010-05-30 12:49 ` Michael S. Tsirkin
2010-05-30 13:01 ` Avi Kivity
2010-05-30 13:03 ` Michael S. Tsirkin
2010-05-30 13:13 ` Avi Kivity
2010-05-30 14:53 ` Michael S. Tsirkin
2010-05-31 11:50 ` Avi Kivity
2010-05-31 17:10 ` Michael S. Tsirkin
2010-06-01 8:10 ` Avi Kivity
2010-06-01 9:55 ` Michael S. Tsirkin
2010-06-01 10:28 ` Avi Kivity
2010-06-01 10:46 ` Michael S. Tsirkin
2010-06-01 12:41 ` Avi Kivity
2010-06-02 9:45 ` Joerg Roedel
2010-06-02 9:49 ` Avi Kivity
2010-06-02 10:04 ` Joerg Roedel
2010-06-02 10:09 ` Michael S. Tsirkin
2010-06-02 11:21 ` Avi Kivity
2010-06-02 16:53 ` Chris Wright
2010-06-06 13:44 ` Avi Kivity
2010-06-02 10:15 ` Michael S. Tsirkin
2010-06-02 10:26 ` Joerg Roedel
2010-06-01 21:26 ` Tom Lyon
2010-06-02 2:59 ` Avi Kivity
2010-06-02 5:29 ` Chris Wright
2010-06-02 5:40 ` Avi Kivity
2010-06-02 4:29 ` Alex Williamson
2010-06-02 4:59 ` Tom Lyon
2010-06-02 5:08 ` Avi Kivity
2010-06-02 9:53 ` Joerg Roedel
2010-06-02 9:42 ` Joerg Roedel
2010-06-02 9:50 ` Avi Kivity
2010-06-02 9:53 ` Michael S. Tsirkin
2010-06-02 10:19 ` Joerg Roedel
2010-06-02 10:21 ` Michael S. Tsirkin
2010-06-02 10:35 ` Joerg Roedel
2010-06-02 10:38 ` Michael S. Tsirkin
2010-06-02 11:12 ` Joerg Roedel
2010-06-02 11:21 ` Michael S. Tsirkin
2010-06-02 12:19 ` Joerg Roedel
2010-06-02 12:25 ` Avi Kivity
2010-06-02 12:50 ` Joerg Roedel
2010-06-02 13:06 ` Avi Kivity
2010-06-02 13:53 ` Joerg Roedel
2010-06-02 13:17 ` Michael S. Tsirkin
2010-06-02 14:01 ` Joerg Roedel
2010-06-02 12:34 ` Michael S. Tsirkin
2010-06-02 13:02 ` Joerg Roedel
2010-06-02 17:46 ` Chris Wright
2010-06-02 18:09 ` Tom Lyon
2010-06-02 19:46 ` Joerg Roedel
2010-06-03 6:23 ` Avi Kivity
2010-06-03 21:41 ` Tom Lyon
2010-06-06 9:54 ` Michael S. Tsirkin
2010-06-07 19:01 ` Tom Lyon
2010-06-08 21:22 ` Michael S. Tsirkin
2010-06-02 10:44 ` Michael S. Tsirkin
2010-05-30 12:59 ` Avi Kivity
2010-05-31 17:17 ` Alan Cox [this message]
2010-06-01 21:29 ` Tom Lyon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100531181735.6bb71a5c@lxorguk.ukuu.org.uk \
--to=alan@lxorguk.ukuu.org.uk \
--cc=aafabbri@cisco.com \
--cc=avi@redhat.com \
--cc=chrisw@sous-sol.org \
--cc=gregkh@suse.de \
--cc=hjk@linutronix.de \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=pugs@cisco.com \
--cc=scofeldm@cisco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®